Timeline.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  1. <template>
  2. <div class="container" style="">
  3. <div class="row">
  4. <div class="col-md-8 col-lg-8 pt-2 px-0 my-3 timeline order-2 order-md-1">
  5. <div class="card mb-4 status-card card-md-rounded-0" :data-status-id="status.id" v-for="(status, index) in feed" :key="status.id">
  6. <div class="card-header d-inline-flex align-items-center bg-white">
  7. <img v-bind:src="status.account.avatar" width="32px" height="32px" style="border-radius: 32px;">
  8. <a class="username font-weight-bold pl-2 text-dark" v-bind:href="status.account.url">
  9. {{status.account.username}}
  10. </a>
  11. <div class="text-right" style="flex-grow:1;">
  12. <button class="btn btn-link text-dark no-caret dropdown-toggle py-0" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" title="Post options">
  13. <span class="fas fa-ellipsis-v fa-lg text-muted"></span>
  14. </button>
  15. <div class="dropdown-menu dropdown-menu-right">
  16. <a class="dropdown-item font-weight-bold" :href="status.url">Go to post</a>
  17. <!-- <a class="dropdown-item font-weight-bold" href="#">Share</a>
  18. <a class="dropdown-item font-weight-bold" href="#">Embed</a> -->
  19. <span v-if="statusOwner(status) == false">
  20. <a class="dropdown-item font-weight-bold" :href="reportUrl(status)">Report</a>
  21. <a class="dropdown-item font-weight-bold" v-on:click="muteProfile(status)">Mute Profile</a>
  22. <a class="dropdown-item font-weight-bold" v-on:click="blockProfile(status)">Block Profile</a>
  23. </span>
  24. <span v-if="statusOwner(status) == true">
  25. <a class="dropdown-item font-weight-bold text-danger" v-on:click="deletePost(status)">Delete</a>
  26. </span>
  27. <span v-if="profile.is_admin == true && modes.mod == true">
  28. <div class="dropdown-divider"></div>
  29. <a v-if="!statusOwner(status)" class="dropdown-item font-weight-bold text-danger" v-on:click="deletePost(status)">Delete</a>
  30. <div class="dropdown-divider"></div>
  31. <h6 class="dropdown-header">Mod Tools</h6>
  32. <a class="dropdown-item font-weight-bold" v-on:click="moderatePost(status, 'autocw')">
  33. <p class="mb-0" data-toggle="tooltip" data-placement="bottom" title="Adds a CW to every post made by this account.">Enforce CW</p>
  34. </a>
  35. <a class="dropdown-item font-weight-bold" v-on:click="moderatePost(status, 'noautolink')">
  36. <p class="mb-0" title="Do not transform mentions, hashtags or urls into HTML.">No Autolinking</p>
  37. </a>
  38. <a class="dropdown-item font-weight-bold" v-on:click="moderatePost(status, 'unlisted')">
  39. <p class="mb-0" title="Removes account from public/network timelines.">Unlisted Posts</p>
  40. </a>
  41. <a class="dropdown-item font-weight-bold" v-on:click="moderatePost(status, 'disable')">
  42. <p class="mb-0" title="Temporarily disable account until next time user log in.">Disable Account</p>
  43. </a>
  44. <a class="dropdown-item font-weight-bold" v-on:click="moderatePost(status, 'suspend')">
  45. <p class="mb-0" title="This prevents any new interactions, without deleting existing data.">Suspend Account</p>
  46. </a>
  47. </span>
  48. </div>
  49. </div>
  50. </div>
  51. <div class="postPresenterContainer">
  52. <div v-if="status.pf_type === 'photo'" class="w-100">
  53. <photo-presenter :status="status"></photo-presenter>
  54. </div>
  55. <div v-else-if="status.pf_type === 'video'" class="w-100">
  56. <video-presenter :status="status"></video-presenter>
  57. </div>
  58. <div v-else-if="status.pf_type === 'photo:album'" class="w-100">
  59. <photo-album-presenter :status="status"></photo-album-presenter>
  60. </div>
  61. <div v-else-if="status.pf_type === 'video:album'" class="w-100">
  62. <video-album-presenter :status="status"></video-album-presenter>
  63. </div>
  64. <div v-else-if="status.pf_type === 'photo:video:album'" class="w-100">
  65. <mixed-album-presenter :status="status"></mixed-album-presenter>
  66. </div>
  67. <div v-else class="w-100">
  68. <p class="text-center p-0 font-weight-bold text-white">Error: Problem rendering preview.</p>
  69. </div>
  70. </div>
  71. <div class="card-body">
  72. <div class="reactions my-1">
  73. <h3 v-bind:class="[status.favourited ? 'fas fa-heart text-danger pr-3 m-0 cursor-pointer' : 'far fa-heart pr-3 m-0 like-btn cursor-pointer']" title="Like" v-on:click="likeStatus(status, $event)"></h3>
  74. <h3 class="far fa-comment pr-3 m-0 cursor-pointer" title="Comment" v-on:click="commentFocus(status, $event)"></h3>
  75. <h3 v-bind:class="[status.reblogged ? 'far fa-share-square pr-3 m-0 text-primary cursor-pointer' : 'far fa-share-square pr-3 m-0 share-btn cursor-pointer']" title="Share" v-on:click="shareStatus(status, $event)"></h3>
  76. </div>
  77. <div class="likes font-weight-bold">
  78. <span class="like-count">{{status.favourites_count}}</span> {{status.favourites_count == 1 ? 'like' : 'likes'}}
  79. </div>
  80. <div class="caption">
  81. <p class="mb-2 read-more" style="overflow: hidden;">
  82. <span class="username font-weight-bold">
  83. <bdi><a class="text-dark" :href="status.account.url">{{status.account.username}}</a></bdi>
  84. </span>
  85. <span v-html="status.content"></span>
  86. </p>
  87. </div>
  88. <div class="comments" v-if="status.id == replyId">
  89. <p class="mb-0 d-flex justify-content-between align-items-top read-more" style="overflow-y: hidden;" v-for="(reply, index) in replies">
  90. <span>
  91. <a class="text-dark font-weight-bold mr-1" :href="reply.account.url">{{reply.account.username}}</a>
  92. <span v-html="reply.content"></span>
  93. </span>
  94. <span class="mb-0" style="min-width:38px">
  95. <span v-on:click="likeStatus(reply, $event)"><i v-bind:class="[reply.favourited ? 'fas fa-heart fa-sm text-danger':'far fa-heart fa-sm text-lighter']"></i></span>
  96. <post-menu :status="reply" :profile="profile" size="sm" :modal="'true'" :feed="feed" class="d-inline-flex pl-2"></post-menu>
  97. </span>
  98. </p>
  99. </div>
  100. <div class="timestamp mt-2">
  101. <p class="small text-uppercase mb-0">
  102. <a :href="status.url" class="text-muted">
  103. <timeago :datetime="status.created_at" :auto-update="60" :converter-options="{includeSeconds:true}" :title="timestampFormat(status.created_at)" v-b-tooltip.hover.bottom></timeago>
  104. </a>
  105. </p>
  106. </div>
  107. </div>
  108. <div class="card-footer bg-white" v-if="status.id == replyId">
  109. <form class="" v-on:submit.prevent="commentSubmit(status, $event)">
  110. <input type="hidden" name="item" value="">
  111. <input class="form-control status-reply-input" name="comment" placeholder="Add a comment…" autocomplete="off">
  112. </form>
  113. </div>
  114. </div>
  115. <div v-if="modes.infinite == true">
  116. <infinite-loading @infinite="infiniteTimeline">
  117. <div slot="no-more" class="font-weight-bold text-light">No more posts to load</div>
  118. <div slot="no-results" class="font-weight-bold text-light">No posts found</div>
  119. </infinite-loading>
  120. </div>
  121. <div v-if="modes.infinite == false" class="pagination d-none">
  122. <p class="btn btn-outline-secondary font-weight-bold btn-block" v-on:click="loadMore">Load more posts</p>
  123. </div>
  124. </div>
  125. <div class="col-md-4 col-lg-4 pt-2 my-3 order-1 order-md-2">
  126. <div class="mb-4">
  127. <div class="card profile-card">
  128. <div class="card-body loader text-center">
  129. <div class="spinner-border" role="status">
  130. <span class="sr-only">Loading...</span>
  131. </div>
  132. </div>
  133. <div class="card-body contents d-none">
  134. <div class="media d-flex align-items-center">
  135. <a :href="profile.url">
  136. <img class="mr-3 rounded-circle box-shadow" :src="profile.avatar || '/storage/avatars/default.png'" alt="avatar" width="64px" height="64px">
  137. </a>
  138. <div class="media-body d-flex justify-content-between">
  139. <div>
  140. <p class="mb-0 px-0 font-weight-bold"><a :href="profile.url" class="text-dark">&commat;{{profile.username}}</a></p>
  141. <p class="my-0 text-muted text-truncate pb-0">{{profile.display_name}}</p>
  142. </div>
  143. <div>
  144. <a :class="[optionMenuState == true ? 'text-primary' :'text-muted']" v-on:click="toggleOptionsMenu()"><i class="fas fa-cog"></i></a>
  145. </div>
  146. </div>
  147. </div>
  148. </div>
  149. <div class="card-footer bg-white py-1 d-none">
  150. <div class="d-flex justify-content-between text-center">
  151. <span class="pl-3 cursor-pointer" v-on:click="redirect(profile.url)">
  152. <p class="mb-0 font-weight-bold">{{profile.statuses_count}}</p>
  153. <p class="mb-0 small text-muted">Posts</p>
  154. </span>
  155. <span class="cursor-pointer" v-on:click="redirect(profile.url + '/followers')">
  156. <p class="mb-0 font-weight-bold">{{profile.followers_count}}</p>
  157. <p class="mb-0 small text-muted">Followers</p>
  158. </span>
  159. <span class="pr-3 cursor-pointer" v-on:click="redirect(profile.url + '/following')">
  160. <p class="mb-0 font-weight-bold">{{profile.following_count}}</p>
  161. <p class="mb-0 small text-muted">Following</p>
  162. </span>
  163. </div>
  164. </div>
  165. </div>
  166. </div>
  167. <div v-if="optionMenuState == true" class="mb-4">
  168. <div class="card options-card">
  169. <div class="card-body small">
  170. <div v-if="profile.is_admin" class="custom-control custom-switch mb-3">
  171. <input type="checkbox" class="custom-control-input" id="mode-mod" v-on:click="modeModToggle()" v-model="modes.mod">
  172. <label class="custom-control-label font-weight-bold" for="mode-mod">Moderator Mode</label>
  173. </div>
  174. <!-- <div class="custom-control custom-switch mb-3">
  175. <input type="checkbox" class="custom-control-input" id="mode-dark" v-on:click="modeDarkToggle()" v-model="modes.dark">
  176. <label class="custom-control-label font-weight-bold" for="mode-dark">Dark Mode</label>
  177. </div> -->
  178. <div class="custom-control custom-switch mb-3">
  179. <input type="checkbox" class="custom-control-input" id="mode-notify" v-on:click="modeNotifyToggle()" v-model="!modes.notify">
  180. <label class="custom-control-label font-weight-bold" for="mode-notify">Disable Notifications</label>
  181. </div>
  182. <div class="custom-control custom-switch">
  183. <input type="checkbox" class="custom-control-input" id="mode-infinite" v-on:click="modeInfiniteToggle()" v-model="modes.infinite">
  184. <label class="custom-control-label font-weight-bold" for="mode-infinite">Enable Infinite Scroll</label>
  185. </div>
  186. </div>
  187. </div>
  188. </div>
  189. <div v-show="modes.notify == true" class="mb-4">
  190. <div class="card notification-card">
  191. <div class="card-header bg-white">
  192. <p class="mb-0 d-flex align-items-center justify-content-between">
  193. <span class="text-muted font-weight-bold">Notifications</span>
  194. <a class="text-dark small" href="/account/activity">See All</a>
  195. </p>
  196. </div>
  197. <div class="card-body loader text-center" style="height: 170px;">
  198. <div class="spinner-border" role="status">
  199. <span class="sr-only">Loading...</span>
  200. </div>
  201. </div>
  202. <div class="card-body pt-2 contents" style="max-height: 170px; overflow-y: scroll;">
  203. <div class="media mb-3 align-items-center" v-for="(n, index) in notifications">
  204. <img class="mr-2 rounded-circle" style="border:1px solid #ccc" :src="n.account.avatar" alt="" width="32px" height="32px">
  205. <div class="media-body font-weight-light small">
  206. <div v-if="n.type == 'favourite'">
  207. <p class="my-0">
  208. <a :href="n.account.url" class="font-weight-bold text-dark word-break">{{n.account.username}}</a> liked your <a class="font-weight-bold" v-bind:href="replyUrl(n.status)">post</a>.
  209. </p>
  210. </div>
  211. <div v-else-if="n.type == 'comment'">
  212. <p class="my-0">
  213. <a :href="n.account.url" class="font-weight-bold text-dark word-break">{{n.account.username}}</a> commented on your <a class="font-weight-bold" v-bind:href="replyUrl(n.status)">post</a>.
  214. </p>
  215. </div>
  216. <div v-else-if="n.type == 'mention'">
  217. <p class="my-0">
  218. <a :href="n.account.url" class="font-weight-bold text-dark word-break">{{n.account.username}}</a> <a class="font-weight-bold" v-bind:href="mentionUrl(n.status)">mentioned</a> you.
  219. </p>
  220. </div>
  221. <div v-else-if="n.type == 'follow'">
  222. <p class="my-0">
  223. <a :href="n.account.url" class="font-weight-bold text-dark word-break">{{n.account.username}}</a> followed you.
  224. </p>
  225. </div>
  226. <div v-else-if="n.type == 'share'">
  227. <p class="my-0">
  228. <a :href="n.account.url" class="font-weight-bold text-dark word-break">{{n.account.username}}</a> shared your <a class="font-weight-bold" v-bind:href="n.status.reblog.url">post</a>.
  229. </p>
  230. </div>
  231. </div>
  232. </div>
  233. </div>
  234. </div>
  235. </div>
  236. <footer>
  237. <div class="container pb-5">
  238. <p class="mb-0 text-uppercase font-weight-bold text-muted small">
  239. <a href="/site/about" class="text-dark pr-2">About Us</a>
  240. <a href="/site/help" class="text-dark pr-2">Help</a>
  241. <a href="/site/open-source" class="text-dark pr-2">Open Source</a>
  242. <a href="/site/language" class="text-dark pr-2">Language</a>
  243. <a href="/site/terms" class="text-dark pr-2">Terms</a>
  244. <a href="/site/privacy" class="text-dark pr-2">Privacy</a>
  245. <a href="/site/platform" class="text-dark pr-2">API</a>
  246. </p>
  247. <p class="mb-0 text-uppercase font-weight-bold text-muted small">
  248. <a href="http://pixelfed.org" class="text-muted" rel="noopener" title="" data-toggle="tooltip">Powered by PixelFed</a>
  249. </p>
  250. </div>
  251. </footer>
  252. </div>
  253. </div>
  254. </div>
  255. </template>
  256. <style type="text/css" scoped>
  257. .text-lighter {
  258. color:#B8C2CC !important;
  259. }
  260. .postPresenterContainer {
  261. display: flex;
  262. align-items: center;
  263. background: #fff;
  264. }
  265. .cursor-pointer {
  266. cursor: pointer;
  267. }
  268. .word-break {
  269. word-break: break-all;
  270. }
  271. .small .custom-control-label {
  272. padding-top: 3px;
  273. }
  274. </style>
  275. <script type="text/javascript">
  276. export default {
  277. data() {
  278. return {
  279. page: 2,
  280. feed: [],
  281. profile: {},
  282. scope: window.location.pathname,
  283. min_id: 0,
  284. max_id: 0,
  285. notifications: {},
  286. stories: {},
  287. suggestions: {},
  288. loading: true,
  289. replies: [],
  290. replyId: null,
  291. optionMenuState: false,
  292. modes: {
  293. 'mod': false,
  294. 'dark': false,
  295. 'notify': true,
  296. 'infinite': false
  297. }
  298. }
  299. },
  300. beforeMount() {
  301. this.fetchTimelineApi();
  302. this.fetchProfile();
  303. },
  304. mounted() {
  305. this.$nextTick(function () {
  306. $('[data-toggle="tooltip"]').tooltip()
  307. let cachedSettings = window.ls.get('pixelfed-classicui-settings');
  308. if(cachedSettings.hasOwnProperty('notify')) {
  309. this.modes = cachedSettings;
  310. } else {
  311. window.ls.set('pixelfed-classicui-settings', this.modes);
  312. }
  313. });
  314. },
  315. updated() {
  316. pixelfed.readmore();
  317. },
  318. methods: {
  319. fetchProfile() {
  320. axios.get('/api/v1/accounts/verify_credentials').then(res => {
  321. this.profile = res.data;
  322. $('.profile-card .loader').addClass('d-none');
  323. $('.profile-card .contents').removeClass('d-none');
  324. $('.profile-card .card-footer').removeClass('d-none');
  325. this.fetchNotifications();
  326. }).catch(err => {
  327. swal(
  328. 'Oops, something went wrong',
  329. 'Please reload the page.',
  330. 'error'
  331. );
  332. });
  333. },
  334. fetchTimelineApi() {
  335. let homeTimeline = '/api/v1/timelines/home?page=1';
  336. let localTimeline = '/api/v1/timelines/public?page=1';
  337. let apiUrl = this.scope == '/' ? homeTimeline : localTimeline;
  338. axios.get(apiUrl).then(res => {
  339. let data = res.data;
  340. this.feed.push(...data);
  341. let ids = data.map(status => status.id);
  342. this.min_id = Math.min(...ids);
  343. if(this.page == 1) {
  344. this.max_id = Math.max(...ids);
  345. }
  346. $('.timeline .pagination').removeClass('d-none');
  347. this.loading = false;
  348. }).catch(err => {
  349. });
  350. },
  351. infiniteTimeline($state) {
  352. let homeTimeline = '/api/v1/timelines/home';
  353. let localTimeline = '/api/v1/timelines/public';
  354. let apiUrl = this.scope == '/' ? homeTimeline : localTimeline;
  355. axios.get(apiUrl, {
  356. params: {
  357. page: this.page,
  358. },
  359. }).then(res => {
  360. if (res.data.length && this.loading == false) {
  361. let data = res.data;
  362. this.feed.push(...data);
  363. let ids = data.map(status => status.id);
  364. this.min_id = Math.min(...ids);
  365. if(this.page == 1) {
  366. this.max_id = Math.max(...ids);
  367. }
  368. this.page += 1;
  369. $state.loaded();
  370. this.loading = false;
  371. } else {
  372. $state.complete();
  373. }
  374. });
  375. },
  376. loadMore() {
  377. let homeTimeline = '/api/v1/timelines/home';
  378. let localTimeline = '/api/v1/timelines/public';
  379. let apiUrl = this.scope == '/' ? homeTimeline : localTimeline;
  380. axios.get(apiUrl, {
  381. params: {
  382. page: this.page,
  383. },
  384. }).then(res => {
  385. if (res.data.length && this.loading == false) {
  386. let data = res.data;
  387. this.feed.push(...data);
  388. let ids = data.map(status => status.id);
  389. this.min_id = Math.min(...ids);
  390. if(this.page == 1) {
  391. this.max_id = Math.max(...ids);
  392. }
  393. this.page += 1;
  394. this.loading = false;
  395. } else {
  396. }
  397. });
  398. },
  399. fetchNotifications() {
  400. axios.get('/api/v1/notifications')
  401. .then(res => {
  402. this.notifications = res.data;
  403. $('.notification-card .loader').addClass('d-none');
  404. $('.notification-card .contents').removeClass('d-none');
  405. });
  406. },
  407. reportUrl(status) {
  408. let type = status.in_reply_to ? 'comment' : 'post';
  409. let id = status.id;
  410. return '/i/report?type=' + type + '&id=' + id;
  411. },
  412. commentFocus(status, $event) {
  413. if(this.replyId == status.id) {
  414. return;
  415. }
  416. this.replies = {};
  417. this.replyId = status.id;
  418. this.fetchStatusComments(status, '');
  419. },
  420. likeStatus(status, $event) {
  421. if($('body').hasClass('loggedIn') == false) {
  422. return;
  423. }
  424. axios.post('/i/like', {
  425. item: status.id
  426. }).then(res => {
  427. status.favourites_count = res.data.count;
  428. status.favourited = !status.favourited;
  429. }).catch(err => {
  430. swal('Error', 'Something went wrong, please try again later.', 'error');
  431. });
  432. },
  433. shareStatus(status, $event) {
  434. if($('body').hasClass('loggedIn') == false) {
  435. return;
  436. }
  437. axios.post('/i/share', {
  438. item: status.id
  439. }).then(res => {
  440. status.reblogs_count = res.data.count;
  441. status.reblogged = !status.reblogged;
  442. }).catch(err => {
  443. swal('Error', 'Something went wrong, please try again later.', 'error');
  444. });
  445. },
  446. timestampFormat(timestamp) {
  447. let ts = new Date(timestamp);
  448. return ts.toDateString() + ' ' + ts.toLocaleTimeString();
  449. },
  450. editUrl(status) {
  451. return status.url + '/edit';
  452. },
  453. redirect(url) {
  454. window.location.href = url;
  455. return;
  456. },
  457. replyUrl(status) {
  458. let username = this.profile.username;
  459. let id = status.account.id == this.profile.id ? status.id : status.in_reply_to_id;
  460. return '/p/' + username + '/' + id;
  461. },
  462. mentionUrl(status) {
  463. let username = status.account.username;
  464. let id = status.id;
  465. return '/p/' + username + '/' + id;
  466. },
  467. statusOwner(status) {
  468. let sid = status.account.id;
  469. let uid = this.profile.id;
  470. if(sid == uid) {
  471. return true;
  472. } else {
  473. return false;
  474. }
  475. },
  476. fetchStatusComments(status, card) {
  477. axios.get('/api/v2/status/'+status.id+'/replies')
  478. .then(res => {
  479. let data = res.data;
  480. this.replies = _.reverse(data);
  481. }).catch(err => {
  482. })
  483. },
  484. muteProfile(status) {
  485. if($('body').hasClass('loggedIn') == false) {
  486. return;
  487. }
  488. axios.post('/i/mute', {
  489. type: 'user',
  490. item: status.account.id
  491. }).then(res => {
  492. this.feed = this.feed.filter(s => s.account.id !== status.account.id);
  493. swal('Success', 'You have successfully muted ' + status.account.acct, 'success');
  494. }).catch(err => {
  495. swal('Error', 'Something went wrong. Please try again later.', 'error');
  496. });
  497. },
  498. blockProfile(status) {
  499. if($('body').hasClass('loggedIn') == false) {
  500. return;
  501. }
  502. axios.post('/i/block', {
  503. type: 'user',
  504. item: status.account.id
  505. }).then(res => {
  506. this.feed = this.feed.filter(s => s.account.id !== status.account.id);
  507. swal('Success', 'You have successfully blocked ' + status.account.acct, 'success');
  508. }).catch(err => {
  509. swal('Error', 'Something went wrong. Please try again later.', 'error');
  510. });
  511. },
  512. deletePost(status, index) {
  513. if($('body').hasClass('loggedIn') == false || status.account.id !== this.profile.id) {
  514. return;
  515. }
  516. axios.post('/i/delete', {
  517. type: 'status',
  518. item: status.id
  519. }).then(res => {
  520. this.feed.splice(index,1);
  521. swal('Success', 'You have successfully deleted this post', 'success');
  522. }).catch(err => {
  523. swal('Error', 'Something went wrong. Please try again later.', 'error');
  524. });
  525. },
  526. commentSubmit(status, $event) {
  527. let id = status.id;
  528. let form = $event.target;
  529. let input = $(form).find('input[name="comment"]');
  530. let comment = input.val();
  531. let comments = form.parentElement.parentElement.getElementsByClassName('comments')[0];
  532. axios.post('/i/comment', {
  533. item: id,
  534. comment: comment
  535. }).then(res => {
  536. form.reset();
  537. form.blur();
  538. this.replies.push(res.data.entity);
  539. });
  540. },
  541. moderatePost(status, action, $event) {
  542. let username = status.account.username;
  543. console.log('action: ' + action + ' status id' + status.id);
  544. switch(action) {
  545. case 'autocw':
  546. let msg = 'Are you sure you want to enforce CW for ' + username + ' ?';
  547. swal({
  548. title: 'Confirm',
  549. text: msg,
  550. icon: 'warning',
  551. buttons: true,
  552. dangerMode: true
  553. }).then(res => {
  554. if(res) {
  555. axios.post('/api/v2/moderator/action', {
  556. action: action,
  557. item_id: status.id,
  558. item_type: 'status'
  559. }).then(res => {
  560. swal('Success', 'Successfully enforced CW for ' + username, 'success');
  561. }).catch(err => {
  562. swal(
  563. 'Error',
  564. 'Something went wrong, please try again later.',
  565. 'error'
  566. );
  567. });
  568. }
  569. });
  570. break;
  571. case 'noautolink':
  572. msg = 'Are you sure you want to disable auto linking for ' + username + ' ?';
  573. swal({
  574. title: 'Confirm',
  575. text: msg,
  576. icon: 'warning',
  577. buttons: true,
  578. dangerMode: true
  579. }).then(res => {
  580. if(res) {
  581. axios.post('/api/v2/moderator/action', {
  582. action: action,
  583. item_id: status.id,
  584. item_type: 'status'
  585. }).then(res => {
  586. swal('Success', 'Successfully disabled autolinking for ' + username, 'success');
  587. }).catch(err => {
  588. swal(
  589. 'Error',
  590. 'Something went wrong, please try again later.',
  591. 'error'
  592. );
  593. });
  594. }
  595. });
  596. break;
  597. case 'unlisted':
  598. msg = 'Are you sure you want to unlist from timelines for ' + username + ' ?';
  599. swal({
  600. title: 'Confirm',
  601. text: msg,
  602. icon: 'warning',
  603. buttons: true,
  604. dangerMode: true
  605. }).then(res => {
  606. if(res) {
  607. axios.post('/api/v2/moderator/action', {
  608. action: action,
  609. item_id: status.id,
  610. item_type: 'status'
  611. }).then(res => {
  612. swal('Success', 'Successfully unlisted for ' + username, 'success');
  613. }).catch(err => {
  614. swal(
  615. 'Error',
  616. 'Something went wrong, please try again later.',
  617. 'error'
  618. );
  619. });
  620. }
  621. });
  622. break;
  623. case 'disable':
  624. msg = 'Are you sure you want to disable ' + username + '\'s account ?';
  625. swal({
  626. title: 'Confirm',
  627. text: msg,
  628. icon: 'warning',
  629. buttons: true,
  630. dangerMode: true
  631. }).then(res => {
  632. if(res) {
  633. axios.post('/api/v2/moderator/action', {
  634. action: action,
  635. item_id: status.id,
  636. item_type: 'status'
  637. }).then(res => {
  638. swal('Success', 'Successfully disabled ' + username + '\'s account', 'success');
  639. }).catch(err => {
  640. swal(
  641. 'Error',
  642. 'Something went wrong, please try again later.',
  643. 'error'
  644. );
  645. });
  646. }
  647. });
  648. break;
  649. case 'suspend':
  650. msg = 'Are you sure you want to suspend ' + username + '\'s account ?';
  651. swal({
  652. title: 'Confirm',
  653. text: msg,
  654. icon: 'warning',
  655. buttons: true,
  656. dangerMode: true
  657. }).then(res => {
  658. if(res) {
  659. axios.post('/api/v2/moderator/action', {
  660. action: action,
  661. item_id: status.id,
  662. item_type: 'status'
  663. }).then(res => {
  664. swal('Success', 'Successfully suspend ' + username + '\'s account', 'success');
  665. }).catch(err => {
  666. swal(
  667. 'Error',
  668. 'Something went wrong, please try again later.',
  669. 'error'
  670. );
  671. });
  672. }
  673. });
  674. break;
  675. }
  676. },
  677. toggleOptionsMenu() {
  678. this.optionMenuState = !this.optionMenuState;
  679. },
  680. modeModToggle() {
  681. this.modes.mod = !this.modes.mod;
  682. window.ls.set('pixelfed-classicui-settings', this.modes);
  683. },
  684. modeNotifyToggle() {
  685. this.modes.notify = !this.modes.notify;
  686. window.ls.set('pixelfed-classicui-settings', this.modes);
  687. },
  688. modeDarkToggle() {
  689. // todo: more graceful stylesheet change
  690. if(this.modes.dark == true) {
  691. this.modes.dark = false;
  692. $('link[rel=stylesheet]').remove();
  693. let head = document.head;
  694. let link = document.createElement("link");
  695. link.type = "text/css";
  696. link.rel = "stylesheet";
  697. link.href = "/css/app.css";
  698. head.appendChild(link);
  699. } else {
  700. this.modes.dark = true;
  701. $('link[rel=stylesheet]').remove();
  702. let head = document.head;
  703. let link = document.createElement("link");
  704. link.id = "darkModeSheet";
  705. link.type = "text/css";
  706. link.rel = "stylesheet";
  707. link.href = "/css/appdark.css";
  708. head.appendChild(link);
  709. }
  710. window.ls.set('pixelfed-classicui-settings', this.modes);
  711. },
  712. modeInfiniteToggle() {
  713. this.modes.infinite = !this.modes.infinite
  714. window.ls.set('pixelfed-classicui-settings', this.modes);
  715. }
  716. }
  717. }
  718. </script>