Direct.vue 13 KB

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