1
0

ContextMenu.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803
  1. <template>
  2. <div class="modal-stack">
  3. <b-modal ref="ctxModal"
  4. id="ctx-modal"
  5. hide-header
  6. hide-footer
  7. centered
  8. rounded
  9. size="sm"
  10. body-class="list-group-flush p-0 rounded">
  11. <div class="list-group text-center">
  12. <div
  13. v-if="status.visibility !== 'archived'"
  14. class="list-group-item rounded cursor-pointer font-weight-bold"
  15. @click="ctxMenuGoToPost()">
  16. {{ $t('menu.viewPost') }}
  17. </div>
  18. <div
  19. v-if="status.visibility !== 'archived'"
  20. class="list-group-item rounded cursor-pointer font-weight-bold"
  21. @click="ctxMenuGoToProfile()">
  22. {{ $t('menu.viewProfile') }}
  23. </div>
  24. <div
  25. v-if="status.visibility !== 'archived'"
  26. class="list-group-item rounded cursor-pointer font-weight-bold"
  27. @click="ctxMenuShare()">
  28. {{ $t('common.share') }}
  29. </div>
  30. <div
  31. v-if="status && profile && profile.is_admin == true && status.visibility !== 'archived'"
  32. class="list-group-item rounded cursor-pointer font-weight-bold"
  33. @click="ctxModMenuShow()">
  34. {{ $t('menu.moderationTools') }}
  35. </div>
  36. <div
  37. v-if="status && status.account.id != profile.id"
  38. class="list-group-item rounded cursor-pointer text-danger font-weight-bold"
  39. @click="ctxMenuReportPost()">
  40. {{ $t('menu.report') }}
  41. </div>
  42. <div
  43. v-if="status && profile.id == status.account.id && status.visibility !== 'archived'"
  44. class="list-group-item rounded cursor-pointer text-danger font-weight-bold"
  45. @click="archivePost(status)">
  46. {{ $t('menu.archive') }}
  47. </div>
  48. <div
  49. v-if="status && profile.id == status.account.id && status.visibility == 'archived'"
  50. class="list-group-item rounded cursor-pointer text-danger font-weight-bold"
  51. @click="unarchivePost(status)">
  52. {{ $t('menu.unarchive') }}
  53. </div>
  54. <div
  55. v-if="config.ab.pue && status && profile.id == status.account.id && status.visibility !== 'archived'"
  56. class="list-group-item rounded cursor-pointer text-danger font-weight-bold"
  57. @click="editPost(status)">
  58. Edit
  59. </div>
  60. <div
  61. v-if="status && (profile.is_admin || profile.id == status.account.id) && status.visibility !== 'archived'"
  62. class="list-group-item rounded cursor-pointer text-danger font-weight-bold"
  63. @click="deletePost(status)">
  64. <div v-if="isDeleting" class="spinner-border spinner-border-sm" role="status">
  65. <span class="sr-only">Loading...</span>
  66. </div>
  67. <div v-else>
  68. {{ $t('common.delete') }}
  69. </div>
  70. </div>
  71. <div
  72. class="list-group-item rounded cursor-pointer text-lighter font-weight-bold"
  73. @click="closeCtxMenu()">
  74. {{ $t('common.cancel') }}
  75. </div>
  76. </div>
  77. </b-modal>
  78. <b-modal ref="ctxModModal"
  79. id="ctx-mod-modal"
  80. hide-header
  81. hide-footer
  82. centered
  83. rounded
  84. size="sm"
  85. body-class="list-group-flush p-0 rounded">
  86. <div class="list-group text-center">
  87. <p class="py-2 px-3 mb-0">
  88. <div
  89. class="text-center font-weight-bold text-danger">
  90. {{ $t('menu.moderationTools') }}
  91. </div>
  92. <div class="small text-center text-muted">
  93. {{ $t('menu.selectOneOption') }}
  94. </div>
  95. </p>
  96. <div
  97. class="list-group-item rounded cursor-pointer"
  98. @click="moderatePost(status, 'unlist')">
  99. {{ $t('menu.unlistFromTimelines') }}
  100. </div>
  101. <div
  102. v-if="status.sensitive"
  103. class="list-group-item rounded cursor-pointer"
  104. @click="moderatePost(status, 'remcw')">
  105. {{ $t('menu.removeCW') }}
  106. </div>
  107. <div
  108. v-else
  109. class="list-group-item rounded cursor-pointer"
  110. @click="moderatePost(status, 'addcw')">
  111. {{ $t('menu.addCW') }}
  112. </div>
  113. <div
  114. class="list-group-item rounded cursor-pointer"
  115. @click="moderatePost(status, 'spammer')">
  116. {{ $t('menu.markAsSpammer') }}<br />
  117. <span class="small">{{ $t('menu.markAsSpammerText') }}</span>
  118. </div>
  119. <div
  120. class="list-group-item rounded cursor-pointer text-lighter"
  121. @click="ctxModMenuClose()">
  122. {{ $t('common.cancel') }}
  123. </div>
  124. </div>
  125. </b-modal>
  126. <b-modal ref="ctxModOtherModal"
  127. id="ctx-mod-other-modal"
  128. hide-header
  129. hide-footer
  130. centered
  131. rounded
  132. size="sm"
  133. body-class="list-group-flush p-0 rounded">
  134. <div class="list-group text-center">
  135. <p class="py-2 px-3 mb-0">
  136. <div class="text-center font-weight-bold text-danger">{{ $t('menu.moderationTools') }}</div>
  137. <div class="small text-center text-muted">{{ $t('menu.selectOneOption') }}</div>
  138. </p>
  139. <div class="list-group-item rounded cursor-pointer font-weight-bold" @click="confirmModal()">Unlist Posts</div>
  140. <div class="list-group-item rounded cursor-pointer font-weight-bold" @click="confirmModal()">Moderation Log</div>
  141. <div class="list-group-item rounded cursor-pointer text-lighter" @click="ctxModOtherMenuClose()">{{ $t('common.cancel') }}</div>
  142. </div>
  143. </b-modal>
  144. <b-modal ref="ctxShareModal"
  145. id="ctx-share-modal"
  146. title="Share"
  147. hide-footer
  148. hide-header
  149. centered
  150. rounded
  151. size="sm"
  152. body-class="list-group-flush p-0 rounded text-center">
  153. <div class="list-group-item rounded cursor-pointer" @click="shareStatus(status, $event)">{{status.reblogged ? 'Unshare' : 'Share'}} {{ $t('menu.toFollowers') }}</div>
  154. <div class="list-group-item rounded cursor-pointer" @click="ctxMenuCopyLink()">{{ $t('common.copyLink') }}</div>
  155. <div v-if="status && status.local == true && !status.in_reply_to_id" class="list-group-item rounded cursor-pointer" @click="ctxMenuEmbed()">{{ $t('menu.embed') }}</div>
  156. <div class="list-group-item rounded cursor-pointer text-lighter" @click="closeCtxShareMenu()">{{ $t('common.cancel') }}</div>
  157. </b-modal>
  158. <b-modal ref="ctxEmbedModal"
  159. id="ctx-embed-modal"
  160. hide-header
  161. hide-footer
  162. centered
  163. rounded
  164. size="md"
  165. body-class="p-2 rounded">
  166. <div>
  167. <div class="form-group">
  168. <textarea class="form-control disabled text-monospace" rows="8" style="overflow-y:hidden;border: 1px solid #efefef; font-size: 12px; line-height: 18px; margin: 0 0 7px;resize:none;" v-model="ctxEmbedPayload" disabled=""></textarea>
  169. </div>
  170. <div class="form-group pl-2 d-flex justify-content-center">
  171. <div class="form-check mr-3">
  172. <input class="form-check-input" type="checkbox" v-model="ctxEmbedShowCaption" :disabled="ctxEmbedCompactMode == true">
  173. <label class="form-check-label font-weight-light">
  174. {{ $t('menu.showCaption') }}
  175. </label>
  176. </div>
  177. <div class="form-check mr-3">
  178. <input class="form-check-input" type="checkbox" v-model="ctxEmbedShowLikes" :disabled="ctxEmbedCompactMode == true">
  179. <label class="form-check-label font-weight-light">
  180. {{ $t('menu.showLikes') }}
  181. </label>
  182. </div>
  183. <div class="form-check">
  184. <input class="form-check-input" type="checkbox" v-model="ctxEmbedCompactMode">
  185. <label class="form-check-label font-weight-light">
  186. {{ $t('menu.compactMode') }}
  187. </label>
  188. </div>
  189. </div>
  190. <hr>
  191. <button :class="copiedEmbed ? 'btn btn-primary btn-block btn-sm py-1 font-weight-bold disabed': 'btn btn-primary btn-block btn-sm py-1 font-weight-bold'" @click="ctxCopyEmbed" :disabled="copiedEmbed">{{copiedEmbed ? 'Embed Code Copied!' : 'Copy Embed Code'}}</button>
  192. <p class="mb-0 px-2 small text-muted">{{ $t('menu.embedConfirmText') }} <a href="/site/terms">{{ $t('site.terms') }}</a></p>
  193. </div>
  194. </b-modal>
  195. <b-modal ref="ctxReport"
  196. id="ctx-report"
  197. hide-header
  198. hide-footer
  199. centered
  200. rounded
  201. size="sm"
  202. body-class="list-group-flush p-0 rounded">
  203. <p class="py-2 px-3 mb-0">
  204. <div class="text-center font-weight-bold text-danger">{{ $t('menu.report') }}</div>
  205. <div class="small text-center text-muted">{{ $t('menu.selectOneOption') }}</div>
  206. </p>
  207. <div class="list-group text-center">
  208. <div class="list-group-item rounded cursor-pointer font-weight-bold" @click="sendReport('spam')">{{ $t('menu.spam') }}</div>
  209. <div class="list-group-item rounded cursor-pointer font-weight-bold" @click="sendReport('sensitive')">{{ $t('menu.sensitive') }}</div>
  210. <div class="list-group-item rounded cursor-pointer font-weight-bold" @click="sendReport('abusive')">{{ $t('menu.abusive') }}</div>
  211. <div class="list-group-item rounded cursor-pointer font-weight-bold" @click="openCtxReportOtherMenu()">{{ $t('common.other') }}</div>
  212. <!-- <div class="list-group-item rounded cursor-pointer" @click="ctxReportMenuGoBack()">Go Back</div> -->
  213. <div class="list-group-item rounded cursor-pointer text-lighter" @click="ctxReportMenuGoBack()">{{ $t('common.cancel') }}</div>
  214. </div>
  215. </b-modal>
  216. <b-modal ref="ctxReportOther"
  217. id="ctx-report-other"
  218. hide-header
  219. hide-footer
  220. centered
  221. rounded
  222. size="sm"
  223. body-class="list-group-flush p-0 rounded">
  224. <p class="py-2 px-3 mb-0">
  225. <div class="text-center font-weight-bold text-danger">{{ $t('menu.report') }}</div>
  226. <div class="small text-center text-muted">{{ $t('menu.selectOneOption') }}</div>
  227. </p>
  228. <div class="list-group text-center">
  229. <div class="list-group-item rounded cursor-pointer font-weight-bold" @click="sendReport('underage')">{{ $t('menu.underageAccount') }}</div>
  230. <div class="list-group-item rounded cursor-pointer font-weight-bold" @click="sendReport('copyright')">{{ $t('menu.copyrightInfringement') }}</div>
  231. <div class="list-group-item rounded cursor-pointer font-weight-bold" @click="sendReport('impersonation')">{{ $t('menu.impersonation') }}</div>
  232. <div class="list-group-item rounded cursor-pointer font-weight-bold" @click="sendReport('scam')">{{ $t('menu.scamOrFraud') }}</div>
  233. <div class="list-group-item rounded cursor-pointer text-lighter" @click="ctxReportOtherMenuGoBack()">{{ $t('common.cancel') }}</div>
  234. </div>
  235. </b-modal>
  236. <b-modal ref="ctxConfirm"
  237. id="ctx-confirm"
  238. hide-header
  239. hide-footer
  240. centered
  241. rounded
  242. size="sm"
  243. body-class="list-group-flush p-0 rounded">
  244. <div class="d-flex align-items-center justify-content-center py-3">
  245. <div>{{ this.confirmModalTitle }}</div>
  246. </div>
  247. <div class="d-flex border-top btn-group btn-group-block rounded-0" role="group">
  248. <button type="button" class="btn btn-outline-lighter border-left-0 border-top-0 border-bottom-0 border-right py-2" style="color: rgb(0,122,255) !important;" @click.prevent="confirmModalCancel()">{{ $t('common.cancel') }}</button>
  249. <button type="button" class="btn btn-outline-lighter border-0" style="color: rgb(0,122,255) !important;" @click.prevent="confirmModalConfirm()">Confirm</button>
  250. </div>
  251. </b-modal>
  252. </div>
  253. </template>
  254. <script type="text/javascript">
  255. export default {
  256. props: [
  257. 'status',
  258. 'profile'
  259. ],
  260. data() {
  261. return {
  262. config: window.App.config,
  263. ctxMenuStatus: false,
  264. ctxMenuRelationship: false,
  265. ctxEmbedPayload: false,
  266. copiedEmbed: false,
  267. replySending: false,
  268. ctxEmbedShowCaption: true,
  269. ctxEmbedShowLikes: false,
  270. ctxEmbedCompactMode: false,
  271. confirmModalTitle: 'Are you sure?',
  272. confirmModalIdentifer: null,
  273. confirmModalType: false,
  274. isDeleting: false
  275. }
  276. },
  277. watch: {
  278. ctxEmbedShowCaption: function (n,o) {
  279. if(n == true) {
  280. this.ctxEmbedCompactMode = false;
  281. }
  282. let mode = this.ctxEmbedCompactMode ? 'compact' : 'full';
  283. this.ctxEmbedPayload = window.App.util.embed.post(this.ctxMenuStatus.url, this.ctxEmbedShowCaption, this.ctxEmbedShowLikes, mode);
  284. },
  285. ctxEmbedShowLikes: function (n,o) {
  286. if(n == true) {
  287. this.ctxEmbedCompactMode = false;
  288. }
  289. let mode = this.ctxEmbedCompactMode ? 'compact' : 'full';
  290. this.ctxEmbedPayload = window.App.util.embed.post(this.ctxMenuStatus.url, this.ctxEmbedShowCaption, this.ctxEmbedShowLikes, mode);
  291. },
  292. ctxEmbedCompactMode: function (n,o) {
  293. if(n == true) {
  294. this.ctxEmbedShowCaption = false;
  295. this.ctxEmbedShowLikes = false;
  296. }
  297. let mode = this.ctxEmbedCompactMode ? 'compact' : 'full';
  298. this.ctxEmbedPayload = window.App.util.embed.post(this.ctxMenuStatus.url, this.ctxEmbedShowCaption, this.ctxEmbedShowLikes, mode);
  299. }
  300. },
  301. methods: {
  302. open() {
  303. this.ctxMenu();
  304. },
  305. openModMenu() {
  306. this.$refs.ctxModModal.show();
  307. },
  308. ctxMenu() {
  309. this.ctxMenuStatus = this.status;
  310. this.ctxEmbedPayload = window.App.util.embed.post(this.status.url);
  311. // if(this.status.account.id == this.profile.id) {
  312. this.ctxMenuRelationship = false;
  313. this.$refs.ctxModal.show();
  314. // } else {
  315. // axios.get('/api/pixelfed/v1/accounts/relationships', {
  316. // params: {
  317. // 'id[]': this.status.account.id
  318. // }
  319. // }).then(res => {
  320. // this.ctxMenuRelationship = res.data[0];
  321. // this.$refs.ctxModal.show();
  322. // });
  323. // }
  324. },
  325. closeCtxMenu() {
  326. this.copiedEmbed = false;
  327. this.ctxMenuStatus = false;
  328. this.ctxMenuRelationship = false;
  329. this.$refs.ctxModal.hide();
  330. this.$refs.ctxReport.hide();
  331. this.$refs.ctxReportOther.hide();
  332. this.closeModals();
  333. },
  334. ctxMenuCopyLink() {
  335. let status = this.ctxMenuStatus;
  336. navigator.clipboard.writeText(status.url);
  337. this.closeModals();
  338. return;
  339. },
  340. ctxMenuGoToPost() {
  341. let status = this.ctxMenuStatus;
  342. this.statusUrl(status);
  343. this.closeCtxMenu();
  344. return;
  345. },
  346. ctxMenuGoToProfile() {
  347. let status = this.ctxMenuStatus;
  348. this.profileUrl(status);
  349. this.closeCtxMenu();
  350. return;
  351. },
  352. ctxMenuReportPost() {
  353. this.$refs.ctxModal.hide();
  354. // this.$refs.ctxReport.show();
  355. this.$emit('report-modal', this.ctxMenuStatus);
  356. return;
  357. },
  358. ctxMenuEmbed() {
  359. this.closeModals();
  360. this.$refs.ctxEmbedModal.show();
  361. },
  362. ctxMenuShare() {
  363. this.$refs.ctxModal.hide();
  364. this.$refs.ctxShareModal.show();
  365. },
  366. closeCtxShareMenu() {
  367. this.$refs.ctxShareModal.hide();
  368. this.$refs.ctxModal.show();
  369. },
  370. ctxCopyEmbed() {
  371. navigator.clipboard.writeText(this.ctxEmbedPayload);
  372. this.ctxEmbedShowCaption = true;
  373. this.ctxEmbedShowLikes = false;
  374. this.ctxEmbedCompactMode = false;
  375. this.$refs.ctxEmbedModal.hide();
  376. },
  377. ctxModMenuShow() {
  378. this.$refs.ctxModal.hide();
  379. this.$refs.ctxModModal.show();
  380. },
  381. ctxModOtherMenuShow() {
  382. this.$refs.ctxModal.hide();
  383. this.$refs.ctxModModal.hide();
  384. this.$refs.ctxModOtherModal.show();
  385. },
  386. ctxModMenu() {
  387. this.$refs.ctxModal.hide();
  388. },
  389. ctxModMenuClose() {
  390. this.closeModals();
  391. },
  392. ctxModOtherMenuClose() {
  393. this.closeModals();
  394. this.$refs.ctxModModal.show();
  395. },
  396. formatCount(count) {
  397. return App.util.format.count(count);
  398. },
  399. openCtxReportOtherMenu() {
  400. let s = this.ctxMenuStatus;
  401. this.closeCtxMenu();
  402. this.ctxMenuStatus = s;
  403. this.$refs.ctxReportOther.show();
  404. },
  405. ctxReportMenuGoBack() {
  406. this.$refs.ctxReportOther.hide();
  407. this.$refs.ctxReport.hide();
  408. this.$refs.ctxModal.show();
  409. },
  410. ctxReportOtherMenuGoBack() {
  411. this.$refs.ctxReportOther.hide();
  412. this.$refs.ctxModal.hide();
  413. this.$refs.ctxReport.show();
  414. },
  415. sendReport(type) {
  416. let id = this.ctxMenuStatus.id;
  417. swal({
  418. 'title': this.$t('menu.confirmReport'),
  419. 'text': this.$t('menu.confirmReportText'),
  420. 'icon': 'warning',
  421. 'buttons': true,
  422. 'dangerMode': true
  423. }).then((res) => {
  424. if(res) {
  425. axios.post('/i/report/', {
  426. 'report': type,
  427. 'type': 'post',
  428. 'id': id,
  429. }).then(res => {
  430. this.closeCtxMenu();
  431. swal(this.$t('menu.reportSent'), this.$t('menu.reportSentText'), 'success');
  432. }).catch(err => {
  433. swal(this.$t('common.oops'), this.$t('menu.reportSentError'), 'error');
  434. })
  435. } else {
  436. this.closeCtxMenu();
  437. }
  438. });
  439. },
  440. closeModals() {
  441. this.$refs.ctxModal.hide();
  442. this.$refs.ctxModModal.hide();
  443. this.$refs.ctxModOtherModal.hide();
  444. this.$refs.ctxShareModal.hide();
  445. this.$refs.ctxEmbedModal.hide();
  446. this.$refs.ctxReport.hide();
  447. this.$refs.ctxReportOther.hide();
  448. this.$refs.ctxConfirm.hide();
  449. },
  450. openCtxStatusModal() {
  451. this.closeModals();
  452. this.$refs.ctxStatusModal.show();
  453. },
  454. openConfirmModal() {
  455. this.closeModals();
  456. this.$refs.ctxConfirm.show();
  457. },
  458. closeConfirmModal() {
  459. this.closeModals();
  460. this.confirmModalTitle = 'Are you sure?';
  461. this.confirmModalType = false;
  462. this.confirmModalIdentifer = null;
  463. },
  464. confirmModalConfirm() {
  465. switch(this.confirmModalType) {
  466. case 'post.delete':
  467. axios.post('/i/delete', {
  468. type: 'status',
  469. item: this.confirmModalIdentifer
  470. }).then(res => {
  471. this.feed = this.feed.filter(s => {
  472. return s.id != this.confirmModalIdentifer;
  473. });
  474. this.closeConfirmModal();
  475. }).catch(err => {
  476. this.closeConfirmModal();
  477. swal(this.$t('common.error'), this.$t('common.errorMsg'), 'error');
  478. });
  479. break;
  480. }
  481. this.closeConfirmModal();
  482. },
  483. confirmModalCancel() {
  484. this.closeConfirmModal();
  485. },
  486. moderatePost(status, action, $event) {
  487. let username = status.account.username;
  488. let pid = status.id;
  489. let msg = '';
  490. let self = this;
  491. switch(action) {
  492. case 'addcw':
  493. msg = this.$t('menu.modAddCWConfirm');
  494. swal({
  495. title: 'Confirm',
  496. text: msg,
  497. icon: 'warning',
  498. buttons: true,
  499. dangerMode: true
  500. }).then(res => {
  501. if(res) {
  502. axios.post('/api/v2/moderator/action', {
  503. action: action,
  504. item_id: status.id,
  505. item_type: 'status'
  506. }).then(res => {
  507. swal(this.$t('common.success'), this.$t('menu.modCWSuccess'), 'success');
  508. // status.sensitive = true;
  509. this.$emit('moderate', 'addcw');
  510. self.closeModals();
  511. self.ctxModMenuClose();
  512. }).catch(err => {
  513. self.closeModals();
  514. self.ctxModMenuClose();
  515. swal(this.$t('common.error'), this.$t('common.errorMsg'), 'error');
  516. });
  517. }
  518. });
  519. break;
  520. case 'remcw':
  521. msg = this.$t('menu.modRemoveCWConfirm');
  522. swal({
  523. title: 'Confirm',
  524. text: msg,
  525. icon: 'warning',
  526. buttons: true,
  527. dangerMode: true
  528. }).then(res => {
  529. if(res) {
  530. axios.post('/api/v2/moderator/action', {
  531. action: action,
  532. item_id: status.id,
  533. item_type: 'status'
  534. }).then(res => {
  535. swal(this.$t('common.success'), this.$t('menu.modRemoveCWSuccess'), 'success');
  536. // status.sensitive = false;
  537. this.$emit('moderate', 'remcw');
  538. self.closeModals();
  539. self.ctxModMenuClose();
  540. }).catch(err => {
  541. self.closeModals();
  542. self.ctxModMenuClose();
  543. swal(this.$t('common.error'), this.$t('common.errorMsg'), 'error');
  544. });
  545. }
  546. });
  547. break;
  548. case 'unlist':
  549. msg = this.$t('menu.modUnlistConfirm');
  550. swal({
  551. title: 'Confirm',
  552. text: msg,
  553. icon: 'warning',
  554. buttons: true,
  555. dangerMode: true
  556. }).then(res => {
  557. if(res) {
  558. axios.post('/api/v2/moderator/action', {
  559. action: action,
  560. item_id: status.id,
  561. item_type: 'status'
  562. }).then(res => {
  563. // this.feed = this.feed.filter(f => {
  564. // return f.id != status.id;
  565. // });
  566. this.$emit('moderate', 'unlist');
  567. swal(this.$t('common.success'), this.$t('menu.modUnlistSuccess'), 'success');
  568. self.closeModals();
  569. self.ctxModMenuClose();
  570. }).catch(err => {
  571. self.closeModals();
  572. self.ctxModMenuClose();
  573. swal(this.$t('common.error'), this.$t('common.errorMsg'), 'error');
  574. });
  575. }
  576. });
  577. break;
  578. case 'spammer':
  579. msg = this.$t('menu.modMarkAsSpammerConfirm');
  580. swal({
  581. title: 'Confirm',
  582. text: msg,
  583. icon: 'warning',
  584. buttons: true,
  585. dangerMode: true
  586. }).then(res => {
  587. if(res) {
  588. axios.post('/api/v2/moderator/action', {
  589. action: action,
  590. item_id: status.id,
  591. item_type: 'status'
  592. }).then(res => {
  593. this.$emit('moderate', 'spammer');
  594. swal(this.$t('common.success'), this.$t('menu.modMarkAsSpammerSuccess'), 'success');
  595. self.closeModals();
  596. self.ctxModMenuClose();
  597. }).catch(err => {
  598. self.closeModals();
  599. self.ctxModMenuClose();
  600. swal(this.$t('common.error'), this.$t('common.errorMsg'), 'error');
  601. });
  602. }
  603. });
  604. break;
  605. }
  606. },
  607. shareStatus(status, $event) {
  608. if($('body').hasClass('loggedIn') == false) {
  609. return;
  610. }
  611. this.closeModals();
  612. axios.post('/i/share', {
  613. item: status.id
  614. }).then(res => {
  615. status.reblogs_count = res.data.count;
  616. status.reblogged = !status.reblogged;
  617. // if(status.reblogged) {
  618. // swal('Success', 'You shared this post', 'success');
  619. // } else {
  620. // swal('Success', 'You unshared this post', 'success');
  621. // }
  622. }).catch(err => {
  623. swal(this.$t('common.error'), this.$t('common.errorMsg'), 'error');
  624. });
  625. },
  626. statusUrl(status) {
  627. if(status.account.local == true) {
  628. this.$router.push({
  629. name: 'post',
  630. path: `/i/web/post/${status.id}`,
  631. params: {
  632. id: status.id,
  633. cachedStatus: status,
  634. cachedProfile: this.profile
  635. }
  636. });
  637. return;
  638. }
  639. let permalink = this.$route.params.hasOwnProperty('id');
  640. if(permalink) {
  641. location.href = status.url;
  642. return;
  643. } else {
  644. this.$router.push({
  645. name: 'post',
  646. path: `/i/web/post/${status.id}`,
  647. params: {
  648. id: status.id,
  649. cachedStatus: status,
  650. cachedProfile: this.profile
  651. }
  652. });
  653. return;
  654. }
  655. },
  656. profileUrl(status) {
  657. this.$router.push({
  658. name: 'profile',
  659. path: `/i/web/profile/${status.account.id}`,
  660. params: {
  661. id: status.account.id,
  662. cachedProfile: status.account,
  663. cachedUser: this.profile
  664. }
  665. });
  666. return;
  667. },
  668. deletePost(status) {
  669. this.isDeleting = true;
  670. if(this.ownerOrAdmin(status) == false) {
  671. return;
  672. }
  673. if(window.confirm(this.$t('menu.deletePostConfirm')) == false) {
  674. return;
  675. }
  676. axios.post('/i/delete', {
  677. type: 'status',
  678. item: status.id
  679. }).then(res => {
  680. this.$emit('delete');
  681. this.closeModals();
  682. this.isDeleting = false;
  683. }).catch(err => {
  684. swal(this.$t('common.error'), this.$t('common.errorMsg'), 'error');
  685. });
  686. },
  687. owner(status) {
  688. return this.profile.id === status.account.id;
  689. },
  690. admin() {
  691. return this.profile.is_admin == true;
  692. },
  693. ownerOrAdmin(status) {
  694. return this.owner(status) || this.admin();
  695. },
  696. archivePost(status) {
  697. if(window.confirm(this.$t('menu.archivePostConfirm')) == false) {
  698. return;
  699. }
  700. axios.post('/api/pixelfed/v2/status/' + status.id + '/archive')
  701. .then(res => {
  702. this.$emit('status-delete', status.id);
  703. this.$emit('archived', status.id);
  704. this.closeModals();
  705. });
  706. },
  707. unarchivePost(status) {
  708. if(window.confirm(this.$t('menu.unarchivePostConfirm')) == false) {
  709. return;
  710. }
  711. axios.post('/api/pixelfed/v2/status/' + status.id + '/unarchive')
  712. .then(res => {
  713. this.$emit('unarchived', status.id);
  714. this.closeModals();
  715. });
  716. },
  717. editPost(status) {
  718. this.closeModals();
  719. this.$emit('edit', status);
  720. }
  721. }
  722. }
  723. </script>