Timeline.vue 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923
  1. <template>
  2. <div class="container" style="">
  3. <div class="row">
  4. <div class="col-md-8 col-lg-8 pt-sm-2 px-0 my-sm-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-sm-4 status-card card-md-rounded-0" :data-status-id="status.id" v-for="(status, index) in feed" :key="`${index}-${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" v-on:lightbox="lightbox"></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" v-on:lightbox="lightbox"></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" v-on:lightbox="lightbox"></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 v-if="!status.comments_disabled" 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" v-if="expLc(status) == true">
  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 && !status.comments_disabled">
  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 d-none d-md-block">
  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="followersModal()">
  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="followingModal()">
  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-notify" v-on:click="modeNotifyToggle()" v-model="!modes.notify">
  195. <label class="custom-control-label font-weight-bold" for="mode-notify">Disable Notifications</label>
  196. </div> -->
  197. <div class="custom-control custom-switch">
  198. <input type="checkbox" class="custom-control-input" id="mode-infinite" v-on:click="modeInfiniteToggle()" v-model="modes.infinite">
  199. <label class="custom-control-label font-weight-bold" for="mode-infinite">Enable Infinite Scroll</label>
  200. </div>
  201. <hr>
  202. <p class="font-weight-bold">BETA FEATURES</p>
  203. <div class="custom-control custom-switch">
  204. <input type="checkbox" class="custom-control-input" id="mode-dark" v-on:click="modeDarkToggle()" v-model="modes.dark">
  205. <label class="custom-control-label font-weight-bold" for="mode-dark">Dark Mode</label>
  206. </div>
  207. </div>
  208. </div>
  209. </div>
  210. <div v-show="modes.notify == true" class="mb-4">
  211. <notification-card></notification-card>
  212. </div>
  213. <footer>
  214. <div class="container pb-5">
  215. <p class="mb-0 text-uppercase font-weight-bold text-muted small">
  216. <a href="/site/about" class="text-dark pr-2">About Us</a>
  217. <a href="/site/help" class="text-dark pr-2">Help</a>
  218. <a href="/site/open-source" class="text-dark pr-2">Open Source</a>
  219. <a href="/site/language" class="text-dark pr-2">Language</a>
  220. <a href="/site/terms" class="text-dark pr-2">Terms</a>
  221. <a href="/site/privacy" class="text-dark pr-2">Privacy</a>
  222. <a href="/site/platform" class="text-dark pr-2">API</a>
  223. </p>
  224. <p class="mb-0 text-uppercase font-weight-bold text-muted small">
  225. <a href="http://pixelfed.org" class="text-muted" rel="noopener" title="" data-toggle="tooltip">Powered by PixelFed</a>
  226. </p>
  227. </div>
  228. </footer>
  229. </div>
  230. </div>
  231. <b-modal ref="followingModal"
  232. id="following-modal"
  233. hide-footer
  234. centered
  235. title="Following"
  236. body-class="list-group-flush p-0">
  237. <div class="list-group">
  238. <div class="list-group-item border-0" v-for="(user, index) in following" :key="'following_'+index">
  239. <div class="media">
  240. <a :href="user.url">
  241. <img class="mr-3 rounded-circle box-shadow" :src="user.avatar" :alt="user.username + '’s avatar'" width="30px">
  242. </a>
  243. <div class="media-body">
  244. <p class="mb-0" style="font-size: 14px">
  245. <a :href="user.url" class="font-weight-bold text-dark">
  246. {{user.username}}
  247. </a>
  248. </p>
  249. <p class="text-muted mb-0" style="font-size: 14px">
  250. {{user.display_name}}
  251. </p>
  252. </div>
  253. </div>
  254. </div>
  255. <div v-if="followingMore" class="list-group-item text-center" v-on:click="followingLoadMore()">
  256. <p class="mb-0 small text-muted font-weight-light cursor-pointer">Load more</p>
  257. </div>
  258. </div>
  259. </b-modal>
  260. <b-modal ref="followerModal"
  261. id="follower-modal"
  262. hide-footer
  263. centered
  264. title="Followers"
  265. body-class="list-group-flush p-0">
  266. <div class="list-group">
  267. <div class="list-group-item border-0" v-for="(user, index) in followers" :key="'follower_'+index">
  268. <div class="media">
  269. <a :href="user.url">
  270. <img class="mr-3 rounded-circle box-shadow" :src="user.avatar" :alt="user.username + '’s avatar'" width="30px">
  271. </a>
  272. <div class="media-body">
  273. <p class="mb-0" style="font-size: 14px">
  274. <a :href="user.url" class="font-weight-bold text-dark">
  275. {{user.username}}
  276. </a>
  277. </p>
  278. <p class="text-muted mb-0" style="font-size: 14px">
  279. {{user.display_name}}
  280. </p>
  281. </div>
  282. </div>
  283. </div>
  284. <div v-if="followerMore" class="list-group-item text-center" v-on:click="followersLoadMore()">
  285. <p class="mb-0 small text-muted font-weight-light cursor-pointer">Load more</p>
  286. </div>
  287. </div>
  288. </b-modal>
  289. <b-modal
  290. id="lightbox"
  291. ref="lightboxModal"
  292. hide-header
  293. hide-footer
  294. centered
  295. size="lg"
  296. body-class="p-0"
  297. >
  298. <div v-if="lightboxMedia" :class="lightboxMedia.filter_class">
  299. <img :src="lightboxMedia.url" class="img-fluid" style="min-height: 100%; min-width: 100%">
  300. </div>
  301. </b-modal>
  302. </div>
  303. </template>
  304. <style type="text/css" scoped>
  305. .postPresenterContainer {
  306. display: flex;
  307. align-items: center;
  308. background: #fff;
  309. }
  310. .word-break {
  311. word-break: break-all;
  312. }
  313. .small .custom-control-label {
  314. padding-top: 3px;
  315. }
  316. </style>
  317. <script type="text/javascript">
  318. export default {
  319. props: ['scope'],
  320. data() {
  321. return {
  322. config: {},
  323. page: 2,
  324. feed: [],
  325. profile: {},
  326. min_id: 0,
  327. max_id: 0,
  328. stories: {},
  329. suggestions: {},
  330. loading: true,
  331. replies: [],
  332. replyId: null,
  333. optionMenuState: false,
  334. modes: {
  335. 'mod': false,
  336. 'dark': false,
  337. 'notify': true,
  338. 'infinite': true
  339. },
  340. followers: [],
  341. followerCursor: 1,
  342. followerMore: true,
  343. following: [],
  344. followingCursor: 1,
  345. followingMore: true,
  346. lightboxMedia: false
  347. }
  348. },
  349. beforeMount() {
  350. axios.get('/api/v2/config')
  351. .then(res => {
  352. this.config = res.data;
  353. this.fetchTimelineApi();
  354. this.fetchProfile();
  355. });
  356. },
  357. mounted() {
  358. this.$nextTick(function () {
  359. $('[data-toggle="tooltip"]').tooltip()
  360. });
  361. },
  362. updated() {
  363. pixelfed.readmore();
  364. },
  365. methods: {
  366. fetchProfile() {
  367. axios.get('/api/v1/accounts/verify_credentials').then(res => {
  368. this.profile = res.data;
  369. $('.profile-card .loader').addClass('d-none');
  370. $('.profile-card .contents').removeClass('d-none');
  371. $('.profile-card .card-footer').removeClass('d-none');
  372. }).catch(err => {
  373. swal(
  374. 'Oops, something went wrong',
  375. 'Please reload the page.',
  376. 'error'
  377. );
  378. });
  379. },
  380. fetchTimelineApi() {
  381. let apiUrl = false;
  382. switch(this.scope) {
  383. case 'home':
  384. apiUrl = '/api/v1/timelines/home';
  385. break;
  386. case 'local':
  387. apiUrl = '/api/v1/timelines/public';
  388. break;
  389. case 'network':
  390. apiUrl = '/api/v1/timelines/network';
  391. break;
  392. }
  393. axios.get(apiUrl, {
  394. params: {
  395. max_id: this.max_id,
  396. limit: 4
  397. }
  398. }).then(res => {
  399. let data = res.data;
  400. this.feed.push(...data);
  401. let ids = data.map(status => status.id);
  402. this.min_id = Math.max(...ids);
  403. this.max_id = Math.min(...ids);
  404. $('.timeline .pagination').removeClass('d-none');
  405. this.loading = false;
  406. }).catch(err => {
  407. });
  408. },
  409. infiniteTimeline($state) {
  410. if(this.loading) {
  411. return;
  412. }
  413. let apiUrl = false;
  414. switch(this.scope) {
  415. case 'home':
  416. apiUrl = '/api/v1/timelines/home';
  417. break;
  418. case 'local':
  419. apiUrl = '/api/v1/timelines/public';
  420. break;
  421. case 'network':
  422. apiUrl = '/api/v1/timelines/network';
  423. break;
  424. }
  425. axios.get(apiUrl, {
  426. params: {
  427. max_id: this.max_id,
  428. limit: 4
  429. },
  430. }).then(res => {
  431. if (res.data.length && this.loading == false) {
  432. let data = res.data;
  433. this.feed.push(...data);
  434. let ids = data.map(status => status.id);
  435. this.min_id = Math.max(...ids);
  436. this.max_id = Math.min(...ids);
  437. this.page += 1;
  438. $state.loaded();
  439. this.loading = false;
  440. } else {
  441. $state.complete();
  442. }
  443. });
  444. },
  445. loadMore(event) {
  446. let homeTimeline = '/api/v1/timelines/home';
  447. let localTimeline = '/api/v1/timelines/public';
  448. let apiUrl = this.scope == 'home' ? homeTimeline : localTimeline;
  449. event.target.innerText = 'Loading...';
  450. axios.get(apiUrl, {
  451. params: {
  452. page: this.page,
  453. },
  454. }).then(res => {
  455. if (res.data.length && this.loading == false) {
  456. let data = res.data;
  457. let ids = data.map(status => status.id);
  458. this.min_id = Math.min(...ids);
  459. if(this.page == 1) {
  460. this.max_id = Math.max(...ids);
  461. }
  462. this.feed.push(...data);
  463. this.page += 1;
  464. this.loading = false;
  465. event.target.innerText = 'Load more posts';
  466. } else {
  467. }
  468. });
  469. },
  470. reportUrl(status) {
  471. let type = status.in_reply_to ? 'comment' : 'post';
  472. let id = status.id;
  473. return '/i/report?type=' + type + '&id=' + id;
  474. },
  475. commentFocus(status, $event) {
  476. if(this.replyId == status.id || status.comments_disabled) {
  477. return;
  478. }
  479. this.replies = {};
  480. this.replyId = status.id;
  481. this.fetchStatusComments(status, '');
  482. },
  483. likeStatus(status, $event) {
  484. if($('body').hasClass('loggedIn') == false) {
  485. return;
  486. }
  487. axios.post('/i/like', {
  488. item: status.id
  489. }).then(res => {
  490. status.favourites_count = res.data.count;
  491. status.favourited = !status.favourited;
  492. }).catch(err => {
  493. swal('Error', 'Something went wrong, please try again later.', 'error');
  494. });
  495. },
  496. shareStatus(status, $event) {
  497. if($('body').hasClass('loggedIn') == false) {
  498. return;
  499. }
  500. axios.post('/i/share', {
  501. item: status.id
  502. }).then(res => {
  503. status.reblogs_count = res.data.count;
  504. status.reblogged = !status.reblogged;
  505. }).catch(err => {
  506. swal('Error', 'Something went wrong, please try again later.', 'error');
  507. });
  508. },
  509. timestampFormat(timestamp) {
  510. let ts = new Date(timestamp);
  511. return ts.toDateString() + ' ' + ts.toLocaleTimeString();
  512. },
  513. editUrl(status) {
  514. return status.url + '/edit';
  515. },
  516. redirect(url) {
  517. window.location.href = url;
  518. return;
  519. },
  520. replyUrl(status) {
  521. let username = this.profile.username;
  522. let id = status.account.id == this.profile.id ? status.id : status.in_reply_to_id;
  523. return '/p/' + username + '/' + id;
  524. },
  525. mentionUrl(status) {
  526. let username = status.account.username;
  527. let id = status.id;
  528. return '/p/' + username + '/' + id;
  529. },
  530. statusOwner(status) {
  531. let sid = status.account.id;
  532. let uid = this.profile.id;
  533. if(sid == uid) {
  534. return true;
  535. } else {
  536. return false;
  537. }
  538. },
  539. fetchStatusComments(status, card) {
  540. axios.get('/api/v2/status/'+status.id+'/replies')
  541. .then(res => {
  542. let data = res.data;
  543. this.replies = _.reverse(data);
  544. }).catch(err => {
  545. })
  546. },
  547. muteProfile(status) {
  548. if($('body').hasClass('loggedIn') == false) {
  549. return;
  550. }
  551. axios.post('/i/mute', {
  552. type: 'user',
  553. item: status.account.id
  554. }).then(res => {
  555. this.feed = this.feed.filter(s => s.account.id !== status.account.id);
  556. swal('Success', 'You have successfully muted ' + status.account.acct, 'success');
  557. }).catch(err => {
  558. swal('Error', 'Something went wrong. Please try again later.', 'error');
  559. });
  560. },
  561. blockProfile(status) {
  562. if($('body').hasClass('loggedIn') == false) {
  563. return;
  564. }
  565. axios.post('/i/block', {
  566. type: 'user',
  567. item: status.account.id
  568. }).then(res => {
  569. this.feed = this.feed.filter(s => s.account.id !== status.account.id);
  570. swal('Success', 'You have successfully blocked ' + status.account.acct, 'success');
  571. }).catch(err => {
  572. swal('Error', 'Something went wrong. Please try again later.', 'error');
  573. });
  574. },
  575. deletePost(status, index) {
  576. if($('body').hasClass('loggedIn') == false || status.account.id !== this.profile.id) {
  577. return;
  578. }
  579. if(window.confirm('Are you sure you want to delete this post?') == false) {
  580. return;
  581. }
  582. axios.post('/i/delete', {
  583. type: 'status',
  584. item: status.id
  585. }).then(res => {
  586. this.feed.splice(index,1);
  587. swal('Success', 'You have successfully deleted this post', 'success');
  588. }).catch(err => {
  589. swal('Error', 'Something went wrong. Please try again later.', 'error');
  590. });
  591. },
  592. commentSubmit(status, $event) {
  593. let id = status.id;
  594. let form = $event.target;
  595. let input = $(form).find('input[name="comment"]');
  596. let comment = input.val();
  597. let comments = form.parentElement.parentElement.getElementsByClassName('comments')[0];
  598. axios.post('/i/comment', {
  599. item: id,
  600. comment: comment
  601. }).then(res => {
  602. form.reset();
  603. form.blur();
  604. this.replies.push(res.data.entity);
  605. });
  606. },
  607. moderatePost(status, action, $event) {
  608. let username = status.account.username;
  609. console.log('action: ' + action + ' status id' + status.id);
  610. switch(action) {
  611. case 'autocw':
  612. let msg = 'Are you sure you want to enforce CW for ' + username + ' ?';
  613. swal({
  614. title: 'Confirm',
  615. text: msg,
  616. icon: 'warning',
  617. buttons: true,
  618. dangerMode: true
  619. }).then(res => {
  620. if(res) {
  621. axios.post('/api/v2/moderator/action', {
  622. action: action,
  623. item_id: status.id,
  624. item_type: 'status'
  625. }).then(res => {
  626. swal('Success', 'Successfully enforced CW for ' + username, 'success');
  627. }).catch(err => {
  628. swal(
  629. 'Error',
  630. 'Something went wrong, please try again later.',
  631. 'error'
  632. );
  633. });
  634. }
  635. });
  636. break;
  637. case 'noautolink':
  638. msg = 'Are you sure you want to disable auto linking for ' + username + ' ?';
  639. swal({
  640. title: 'Confirm',
  641. text: msg,
  642. icon: 'warning',
  643. buttons: true,
  644. dangerMode: true
  645. }).then(res => {
  646. if(res) {
  647. axios.post('/api/v2/moderator/action', {
  648. action: action,
  649. item_id: status.id,
  650. item_type: 'status'
  651. }).then(res => {
  652. swal('Success', 'Successfully disabled autolinking for ' + username, 'success');
  653. }).catch(err => {
  654. swal(
  655. 'Error',
  656. 'Something went wrong, please try again later.',
  657. 'error'
  658. );
  659. });
  660. }
  661. });
  662. break;
  663. case 'unlisted':
  664. msg = 'Are you sure you want to unlist from timelines for ' + username + ' ?';
  665. swal({
  666. title: 'Confirm',
  667. text: msg,
  668. icon: 'warning',
  669. buttons: true,
  670. dangerMode: true
  671. }).then(res => {
  672. if(res) {
  673. axios.post('/api/v2/moderator/action', {
  674. action: action,
  675. item_id: status.id,
  676. item_type: 'status'
  677. }).then(res => {
  678. swal('Success', 'Successfully unlisted for ' + username, 'success');
  679. }).catch(err => {
  680. swal(
  681. 'Error',
  682. 'Something went wrong, please try again later.',
  683. 'error'
  684. );
  685. });
  686. }
  687. });
  688. break;
  689. case 'disable':
  690. msg = 'Are you sure you want to disable ' + username + '’s account ?';
  691. swal({
  692. title: 'Confirm',
  693. text: msg,
  694. icon: 'warning',
  695. buttons: true,
  696. dangerMode: true
  697. }).then(res => {
  698. if(res) {
  699. axios.post('/api/v2/moderator/action', {
  700. action: action,
  701. item_id: status.id,
  702. item_type: 'status'
  703. }).then(res => {
  704. swal('Success', 'Successfully disabled ' + username + '’s account', 'success');
  705. }).catch(err => {
  706. swal(
  707. 'Error',
  708. 'Something went wrong, please try again later.',
  709. 'error'
  710. );
  711. });
  712. }
  713. });
  714. break;
  715. case 'suspend':
  716. msg = 'Are you sure you want to suspend ' + username + '’s account ?';
  717. swal({
  718. title: 'Confirm',
  719. text: msg,
  720. icon: 'warning',
  721. buttons: true,
  722. dangerMode: true
  723. }).then(res => {
  724. if(res) {
  725. axios.post('/api/v2/moderator/action', {
  726. action: action,
  727. item_id: status.id,
  728. item_type: 'status'
  729. }).then(res => {
  730. swal('Success', 'Successfully suspend ' + username + '’s account', 'success');
  731. }).catch(err => {
  732. swal(
  733. 'Error',
  734. 'Something went wrong, please try again later.',
  735. 'error'
  736. );
  737. });
  738. }
  739. });
  740. break;
  741. }
  742. },
  743. toggleOptionsMenu() {
  744. this.optionMenuState = !this.optionMenuState;
  745. },
  746. modeModToggle() {
  747. this.modes.mod = !this.modes.mod;
  748. window.ls.set('pixelfed-classicui-settings', this.modes);
  749. },
  750. modeNotifyToggle() {
  751. this.modes.notify = !this.modes.notify;
  752. window.ls.set('pixelfed-classicui-settings', this.modes);
  753. },
  754. modeDarkToggle() {
  755. // todo: more graceful stylesheet change
  756. if(this.modes.dark == true) {
  757. this.modes.dark = false;
  758. $('link[data-stylesheet=dark]').remove();
  759. } else {
  760. this.modes.dark = true;
  761. let head = document.head;
  762. let link = document.createElement("link");
  763. link.type = "text/css";
  764. link.rel = "stylesheet";
  765. link.href = "/css/appdark.css";
  766. link.setAttribute('data-stylesheet','dark');
  767. head.appendChild(link);
  768. }
  769. window.ls.set('pixelfed-classicui-settings', this.modes);
  770. },
  771. modeInfiniteToggle() {
  772. this.modes.infinite = !this.modes.infinite
  773. window.ls.set('pixelfed-classicui-settings', this.modes);
  774. },
  775. followingModal() {
  776. if(this.following.length > 0) {
  777. this.$refs.followingModal.show();
  778. return;
  779. }
  780. axios.get('/api/v1/accounts/'+this.profile.id+'/following', {
  781. params: {
  782. page: this.followingCursor
  783. }
  784. })
  785. .then(res => {
  786. this.following = res.data;
  787. this.followingCursor++;
  788. });
  789. if(res.data.length < 10) {
  790. this.followingMore = false;
  791. }
  792. this.$refs.followingModal.show();
  793. },
  794. followersModal() {
  795. if(this.followers.length > 0) {
  796. this.$refs.followerModal.show();
  797. return;
  798. }
  799. axios.get('/api/v1/accounts/'+this.profile.id+'/followers', {
  800. params: {
  801. page: this.followerCursor
  802. }
  803. })
  804. .then(res => {
  805. this.followers = res.data;
  806. this.followerCursor++;
  807. })
  808. if(res.data.length < 10) {
  809. this.followerMore = false;
  810. }
  811. this.$refs.followerModal.show();
  812. },
  813. followingLoadMore() {
  814. axios.get('/api/v1/accounts/'+this.profile.id+'/following', {
  815. params: {
  816. page: this.followingCursor
  817. }
  818. })
  819. .then(res => {
  820. if(res.data.length > 0) {
  821. this.following.push(...res.data);
  822. this.followingCursor++;
  823. }
  824. if(res.data.length < 10) {
  825. this.followingMore = false;
  826. }
  827. });
  828. },
  829. followersLoadMore() {
  830. axios.get('/api/v1/accounts/'+this.profile.id+'/followers', {
  831. params: {
  832. page: this.followerCursor
  833. }
  834. })
  835. .then(res => {
  836. if(res.data.length > 0) {
  837. this.followers.push(...res.data);
  838. this.followerCursor++;
  839. }
  840. if(res.data.length < 10) {
  841. this.followerMore = false;
  842. }
  843. });
  844. },
  845. lightbox(src) {
  846. this.lightboxMedia = src;
  847. this.$refs.lightboxModal.show();
  848. },
  849. expLc(status) {
  850. if(this.config.ab.lc == false) {
  851. return true;
  852. }
  853. if(this.statusOwner(status) == true) {
  854. return true;
  855. }
  856. return false;
  857. }
  858. }
  859. }
  860. </script>