Direct.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. <template>
  2. <div>
  3. <div v-if="loaded && page == 'browse'" class="container messages-page p-0 p-md-2 mt-n4" style="min-height: 50vh;">
  4. <div class="col-12 col-md-8 offset-md-2 p-0 px-md-2">
  5. <div class="card shadow-none border mt-4">
  6. <div class="card-header bg-white py-4">
  7. <span class="h4 font-weight-bold mb-0">Direct Messages</span>
  8. <span class="float-right">
  9. <a class="btn btn-outline-primary font-weight-bold py-0 rounded-pill" href="#" @click.prevent="goto('add')">New Message</a>
  10. </span>
  11. </div>
  12. <div class="card-header bg-white">
  13. <ul class="nav nav-pills nav-fill">
  14. <li class="nav-item">
  15. <a :class="[tab == 'inbox' ? 'nav-link px-4 font-weight-bold rounded-pill active' : 'nav-link px-4 font-weight-bold rounded-pill']" @click.prevent="switchTab('inbox')" href="#">Inbox</a>
  16. </li>
  17. <li class="nav-item">
  18. <a :class="[tab == 'sent' ? 'nav-link px-4 font-weight-bold rounded-pill active' : 'nav-link px-4 font-weight-bold rounded-pill']" @click.prevent="switchTab('sent')" href="#">Sent</a>
  19. </li>
  20. <li class="nav-item">
  21. <a :class="[tab == 'filtered' ? 'nav-link px-4 font-weight-bold rounded-pill active' : 'nav-link px-4 font-weight-bold rounded-pill']" @click.prevent="switchTab('filtered')" href="#">Filtered</a>
  22. </li>
  23. </ul>
  24. </div>
  25. <ul v-if="tab == 'inbox'" class="list-group list-group-flush">
  26. <div v-if="!messages.inbox.length" class="list-group-item d-flex justify-content-center align-items-center" style="min-height: 40vh;">
  27. <p class="lead mb-0">No messages found :(</p>
  28. </div>
  29. <div v-else v-for="(thread, index) in messages.inbox" :key="'dm_inbox'+index">
  30. <a class="list-group-item text-dark text-decoration-none border-left-0 border-right-0 border-top-0" :href="'/account/direct/t/'+thread.id">
  31. <div class="media d-flex align-items-center">
  32. <img class="mr-3 rounded-circle img-thumbnail" :src="thread.avatar" width="32" onerror="this.onerror=null;this.src='/storage/avatars/default.jpg';" v-once>
  33. <div class="media-body">
  34. <p class="mb-0">
  35. <span class="font-weight-bold text-truncate">
  36. {{thread.name}}
  37. </span>
  38. <span class="pl-1 text-muted small text-truncate" style="font-weight: 500;">
  39. {{thread.isLocal ? '@' + thread.username : thread.username}}
  40. </span>
  41. </p>
  42. <p class="text-muted mb-0" style="font-size:13px;font-weight: 500;">
  43. <span>
  44. <i class="far fa-comment text-primary"></i>
  45. </span>
  46. <span class="pl-1 pr-3">
  47. Received
  48. </span>
  49. <span>
  50. {{thread.timeAgo}}
  51. </span>
  52. </p>
  53. </div>
  54. <span class="float-right">
  55. <i class="fas fa-chevron-right fa-lg text-lighter"></i>
  56. </span>
  57. </div>
  58. </a>
  59. </div>
  60. </ul>
  61. <ul v-if="tab == 'sent'" class="list-group list-group-flush">
  62. <div v-if="!messages.sent.length" class="list-group-item d-flex justify-content-center align-items-center" style="min-height: 40vh;">
  63. <p class="lead mb-0">No messages found :(</p>
  64. </div>
  65. <div v-else v-for="(thread, index) in messages.sent" :key="'dm_sent'+index">
  66. <a class="list-group-item text-dark text-decoration-none border-left-0 border-right-0 border-top-0" href="#" @click.prevent="loadMessage(thread.id)">
  67. <div class="media d-flex align-items-center">
  68. <img class="mr-3 rounded-circle img-thumbnail" :src="thread.avatar" width="32" onerror="this.onerror=null;this.src='/storage/avatars/default.jpg';" v-once>
  69. <div class="media-body">
  70. <p class="mb-0">
  71. <span class="font-weight-bold text-truncate">
  72. {{thread.name}}
  73. </span>
  74. <span class="pl-1 text-muted small text-truncate" style="font-weight: 500;">
  75. {{thread.isLocal ? '@' + thread.username : thread.username}}
  76. </span>
  77. </p>
  78. <p class="text-muted mb-0" style="font-size:13px;font-weight: 500;">
  79. <span>
  80. <i class="far fa-paper-plane text-primary"></i>
  81. </span>
  82. <span class="pl-1 pr-3">
  83. Delivered
  84. </span>
  85. <span>
  86. {{thread.timeAgo}}
  87. </span>
  88. </p>
  89. </div>
  90. <span class="float-right">
  91. <i class="fas fa-chevron-right fa-lg text-lighter"></i>
  92. </span>
  93. </div>
  94. </a>
  95. </div>
  96. </ul>
  97. <ul v-if="tab == 'filtered'" class="list-group list-group-flush">
  98. <div v-if="!messages.filtered.length" class="list-group-item d-flex justify-content-center align-items-center" style="min-height: 40vh;">
  99. <p class="lead mb-0">No messages found :(</p>
  100. </div>
  101. <div v-else v-for="(thread, index) in messages.filtered" :key="'dm_filtered'+index">
  102. <a class="list-group-item text-dark text-decoration-none border-left-0 border-right-0 border-top-0" href="#" @click.prevent="loadMessage(thread.id)">
  103. <div class="media d-flex align-items-center">
  104. <img class="mr-3 rounded-circle img-thumbnail" :src="thread.avatar" width="32" onerror="this.onerror=null;this.src='/storage/avatars/default.jpg';" v-once>
  105. <div class="media-body">
  106. <p class="mb-0">
  107. <span class="font-weight-bold text-truncate">
  108. {{thread.name}}
  109. </span>
  110. <span class="pl-1 text-muted small text-truncate" style="font-weight: 500;">
  111. {{thread.isLocal ? '@' + thread.username : thread.username}}
  112. </span>
  113. </p>
  114. <p class="text-muted mb-0" style="font-size:13px;font-weight: 500;">
  115. <span>
  116. <i class="fas fa-shield-alt" style="color:#fd9426"></i>
  117. </span>
  118. <span class="pl-1 pr-3">
  119. Filtered
  120. </span>
  121. <span>
  122. {{thread.timeAgo}}
  123. </span>
  124. </p>
  125. </div>
  126. <span class="float-right">
  127. <i class="fas fa-chevron-right fa-lg text-lighter"></i>
  128. </span>
  129. </div>
  130. </a>
  131. </div>
  132. </ul>
  133. </div>
  134. <div v-if="tab == 'inbox'" class="mt-3 text-center">
  135. <button class="btn btn-outline-primary rounded-pill btn-sm" :disabled="inboxPage == 1" @click="messagePagination('inbox', 'prev')">Prev</button>
  136. <button class="btn btn-outline-primary rounded-pill btn-sm" :disabled="messages.inbox.length != 8" @click="messagePagination('inbox', 'next')">Next</button>
  137. </div>
  138. <div v-if="tab == 'sent'" class="mt-3 text-center">
  139. <button class="btn btn-outline-primary rounded-pill btn-sm" :disabled="sentPage == 1" @click="messagePagination('sent', 'prev')">Prev</button>
  140. <button class="btn btn-outline-primary rounded-pill btn-sm" :disabled="messages.sent.length != 8" @click="messagePagination('sent', 'next')">Next</button>
  141. </div>
  142. <div v-if="tab == 'filtered'" class="mt-3 text-center">
  143. <button class="btn btn-outline-primary rounded-pill btn-sm" :disabled="filteredPage == 1" @click="messagePagination('filtered', 'prev')">Prev</button>
  144. <button class="btn btn-outline-primary rounded-pill btn-sm" :disabled="messages.filtered.length != 8" @click="messagePagination('filtered', 'next')">Next</button>
  145. </div>
  146. </div>
  147. </div>
  148. <div v-if="loaded && page == 'add'" class="container messages-page p-0 p-md-2 mt-n4" style="min-height: 60vh;">
  149. <div class="col-12 col-md-8 offset-md-2 p-0 px-md-2">
  150. <div class="card shadow-none border mt-4">
  151. <div class="card-header bg-white py-4 d-flex justify-content-between">
  152. <span class="cursor-pointer px-3" @click="goto('browse')"><i class="fas fa-chevron-left"></i></span>
  153. <span class="h4 font-weight-bold mb-0">New Direct Message</span>
  154. <span><i class="fas fa-chevron-right text-white"></i></span>
  155. </div>
  156. <div class="card-body d-flex align-items-center justify-content-center" style="height: 60vh;">
  157. <div>
  158. <p class="mb-0 font-weight-bold">Select Recipient</p>
  159. <autocomplete
  160. :search="composeSearch"
  161. :disabled="composeLoading"
  162. placeholder="@dansup"
  163. aria-label="Search usernames"
  164. :get-result-value="getTagResultValue"
  165. @submit="onTagSubmitLocation"
  166. ref="autocomplete"
  167. >
  168. </autocomplete>
  169. <div style="width:300px;"></div>
  170. </div>
  171. </div>
  172. </div>
  173. </div>
  174. </div>
  175. </div>
  176. </template>
  177. <style type="text/css" scoped>
  178. </style>
  179. <script type="text/javascript">
  180. import Autocomplete from '@trevoreyre/autocomplete-vue'
  181. import '@trevoreyre/autocomplete-vue/dist/style.css'
  182. export default {
  183. components: {
  184. Autocomplete
  185. },
  186. data() {
  187. return {
  188. config: window.App.config,
  189. loaded: false,
  190. profile: {},
  191. page: 'browse',
  192. pages: ['browse', 'add', 'read'],
  193. tab: 'inbox',
  194. tabs: ['inbox', 'sent', 'filtered'],
  195. inboxPage: 1,
  196. sentPage: 1,
  197. filteredPage: 1,
  198. threads: [],
  199. thread: false,
  200. threadIndex: false,
  201. replyText: '',
  202. composeUsername: '',
  203. ctxContext: null,
  204. ctxIndex: null,
  205. uploading: false,
  206. uploadProgress: null,
  207. messages: {
  208. inbox: [],
  209. sent: [],
  210. filtered: []
  211. },
  212. newType: 'select',
  213. composeLoading: false,
  214. }
  215. },
  216. mounted() {
  217. this.fetchProfile();
  218. let self = this;
  219. axios.get('/api/direct/browse', {
  220. params: {
  221. a: 'inbox'
  222. }
  223. })
  224. .then(res => {
  225. self.loaded = true;
  226. this.threads = res.data
  227. this.messages.inbox = res.data;
  228. });
  229. },
  230. updated() {
  231. $('[data-toggle="tooltip"]').tooltip();
  232. },
  233. methods: {
  234. fetchProfile() {
  235. axios.get('/api/pixelfed/v1/accounts/verify_credentials').then(res => {
  236. this.profile = res.data;
  237. window._sharedData.curUser = res.data;
  238. window.App.util.navatar();
  239. });
  240. },
  241. goto(l = 'browse') {
  242. this.page = l;
  243. },
  244. loadMessage(id) {
  245. let url = '/account/direct/t/' + id;
  246. window.location.href = url;
  247. return;
  248. },
  249. truncate(t) {
  250. return _.truncate(t);
  251. },
  252. switchTab(tab) {
  253. let self = this;
  254. switch(tab) {
  255. case 'inbox':
  256. if(this.messages.inbox.length == 0) {
  257. // fetch
  258. }
  259. break;
  260. case 'sent':
  261. if(this.messages.sent.length == 0) {
  262. axios.get('/api/direct/browse', {
  263. params: {
  264. a: 'sent'
  265. }
  266. })
  267. .then(res => {
  268. self.loaded = true;
  269. self.threads = res.data
  270. self.messages.sent = res.data;
  271. });
  272. }
  273. break;
  274. case 'filtered':
  275. if(this.messages.filtered.length == 0) {
  276. axios.get('/api/direct/browse', {
  277. params: {
  278. a: 'filtered'
  279. }
  280. })
  281. .then(res => {
  282. self.loaded = true;
  283. self.threads = res.data
  284. self.messages.filtered = res.data;
  285. });
  286. }
  287. break;
  288. }
  289. this.tab = tab;
  290. },
  291. composeSearch(input) {
  292. if (input.length < 1) { return []; };
  293. let self = this;
  294. let results = [];
  295. return axios.post('/api/direct/lookup', {
  296. q: input
  297. }).then(res => {
  298. return res.data;
  299. });
  300. },
  301. getTagResultValue(result) {
  302. // return '@' + result.name;
  303. return result.local ? '@' + result.name : result.name;
  304. },
  305. onTagSubmitLocation(result) {
  306. //this.$refs.autocomplete.value = '';
  307. this.composeLoading = true;
  308. window.location.href = '/account/direct/t/' + result.id;
  309. return;
  310. },
  311. messagePagination(tab, dir) {
  312. if(tab == 'inbox') {
  313. this.inboxPage = dir == 'prev' ? this.inboxPage - 1 : this.inboxPage + 1;
  314. axios.get('/api/direct/browse', {
  315. params: {
  316. a: 'inbox',
  317. page: this.inboxPage
  318. }
  319. })
  320. .then(res => {
  321. self.loaded = true;
  322. this.threads = res.data
  323. this.messages.inbox = res.data;
  324. });
  325. }
  326. if(tab == 'sent') {
  327. this.sentPage = dir == 'prev' ? this.sentPage - 1 : this.sentPage + 1;
  328. axios.get('/api/direct/browse', {
  329. params: {
  330. a: 'sent',
  331. page: this.sentPage
  332. }
  333. })
  334. .then(res => {
  335. self.loaded = true;
  336. this.threads = res.data
  337. this.messages.sent = res.data;
  338. });
  339. }
  340. if(tab == 'filtered') {
  341. this.filteredPage = dir == 'prev' ? this.filteredPage - 1 : this.filteredPage + 1;
  342. axios.get('/api/direct/browse', {
  343. params: {
  344. a: 'filtered',
  345. page: this.filteredPage
  346. }
  347. })
  348. .then(res => {
  349. self.loaded = true;
  350. this.threads = res.data
  351. this.messages.filtered = res.data;
  352. });
  353. }
  354. }
  355. }
  356. }
  357. </script>