Timeline.vue 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012
  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 style="padding-top:10px;">
  6. <div v-if="loading" class="text-center">
  7. <div class="spinner-border" role="status">
  8. <span class="sr-only">Loading...</span>
  9. </div>
  10. </div>
  11. <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}`">
  12. <div class="card-header d-inline-flex align-items-center bg-white">
  13. <img v-bind:src="status.account.avatar" width="32px" height="32px" style="border-radius: 32px;">
  14. <a class="username font-weight-bold pl-2 text-dark" v-bind:href="status.account.url">
  15. {{status.account.username}}
  16. </a>
  17. <div class="text-right" style="flex-grow:1;">
  18. <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">
  19. <span class="fas fa-ellipsis-v fa-lg text-muted"></span>
  20. </button>
  21. <div class="dropdown-menu dropdown-menu-right">
  22. <a class="dropdown-item font-weight-bold" :href="status.url">Go to post</a>
  23. <!-- <a class="dropdown-item font-weight-bold" href="#">Share</a>
  24. <a class="dropdown-item font-weight-bold" href="#">Embed</a> -->
  25. <span v-if="statusOwner(status) == false">
  26. <a class="dropdown-item font-weight-bold" :href="reportUrl(status)">Report</a>
  27. <a class="dropdown-item font-weight-bold" v-on:click="muteProfile(status)">Mute Profile</a>
  28. <a class="dropdown-item font-weight-bold" v-on:click="blockProfile(status)">Block Profile</a>
  29. </span>
  30. <span v-if="statusOwner(status) == true">
  31. <a class="dropdown-item font-weight-bold text-danger" v-on:click="deletePost(status)">Delete</a>
  32. </span>
  33. <span v-if="profile.is_admin == true && modes.mod == true">
  34. <div class="dropdown-divider"></div>
  35. <a v-if="!statusOwner(status)" class="dropdown-item font-weight-bold text-danger" v-on:click="deletePost(status)">Delete</a>
  36. <div class="dropdown-divider"></div>
  37. <h6 class="dropdown-header">Mod Tools</h6>
  38. <a class="dropdown-item font-weight-bold" v-on:click="moderatePost(status, 'autocw')">
  39. <p class="mb-0" data-toggle="tooltip" data-placement="bottom" title="Adds a CW to every post made by this account.">Enforce CW</p>
  40. </a>
  41. <a class="dropdown-item font-weight-bold" v-on:click="moderatePost(status, 'noautolink')">
  42. <p class="mb-0" title="Do not transform mentions, hashtags or urls into HTML.">No Autolinking</p>
  43. </a>
  44. <a class="dropdown-item font-weight-bold" v-on:click="moderatePost(status, 'unlisted')">
  45. <p class="mb-0" title="Removes account from public/network timelines.">Unlisted Posts</p>
  46. </a>
  47. <a class="dropdown-item font-weight-bold" v-on:click="moderatePost(status, 'disable')">
  48. <p class="mb-0" title="Temporarily disable account until next time user log in.">Disable Account</p>
  49. </a>
  50. <a class="dropdown-item font-weight-bold" v-on:click="moderatePost(status, 'suspend')">
  51. <p class="mb-0" title="This prevents any new interactions, without deleting existing data.">Suspend Account</p>
  52. </a>
  53. </span>
  54. </div>
  55. </div>
  56. </div>
  57. <div class="postPresenterContainer">
  58. <div v-if="status.pf_type === 'photo'" class="w-100">
  59. <photo-presenter :status="status" v-on:lightbox="lightbox"></photo-presenter>
  60. </div>
  61. <div v-else-if="status.pf_type === 'video'" class="w-100">
  62. <video-presenter :status="status"></video-presenter>
  63. </div>
  64. <div v-else-if="status.pf_type === 'photo:album'" class="w-100">
  65. <photo-album-presenter :status="status" v-on:lightbox="lightbox"></photo-album-presenter>
  66. </div>
  67. <div v-else-if="status.pf_type === 'video:album'" class="w-100">
  68. <video-album-presenter :status="status"></video-album-presenter>
  69. </div>
  70. <div v-else-if="status.pf_type === 'photo:video:album'" class="w-100">
  71. <mixed-album-presenter :status="status" v-on:lightbox="lightbox"></mixed-album-presenter>
  72. </div>
  73. <div v-else class="w-100">
  74. <p class="text-center p-0 font-weight-bold text-white">Error: Problem rendering preview.</p>
  75. </div>
  76. </div>
  77. <div class="card-body">
  78. <div class="reactions my-1">
  79. <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>
  80. <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>
  81. <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>
  82. </div>
  83. <div class="likes font-weight-bold" v-if="expLc(status) == true">
  84. <span class="like-count">{{status.favourites_count}}</span> {{status.favourites_count == 1 ? 'like' : 'likes'}}
  85. </div>
  86. <div class="caption">
  87. <p class="mb-2 read-more" style="overflow: hidden;">
  88. <span class="username font-weight-bold">
  89. <bdi><a class="text-dark" :href="status.account.url">{{status.account.username}}</a></bdi>
  90. </span>
  91. <span v-html="status.content"></span>
  92. </p>
  93. </div>
  94. <div class="comments" v-if="status.id == replyId && !status.comments_disabled">
  95. <p class="mb-0 d-flex justify-content-between align-items-top read-more" style="overflow-y: hidden;" v-for="(reply, index) in replies">
  96. <span>
  97. <a class="text-dark font-weight-bold mr-1" :href="reply.account.url">{{reply.account.username}}</a>
  98. <span v-html="reply.content"></span>
  99. </span>
  100. <span class="mb-0" style="min-width:38px">
  101. <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>
  102. <post-menu :status="reply" :profile="profile" size="sm" :modal="'true'" :feed="feed" class="d-inline-flex pl-2"></post-menu>
  103. </span>
  104. </p>
  105. </div>
  106. <div class="timestamp mt-2">
  107. <p class="small text-uppercase mb-0">
  108. <a :href="status.url" class="text-muted">
  109. <timeago :datetime="status.created_at" :auto-update="60" :converter-options="{includeSeconds:true}" :title="timestampFormat(status.created_at)" v-b-tooltip.hover.bottom></timeago>
  110. </a>
  111. </p>
  112. </div>
  113. </div>
  114. <div class="card-footer bg-white" v-if="status.id == replyId">
  115. <form class="" v-on:submit.prevent="commentSubmit(status, $event)">
  116. <input type="hidden" name="item" value="">
  117. <input class="form-control status-reply-input" name="comment" placeholder="Add a comment…" autocomplete="off">
  118. </form>
  119. </div>
  120. </div>
  121. <div v-if="modes.infinite == true && !loading && feed.length > 0">
  122. <div class="card">
  123. <div class="card-body">
  124. <infinite-loading @infinite="infiniteTimeline" :distance="800">
  125. <div slot="no-more" class="font-weight-bold">No more posts to load</div>
  126. <div slot="no-results" class="font-weight-bold">No posts found</div>
  127. </infinite-loading>
  128. </div>
  129. </div>
  130. </div>
  131. <div v-if="modes.infinite == false && !loading && feed.length > 0" class="pagination">
  132. <p class="btn btn-outline-secondary font-weight-bold btn-block" v-on:click="loadMore">Load more posts</p>
  133. </div>
  134. <div v-if="!loading && scope == 'home' && feed.length == 0">
  135. <div class="card">
  136. <div class="card-body text-center">
  137. <p class="h2 font-weight-lighter p-5">Hello, {{profile.acct}}</p>
  138. <p class="text-lighter"><i class="fas fa-camera-retro fa-5x"></i></p>
  139. <p class="h3 font-weight-lighter p-5">Start following people to build your timeline.</p>
  140. <p><a href="/discover" class="btn btn-primary font-weight-bold py-0">Discover new people and posts</a></p>
  141. </div>
  142. </div>
  143. </div>
  144. </div>
  145. </div>
  146. <div class="col-md-4 col-lg-4 pt-2 my-3 order-1 order-md-2 d-none d-md-block">
  147. <div class="position-sticky" style="top:68px;">
  148. <div class="mb-4">
  149. <div class="">
  150. <div class="">
  151. <div class="media d-flex align-items-center">
  152. <a :href="profile.url">
  153. <img class="mr-3 rounded-circle box-shadow" :src="profile.avatar || '/storage/avatars/default.png'" alt="avatar" width="64px" height="64px">
  154. </a>
  155. <div class="media-body d-flex justify-content-between word-break" >
  156. <div>
  157. <p class="mb-0 px-0 font-weight-bold"><a :href="profile.url" class="text-dark">{{profile.username || 'loading...'}}</a></p>
  158. <p class="my-0 text-muted pb-0">{{profile.display_name || 'loading...'}}</p>
  159. </div>
  160. <div class="ml-2">
  161. <a :class="[optionMenuState == true ? 'text-primary' :'text-muted']" v-on:click="toggleOptionsMenu()"><i class="fas fa-cog fa-lg"></i></a>
  162. </div>
  163. </div>
  164. </div>
  165. </div>
  166. <!-- <div class="card-footer bg-white py-1 d-none">
  167. <div class="d-flex justify-content-between text-center">
  168. <span class="pl-3 cursor-pointer" v-on:click="redirect(profile.url)">
  169. <p class="mb-0 font-weight-bold">{{profile.statuses_count}}</p>
  170. <p class="mb-0 small text-muted">Posts</p>
  171. </span>
  172. <span class="cursor-pointer" v-on:click="followersModal()">
  173. <p class="mb-0 font-weight-bold">{{profile.followers_count}}</p>
  174. <p class="mb-0 small text-muted">Followers</p>
  175. </span>
  176. <span class="pr-3 cursor-pointer" v-on:click="followingModal()">
  177. <p class="mb-0 font-weight-bold">{{profile.following_count}}</p>
  178. <p class="mb-0 small text-muted">Following</p>
  179. </span>
  180. </div>
  181. </div> -->
  182. </div>
  183. </div>
  184. <div v-if="optionMenuState == true" class="mb-4">
  185. <div class="card options-card">
  186. <div class="card-body small">
  187. <div v-if="profile.is_admin" class="custom-control custom-switch mb-3">
  188. <input type="checkbox" class="custom-control-input" id="mode-mod" v-on:click="modeModToggle()" v-model="modes.mod">
  189. <label class="custom-control-label font-weight-bold" for="mode-mod">Moderator Mode</label>
  190. </div>
  191. <!-- <div class="custom-control custom-switch mb-3">
  192. <input type="checkbox" class="custom-control-input" id="mode-notify" v-on:click="modeNotifyToggle()" v-model="!modes.notify">
  193. <label class="custom-control-label font-weight-bold" for="mode-notify">Disable Notifications</label>
  194. </div> -->
  195. <div class="custom-control custom-switch">
  196. <input type="checkbox" class="custom-control-input" id="mode-infinite" v-on:click="modeInfiniteToggle()" v-model="modes.infinite">
  197. <label class="custom-control-label font-weight-bold" for="mode-infinite">Enable Infinite Scroll</label>
  198. </div>
  199. <hr>
  200. <p class="font-weight-bold">BETA FEATURES</p>
  201. <div class="alert alert-primary font-weight-bold text-center">Experimental features have been moved to the <a href="/settings/labs">Labs</a> settings page.</div>
  202. </div>
  203. </div>
  204. </div>
  205. <div v-show="modes.notify == true" class="mb-4">
  206. <notification-card></notification-card>
  207. </div>
  208. <div v-show="suggestions.length && config.ab && config.ab.rec == true" class="mb-4">
  209. <div class="card">
  210. <div class="card-header bg-white text-center">
  211. <div class="small text-dark text-uppercase font-weight-bold">Suggestions</div>
  212. </div>
  213. <div class="card-body pt-0">
  214. <div v-for="(rec, index) in suggestions" class="media align-items-center mt-3">
  215. <a :href="'/'+rec.username">
  216. <img :src="rec.avatar" width="32px" height="32px" class="rounded-circle mr-3">
  217. </a>
  218. <div class="media-body">
  219. <p class="mb-0 font-weight-bold small">
  220. <a :href="'/'+rec.username" class="text-decoration-none text-dark">
  221. {{rec.username}}
  222. </a>
  223. </p>
  224. <p class="mb-0 small text-muted">{{rec.message}}</p>
  225. </div>
  226. <a class="font-weight-bold small" href="#" @click.prevent="expRecFollow(rec.id, index)">Follow</a>
  227. </div>
  228. </div>
  229. </div>
  230. </div>
  231. <footer>
  232. <div class="container pb-5">
  233. <p class="mb-0 text-uppercase font-weight-bold text-muted small">
  234. <a href="/site/about" class="text-dark pr-2">About Us</a>
  235. <a href="/site/help" class="text-dark pr-2">Help</a>
  236. <a href="/site/open-source" class="text-dark pr-2">Open Source</a>
  237. <a href="/site/language" class="text-dark pr-2">Language</a>
  238. <a href="/site/terms" class="text-dark pr-2">Terms</a>
  239. <a href="/site/privacy" class="text-dark pr-2">Privacy</a>
  240. <a href="/site/platform" class="text-dark pr-2">API</a>
  241. </p>
  242. <p class="mb-0 text-uppercase font-weight-bold text-muted small">
  243. <a href="http://pixelfed.org" class="text-muted" rel="noopener" title="" data-toggle="tooltip">Powered by PixelFed</a>
  244. </p>
  245. </div>
  246. </footer>
  247. </div>
  248. </div>
  249. </div>
  250. <!-- <b-modal ref="followingModal"
  251. id="following-modal"
  252. hide-footer
  253. centered
  254. title="Following"
  255. body-class="list-group-flush p-0">
  256. <div class="list-group">
  257. <div class="list-group-item border-0" v-for="(user, index) in following" :key="'following_'+index">
  258. <div class="media">
  259. <a :href="user.url">
  260. <img class="mr-3 rounded-circle box-shadow" :src="user.avatar" :alt="user.username + '’s avatar'" width="30px">
  261. </a>
  262. <div class="media-body">
  263. <p class="mb-0" style="font-size: 14px">
  264. <a :href="user.url" class="font-weight-bold text-dark">
  265. {{user.username}}
  266. </a>
  267. </p>
  268. <p class="text-muted mb-0" style="font-size: 14px">
  269. {{user.display_name}}
  270. </p>
  271. </div>
  272. <a class="btn btn-outline-secondary btn-sm" href="#" @click.prevent="followModalAction(user.id, index, 'following')">Unfollow</a>
  273. </div>
  274. </div>
  275. <div v-if="following.length == 0" class="list-group-item border-0">
  276. <div class="list-group-item border-0">
  277. <p class="p-3 text-center mb-0 lead">You are not following anyone.</p>
  278. </div>
  279. </div>
  280. <div v-if="following.length != 0 && followingMore" class="list-group-item text-center" v-on:click="followingLoadMore()">
  281. <p class="mb-0 small text-muted font-weight-light cursor-pointer">Load more</p>
  282. </div>
  283. </div>
  284. </b-modal>
  285. <b-modal ref="followerModal"
  286. id="follower-modal"
  287. hide-footer
  288. centered
  289. title="Followers"
  290. body-class="list-group-flush p-0">
  291. <div class="list-group">
  292. <div class="list-group-item border-0" v-for="(user, index) in followers" :key="'follower_'+index">
  293. <div class="media">
  294. <a :href="user.url">
  295. <img class="mr-3 rounded-circle box-shadow" :src="user.avatar" :alt="user.username + '’s avatar'" width="30px">
  296. </a>
  297. <div class="media-body">
  298. <p class="mb-0" style="font-size: 14px">
  299. <a :href="user.url" class="font-weight-bold text-dark">
  300. {{user.username}}
  301. </a>
  302. </p>
  303. <p class="text-muted mb-0" style="font-size: 14px">
  304. {{user.display_name}}
  305. </p>
  306. </div>
  307. </div>
  308. </div>
  309. <div v-if="followerMore" class="list-group-item text-center" v-on:click="followersLoadMore()">
  310. <p class="mb-0 small text-muted font-weight-light cursor-pointer">Load more</p>
  311. </div>
  312. </div>
  313. </b-modal> -->
  314. <b-modal
  315. id="lightbox"
  316. ref="lightboxModal"
  317. hide-header
  318. hide-footer
  319. centered
  320. size="lg"
  321. body-class="p-0"
  322. >
  323. <div v-if="lightboxMedia" :class="lightboxMedia.filter_class">
  324. <img :src="lightboxMedia.url" class="img-fluid" style="min-height: 100%; min-width: 100%">
  325. </div>
  326. </b-modal>
  327. </div>
  328. </template>
  329. <style type="text/css" scoped>
  330. .postPresenterContainer {
  331. display: flex;
  332. align-items: center;
  333. background: #fff;
  334. }
  335. .word-break {
  336. word-break: break-all;
  337. }
  338. .small .custom-control-label {
  339. padding-top: 3px;
  340. }
  341. </style>
  342. <script type="text/javascript">
  343. export default {
  344. props: ['scope'],
  345. data() {
  346. return {
  347. config: {},
  348. page: 2,
  349. feed: [],
  350. profile: {},
  351. min_id: 0,
  352. max_id: 0,
  353. stories: {},
  354. suggestions: {},
  355. loading: true,
  356. replies: [],
  357. replyId: null,
  358. optionMenuState: false,
  359. modes: {
  360. 'mod': false,
  361. 'dark': false,
  362. 'notify': true,
  363. 'infinite': true
  364. },
  365. followers: [],
  366. followerCursor: 1,
  367. followerMore: true,
  368. following: [],
  369. followingCursor: 1,
  370. followingMore: true,
  371. lightboxMedia: false
  372. }
  373. },
  374. beforeMount() {
  375. axios.get('/api/v2/config')
  376. .then(res => {
  377. this.config = res.data;
  378. this.fetchTimelineApi();
  379. if(window.outerWidth > 767) {
  380. this.fetchProfile();
  381. }
  382. });
  383. },
  384. mounted() {
  385. if($('link[data-stylesheet="dark"]').length != 0) {
  386. this.modes.dark = true;
  387. }
  388. this.$nextTick(function () {
  389. $('[data-toggle="tooltip"]').tooltip()
  390. });
  391. },
  392. updated() {
  393. pixelfed.readmore();
  394. },
  395. methods: {
  396. fetchProfile() {
  397. axios.get('/api/v1/accounts/verify_credentials').then(res => {
  398. this.profile = res.data;
  399. if(this.profile.is_admin == true) {
  400. this.modes.mod = true;
  401. }
  402. $('.profile-card .loader').addClass('d-none');
  403. $('.profile-card .contents').removeClass('d-none');
  404. $('.profile-card .card-footer').removeClass('d-none');
  405. }).catch(err => {
  406. swal(
  407. 'Oops, something went wrong',
  408. 'Please reload the page.',
  409. 'error'
  410. );
  411. });
  412. },
  413. fetchTimelineApi() {
  414. let apiUrl = false;
  415. switch(this.scope) {
  416. case 'home':
  417. apiUrl = '/api/v1/timelines/home';
  418. break;
  419. case 'local':
  420. apiUrl = '/api/v1/timelines/public';
  421. break;
  422. case 'network':
  423. apiUrl = '/api/v1/timelines/network';
  424. break;
  425. }
  426. axios.get(apiUrl, {
  427. params: {
  428. max_id: this.max_id,
  429. limit: 6
  430. }
  431. }).then(res => {
  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. $('.timeline .pagination').removeClass('d-none');
  438. this.loading = false;
  439. if(window.outerWidth > 767) {
  440. this.expRec();
  441. }
  442. }).catch(err => {
  443. });
  444. },
  445. infiniteTimeline($state) {
  446. if(this.loading) {
  447. return;
  448. }
  449. let apiUrl = false;
  450. switch(this.scope) {
  451. case 'home':
  452. apiUrl = '/api/v1/timelines/home';
  453. break;
  454. case 'local':
  455. apiUrl = '/api/v1/timelines/public';
  456. break;
  457. case 'network':
  458. apiUrl = '/api/v1/timelines/network';
  459. break;
  460. }
  461. axios.get(apiUrl, {
  462. params: {
  463. max_id: this.max_id,
  464. limit: 6
  465. },
  466. }).then(res => {
  467. if (res.data.length && this.loading == false) {
  468. let data = res.data;
  469. this.feed.push(...data);
  470. let ids = data.map(status => status.id);
  471. this.min_id = Math.max(...ids);
  472. this.max_id = Math.min(...ids);
  473. this.page += 1;
  474. $state.loaded();
  475. this.loading = false;
  476. } else {
  477. $state.complete();
  478. }
  479. });
  480. },
  481. loadMore(event) {
  482. let homeTimeline = '/api/v1/timelines/home';
  483. let localTimeline = '/api/v1/timelines/public';
  484. let apiUrl = this.scope == 'home' ? homeTimeline : localTimeline;
  485. event.target.innerText = 'Loading...';
  486. axios.get(apiUrl, {
  487. params: {
  488. page: this.page,
  489. },
  490. }).then(res => {
  491. if (res.data.length && this.loading == false) {
  492. let data = res.data;
  493. let ids = data.map(status => status.id);
  494. this.min_id = Math.min(...ids);
  495. if(this.page == 1) {
  496. this.max_id = Math.max(...ids);
  497. }
  498. this.feed.push(...data);
  499. this.page += 1;
  500. this.loading = false;
  501. event.target.innerText = 'Load more posts';
  502. } else {
  503. }
  504. });
  505. },
  506. reportUrl(status) {
  507. let type = status.in_reply_to ? 'comment' : 'post';
  508. let id = status.id;
  509. return '/i/report?type=' + type + '&id=' + id;
  510. },
  511. commentFocus(status, $event) {
  512. if(this.replyId == status.id || status.comments_disabled) {
  513. return;
  514. }
  515. this.replies = {};
  516. this.replyId = status.id;
  517. this.fetchStatusComments(status, '');
  518. },
  519. likeStatus(status, $event) {
  520. if($('body').hasClass('loggedIn') == false) {
  521. return;
  522. }
  523. axios.post('/i/like', {
  524. item: status.id
  525. }).then(res => {
  526. status.favourites_count = res.data.count;
  527. status.favourited = !status.favourited;
  528. }).catch(err => {
  529. swal('Error', 'Something went wrong, please try again later.', 'error');
  530. });
  531. },
  532. shareStatus(status, $event) {
  533. if($('body').hasClass('loggedIn') == false) {
  534. return;
  535. }
  536. axios.post('/i/share', {
  537. item: status.id
  538. }).then(res => {
  539. status.reblogs_count = res.data.count;
  540. status.reblogged = !status.reblogged;
  541. }).catch(err => {
  542. swal('Error', 'Something went wrong, please try again later.', 'error');
  543. });
  544. },
  545. timestampFormat(timestamp) {
  546. let ts = new Date(timestamp);
  547. return ts.toDateString() + ' ' + ts.toLocaleTimeString();
  548. },
  549. editUrl(status) {
  550. return status.url + '/edit';
  551. },
  552. redirect(url) {
  553. window.location.href = url;
  554. return;
  555. },
  556. replyUrl(status) {
  557. let username = this.profile.username;
  558. let id = status.account.id == this.profile.id ? status.id : status.in_reply_to_id;
  559. return '/p/' + username + '/' + id;
  560. },
  561. mentionUrl(status) {
  562. let username = status.account.username;
  563. let id = status.id;
  564. return '/p/' + username + '/' + id;
  565. },
  566. statusOwner(status) {
  567. let sid = status.account.id;
  568. let uid = this.profile.id;
  569. if(sid == uid) {
  570. return true;
  571. } else {
  572. return false;
  573. }
  574. },
  575. fetchStatusComments(status, card) {
  576. axios.get('/api/v2/status/'+status.id+'/replies')
  577. .then(res => {
  578. let data = res.data;
  579. this.replies = _.reverse(data);
  580. }).catch(err => {
  581. })
  582. },
  583. muteProfile(status) {
  584. if($('body').hasClass('loggedIn') == false) {
  585. return;
  586. }
  587. axios.post('/i/mute', {
  588. type: 'user',
  589. item: status.account.id
  590. }).then(res => {
  591. this.feed = this.feed.filter(s => s.account.id !== status.account.id);
  592. swal('Success', 'You have successfully muted ' + status.account.acct, 'success');
  593. }).catch(err => {
  594. swal('Error', 'Something went wrong. Please try again later.', 'error');
  595. });
  596. },
  597. blockProfile(status) {
  598. if($('body').hasClass('loggedIn') == false) {
  599. return;
  600. }
  601. axios.post('/i/block', {
  602. type: 'user',
  603. item: status.account.id
  604. }).then(res => {
  605. this.feed = this.feed.filter(s => s.account.id !== status.account.id);
  606. swal('Success', 'You have successfully blocked ' + status.account.acct, 'success');
  607. }).catch(err => {
  608. swal('Error', 'Something went wrong. Please try again later.', 'error');
  609. });
  610. },
  611. deletePost(status, index) {
  612. if($('body').hasClass('loggedIn') == false || this.ownerOrAdmin(status) == false) {
  613. return;
  614. }
  615. if(window.confirm('Are you sure you want to delete this post?') == false) {
  616. return;
  617. }
  618. axios.post('/i/delete', {
  619. type: 'status',
  620. item: status.id
  621. }).then(res => {
  622. this.feed.splice(index,1);
  623. swal('Success', 'You have successfully deleted this post', 'success');
  624. }).catch(err => {
  625. swal('Error', 'Something went wrong. Please try again later.', 'error');
  626. });
  627. },
  628. commentSubmit(status, $event) {
  629. let id = status.id;
  630. let form = $event.target;
  631. let input = $(form).find('input[name="comment"]');
  632. let comment = input.val();
  633. let comments = form.parentElement.parentElement.getElementsByClassName('comments')[0];
  634. axios.post('/i/comment', {
  635. item: id,
  636. comment: comment
  637. }).then(res => {
  638. form.reset();
  639. form.blur();
  640. this.replies.push(res.data.entity);
  641. });
  642. },
  643. moderatePost(status, action, $event) {
  644. let username = status.account.username;
  645. console.log('action: ' + action + ' status id' + status.id);
  646. switch(action) {
  647. case 'autocw':
  648. let msg = 'Are you sure you want to enforce CW for ' + username + ' ?';
  649. swal({
  650. title: 'Confirm',
  651. text: msg,
  652. icon: 'warning',
  653. buttons: true,
  654. dangerMode: true
  655. }).then(res => {
  656. if(res) {
  657. axios.post('/api/v2/moderator/action', {
  658. action: action,
  659. item_id: status.id,
  660. item_type: 'status'
  661. }).then(res => {
  662. swal('Success', 'Successfully enforced CW for ' + username, 'success');
  663. }).catch(err => {
  664. swal(
  665. 'Error',
  666. 'Something went wrong, please try again later.',
  667. 'error'
  668. );
  669. });
  670. }
  671. });
  672. break;
  673. case 'noautolink':
  674. msg = 'Are you sure you want to disable auto linking for ' + username + ' ?';
  675. swal({
  676. title: 'Confirm',
  677. text: msg,
  678. icon: 'warning',
  679. buttons: true,
  680. dangerMode: true
  681. }).then(res => {
  682. if(res) {
  683. axios.post('/api/v2/moderator/action', {
  684. action: action,
  685. item_id: status.id,
  686. item_type: 'status'
  687. }).then(res => {
  688. swal('Success', 'Successfully disabled autolinking for ' + username, 'success');
  689. }).catch(err => {
  690. swal(
  691. 'Error',
  692. 'Something went wrong, please try again later.',
  693. 'error'
  694. );
  695. });
  696. }
  697. });
  698. break;
  699. case 'unlisted':
  700. msg = 'Are you sure you want to unlist from timelines for ' + username + ' ?';
  701. swal({
  702. title: 'Confirm',
  703. text: msg,
  704. icon: 'warning',
  705. buttons: true,
  706. dangerMode: true
  707. }).then(res => {
  708. if(res) {
  709. axios.post('/api/v2/moderator/action', {
  710. action: action,
  711. item_id: status.id,
  712. item_type: 'status'
  713. }).then(res => {
  714. swal('Success', 'Successfully unlisted for ' + username, 'success');
  715. }).catch(err => {
  716. swal(
  717. 'Error',
  718. 'Something went wrong, please try again later.',
  719. 'error'
  720. );
  721. });
  722. }
  723. });
  724. break;
  725. case 'disable':
  726. msg = 'Are you sure you want to disable ' + username + '’s account ?';
  727. swal({
  728. title: 'Confirm',
  729. text: msg,
  730. icon: 'warning',
  731. buttons: true,
  732. dangerMode: true
  733. }).then(res => {
  734. if(res) {
  735. axios.post('/api/v2/moderator/action', {
  736. action: action,
  737. item_id: status.id,
  738. item_type: 'status'
  739. }).then(res => {
  740. swal('Success', 'Successfully disabled ' + username + '’s account', 'success');
  741. }).catch(err => {
  742. swal(
  743. 'Error',
  744. 'Something went wrong, please try again later.',
  745. 'error'
  746. );
  747. });
  748. }
  749. });
  750. break;
  751. case 'suspend':
  752. msg = 'Are you sure you want to suspend ' + username + '’s account ?';
  753. swal({
  754. title: 'Confirm',
  755. text: msg,
  756. icon: 'warning',
  757. buttons: true,
  758. dangerMode: true
  759. }).then(res => {
  760. if(res) {
  761. axios.post('/api/v2/moderator/action', {
  762. action: action,
  763. item_id: status.id,
  764. item_type: 'status'
  765. }).then(res => {
  766. swal('Success', 'Successfully suspend ' + username + '’s account', 'success');
  767. }).catch(err => {
  768. swal(
  769. 'Error',
  770. 'Something went wrong, please try again later.',
  771. 'error'
  772. );
  773. });
  774. }
  775. });
  776. break;
  777. }
  778. },
  779. toggleOptionsMenu() {
  780. this.optionMenuState = !this.optionMenuState;
  781. },
  782. modeModToggle() {
  783. this.modes.mod = !this.modes.mod;
  784. //window.ls.set('pixelfed-classicui-settings', this.modes);
  785. },
  786. modeNotifyToggle() {
  787. this.modes.notify = !this.modes.notify;
  788. //window.ls.set('pixelfed-classicui-settings', this.modes);
  789. },
  790. modeDarkToggle() {
  791. // todo: more graceful stylesheet change
  792. if(this.modes.dark == true) {
  793. axios.post('/i/metro/dark-mode', {
  794. mode: 'light'
  795. }).then(res => {
  796. $('link[data-stylesheet=dark]')
  797. .attr('data-stylesheet', 'light')
  798. .attr('href', '/css/app.css?v=' + Date.now());
  799. this.modes.dark = false;
  800. });
  801. } else {
  802. axios.post('/i/metro/dark-mode', {
  803. mode: 'dark'
  804. }).then(res => {
  805. $('link[data-stylesheet=light]')
  806. .attr('data-stylesheet', 'dark')
  807. .attr('href', '/css/appdark.css?v=' + Date.now());
  808. this.modes.dark = true;
  809. });
  810. }
  811. //window.ls.set('pixelfed-classicui-settings', this.modes);
  812. },
  813. modeInfiniteToggle() {
  814. this.modes.infinite = !this.modes.infinite
  815. //window.ls.set('pixelfed-classicui-settings', this.modes);
  816. },
  817. followingModal() {
  818. if(this.following.length > 0) {
  819. this.$refs.followingModal.show();
  820. return;
  821. }
  822. axios.get('/api/v1/accounts/'+this.profile.id+'/following', {
  823. params: {
  824. page: this.followingCursor
  825. }
  826. })
  827. .then(res => {
  828. this.following = res.data;
  829. this.followingCursor++;
  830. });
  831. if(res.data.length < 10) {
  832. this.followingMore = false;
  833. }
  834. this.$refs.followingModal.show();
  835. },
  836. followersModal() {
  837. if(this.followers.length > 0) {
  838. this.$refs.followerModal.show();
  839. return;
  840. }
  841. axios.get('/api/v1/accounts/'+this.profile.id+'/followers', {
  842. params: {
  843. page: this.followerCursor
  844. }
  845. })
  846. .then(res => {
  847. this.followers = res.data;
  848. this.followerCursor++;
  849. })
  850. if(res.data.length < 10) {
  851. this.followerMore = false;
  852. }
  853. this.$refs.followerModal.show();
  854. },
  855. followingLoadMore() {
  856. axios.get('/api/v1/accounts/'+this.profile.id+'/following', {
  857. params: {
  858. page: this.followingCursor
  859. }
  860. })
  861. .then(res => {
  862. if(res.data.length > 0) {
  863. this.following.push(...res.data);
  864. this.followingCursor++;
  865. }
  866. if(res.data.length < 10) {
  867. this.followingMore = false;
  868. }
  869. });
  870. },
  871. followersLoadMore() {
  872. axios.get('/api/v1/accounts/'+this.profile.id+'/followers', {
  873. params: {
  874. page: this.followerCursor
  875. }
  876. })
  877. .then(res => {
  878. if(res.data.length > 0) {
  879. this.followers.push(...res.data);
  880. this.followerCursor++;
  881. }
  882. if(res.data.length < 10) {
  883. this.followerMore = false;
  884. }
  885. });
  886. },
  887. lightbox(src) {
  888. this.lightboxMedia = src;
  889. this.$refs.lightboxModal.show();
  890. },
  891. expLc(status) {
  892. if(this.config.ab.lc == false) {
  893. return true;
  894. }
  895. if(this.statusOwner(status) == true) {
  896. return true;
  897. }
  898. return false;
  899. },
  900. expRec() {
  901. if(this.config.ab.rec == false) {
  902. return;
  903. }
  904. axios.get('/api/local/exp/rec')
  905. .then(res => {
  906. this.suggestions = res.data;
  907. })
  908. },
  909. expRecFollow(id, index) {
  910. if(this.config.ab.rec == false) {
  911. return;
  912. }
  913. axios.post('/i/follow', {
  914. item: id
  915. }).then(res => {
  916. this.suggestions.splice(index, 1);
  917. })
  918. },
  919. followModalAction(id, index, type = 'following') {
  920. axios.post('/i/follow', {
  921. item: id
  922. }).then(res => {
  923. if(type == 'following') {
  924. this.following.splice(index, 1);
  925. }
  926. })
  927. },
  928. owner(status) {
  929. return this.profile.id === status.account.id;
  930. },
  931. admin() {
  932. return this.profile.is_admin == true;
  933. },
  934. ownerOrAdmin(status) {
  935. return this.owner(status) || this.admin();
  936. }
  937. }
  938. }
  939. </script>