DirectMessage.vue 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  1. <template>
  2. <div class="dm-page-component">
  3. <div v-if="isLoaded" class="container-fluid mt-lg-3 pb-lg-5">
  4. <div class="row dm-page-component-row">
  5. <div class="col-md-3 d-md-block">
  6. <sidebar :user="profile" />
  7. </div>
  8. <div class="col-md-6 p-0">
  9. <div v-if="loaded && page == 'read'" class="messages-page">
  10. <div class="card shadow-none">
  11. <div class="h4 card-header font-weight-bold text-dark d-flex justify-content-between align-items-center" style="letter-spacing: -0.3px;">
  12. <button class="btn btn-light rounded-pill text-dark" @click="goBack()">
  13. <i class="far fa-chevron-left fa-lg"></i>
  14. </button>
  15. <div>Direct Message</div>
  16. <button class="btn btn-light rounded-pill text-dark" @click="showOptions()">
  17. <i class="far fa-cog fa-lg"></i>
  18. </button>
  19. </div>
  20. <ul class="list-group list-group-flush" style="position:relative;">
  21. <li class="list-group-item border-bottom sticky-top">
  22. <p class="text-center small text-muted mb-0">
  23. Conversation with <span class="font-weight-bold">{{thread.username}}</span>
  24. </p>
  25. </li>
  26. </ul>
  27. <transition name="fade">
  28. <ul v-if="showDMPrivacyWarning && showPrivacyWarning" class="list-group list-group-flush dm-privacy-warning" style="position:absolute;top:105px;width:100%;">
  29. <li class="list-group-item border-bottom sticky-top bg-warning">
  30. <div class="d-flex align-items-center justify-content-between">
  31. <div class="d-none d-lg-block">
  32. <i class="fas fa-exclamation-triangle text-danger fa-lg mr-3"></i>
  33. </div>
  34. <div>
  35. <p class="small warning-text mb-0 font-weight-bold"><span class="d-inline d-lg-none">DMs</span><span class="d-none d-lg-inline">Direct messages on Pixelfed</span> are not end-to-end encrypted.
  36. </p>
  37. <p class="small warning-text mb-0 font-weight-bold">
  38. Use caution when sharing sensitive data.
  39. </p>
  40. </div>
  41. <button class="btn btn-link text-decoration-none" @click="togglePrivacyWarning">
  42. <i class="far fa-times-circle fa-lg"></i>
  43. <span class="d-none d-lg-block">Close</span>
  44. </button>
  45. </div>
  46. </li>
  47. </ul>
  48. </transition>
  49. <ul class="list-group list-group-flush dm-wrapper" style="overflow-y: scroll;position:relative;flex-direction: column-reverse;">
  50. <li v-for="(convo, index) in thread.messages" class="list-group-item border-0 chat-msg mb-n2">
  51. <message
  52. :convo="convo"
  53. :thread="thread"
  54. :hideAvatars="hideAvatars"
  55. :hideTimestamps="hideTimestamps"
  56. :largerText="largerText"
  57. v-on:confirm-delete="deleteMessage(index)" />
  58. </li>
  59. <li v-if="showLoadMore && thread.messages && thread.messages.length > 5" class="list-group-item border-0">
  60. <p class="text-center small text-muted">
  61. <button v-if="!loadingMessages" class="btn btn-primary font-weight-bold rounded-pill btn-sm px-3" @click="loadOlderMessages()">Load Older Messages</button>
  62. <button v-else class="btn btn-primary font-weight-bold rounded-pill btn-sm px-3" disabled>Loading...</button>
  63. </p>
  64. </li>
  65. </ul>
  66. <div class="card-footer bg-white p-0">
  67. <!-- <form class="border-0 rounded-0 align-middle" method="post" action="#">
  68. <textarea class="form-control border-0 rounded-0 no-focus" name="comment" placeholder="Reply ..." autocomplete="off" autocorrect="off" style="height:86px;line-height: 18px;max-height:80px;resize: none; padding-right:115.22px;" v-model="replyText" :disabled="blocked"></textarea>
  69. <input type="button" value="Send" :class="[replyText.length ? 'd-inline-block btn btn-sm btn-primary rounded-pill font-weight-bold reply-btn text-decoration-none text-uppercase' : 'd-inline-block btn btn-sm btn-primary rounded-pill font-weight-bold reply-btn text-decoration-none text-uppercase disabled']" :disabled="replyText.length == 0" @click.prevent="sendMessage"/>
  70. </form> -->
  71. <div class="dm-reply-form">
  72. <div class="dm-reply-form-input-group">
  73. <input
  74. class="form-control form-control-lg"
  75. placeholder="Type a message..."
  76. :disabled="uploading"
  77. v-model="replyText">
  78. <button
  79. class="upload-media-btn btn btn-link"
  80. :disabled="uploading"
  81. @click="uploadMedia">
  82. <i class="far fa-image fa-2x"></i>
  83. </button>
  84. </div>
  85. <button
  86. class="dm-reply-form-submit-btn btn btn-primary"
  87. :disabled="!replyText || !replyText.length || showReplyTooLong"
  88. @click="sendMessage">
  89. <i class="far fa-paper-plane fa-lg"></i>
  90. </button>
  91. </div>
  92. </div>
  93. <div v-if="uploading" class="card-footer dm-status-bar">
  94. <p>Uploading ({{uploadProgress}}%) ...</p>
  95. </div>
  96. <div v-if="showReplyLong" class="card-footer dm-status-bar">
  97. <p class="text-warning">{{ replyText.length }}/500</p>
  98. </div>
  99. <div v-if="showReplyTooLong" class="card-footer dm-status-bar">
  100. <p class="text-danger">{{ replyText.length }}/500 - Your message exceeds the limit of 500 characters</p>
  101. </div>
  102. <div class="d-none card-footer p-0">
  103. <p class="d-flex justify-content-between align-items-center mb-0 px-3 py-1 small">
  104. <!-- <span class="font-weight-bold" style="color: #D69E2E">
  105. <i class="fas fa-circle mr-1"></i>
  106. Typing ...
  107. </span> -->
  108. <span>
  109. <!-- <span class="btn btn-primary btn-sm font-weight-bold py-0 px-3 rounded-pill" @click="uploadMedia">
  110. <i class="fas fa-share mr-1"></i>
  111. Share
  112. </span> -->
  113. <span class="btn btn-primary btn-sm font-weight-bold py-0 px-3 rounded-pill" @click="uploadMedia">
  114. <i class="fas fa-upload mr-1"></i>
  115. Add Photo/Video
  116. </span>
  117. </span>
  118. <input type="file" id="uploadMedia" class="d-none" name="uploadMedia" accept="image/jpeg,image/png,image/gif,video/mp4" >
  119. <span class="text-muted font-weight-bold">{{replyText.length}}/500</span>
  120. </p>
  121. </div>
  122. </div>
  123. </div>
  124. <div v-if="loaded && page == 'options'" class="messages-page">
  125. <div class="card shadow-none">
  126. <div class="h4 card-header font-weight-bold text-dark d-flex justify-content-between align-items-center" style="letter-spacing: -0.3px;">
  127. <button class="btn btn-light rounded-pill text-dark" @click.prevent="goBack('read')">
  128. <i class="far fa-chevron-left fa-lg"></i>
  129. </button>
  130. <div>Direct Message Settings</div>
  131. <div class="btn btn-light rounded-pill text-dark">
  132. <i class="far fa-smile fa-lg"></i>
  133. </div>
  134. </div>
  135. <ul class="list-group list-group-flush" style="height: 698px;">
  136. <div class="list-group-item media border-bottom">
  137. <div class="d-inline-block custom-control custom-switch ml-3">
  138. <input type="checkbox" class="custom-control-input" id="customSwitch0" v-model="hideAvatars">
  139. <label class="custom-control-label" for="customSwitch0"></label>
  140. </div>
  141. <div class="d-inline-block ml-3 font-weight-bold">
  142. Hide Avatars
  143. </div>
  144. </div>
  145. <div class="list-group-item media border-bottom">
  146. <div class="d-inline-block custom-control custom-switch ml-3">
  147. <input type="checkbox" class="custom-control-input" id="customSwitch1" v-model="hideTimestamps">
  148. <label class="custom-control-label" for="customSwitch1"></label>
  149. </div>
  150. <div class="d-inline-block ml-3 font-weight-bold">
  151. Hide Timestamps
  152. </div>
  153. </div>
  154. <div class="list-group-item media border-bottom">
  155. <div class="d-inline-block custom-control custom-switch ml-3">
  156. <input type="checkbox" class="custom-control-input" id="customSwitch2" v-model="largerText">
  157. <label class="custom-control-label" for="customSwitch2"></label>
  158. </div>
  159. <div class="d-inline-block ml-3 font-weight-bold">
  160. Larger Text
  161. </div>
  162. </div>
  163. <!-- <div class="list-group-item media border-bottom">
  164. <div class="d-inline-block custom-control custom-switch ml-3">
  165. <input type="checkbox" class="custom-control-input" id="customSwitch3" v-model="autoRefresh">
  166. <label class="custom-control-label" for="customSwitch3"></label>
  167. </div>
  168. <div class="d-inline-block ml-3 font-weight-bold">
  169. Auto Refresh
  170. </div>
  171. </div> -->
  172. <div class="list-group-item media border-bottom d-flex align-items-center">
  173. <div class="d-inline-block custom-control custom-switch ml-3">
  174. <input type="checkbox" class="custom-control-input" id="customSwitch4" v-model="mutedNotifications">
  175. <label class="custom-control-label" for="customSwitch4"></label>
  176. </div>
  177. <div class="d-inline-block ml-3 font-weight-bold">
  178. Mute Notifications
  179. <p class="small mb-0">You will not receive any direct message notifications from <strong>{{thread.username}}</strong>.</p>
  180. </div>
  181. </div>
  182. <div class="list-group-item media border-bottom d-flex align-items-center">
  183. <div class="d-inline-block custom-control custom-switch ml-3">
  184. <input type="checkbox" class="custom-control-input" id="customSwitch5" v-model="showDMPrivacyWarning">
  185. <label class="custom-control-label" for="customSwitch5"></label>
  186. </div>
  187. <div class="d-inline-block ml-3 font-weight-bold">
  188. Show Privacy Warning
  189. <p class="small mb-0">Show privacy warning indicating that direct messages are not end-to-end encrypted and that caution is advised when sending sensitive/confidential information.</p>
  190. </div>
  191. </div>
  192. </ul>
  193. </div>
  194. </div>
  195. </div>
  196. <div v-if="conversationProfile" class="col-md-3 d-none d-md-block">
  197. <div class="card shadow-sm mb-3" style="border-radius: 15px;">
  198. <div class="small card-header font-weight-bold text-uppercase text-lighter" style="letter-spacing: -0.3px;">
  199. Conversation
  200. </div>
  201. <div class="card-body p-2">
  202. <div class="media user-card user-select-none">
  203. <div>
  204. <img :src="conversationProfile.avatar" class="avatar shadow cursor-pointer" draggable="false" onerror="this.onerror=null;this.src='/storage/avatars/default.png?v=0';">
  205. </div>
  206. <div class="media-body">
  207. <p
  208. class="display-name"
  209. v-html="conversationProfile.display_name"
  210. @click="gotoProfile(conversationProfile)"
  211. >
  212. </p>
  213. <p
  214. class="username primary"
  215. @click="gotoProfile(conversationProfile)">
  216. &commat;{{ conversationProfile.acct }}
  217. </p>
  218. <p class="stats">
  219. <span class="stats-following">
  220. <span class="following-count">{{ formatCount(conversationProfile.following_count) }}</span> Following
  221. </span>
  222. <span class="stats-followers">
  223. <span class="followers-count">{{ formatCount(conversationProfile.followers_count) }}</span> Followers
  224. </span>
  225. </p>
  226. </div>
  227. </div>
  228. </div>
  229. </div>
  230. <!-- <div class="card shadow-sm mb-3" style="border-radius: 15px;">
  231. <div class="small card-header font-weight-bold text-uppercase text-lighter" style="border-top-left-radius: 15px;letter-spacing: -0.3px;">
  232. History
  233. </div>
  234. </div> -->
  235. <!-- <div class="list-group shadow-sm">
  236. <div class="list-group-item border-0 border-bottom" style="border-width: 1px;">
  237. <p class="mb-0"><i class="far fa-user-plus mr-2"></i> You both follow each other</p>
  238. </div>
  239. <div class="list-group-item border-0">
  240. <p class="mb-0"><i class="far fa-users mr-2"></i> You both follow <a class="font-weight-bold">&commat;pixelfed</a>,<a class="font-weight-bold">&commat;pixeldev</a> and <a class="font-weight-bold">&commat;pixel</a></p>
  241. </div>
  242. </div> -->
  243. </div>
  244. </div>
  245. </div>
  246. <div v-else class="d-flex justify-content-center align-items-center" style="height:calc(100vh - 58px);">
  247. <b-spinner />
  248. </div>
  249. </div>
  250. </template>
  251. <script type="text/javascript">
  252. import Drawer from './partials/drawer.vue';
  253. import Sidebar from './partials/sidebar.vue';
  254. import Placeholder from './partials/placeholders/DirectMessagePlaceholder.vue';
  255. import Intersect from 'vue-intersect'
  256. import ProfileCard from './partials/profile/ProfileHoverCard.vue';
  257. import Message from './partials/direct/Message.vue';
  258. export default {
  259. props: ['accountId'],
  260. components: {
  261. "drawer": Drawer,
  262. "sidebar": Sidebar,
  263. "intersect": Intersect,
  264. "dm-placeholder": Placeholder,
  265. "profile-card": ProfileCard,
  266. "message": Message
  267. },
  268. data() {
  269. return {
  270. isLoaded: false,
  271. profile: undefined,
  272. conversationProfile: undefined,
  273. isIntersecting: false,
  274. config: window.App.config,
  275. hideAvatars: true,
  276. hideTimestamps: false,
  277. largerText: false,
  278. autoRefresh: false,
  279. mutedNotifications: false,
  280. blocked: false,
  281. loaded: false,
  282. page: 'read',
  283. pages: ['browse', 'add', 'read'],
  284. threads: [],
  285. thread: false,
  286. threadIndex: false,
  287. replyText: '',
  288. composeUsername: '',
  289. uploading: false,
  290. uploadProgress: null,
  291. min_id: null,
  292. max_id: null,
  293. loadingMessages: false,
  294. showLoadMore: true,
  295. showReplyLong: false,
  296. showReplyTooLong: false,
  297. showPrivacyWarning: true,
  298. }
  299. },
  300. mounted() {
  301. this.profile = window._sharedData.user;
  302. this.isLoaded = true;
  303. let self = this;
  304. axios.get('/api/v1/accounts/' + this.accountId)
  305. .then(res => {
  306. this.conversationProfile = res.data;
  307. });
  308. axios.get('/api/direct/thread', {
  309. params: {
  310. pid: self.accountId
  311. }
  312. })
  313. .then(res => {
  314. self.loaded = true;
  315. let d = res.data;
  316. this.thread = d;
  317. this.threads = [d];
  318. this.threadIndex = 0;
  319. let mids = d.messages.map(m => m.id);
  320. this.max_id = Math.max(...mids);
  321. this.min_id = Math.min(...mids);
  322. this.mutedNotifications = d.muted;
  323. this.markAsRead();
  324. //this.messagePoll();
  325. // setTimeout(function() {
  326. // let objDiv = document.querySelector('.dm-wrapper');
  327. // objDiv.scrollTop = objDiv.scrollHeight;
  328. // }, 300);
  329. });
  330. let options = localStorage.getItem('px_dm_options');
  331. if(options) {
  332. options = JSON.parse(options);
  333. this.hideAvatars = options.hideAvatars;
  334. this.hideTimestamps = options.hideTimestamps;
  335. this.largerText = options.largerText;
  336. }
  337. },
  338. computed: {
  339. showDMPrivacyWarning: {
  340. get() {
  341. return this.$store.state.showDMPrivacyWarning;
  342. },
  343. set(val) {
  344. window.localStorage.removeItem('pf_m2s.dmwarncounter');
  345. this.$store.commit('setShowDMPrivacyWarning', val);
  346. }
  347. },
  348. },
  349. watch: {
  350. mutedNotifications: function(v) {
  351. if(v) {
  352. axios.post('/api/direct/mute', {
  353. id: this.accountId
  354. }).then(res => {
  355. });
  356. } else {
  357. axios.post('/api/direct/unmute', {
  358. id: this.accountId
  359. }).then(res => {
  360. });
  361. }
  362. this.mutedNotifications = v;
  363. },
  364. hideAvatars: function(v) {
  365. this.hideAvatars = v;
  366. this.updateOptions();
  367. },
  368. hideTimestamps: function(v) {
  369. this.hideTimestamps = v;
  370. this.updateOptions();
  371. },
  372. largerText: function(v) {
  373. this.largerText = v;
  374. this.updateOptions();
  375. },
  376. replyText: function(v) {
  377. let limit = 500;
  378. if(v.length < limit) {
  379. this.showReplyLong = false;
  380. this.showReplyTooLong = false;
  381. }
  382. if(v.length > limit) {
  383. this.showReplyLong = false;
  384. this.showReplyTooLong = true;
  385. return;
  386. }
  387. if(v.length > (limit - 50)) {
  388. this.showReplyTooLong = false;
  389. this.showReplyLong = true;
  390. return;
  391. }
  392. }
  393. },
  394. methods: {
  395. sendMessage() {
  396. let self = this;
  397. let rt = this.replyText;
  398. axios.post('/api/direct/create', {
  399. 'to_id': this.threads[this.threadIndex].id,
  400. 'message': rt,
  401. 'type': self.isEmoji(rt) && rt.length < 10 ? 'emoji' : 'text'
  402. }).then(res => {
  403. let msg = res.data;
  404. self.threads[self.threadIndex].messages.unshift(msg);
  405. let mids = self.threads[self.threadIndex].messages.map(m => m.id);
  406. this.max_id = Math.max(...mids)
  407. this.min_id = Math.min(...mids)
  408. // setTimeout(function() {
  409. // var objDiv = document.querySelector('.dm-wrapper');
  410. // objDiv.scrollTop = objDiv.scrollHeight;
  411. // }, 300);
  412. }).catch(err => {
  413. if(err.response.status == 403) {
  414. self.blocked = true;
  415. swal('Profile Unavailable', 'You cannot message this profile at this time.', 'error');
  416. }
  417. })
  418. this.replyText = '';
  419. },
  420. truncate(t) {
  421. return _.truncate(t);
  422. },
  423. deleteMessage(index) {
  424. let c = window.confirm('Are you sure you want to delete this message?');
  425. if(c) {
  426. axios.delete('/api/direct/message', {
  427. params: {
  428. id: this.thread.messages[index].reportId
  429. }
  430. }).then(res => {
  431. this.thread.messages.splice(index ,1);
  432. });
  433. }
  434. },
  435. reportMessage() {
  436. this.closeCtxMenu();
  437. let url = '/i/report?type=post&id=' + this.ctxContext.reportId;
  438. window.location.href = url;
  439. return;
  440. },
  441. uploadMedia(event) {
  442. let self = this;
  443. $(document).on('change', '#uploadMedia', function(e) {
  444. self.handleUpload();
  445. });
  446. let el = $(event.target);
  447. el.attr('disabled', '');
  448. $('#uploadMedia').click();
  449. el.blur();
  450. el.removeAttr('disabled');
  451. },
  452. handleUpload() {
  453. let self = this;
  454. if(self.uploading) {
  455. return;
  456. }
  457. self.uploading = true;
  458. let io = document.querySelector('#uploadMedia');
  459. if(!io.files.length) {
  460. this.uploading = false;
  461. }
  462. Array.prototype.forEach.call(io.files, function(io, i) {
  463. let type = io.type;
  464. let acceptedMimes = self.config.uploader.media_types.split(',');
  465. let validated = $.inArray(type, acceptedMimes);
  466. if(validated == -1) {
  467. swal('Invalid File Type', 'The file you are trying to add is not a valid mime type. Please upload a '+self.config.uploader.media_types+' only.', 'error');
  468. self.uploading = false;
  469. return;
  470. }
  471. let form = new FormData();
  472. form.append('file', io);
  473. form.append('to_id', self.threads[self.threadIndex].id);
  474. let xhrConfig = {
  475. onUploadProgress: function(e) {
  476. let progress = Math.round( (e.loaded * 100) / e.total );
  477. self.uploadProgress = progress;
  478. }
  479. };
  480. axios.post('/api/direct/media', form, xhrConfig)
  481. .then(function(e) {
  482. self.uploadProgress = 100;
  483. self.uploading = false;
  484. let msg = {
  485. id: e.data.id,
  486. type: e.data.type,
  487. reportId: e.data.reportId,
  488. isAuthor: true,
  489. text: null,
  490. media: e.data.url,
  491. timeAgo: '1s',
  492. seen: null
  493. };
  494. self.threads[self.threadIndex].messages.unshift(msg);
  495. // setTimeout(function() {
  496. // var objDiv = document.querySelector('.dm-wrapper');
  497. // objDiv.scrollTop = objDiv.scrollHeight;
  498. // }, 300);
  499. }).catch(function(e) {
  500. if(e.hasOwnProperty('response') && e.response.hasOwnProperty('status') ) {
  501. switch(e.response.status) {
  502. case 451:
  503. self.uploading = false;
  504. io.value = null;
  505. swal('Banned Content', 'This content has been banned and cannot be uploaded.', 'error');
  506. break;
  507. default:
  508. self.uploading = false;
  509. io.value = null;
  510. swal('Oops, something went wrong!', 'An unexpected error occurred.', 'error');
  511. break;
  512. }
  513. }
  514. });
  515. io.value = null;
  516. self.uploadProgress = 0;
  517. });
  518. },
  519. viewOriginal() {
  520. let url = this.ctxContext.media;
  521. window.location.href = url;
  522. return;
  523. },
  524. isEmoji(text) {
  525. const onlyEmojis = text.replace(new RegExp('[\u0000-\u1eeff]', 'g'), '')
  526. const visibleChars = text.replace(new RegExp('[\n\r\s]+|( )+', 'g'), '')
  527. return onlyEmojis.length === visibleChars.length
  528. },
  529. copyText() {
  530. window.App.util.clipboard(this.ctxContext.text);
  531. this.closeCtxMenu();
  532. return;
  533. },
  534. clickLink() {
  535. let url = this.ctxContext.text;
  536. if(this.ctxContext.meta.local != true) {
  537. url = '/i/redirect?url=' + encodeURI(this.ctxContext.text);
  538. }
  539. window.location.href = url;
  540. },
  541. markAsRead() {
  542. return;
  543. axios.post('/api/direct/read', {
  544. pid: this.accountId,
  545. sid: this.max_id
  546. }).then(res => {
  547. }).catch(err => {
  548. });
  549. },
  550. loadOlderMessages() {
  551. let self = this;
  552. this.loadingMessages = true;
  553. axios.get('/api/direct/thread', {
  554. params: {
  555. pid: this.accountId,
  556. max_id: this.min_id,
  557. }
  558. }).then(res => {
  559. let d = res.data;
  560. if(!d.messages.length) {
  561. this.showLoadMore = false;
  562. this.loadingMessages = false;
  563. return;
  564. }
  565. let cids = this.thread.messages.map(m => m.id);
  566. let m = d.messages.filter(m => {
  567. return cids.indexOf(m.id) == -1;
  568. }).reverse();
  569. let mids = m.map(m => m.id);
  570. let min_id = Math.min(...mids);
  571. if(min_id == this.min_id) {
  572. this.showLoadMore = false;
  573. this.loadingMessages = false;
  574. return;
  575. }
  576. this.min_id = min_id;
  577. this.thread.messages.push(...m);
  578. setTimeout(function() {
  579. self.loadingMessages = false;
  580. }, 500);
  581. }).catch(err => {
  582. this.loadingMessages = false;
  583. })
  584. },
  585. messagePoll() {
  586. let self = this;
  587. setInterval(function() {
  588. axios.get('/api/direct/thread', {
  589. params: {
  590. pid: self.accountId,
  591. min_id: self.thread.messages[self.thread.messages.length - 1].id
  592. }
  593. }).then(res => {
  594. });
  595. }, 5000);
  596. },
  597. showOptions() {
  598. this.page = 'options';
  599. },
  600. updateOptions() {
  601. let options = {
  602. v: 1,
  603. hideAvatars: this.hideAvatars,
  604. hideTimestamps: this.hideTimestamps,
  605. largerText: this.largerText
  606. }
  607. window.localStorage.setItem('px_dm_options', JSON.stringify(options));
  608. },
  609. formatCount(val) {
  610. return window.App.util.format.count(val);
  611. },
  612. goBack(page = false) {
  613. if(page) {
  614. this.page = page;
  615. } else {
  616. this.$router.push('/i/web/direct');
  617. }
  618. },
  619. gotoProfile(profile) {
  620. this.$router.push(`/i/web/profile/${profile.id}`);
  621. },
  622. togglePrivacyWarning() {
  623. console.log('clicked toggle privacy warning');
  624. let ls = window.localStorage;
  625. let key = 'pf_m2s.dmwarncounter';
  626. this.showPrivacyWarning = false;
  627. if(ls.getItem(key)) {
  628. let count = ls.getItem(key);
  629. count++;
  630. ls.setItem(key, count);
  631. if(count > 5) {
  632. this.showDMPrivacyWarning = false;
  633. }
  634. } else {
  635. ls.setItem(key, 1);
  636. }
  637. }
  638. }
  639. }
  640. </script>
  641. <style lang="scss" scoped>
  642. .dm-page-component {
  643. font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
  644. .user-card {
  645. align-items: center;
  646. .avatar {
  647. width: 60px;
  648. height: 60px;
  649. border-radius: 15px;
  650. margin-right: 0.8rem;
  651. border: 1px solid var(--border-color);
  652. }
  653. .avatar-update-btn {
  654. position: absolute;
  655. right: 12px;
  656. bottom: 0;
  657. width: 20px;
  658. height: 20px;
  659. background: rgba(255,255,255,0.9);
  660. border: 1px solid #dee2e6 !important;
  661. padding: 0;
  662. border-radius: 50rem;
  663. &-icon {
  664. font-family: 'Font Awesome 5 Free';
  665. font-weight: 400;
  666. -webkit-font-smoothing: antialiased;
  667. display: inline-block;
  668. font-style: normal;
  669. font-variant: normal;
  670. text-rendering: auto;
  671. line-height: 1;
  672. &:before {
  673. content: "\F013";
  674. }
  675. }
  676. }
  677. .username {
  678. font-weight: 600;
  679. font-size: 13px;
  680. margin-bottom: 0;
  681. cursor: pointer;
  682. }
  683. .display-name {
  684. color: var(--body-color);
  685. line-height: 0.8;
  686. font-size: 14px;
  687. font-weight: 800 !important;
  688. user-select: all;
  689. font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
  690. margin-bottom: 0;
  691. cursor: pointer;
  692. }
  693. .stats {
  694. margin-top: 0;
  695. margin-bottom: 0;
  696. font-size: 12px;
  697. user-select: none;
  698. .stats-following {
  699. margin-right: 0.8rem;
  700. }
  701. .following-count,
  702. .followers-count {
  703. font-weight: 800;
  704. }
  705. }
  706. }
  707. .dm-reply-form {
  708. display: flex;
  709. justify-content: space-between;
  710. background-color: var(--card-bg);
  711. padding: 1rem;
  712. .btn:focus,
  713. .btn.focus,
  714. input:focus,
  715. input.focus {
  716. outline: 0;
  717. box-shadow: none;
  718. }
  719. :disabled {
  720. opacity: 20% !important;
  721. }
  722. &-input-group {
  723. width: 100%;
  724. margin-right: 10px;
  725. position: relative;
  726. input {
  727. position: absolute;
  728. padding-right: 60px;
  729. background-color: var(--comment-bg);
  730. border-radius: 25px;
  731. border-color: var(--comment-bg) !important;
  732. font-size: 15px;
  733. color: var(--dark);
  734. }
  735. .upload-media-btn {
  736. position: absolute;
  737. right: 10px;
  738. top: 50%;
  739. transform: translateY(-50%);
  740. color: var(--text-lighter);
  741. }
  742. }
  743. &-submit-btn {
  744. width: 48px;
  745. height: 48px;
  746. border-radius: 24px;
  747. }
  748. }
  749. .dm-status-bar {
  750. font-size: 12px;
  751. font-weight: 600;
  752. color: var(--text-lighter);
  753. p {
  754. margin-bottom: 0;
  755. }
  756. }
  757. .dm-privacy-warning {
  758. p,
  759. .btn {
  760. color: #000;
  761. }
  762. .warning-text {
  763. text-align: left;
  764. @media (min-width: 992px) {
  765. text-align: center;
  766. }
  767. }
  768. }
  769. &-row {
  770. .dm-wrapper {
  771. padding-top: 100px;
  772. height: calc(100vh - 240px);
  773. @media (min-width: 500px) {
  774. min-height: 40vh;
  775. }
  776. @media (min-width: 700px) {
  777. height: 60vh;
  778. }
  779. }
  780. }
  781. }
  782. </style>