ContextMenu.vue 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070
  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. axios.post('/api/v2/statuses/' + status.id + '/pin')
  912. .then(res => {
  913. const data = res.data;
  914. if(data.status){
  915. swal('Success', "Post was pinned successfully!" , 'success');
  916. }else {
  917. swal('Error', data.message, 'error');
  918. }
  919. this.closeModals();
  920. });
  921. },
  922. unpinPost(status) {
  923. if(window.confirm(this.$t('menu.unpinPostConfirm')) == false) {
  924. return;
  925. }
  926. axios.post('/api/v2/statuses/' + status.id + '/unpin')
  927. .then(res => {
  928. const data = res.data;
  929. if(data.status){
  930. swal('Success', "Post was unpinned successfully!" , 'success');
  931. }else {
  932. swal('Error', data.message, 'error');
  933. }
  934. this.closeModals();
  935. });
  936. },
  937. }
  938. }
  939. </script>
  940. <style lang="scss" scoped>
  941. .menu-option {
  942. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  943. text-decoration: none;
  944. font-weight: 500;
  945. color: var(--dark);
  946. }
  947. .list-group-item {
  948. border-color: var(--border-color);
  949. }
  950. .action-icon-link {
  951. display: flex;
  952. flex-direction: column;
  953. .icon {
  954. opacity: 0.5;
  955. margin-bottom: 5px;
  956. }
  957. p {
  958. font-weight: 600;
  959. font-size: 11px;
  960. }
  961. &-inline {
  962. display: flex;
  963. flex-direction: row;
  964. justify-content: center;
  965. align-items: center;
  966. gap: 8px;
  967. p {
  968. font-weight: bold;
  969. }
  970. }
  971. }
  972. </style>