Timeline.vue 27 KB

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