DirectMessage.vue 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884
  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 == 400) {
  414. swal('Error', err.response.data.error, 'error');
  415. } else if(err.response.status == 403) {
  416. self.blocked = true;
  417. swal('Profile Unavailable', 'You cannot message this profile at this time.', 'error');
  418. }
  419. })
  420. this.replyText = '';
  421. },
  422. truncate(t) {
  423. return _.truncate(t);
  424. },
  425. deleteMessage(index) {
  426. let c = window.confirm('Are you sure you want to delete this message?');
  427. if(c) {
  428. axios.delete('/api/direct/message', {
  429. params: {
  430. id: this.thread.messages[index].reportId
  431. }
  432. }).then(res => {
  433. this.thread.messages.splice(index ,1);
  434. });
  435. }
  436. },
  437. reportMessage() {
  438. this.closeCtxMenu();
  439. let url = '/i/report?type=post&id=' + this.ctxContext.reportId;
  440. window.location.href = url;
  441. return;
  442. },
  443. uploadMedia(event) {
  444. let self = this;
  445. $(document).on('change', '#uploadMedia', function(e) {
  446. self.handleUpload();
  447. });
  448. let el = $(event.target);
  449. el.attr('disabled', '');
  450. $('#uploadMedia').click();
  451. el.blur();
  452. el.removeAttr('disabled');
  453. },
  454. handleUpload() {
  455. let self = this;
  456. if(self.uploading) {
  457. return;
  458. }
  459. self.uploading = true;
  460. let io = document.querySelector('#uploadMedia');
  461. if(!io.files.length) {
  462. this.uploading = false;
  463. }
  464. Array.prototype.forEach.call(io.files, function(io, i) {
  465. let type = io.type;
  466. let acceptedMimes = self.config.uploader.media_types.split(',');
  467. let validated = $.inArray(type, acceptedMimes);
  468. if(validated == -1) {
  469. 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');
  470. self.uploading = false;
  471. return;
  472. }
  473. let form = new FormData();
  474. form.append('file', io);
  475. form.append('to_id', self.threads[self.threadIndex].id);
  476. let xhrConfig = {
  477. onUploadProgress: function(e) {
  478. let progress = Math.round( (e.loaded * 100) / e.total );
  479. self.uploadProgress = progress;
  480. }
  481. };
  482. axios.post('/api/direct/media', form, xhrConfig)
  483. .then(function(e) {
  484. self.uploadProgress = 100;
  485. self.uploading = false;
  486. let msg = {
  487. id: e.data.id,
  488. type: e.data.type,
  489. reportId: e.data.reportId,
  490. isAuthor: true,
  491. text: null,
  492. media: e.data.url,
  493. timeAgo: '1s',
  494. seen: null
  495. };
  496. self.threads[self.threadIndex].messages.unshift(msg);
  497. // setTimeout(function() {
  498. // var objDiv = document.querySelector('.dm-wrapper');
  499. // objDiv.scrollTop = objDiv.scrollHeight;
  500. // }, 300);
  501. }).catch(function(e) {
  502. if(e.hasOwnProperty('response') && e.response.hasOwnProperty('status') ) {
  503. switch(e.response.status) {
  504. case 451:
  505. self.uploading = false;
  506. io.value = null;
  507. swal('Banned Content', 'This content has been banned and cannot be uploaded.', 'error');
  508. break;
  509. default:
  510. self.uploading = false;
  511. io.value = null;
  512. swal('Oops, something went wrong!', 'An unexpected error occurred.', 'error');
  513. break;
  514. }
  515. }
  516. });
  517. io.value = null;
  518. self.uploadProgress = 0;
  519. });
  520. },
  521. viewOriginal() {
  522. let url = this.ctxContext.media;
  523. window.location.href = url;
  524. return;
  525. },
  526. isEmoji(text) {
  527. const onlyEmojis = text.replace(new RegExp('[\u0000-\u1eeff]', 'g'), '')
  528. const visibleChars = text.replace(new RegExp('[\n\r\s]+|( )+', 'g'), '')
  529. return onlyEmojis.length === visibleChars.length
  530. },
  531. copyText() {
  532. window.App.util.clipboard(this.ctxContext.text);
  533. this.closeCtxMenu();
  534. return;
  535. },
  536. clickLink() {
  537. let url = this.ctxContext.text;
  538. if(this.ctxContext.meta.local != true) {
  539. url = '/i/redirect?url=' + encodeURI(this.ctxContext.text);
  540. }
  541. window.location.href = url;
  542. },
  543. markAsRead() {
  544. return;
  545. axios.post('/api/direct/read', {
  546. pid: this.accountId,
  547. sid: this.max_id
  548. }).then(res => {
  549. }).catch(err => {
  550. });
  551. },
  552. loadOlderMessages() {
  553. let self = this;
  554. this.loadingMessages = true;
  555. axios.get('/api/direct/thread', {
  556. params: {
  557. pid: this.accountId,
  558. max_id: this.min_id,
  559. }
  560. }).then(res => {
  561. let d = res.data;
  562. if(!d.messages.length) {
  563. this.showLoadMore = false;
  564. this.loadingMessages = false;
  565. return;
  566. }
  567. let cids = this.thread.messages.map(m => m.id);
  568. let m = d.messages.filter(m => {
  569. return cids.indexOf(m.id) == -1;
  570. }).reverse();
  571. let mids = m.map(m => m.id);
  572. let min_id = Math.min(...mids);
  573. if(min_id == this.min_id) {
  574. this.showLoadMore = false;
  575. this.loadingMessages = false;
  576. return;
  577. }
  578. this.min_id = min_id;
  579. this.thread.messages.push(...m);
  580. setTimeout(function() {
  581. self.loadingMessages = false;
  582. }, 500);
  583. }).catch(err => {
  584. this.loadingMessages = false;
  585. })
  586. },
  587. messagePoll() {
  588. let self = this;
  589. setInterval(function() {
  590. axios.get('/api/direct/thread', {
  591. params: {
  592. pid: self.accountId,
  593. min_id: self.thread.messages[self.thread.messages.length - 1].id
  594. }
  595. }).then(res => {
  596. });
  597. }, 5000);
  598. },
  599. showOptions() {
  600. this.page = 'options';
  601. },
  602. updateOptions() {
  603. let options = {
  604. v: 1,
  605. hideAvatars: this.hideAvatars,
  606. hideTimestamps: this.hideTimestamps,
  607. largerText: this.largerText
  608. }
  609. window.localStorage.setItem('px_dm_options', JSON.stringify(options));
  610. },
  611. formatCount(val) {
  612. return window.App.util.format.count(val);
  613. },
  614. goBack(page = false) {
  615. if(page) {
  616. this.page = page;
  617. } else {
  618. this.$router.push('/i/web/direct');
  619. }
  620. },
  621. gotoProfile(profile) {
  622. this.$router.push(`/i/web/profile/${profile.id}`);
  623. },
  624. togglePrivacyWarning() {
  625. console.log('clicked toggle privacy warning');
  626. let ls = window.localStorage;
  627. let key = 'pf_m2s.dmwarncounter';
  628. this.showPrivacyWarning = false;
  629. if(ls.getItem(key)) {
  630. let count = ls.getItem(key);
  631. count++;
  632. ls.setItem(key, count);
  633. if(count > 5) {
  634. this.showDMPrivacyWarning = false;
  635. }
  636. } else {
  637. ls.setItem(key, 1);
  638. }
  639. }
  640. }
  641. }
  642. </script>
  643. <style lang="scss" scoped>
  644. .dm-page-component {
  645. font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
  646. .user-card {
  647. align-items: center;
  648. .avatar {
  649. width: 60px;
  650. height: 60px;
  651. border-radius: 15px;
  652. margin-right: 0.8rem;
  653. border: 1px solid var(--border-color);
  654. }
  655. .avatar-update-btn {
  656. position: absolute;
  657. right: 12px;
  658. bottom: 0;
  659. width: 20px;
  660. height: 20px;
  661. background: rgba(255,255,255,0.9);
  662. border: 1px solid #dee2e6 !important;
  663. padding: 0;
  664. border-radius: 50rem;
  665. &-icon {
  666. font-family: 'Font Awesome 5 Free';
  667. font-weight: 400;
  668. -webkit-font-smoothing: antialiased;
  669. display: inline-block;
  670. font-style: normal;
  671. font-variant: normal;
  672. text-rendering: auto;
  673. line-height: 1;
  674. &:before {
  675. content: "\F013";
  676. }
  677. }
  678. }
  679. .username {
  680. font-weight: 600;
  681. font-size: 13px;
  682. margin-bottom: 0;
  683. cursor: pointer;
  684. }
  685. .display-name {
  686. color: var(--body-color);
  687. line-height: 0.8;
  688. font-size: 14px;
  689. font-weight: 800 !important;
  690. user-select: all;
  691. font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
  692. margin-bottom: 0;
  693. cursor: pointer;
  694. }
  695. .stats {
  696. margin-top: 0;
  697. margin-bottom: 0;
  698. font-size: 12px;
  699. user-select: none;
  700. .stats-following {
  701. margin-right: 0.8rem;
  702. }
  703. .following-count,
  704. .followers-count {
  705. font-weight: 800;
  706. }
  707. }
  708. }
  709. .dm-reply-form {
  710. display: flex;
  711. justify-content: space-between;
  712. background-color: var(--card-bg);
  713. padding: 1rem;
  714. .btn:focus,
  715. .btn.focus,
  716. input:focus,
  717. input.focus {
  718. outline: 0;
  719. box-shadow: none;
  720. }
  721. :disabled {
  722. opacity: 20% !important;
  723. }
  724. &-input-group {
  725. width: 100%;
  726. margin-right: 10px;
  727. position: relative;
  728. input {
  729. position: absolute;
  730. padding-right: 60px;
  731. background-color: var(--comment-bg);
  732. border-radius: 25px;
  733. border-color: var(--comment-bg) !important;
  734. font-size: 15px;
  735. color: var(--dark);
  736. }
  737. .upload-media-btn {
  738. position: absolute;
  739. right: 10px;
  740. top: 50%;
  741. transform: translateY(-50%);
  742. color: var(--text-lighter);
  743. }
  744. }
  745. &-submit-btn {
  746. width: 48px;
  747. height: 48px;
  748. border-radius: 24px;
  749. }
  750. }
  751. .dm-status-bar {
  752. font-size: 12px;
  753. font-weight: 600;
  754. color: var(--text-lighter);
  755. p {
  756. margin-bottom: 0;
  757. }
  758. }
  759. .dm-privacy-warning {
  760. p,
  761. .btn {
  762. color: #000;
  763. }
  764. .warning-text {
  765. text-align: left;
  766. @media (min-width: 992px) {
  767. text-align: center;
  768. }
  769. }
  770. }
  771. &-row {
  772. .dm-wrapper {
  773. padding-top: 100px;
  774. height: calc(100vh - 240px);
  775. @media (min-width: 500px) {
  776. min-height: 40vh;
  777. }
  778. @media (min-width: 700px) {
  779. height: 60vh;
  780. }
  781. }
  782. }
  783. }
  784. </style>