ContextMenu.vue 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087
  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 v-if="status.visibility !== 'archived'" class="list-group-item d-flex p-0 m-0">
  13. <div class="border-right p-2 w-50">
  14. <a
  15. v-if="status"
  16. class="menu-option"
  17. :href="status.url"
  18. @click.prevent="ctxMenuGoToPost()">
  19. <div class="action-icon-link">
  20. <div class="icon"><i class="fal fa-images fa-lg"></i></div>
  21. <p class="mb-0">{{ $t('menu.viewPost') }}</p>
  22. </div>
  23. </a>
  24. </div>
  25. <div class="p-2 flex-grow-1">
  26. <a
  27. v-if="status"
  28. class="menu-option"
  29. :href="status.account.url"
  30. @click.prevent="ctxMenuGoToProfile()">
  31. <div class="action-icon-link">
  32. <div class="icon"><i class="fal fa-user fa-lg"></i></div>
  33. <p class="mb-0">{{ $t('menu.viewProfile') }}</p>
  34. </div>
  35. </a>
  36. </div>
  37. </div>
  38. <template v-if="ctxMenuRelationship">
  39. <a
  40. v-if="ctxMenuRelationship.following"
  41. class="list-group-item menu-option text-danger"
  42. href="#"
  43. @click.prevent="handleUnfollow">
  44. {{ $t('profile.unfollow') }}
  45. </a>
  46. <div v-else class="d-flex">
  47. <div class="p-3 border-right w-50 text-center">
  48. <a
  49. class="small menu-option text-muted"
  50. href="#"
  51. @click.prevent="handleMute">
  52. <div class="action-icon-link-inline">
  53. <div class="icon"><i class="far" :class="[ ctxMenuRelationship.muting ? 'fa-eye' : 'fa-eye-slash' ]"></i></div>
  54. <p class="text-muted mb-0">{{ ctxMenuRelationship.muting ? 'Unmute' : 'Mute' }}</p>
  55. </div>
  56. </a>
  57. </div>
  58. <div class="p-3 w-50">
  59. <a
  60. class="small menu-option text-danger"
  61. href="#"
  62. @click.prevent="handleBlock">
  63. <div class="action-icon-link-inline">
  64. <div class="icon"><i class="far fa-shield-alt"></i></div>
  65. <p class="text-danger mb-0">Block</p>
  66. </div>
  67. </a>
  68. </div>
  69. </div>
  70. </template>
  71. <a
  72. v-if="status.visibility !== 'archived'"
  73. class="list-group-item menu-option"
  74. href="#"
  75. @click.prevent="ctxMenuShare()">
  76. {{ $t('common.share') }}
  77. </a>
  78. <a
  79. v-if="status && profile && profile.is_admin == true && status.visibility !== 'archived'"
  80. class="list-group-item menu-option"
  81. href="#"
  82. @click.prevent="ctxModMenuShow()">
  83. {{ $t('menu.moderationTools') }}
  84. </a>
  85. <a
  86. v-if="status && status.account.id != profile.id"
  87. class="list-group-item menu-option text-danger"
  88. href="#"
  89. @click.prevent="ctxMenuReportPost()">
  90. {{ $t('menu.report') }}
  91. </a>
  92. <a
  93. v-if="status && profile.id == status.account.id && status.visibility !== 'archived'"
  94. class="list-group-item menu-option text-danger"
  95. href="#"
  96. @click.prevent="archivePost(status)">
  97. {{ $t('menu.archive') }}
  98. </a>
  99. <a
  100. v-if="status && profile.id == status.account.id && status.visibility == 'archived'"
  101. class="list-group-item menu-option text-danger"
  102. href="#"
  103. @click.prevent="unarchivePost(status)">
  104. {{ $t('menu.unarchive') }}
  105. </a>
  106. <a
  107. v-if="status && profile.id == status.account.id && !status.pinned"
  108. class="list-group-item menu-option text-danger"
  109. href="#"
  110. @click.prevent="pinPost(status)">
  111. {{ $t('menu.pin') }}
  112. </a>
  113. <a
  114. v-if="status && profile.id == status.account.id && status.pinned"
  115. class="list-group-item menu-option text-danger"
  116. href="#"
  117. @click.prevent="unpinPost(status)">
  118. {{ $t('menu.unpin') }}
  119. </a>
  120. <a
  121. v-if="config.ab.pue && status && profile.id == status.account.id && status.visibility !== 'archived'"
  122. class="list-group-item menu-option text-danger"
  123. href="#"
  124. @click.prevent="editPost(status)">
  125. Edit
  126. </a>
  127. <a
  128. v-if="status && (profile.is_admin || profile.id == status.account.id) && status.visibility !== 'archived'"
  129. class="list-group-item menu-option text-danger"
  130. href="#"
  131. @click.prevent="deletePost(status)">
  132. <div v-if="isDeleting" class="spinner-border spinner-border-sm" role="status">
  133. <span class="sr-only">Loading...</span>
  134. </div>
  135. <div v-else>
  136. {{ $t('common.delete') }}
  137. </div>
  138. </a>
  139. <a
  140. class="list-group-item menu-option text-lighter"
  141. href="#"
  142. @click.prevent="closeCtxMenu()">
  143. {{ $t('common.cancel') }}
  144. </a>
  145. </div>
  146. </b-modal>
  147. <b-modal ref="ctxModModal"
  148. id="ctx-mod-modal"
  149. hide-header
  150. hide-footer
  151. centered
  152. rounded
  153. size="sm"
  154. body-class="list-group-flush p-0 rounded">
  155. <div class="list-group text-center">
  156. <p class="py-2 px-3 mb-0">
  157. <div
  158. class="text-center menu-option text-danger">
  159. {{ $t('menu.moderationTools') }}
  160. </div>
  161. <div class="small text-center text-muted">
  162. {{ $t('menu.selectOneOption') }}
  163. </div>
  164. </p>
  165. <a
  166. class="list-group-item menu-option"
  167. href="#"
  168. @click.prevent="moderatePost(status, 'unlist')">
  169. {{ $t('menu.unlistFromTimelines') }}
  170. </a>
  171. <a
  172. v-if="status.sensitive"
  173. class="list-group-item menu-option"
  174. href="#"
  175. @click.prevent="moderatePost(status, 'remcw')">
  176. {{ $t('menu.removeCW') }}
  177. </a>
  178. <a
  179. v-else
  180. class="list-group-item menu-option"
  181. href="#"
  182. @click.prevent="moderatePost(status, 'addcw')">
  183. {{ $t('menu.addCW') }}
  184. </a>
  185. <a
  186. class="list-group-item menu-option"
  187. href="#"
  188. @click.prevent="moderatePost(status, 'spammer')">
  189. {{ $t('menu.markAsSpammer') }}<br />
  190. <span class="small">{{ $t('menu.markAsSpammerText') }}</span>
  191. </a>
  192. <a
  193. class="list-group-item menu-option text-lighter"
  194. href="#"
  195. @click.prevent="ctxModMenuClose()">
  196. {{ $t('common.cancel') }}
  197. </a>
  198. </div>
  199. </b-modal>
  200. <b-modal ref="ctxModOtherModal"
  201. id="ctx-mod-other-modal"
  202. hide-header
  203. hide-footer
  204. centered
  205. rounded
  206. size="sm"
  207. body-class="list-group-flush p-0 rounded">
  208. <div class="list-group text-center">
  209. <p class="py-2 px-3 mb-0">
  210. <div class="text-center font-weight-bold text-danger">{{ $t('menu.moderationTools') }}</div>
  211. <div class="small text-center text-muted">{{ $t('menu.selectOneOption') }}</div>
  212. </p>
  213. <div class="list-group-item rounded cursor-pointer font-weight-bold" @click="confirmModal()">Unlist Posts</div>
  214. <div class="list-group-item rounded cursor-pointer font-weight-bold" @click="confirmModal()">Moderation Log</div>
  215. <div class="list-group-item rounded cursor-pointer text-lighter" @click="ctxModOtherMenuClose()">{{ $t('common.cancel') }}</div>
  216. </div>
  217. </b-modal>
  218. <b-modal ref="ctxShareModal"
  219. id="ctx-share-modal"
  220. title="Share"
  221. hide-footer
  222. hide-header
  223. centered
  224. rounded
  225. size="sm"
  226. body-class="list-group-flush p-0 rounded text-center">
  227. <a
  228. class="list-group-item menu-option"
  229. href="#"
  230. @click.prevent="ctxMenuCopyLink()">
  231. {{ $t('common.copyLink') }}
  232. </a>
  233. <a
  234. v-if="status && status.local == true && !status.in_reply_to_id"
  235. class="list-group-item menu-option"
  236. @click.prevent="ctxMenuEmbed()">
  237. {{ $t('menu.embed') }}
  238. </a>
  239. <a
  240. class="list-group-item menu-option text-lighter"
  241. href="#"
  242. @click.prevent="closeCtxShareMenu()">
  243. {{ $t('common.cancel') }}
  244. </a>
  245. </b-modal>
  246. <b-modal ref="ctxEmbedModal"
  247. id="ctx-embed-modal"
  248. hide-header
  249. hide-footer
  250. centered
  251. rounded
  252. size="md"
  253. body-class="p-2 rounded">
  254. <div>
  255. <div class="form-group">
  256. <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>
  257. </div>
  258. <div class="form-group pl-2 d-flex justify-content-center">
  259. <div class="form-check mr-3">
  260. <input class="form-check-input" type="checkbox" v-model="ctxEmbedShowCaption" :disabled="ctxEmbedCompactMode == true">
  261. <label class="form-check-label font-weight-light">
  262. {{ $t('menu.showCaption') }}
  263. </label>
  264. </div>
  265. <div class="form-check mr-3">
  266. <input class="form-check-input" type="checkbox" v-model="ctxEmbedShowLikes" :disabled="ctxEmbedCompactMode == true">
  267. <label class="form-check-label font-weight-light">
  268. {{ $t('menu.showLikes') }}
  269. </label>
  270. </div>
  271. <div class="form-check">
  272. <input class="form-check-input" type="checkbox" v-model="ctxEmbedCompactMode">
  273. <label class="form-check-label font-weight-light">
  274. {{ $t('menu.compactMode') }}
  275. </label>
  276. </div>
  277. </div>
  278. <hr>
  279. <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>
  280. <p class="mb-0 px-2 small text-muted">{{ $t('menu.embedConfirmText') }} <a href="/site/terms">{{ $t('site.terms') }}</a></p>
  281. </div>
  282. </b-modal>
  283. <b-modal ref="ctxReport"
  284. id="ctx-report"
  285. hide-header
  286. hide-footer
  287. centered
  288. rounded
  289. size="sm"
  290. body-class="list-group-flush p-0 rounded">
  291. <p class="py-2 px-3 mb-0">
  292. <div class="text-center font-weight-bold text-danger">{{ $t('menu.report') }}</div>
  293. <div class="small text-center text-muted">{{ $t('menu.selectOneOption') }}</div>
  294. </p>
  295. <div class="list-group text-center">
  296. <div class="list-group-item rounded cursor-pointer font-weight-bold" @click="sendReport('spam')">{{ $t('menu.spam') }}</div>
  297. <div class="list-group-item rounded cursor-pointer font-weight-bold" @click="sendReport('sensitive')">{{ $t('menu.sensitive') }}</div>
  298. <div class="list-group-item rounded cursor-pointer font-weight-bold" @click="sendReport('abusive')">{{ $t('menu.abusive') }}</div>
  299. <div class="list-group-item rounded cursor-pointer font-weight-bold" @click="openCtxReportOtherMenu()">{{ $t('common.other') }}</div>
  300. <!-- <div class="list-group-item rounded cursor-pointer" @click="ctxReportMenuGoBack()">Go Back</div> -->
  301. <div class="list-group-item rounded cursor-pointer text-lighter" @click="ctxReportMenuGoBack()">{{ $t('common.cancel') }}</div>
  302. </div>
  303. </b-modal>
  304. <b-modal ref="ctxReportOther"
  305. id="ctx-report-other"
  306. hide-header
  307. hide-footer
  308. centered
  309. rounded
  310. size="sm"
  311. body-class="list-group-flush p-0 rounded">
  312. <p class="py-2 px-3 mb-0">
  313. <div class="text-center font-weight-bold text-danger">{{ $t('menu.report') }}</div>
  314. <div class="small text-center text-muted">{{ $t('menu.selectOneOption') }}</div>
  315. </p>
  316. <div class="list-group text-center">
  317. <div class="list-group-item rounded cursor-pointer font-weight-bold" @click="sendReport('underage')">{{ $t('menu.underageAccount') }}</div>
  318. <div class="list-group-item rounded cursor-pointer font-weight-bold" @click="sendReport('copyright')">{{ $t('menu.copyrightInfringement') }}</div>
  319. <div class="list-group-item rounded cursor-pointer font-weight-bold" @click="sendReport('impersonation')">{{ $t('menu.impersonation') }}</div>
  320. <div class="list-group-item rounded cursor-pointer font-weight-bold" @click="sendReport('scam')">{{ $t('menu.scamOrFraud') }}</div>
  321. <div class="list-group-item rounded cursor-pointer text-lighter" @click="ctxReportOtherMenuGoBack()">{{ $t('common.cancel') }}</div>
  322. </div>
  323. </b-modal>
  324. <b-modal ref="ctxConfirm"
  325. id="ctx-confirm"
  326. hide-header
  327. hide-footer
  328. centered
  329. rounded
  330. size="sm"
  331. body-class="list-group-flush p-0 rounded">
  332. <div class="d-flex align-items-center justify-content-center py-3">
  333. <div>{{ this.confirmModalTitle }}</div>
  334. </div>
  335. <div class="d-flex border-top btn-group btn-group-block rounded-0" role="group">
  336. <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>
  337. <button type="button" class="btn btn-outline-lighter border-0" style="color: rgb(0,122,255) !important;" @click.prevent="confirmModalConfirm()">Confirm</button>
  338. </div>
  339. </b-modal>
  340. </div>
  341. </template>
  342. <script type="text/javascript">
  343. export default {
  344. props: [
  345. 'status',
  346. 'profile'
  347. ],
  348. data() {
  349. return {
  350. config: window.App.config,
  351. ctxMenuStatus: false,
  352. ctxMenuRelationship: false,
  353. ctxEmbedPayload: false,
  354. copiedEmbed: false,
  355. replySending: false,
  356. ctxEmbedShowCaption: true,
  357. ctxEmbedShowLikes: false,
  358. ctxEmbedCompactMode: false,
  359. confirmModalTitle: 'Are you sure?',
  360. confirmModalIdentifer: null,
  361. confirmModalType: false,
  362. isDeleting: false
  363. }
  364. },
  365. watch: {
  366. ctxEmbedShowCaption: function (n,o) {
  367. if(n == true) {
  368. this.ctxEmbedCompactMode = false;
  369. }
  370. let mode = this.ctxEmbedCompactMode ? 'compact' : 'full';
  371. this.ctxEmbedPayload = window.App.util.embed.post(this.ctxMenuStatus.url, this.ctxEmbedShowCaption, this.ctxEmbedShowLikes, mode);
  372. },
  373. ctxEmbedShowLikes: function (n,o) {
  374. if(n == true) {
  375. this.ctxEmbedCompactMode = false;
  376. }
  377. let mode = this.ctxEmbedCompactMode ? 'compact' : 'full';
  378. this.ctxEmbedPayload = window.App.util.embed.post(this.ctxMenuStatus.url, this.ctxEmbedShowCaption, this.ctxEmbedShowLikes, mode);
  379. },
  380. ctxEmbedCompactMode: function (n,o) {
  381. if(n == true) {
  382. this.ctxEmbedShowCaption = false;
  383. this.ctxEmbedShowLikes = false;
  384. }
  385. let mode = this.ctxEmbedCompactMode ? 'compact' : 'full';
  386. this.ctxEmbedPayload = window.App.util.embed.post(this.ctxMenuStatus.url, this.ctxEmbedShowCaption, this.ctxEmbedShowLikes, mode);
  387. }
  388. },
  389. methods: {
  390. open() {
  391. this.ctxMenu();
  392. },
  393. openModMenu() {
  394. this.$refs.ctxModModal.show();
  395. },
  396. ctxMenu() {
  397. this.ctxMenuStatus = this.status;
  398. this.ctxEmbedPayload = window.App.util.embed.post(this.status.url);
  399. if(this.status.account.id == this.profile.id) {
  400. this.ctxMenuRelationship = false;
  401. this.$refs.ctxModal.show();
  402. } else {
  403. axios.get('/api/v1/accounts/relationships', {
  404. params: {
  405. 'id[]': this.status.account.id
  406. }
  407. }).then(res => {
  408. this.ctxMenuRelationship = res.data[0];
  409. this.$refs.ctxModal.show();
  410. });
  411. }
  412. },
  413. closeCtxMenu() {
  414. this.copiedEmbed = false;
  415. this.ctxMenuStatus = false;
  416. this.ctxMenuRelationship = false;
  417. this.$refs.ctxModal.hide();
  418. this.$refs.ctxReport.hide();
  419. this.$refs.ctxReportOther.hide();
  420. this.closeModals();
  421. },
  422. ctxMenuCopyLink() {
  423. let status = this.ctxMenuStatus;
  424. navigator.clipboard.writeText(status.url);
  425. this.closeModals();
  426. return;
  427. },
  428. ctxMenuGoToPost() {
  429. let status = this.ctxMenuStatus;
  430. this.statusUrl(status);
  431. this.closeCtxMenu();
  432. return;
  433. },
  434. ctxMenuGoToProfile() {
  435. let status = this.ctxMenuStatus;
  436. this.profileUrl(status);
  437. this.closeCtxMenu();
  438. return;
  439. },
  440. ctxMenuReportPost() {
  441. this.$refs.ctxModal.hide();
  442. // this.$refs.ctxReport.show();
  443. this.$emit('report-modal', this.ctxMenuStatus);
  444. return;
  445. },
  446. ctxMenuEmbed() {
  447. this.closeModals();
  448. this.$refs.ctxEmbedModal.show();
  449. },
  450. ctxMenuShare() {
  451. this.$refs.ctxModal.hide();
  452. this.$refs.ctxShareModal.show();
  453. },
  454. closeCtxShareMenu() {
  455. this.$refs.ctxShareModal.hide();
  456. this.$refs.ctxModal.show();
  457. },
  458. ctxCopyEmbed() {
  459. navigator.clipboard.writeText(this.ctxEmbedPayload);
  460. this.ctxEmbedShowCaption = true;
  461. this.ctxEmbedShowLikes = false;
  462. this.ctxEmbedCompactMode = false;
  463. this.$refs.ctxEmbedModal.hide();
  464. },
  465. ctxModMenuShow() {
  466. this.$refs.ctxModal.hide();
  467. this.$refs.ctxModModal.show();
  468. },
  469. ctxModOtherMenuShow() {
  470. this.$refs.ctxModal.hide();
  471. this.$refs.ctxModModal.hide();
  472. this.$refs.ctxModOtherModal.show();
  473. },
  474. ctxModMenu() {
  475. this.$refs.ctxModal.hide();
  476. },
  477. ctxModMenuClose() {
  478. this.closeModals();
  479. },
  480. ctxModOtherMenuClose() {
  481. this.closeModals();
  482. this.$refs.ctxModModal.show();
  483. },
  484. formatCount(count) {
  485. return App.util.format.count(count);
  486. },
  487. openCtxReportOtherMenu() {
  488. let s = this.ctxMenuStatus;
  489. this.closeCtxMenu();
  490. this.ctxMenuStatus = s;
  491. this.$refs.ctxReportOther.show();
  492. },
  493. ctxReportMenuGoBack() {
  494. this.$refs.ctxReportOther.hide();
  495. this.$refs.ctxReport.hide();
  496. this.$refs.ctxModal.show();
  497. },
  498. ctxReportOtherMenuGoBack() {
  499. this.$refs.ctxReportOther.hide();
  500. this.$refs.ctxModal.hide();
  501. this.$refs.ctxReport.show();
  502. },
  503. sendReport(type) {
  504. let id = this.ctxMenuStatus.id;
  505. swal({
  506. 'title': this.$t('menu.confirmReport'),
  507. 'text': this.$t('menu.confirmReportText'),
  508. 'icon': 'warning',
  509. 'buttons': true,
  510. 'dangerMode': true
  511. }).then((res) => {
  512. if(res) {
  513. axios.post('/i/report/', {
  514. 'report': type,
  515. 'type': 'post',
  516. 'id': id,
  517. }).then(res => {
  518. this.closeCtxMenu();
  519. swal(this.$t('menu.reportSent'), this.$t('menu.reportSentText'), 'success');
  520. }).catch(err => {
  521. swal(this.$t('common.oops'), this.$t('menu.reportSentError'), 'error');
  522. })
  523. } else {
  524. this.closeCtxMenu();
  525. }
  526. });
  527. },
  528. closeModals() {
  529. this.$refs.ctxModal.hide();
  530. this.$refs.ctxModModal.hide();
  531. this.$refs.ctxModOtherModal.hide();
  532. this.$refs.ctxShareModal.hide();
  533. this.$refs.ctxEmbedModal.hide();
  534. this.$refs.ctxReport.hide();
  535. this.$refs.ctxReportOther.hide();
  536. this.$refs.ctxConfirm.hide();
  537. },
  538. openCtxStatusModal() {
  539. this.closeModals();
  540. this.$refs.ctxStatusModal.show();
  541. },
  542. openConfirmModal() {
  543. this.closeModals();
  544. this.$refs.ctxConfirm.show();
  545. },
  546. closeConfirmModal() {
  547. this.closeModals();
  548. this.confirmModalTitle = 'Are you sure?';
  549. this.confirmModalType = false;
  550. this.confirmModalIdentifer = null;
  551. },
  552. confirmModalConfirm() {
  553. switch(this.confirmModalType) {
  554. case 'post.delete':
  555. axios.post('/i/delete', {
  556. type: 'status',
  557. item: this.confirmModalIdentifer
  558. }).then(res => {
  559. this.feed = this.feed.filter(s => {
  560. return s.id != this.confirmModalIdentifer;
  561. });
  562. this.closeConfirmModal();
  563. }).catch(err => {
  564. this.closeConfirmModal();
  565. swal(this.$t('common.error'), this.$t('common.errorMsg'), 'error');
  566. });
  567. break;
  568. }
  569. this.closeConfirmModal();
  570. },
  571. confirmModalCancel() {
  572. this.closeConfirmModal();
  573. },
  574. moderatePost(status, action, $event) {
  575. let username = status.account.username;
  576. let pid = status.id;
  577. let msg = '';
  578. let self = this;
  579. switch(action) {
  580. case 'addcw':
  581. msg = this.$t('menu.modAddCWConfirm');
  582. swal({
  583. title: 'Confirm',
  584. text: msg,
  585. icon: 'warning',
  586. buttons: true,
  587. dangerMode: true
  588. }).then(res => {
  589. if(res) {
  590. axios.post('/api/v2/moderator/action', {
  591. action: action,
  592. item_id: status.id,
  593. item_type: 'status'
  594. }).then(res => {
  595. swal(this.$t('common.success'), this.$t('menu.modCWSuccess'), 'success');
  596. // status.sensitive = true;
  597. this.$emit('moderate', 'addcw');
  598. self.closeModals();
  599. self.ctxModMenuClose();
  600. }).catch(err => {
  601. self.closeModals();
  602. self.ctxModMenuClose();
  603. swal(this.$t('common.error'), this.$t('common.errorMsg'), 'error');
  604. });
  605. }
  606. });
  607. break;
  608. case 'remcw':
  609. msg = this.$t('menu.modRemoveCWConfirm');
  610. swal({
  611. title: 'Confirm',
  612. text: msg,
  613. icon: 'warning',
  614. buttons: true,
  615. dangerMode: true
  616. }).then(res => {
  617. if(res) {
  618. axios.post('/api/v2/moderator/action', {
  619. action: action,
  620. item_id: status.id,
  621. item_type: 'status'
  622. }).then(res => {
  623. swal(this.$t('common.success'), this.$t('menu.modRemoveCWSuccess'), 'success');
  624. // status.sensitive = false;
  625. this.$emit('moderate', 'remcw');
  626. self.closeModals();
  627. self.ctxModMenuClose();
  628. }).catch(err => {
  629. self.closeModals();
  630. self.ctxModMenuClose();
  631. swal(this.$t('common.error'), this.$t('common.errorMsg'), 'error');
  632. });
  633. }
  634. });
  635. break;
  636. case 'unlist':
  637. msg = this.$t('menu.modUnlistConfirm');
  638. swal({
  639. title: 'Confirm',
  640. text: msg,
  641. icon: 'warning',
  642. buttons: true,
  643. dangerMode: true
  644. }).then(res => {
  645. if(res) {
  646. axios.post('/api/v2/moderator/action', {
  647. action: action,
  648. item_id: status.id,
  649. item_type: 'status'
  650. }).then(res => {
  651. // this.feed = this.feed.filter(f => {
  652. // return f.id != status.id;
  653. // });
  654. this.$emit('moderate', 'unlist');
  655. swal(this.$t('common.success'), this.$t('menu.modUnlistSuccess'), 'success');
  656. self.closeModals();
  657. self.ctxModMenuClose();
  658. }).catch(err => {
  659. self.closeModals();
  660. self.ctxModMenuClose();
  661. swal(this.$t('common.error'), this.$t('common.errorMsg'), 'error');
  662. });
  663. }
  664. });
  665. break;
  666. case 'spammer':
  667. msg = this.$t('menu.modMarkAsSpammerConfirm');
  668. swal({
  669. title: 'Confirm',
  670. text: msg,
  671. icon: 'warning',
  672. buttons: true,
  673. dangerMode: true
  674. }).then(res => {
  675. if(res) {
  676. axios.post('/api/v2/moderator/action', {
  677. action: action,
  678. item_id: status.id,
  679. item_type: 'status'
  680. }).then(res => {
  681. this.$emit('moderate', 'spammer');
  682. swal(this.$t('common.success'), this.$t('menu.modMarkAsSpammerSuccess'), 'success');
  683. self.closeModals();
  684. self.ctxModMenuClose();
  685. }).catch(err => {
  686. self.closeModals();
  687. self.ctxModMenuClose();
  688. swal(this.$t('common.error'), this.$t('common.errorMsg'), 'error');
  689. });
  690. }
  691. });
  692. break;
  693. }
  694. },
  695. statusUrl(status) {
  696. if(status.account.local == true) {
  697. this.$router.push({
  698. name: 'post',
  699. path: `/i/web/post/${status.id}`,
  700. params: {
  701. id: status.id,
  702. cachedStatus: status,
  703. cachedProfile: this.profile
  704. }
  705. });
  706. return;
  707. }
  708. let permalink = this.$route.params.hasOwnProperty('id');
  709. if(permalink) {
  710. location.href = status.url;
  711. return;
  712. } else {
  713. this.$router.push({
  714. name: 'post',
  715. path: `/i/web/post/${status.id}`,
  716. params: {
  717. id: status.id,
  718. cachedStatus: status,
  719. cachedProfile: this.profile
  720. }
  721. });
  722. return;
  723. }
  724. },
  725. profileUrl(status) {
  726. this.$router.push({
  727. name: 'profile',
  728. path: `/i/web/profile/${status.account.id}`,
  729. params: {
  730. id: status.account.id,
  731. cachedProfile: status.account,
  732. cachedUser: this.profile
  733. }
  734. });
  735. return;
  736. },
  737. deletePost(status) {
  738. this.isDeleting = true;
  739. if(this.ownerOrAdmin(status) == false) {
  740. return;
  741. }
  742. swal({
  743. title: 'Confirm Delete',
  744. text: 'Are you sure you want to delete this post?',
  745. icon: "warning",
  746. buttons: true,
  747. dangerMode: true,
  748. })
  749. .then(res => {
  750. if(!res) {
  751. this.closeModals();
  752. this.isDeleting = false;
  753. } else {
  754. axios.post('/i/delete', {
  755. type: 'status',
  756. item: status.id
  757. }).then(res => {
  758. this.$emit('delete');
  759. this.closeModals();
  760. this.isDeleting = false;
  761. }).catch(err => {
  762. this.closeModals();
  763. this.isDeleting = false;
  764. swal(this.$t('common.error'), this.$t('common.errorMsg'), 'error');
  765. });
  766. }
  767. })
  768. },
  769. owner(status) {
  770. return this.profile.id === status.account.id;
  771. },
  772. admin() {
  773. return this.profile.is_admin == true;
  774. },
  775. ownerOrAdmin(status) {
  776. return this.owner(status) || this.admin();
  777. },
  778. archivePost(status) {
  779. if(window.confirm(this.$t('menu.archivePostConfirm')) == false) {
  780. return;
  781. }
  782. axios.post('/api/pixelfed/v2/status/' + status.id + '/archive')
  783. .then(res => {
  784. this.$emit('delete', status.id);
  785. this.$emit('archived', status.id);
  786. this.closeModals();
  787. });
  788. },
  789. unarchivePost(status) {
  790. if(window.confirm(this.$t('menu.unarchivePostConfirm')) == false) {
  791. return;
  792. }
  793. axios.post('/api/pixelfed/v2/status/' + status.id + '/unarchive')
  794. .then(res => {
  795. this.$emit('unarchived', status.id);
  796. this.closeModals();
  797. });
  798. },
  799. editPost(status) {
  800. this.closeModals();
  801. this.$emit('edit', status);
  802. },
  803. handleMute() {
  804. if(!this.ctxMenuRelationship) {
  805. return;
  806. }
  807. let curState = this.ctxMenuRelationship.muting;
  808. swal({
  809. title: curState ? 'Confirm Unmute' : 'Confirm Mute',
  810. text: curState ? 'Are you sure you want to unmute this account?' : 'Are you sure you want to mute this account?',
  811. icon: "warning",
  812. buttons: true,
  813. dangerMode: true,
  814. })
  815. .then(res => {
  816. if(!res) {
  817. this.closeModals();
  818. } else {
  819. let url = curState ?
  820. `/api/v1/accounts/${this.status.account.id}/unmute` :
  821. `/api/v1/accounts/${this.status.account.id}/mute`;
  822. axios.post(url)
  823. .then(res => {
  824. this.closeModals();
  825. this.$emit('muted', this.status);
  826. this.$store.commit('updateRelationship', [res.data]);
  827. })
  828. .catch(err => {
  829. this.closeModals();
  830. if(err && err.response && err.response.data && err.response.data.error) {
  831. swal('Error', err.response.data.error, 'error');
  832. } else {
  833. swal('Oops!', 'An error occured, please try again later.', 'error');
  834. }
  835. })
  836. }
  837. })
  838. },
  839. handleBlock() {
  840. if(!this.ctxMenuRelationship) {
  841. return;
  842. }
  843. let curState = this.ctxMenuRelationship.blocking;
  844. swal({
  845. title: curState ? 'Confirm Unblock' : 'Confirm Block',
  846. text: curState ? 'Are you sure you want to unblock this account?' : 'Are you sure you want to block this account?',
  847. icon: "warning",
  848. buttons: true,
  849. dangerMode: true,
  850. })
  851. .then(res => {
  852. if(!res) {
  853. this.closeModals();
  854. } else {
  855. let url = curState ?
  856. `/api/v1/accounts/${this.status.account.id}/unblock` :
  857. `/api/v1/accounts/${this.status.account.id}/block`;
  858. axios.post(url)
  859. .then(res => {
  860. this.closeModals();
  861. this.$store.commit('updateRelationship', [res.data]);
  862. this.$emit('muted', this.status);
  863. })
  864. .catch(err => {
  865. this.closeModals();
  866. if(err && err.response && err.response.data && err.response.data.error) {
  867. swal('Error', err.response.data.error, 'error');
  868. } else {
  869. swal('Oops!', 'An error occured, please try again later.', 'error');
  870. }
  871. })
  872. }
  873. })
  874. },
  875. handleUnfollow() {
  876. if(!this.ctxMenuRelationship) {
  877. return;
  878. }
  879. swal({
  880. title: 'Unfollow',
  881. text: 'Are you sure you want to unfollow ' + this.status.account.username + '?',
  882. icon: "warning",
  883. buttons: true,
  884. dangerMode: true,
  885. })
  886. .then(res => {
  887. if(!res) {
  888. this.closeModals();
  889. } else {
  890. axios.post(`/api/v1/accounts/${this.status.account.id}/unfollow`)
  891. .then(res => {
  892. this.closeModals();
  893. this.$store.commit('updateRelationship', [res.data]);
  894. this.$emit('unfollow', this.status);
  895. })
  896. .catch(err => {
  897. this.closeModals();
  898. if(err && err.response && err.response.data && err.response.data.error) {
  899. swal('Error', err.response.data.error, 'error');
  900. } else {
  901. swal('Oops!', 'An error occured, please try again later.', 'error');
  902. }
  903. })
  904. }
  905. })
  906. },
  907. pinPost(status) {
  908. if(window.confirm(this.$t('menu.pinPostConfirm')) == false) {
  909. return;
  910. }
  911. this.closeModals();
  912. axios.post('/api/pixelfed/v1/statuses/' + status.id.toString() + '/pin')
  913. .then(res => {
  914. const data = res.data;
  915. if(data.id && data.pinned) {
  916. this.$emit('pinned');
  917. swal('Pinned', 'Successfully pinned post to your profile', 'success');
  918. } else {
  919. swal('Error', 'An error occured when attempting to pin', 'error');
  920. }
  921. })
  922. .catch(err => {
  923. this.closeModals();
  924. if(err.response?.data?.error) {
  925. swal('Error', err.response?.data?.error, 'error');
  926. }
  927. });
  928. },
  929. unpinPost(status) {
  930. if(window.confirm(this.$t('menu.unpinPostConfirm')) == false) {
  931. return;
  932. }
  933. this.closeModals();
  934. axios.post('/api/pixelfed/v1/statuses/' + status.id.toString() + '/unpin')
  935. .then(res => {
  936. const data = res.data;
  937. if(data.id) {
  938. this.$emit('unpinned');
  939. swal('Unpinned', 'Successfully unpinned post from your profile', 'success');
  940. } else {
  941. swal('Error', data.error, 'error');
  942. }
  943. })
  944. .catch(err => {
  945. this.closeModals();
  946. if(err.response?.data?.error) {
  947. swal('Error', err.response?.data?.error, 'error');
  948. } else {
  949. window.location.reload()
  950. }
  951. });
  952. },
  953. }
  954. }
  955. </script>
  956. <style lang="scss" scoped>
  957. .menu-option {
  958. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  959. text-decoration: none;
  960. font-weight: 500;
  961. color: var(--dark);
  962. }
  963. .list-group-item {
  964. border-color: var(--border-color);
  965. }
  966. .action-icon-link {
  967. display: flex;
  968. flex-direction: column;
  969. .icon {
  970. opacity: 0.5;
  971. margin-bottom: 5px;
  972. }
  973. p {
  974. font-weight: 600;
  975. font-size: 11px;
  976. }
  977. &-inline {
  978. display: flex;
  979. flex-direction: row;
  980. justify-content: center;
  981. align-items: center;
  982. gap: 8px;
  983. p {
  984. font-weight: bold;
  985. }
  986. }
  987. }
  988. </style>