Timeline.vue 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997
  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. $('.profile-card .loader').addClass('d-none');
  400. $('.profile-card .contents').removeClass('d-none');
  401. $('.profile-card .card-footer').removeClass('d-none');
  402. }).catch(err => {
  403. swal(
  404. 'Oops, something went wrong',
  405. 'Please reload the page.',
  406. 'error'
  407. );
  408. });
  409. },
  410. fetchTimelineApi() {
  411. let apiUrl = false;
  412. switch(this.scope) {
  413. case 'home':
  414. apiUrl = '/api/v1/timelines/home';
  415. break;
  416. case 'local':
  417. apiUrl = '/api/v1/timelines/public';
  418. break;
  419. case 'network':
  420. apiUrl = '/api/v1/timelines/network';
  421. break;
  422. }
  423. axios.get(apiUrl, {
  424. params: {
  425. max_id: this.max_id,
  426. limit: 6
  427. }
  428. }).then(res => {
  429. let data = res.data;
  430. this.feed.push(...data);
  431. let ids = data.map(status => status.id);
  432. this.min_id = Math.max(...ids);
  433. this.max_id = Math.min(...ids);
  434. $('.timeline .pagination').removeClass('d-none');
  435. this.loading = false;
  436. if(window.outerWidth > 767) {
  437. this.expRec();
  438. }
  439. }).catch(err => {
  440. });
  441. },
  442. infiniteTimeline($state) {
  443. if(this.loading) {
  444. return;
  445. }
  446. let apiUrl = false;
  447. switch(this.scope) {
  448. case 'home':
  449. apiUrl = '/api/v1/timelines/home';
  450. break;
  451. case 'local':
  452. apiUrl = '/api/v1/timelines/public';
  453. break;
  454. case 'network':
  455. apiUrl = '/api/v1/timelines/network';
  456. break;
  457. }
  458. axios.get(apiUrl, {
  459. params: {
  460. max_id: this.max_id,
  461. limit: 6
  462. },
  463. }).then(res => {
  464. if (res.data.length && this.loading == false) {
  465. let data = res.data;
  466. this.feed.push(...data);
  467. let ids = data.map(status => status.id);
  468. this.min_id = Math.max(...ids);
  469. this.max_id = Math.min(...ids);
  470. this.page += 1;
  471. $state.loaded();
  472. this.loading = false;
  473. } else {
  474. $state.complete();
  475. }
  476. });
  477. },
  478. loadMore(event) {
  479. let homeTimeline = '/api/v1/timelines/home';
  480. let localTimeline = '/api/v1/timelines/public';
  481. let apiUrl = this.scope == 'home' ? homeTimeline : localTimeline;
  482. event.target.innerText = 'Loading...';
  483. axios.get(apiUrl, {
  484. params: {
  485. page: this.page,
  486. },
  487. }).then(res => {
  488. if (res.data.length && this.loading == false) {
  489. let data = res.data;
  490. let ids = data.map(status => status.id);
  491. this.min_id = Math.min(...ids);
  492. if(this.page == 1) {
  493. this.max_id = Math.max(...ids);
  494. }
  495. this.feed.push(...data);
  496. this.page += 1;
  497. this.loading = false;
  498. event.target.innerText = 'Load more posts';
  499. } else {
  500. }
  501. });
  502. },
  503. reportUrl(status) {
  504. let type = status.in_reply_to ? 'comment' : 'post';
  505. let id = status.id;
  506. return '/i/report?type=' + type + '&id=' + id;
  507. },
  508. commentFocus(status, $event) {
  509. if(this.replyId == status.id || status.comments_disabled) {
  510. return;
  511. }
  512. this.replies = {};
  513. this.replyId = status.id;
  514. this.fetchStatusComments(status, '');
  515. },
  516. likeStatus(status, $event) {
  517. if($('body').hasClass('loggedIn') == false) {
  518. return;
  519. }
  520. axios.post('/i/like', {
  521. item: status.id
  522. }).then(res => {
  523. status.favourites_count = res.data.count;
  524. status.favourited = !status.favourited;
  525. }).catch(err => {
  526. swal('Error', 'Something went wrong, please try again later.', 'error');
  527. });
  528. },
  529. shareStatus(status, $event) {
  530. if($('body').hasClass('loggedIn') == false) {
  531. return;
  532. }
  533. axios.post('/i/share', {
  534. item: status.id
  535. }).then(res => {
  536. status.reblogs_count = res.data.count;
  537. status.reblogged = !status.reblogged;
  538. }).catch(err => {
  539. swal('Error', 'Something went wrong, please try again later.', 'error');
  540. });
  541. },
  542. timestampFormat(timestamp) {
  543. let ts = new Date(timestamp);
  544. return ts.toDateString() + ' ' + ts.toLocaleTimeString();
  545. },
  546. editUrl(status) {
  547. return status.url + '/edit';
  548. },
  549. redirect(url) {
  550. window.location.href = url;
  551. return;
  552. },
  553. replyUrl(status) {
  554. let username = this.profile.username;
  555. let id = status.account.id == this.profile.id ? status.id : status.in_reply_to_id;
  556. return '/p/' + username + '/' + id;
  557. },
  558. mentionUrl(status) {
  559. let username = status.account.username;
  560. let id = status.id;
  561. return '/p/' + username + '/' + id;
  562. },
  563. statusOwner(status) {
  564. let sid = status.account.id;
  565. let uid = this.profile.id;
  566. if(sid == uid) {
  567. return true;
  568. } else {
  569. return false;
  570. }
  571. },
  572. fetchStatusComments(status, card) {
  573. axios.get('/api/v2/status/'+status.id+'/replies')
  574. .then(res => {
  575. let data = res.data;
  576. this.replies = _.reverse(data);
  577. }).catch(err => {
  578. })
  579. },
  580. muteProfile(status) {
  581. if($('body').hasClass('loggedIn') == false) {
  582. return;
  583. }
  584. axios.post('/i/mute', {
  585. type: 'user',
  586. item: status.account.id
  587. }).then(res => {
  588. this.feed = this.feed.filter(s => s.account.id !== status.account.id);
  589. swal('Success', 'You have successfully muted ' + status.account.acct, 'success');
  590. }).catch(err => {
  591. swal('Error', 'Something went wrong. Please try again later.', 'error');
  592. });
  593. },
  594. blockProfile(status) {
  595. if($('body').hasClass('loggedIn') == false) {
  596. return;
  597. }
  598. axios.post('/i/block', {
  599. type: 'user',
  600. item: status.account.id
  601. }).then(res => {
  602. this.feed = this.feed.filter(s => s.account.id !== status.account.id);
  603. swal('Success', 'You have successfully blocked ' + status.account.acct, 'success');
  604. }).catch(err => {
  605. swal('Error', 'Something went wrong. Please try again later.', 'error');
  606. });
  607. },
  608. deletePost(status, index) {
  609. if($('body').hasClass('loggedIn') == false || status.account.id !== this.profile.id) {
  610. return;
  611. }
  612. if(window.confirm('Are you sure you want to delete this post?') == false) {
  613. return;
  614. }
  615. axios.post('/i/delete', {
  616. type: 'status',
  617. item: status.id
  618. }).then(res => {
  619. this.feed.splice(index,1);
  620. swal('Success', 'You have successfully deleted this post', 'success');
  621. }).catch(err => {
  622. swal('Error', 'Something went wrong. Please try again later.', 'error');
  623. });
  624. },
  625. commentSubmit(status, $event) {
  626. let id = status.id;
  627. let form = $event.target;
  628. let input = $(form).find('input[name="comment"]');
  629. let comment = input.val();
  630. let comments = form.parentElement.parentElement.getElementsByClassName('comments')[0];
  631. axios.post('/i/comment', {
  632. item: id,
  633. comment: comment
  634. }).then(res => {
  635. form.reset();
  636. form.blur();
  637. this.replies.push(res.data.entity);
  638. });
  639. },
  640. moderatePost(status, action, $event) {
  641. let username = status.account.username;
  642. console.log('action: ' + action + ' status id' + status.id);
  643. switch(action) {
  644. case 'autocw':
  645. let msg = 'Are you sure you want to enforce CW for ' + username + ' ?';
  646. swal({
  647. title: 'Confirm',
  648. text: msg,
  649. icon: 'warning',
  650. buttons: true,
  651. dangerMode: true
  652. }).then(res => {
  653. if(res) {
  654. axios.post('/api/v2/moderator/action', {
  655. action: action,
  656. item_id: status.id,
  657. item_type: 'status'
  658. }).then(res => {
  659. swal('Success', 'Successfully enforced CW for ' + username, 'success');
  660. }).catch(err => {
  661. swal(
  662. 'Error',
  663. 'Something went wrong, please try again later.',
  664. 'error'
  665. );
  666. });
  667. }
  668. });
  669. break;
  670. case 'noautolink':
  671. msg = 'Are you sure you want to disable auto linking for ' + username + ' ?';
  672. swal({
  673. title: 'Confirm',
  674. text: msg,
  675. icon: 'warning',
  676. buttons: true,
  677. dangerMode: true
  678. }).then(res => {
  679. if(res) {
  680. axios.post('/api/v2/moderator/action', {
  681. action: action,
  682. item_id: status.id,
  683. item_type: 'status'
  684. }).then(res => {
  685. swal('Success', 'Successfully disabled autolinking for ' + username, 'success');
  686. }).catch(err => {
  687. swal(
  688. 'Error',
  689. 'Something went wrong, please try again later.',
  690. 'error'
  691. );
  692. });
  693. }
  694. });
  695. break;
  696. case 'unlisted':
  697. msg = 'Are you sure you want to unlist from timelines for ' + username + ' ?';
  698. swal({
  699. title: 'Confirm',
  700. text: msg,
  701. icon: 'warning',
  702. buttons: true,
  703. dangerMode: true
  704. }).then(res => {
  705. if(res) {
  706. axios.post('/api/v2/moderator/action', {
  707. action: action,
  708. item_id: status.id,
  709. item_type: 'status'
  710. }).then(res => {
  711. swal('Success', 'Successfully unlisted for ' + username, 'success');
  712. }).catch(err => {
  713. swal(
  714. 'Error',
  715. 'Something went wrong, please try again later.',
  716. 'error'
  717. );
  718. });
  719. }
  720. });
  721. break;
  722. case 'disable':
  723. msg = 'Are you sure you want to disable ' + username + '’s account ?';
  724. swal({
  725. title: 'Confirm',
  726. text: msg,
  727. icon: 'warning',
  728. buttons: true,
  729. dangerMode: true
  730. }).then(res => {
  731. if(res) {
  732. axios.post('/api/v2/moderator/action', {
  733. action: action,
  734. item_id: status.id,
  735. item_type: 'status'
  736. }).then(res => {
  737. swal('Success', 'Successfully disabled ' + username + '’s account', 'success');
  738. }).catch(err => {
  739. swal(
  740. 'Error',
  741. 'Something went wrong, please try again later.',
  742. 'error'
  743. );
  744. });
  745. }
  746. });
  747. break;
  748. case 'suspend':
  749. msg = 'Are you sure you want to suspend ' + username + '’s account ?';
  750. swal({
  751. title: 'Confirm',
  752. text: msg,
  753. icon: 'warning',
  754. buttons: true,
  755. dangerMode: true
  756. }).then(res => {
  757. if(res) {
  758. axios.post('/api/v2/moderator/action', {
  759. action: action,
  760. item_id: status.id,
  761. item_type: 'status'
  762. }).then(res => {
  763. swal('Success', 'Successfully suspend ' + username + '’s account', 'success');
  764. }).catch(err => {
  765. swal(
  766. 'Error',
  767. 'Something went wrong, please try again later.',
  768. 'error'
  769. );
  770. });
  771. }
  772. });
  773. break;
  774. }
  775. },
  776. toggleOptionsMenu() {
  777. this.optionMenuState = !this.optionMenuState;
  778. },
  779. modeModToggle() {
  780. this.modes.mod = !this.modes.mod;
  781. window.ls.set('pixelfed-classicui-settings', this.modes);
  782. },
  783. modeNotifyToggle() {
  784. this.modes.notify = !this.modes.notify;
  785. window.ls.set('pixelfed-classicui-settings', this.modes);
  786. },
  787. modeDarkToggle() {
  788. // todo: more graceful stylesheet change
  789. if(this.modes.dark == true) {
  790. axios.post('/i/metro/dark-mode', {
  791. mode: 'light'
  792. }).then(res => {
  793. $('link[data-stylesheet=dark]')
  794. .attr('data-stylesheet', 'light')
  795. .attr('href', '/css/app.css?v=' + Date.now());
  796. this.modes.dark = false;
  797. });
  798. } else {
  799. axios.post('/i/metro/dark-mode', {
  800. mode: 'dark'
  801. }).then(res => {
  802. $('link[data-stylesheet=light]')
  803. .attr('data-stylesheet', 'dark')
  804. .attr('href', '/css/appdark.css?v=' + Date.now());
  805. this.modes.dark = true;
  806. });
  807. }
  808. window.ls.set('pixelfed-classicui-settings', this.modes);
  809. },
  810. modeInfiniteToggle() {
  811. this.modes.infinite = !this.modes.infinite
  812. window.ls.set('pixelfed-classicui-settings', this.modes);
  813. },
  814. followingModal() {
  815. if(this.following.length > 0) {
  816. this.$refs.followingModal.show();
  817. return;
  818. }
  819. axios.get('/api/v1/accounts/'+this.profile.id+'/following', {
  820. params: {
  821. page: this.followingCursor
  822. }
  823. })
  824. .then(res => {
  825. this.following = res.data;
  826. this.followingCursor++;
  827. });
  828. if(res.data.length < 10) {
  829. this.followingMore = false;
  830. }
  831. this.$refs.followingModal.show();
  832. },
  833. followersModal() {
  834. if(this.followers.length > 0) {
  835. this.$refs.followerModal.show();
  836. return;
  837. }
  838. axios.get('/api/v1/accounts/'+this.profile.id+'/followers', {
  839. params: {
  840. page: this.followerCursor
  841. }
  842. })
  843. .then(res => {
  844. this.followers = res.data;
  845. this.followerCursor++;
  846. })
  847. if(res.data.length < 10) {
  848. this.followerMore = false;
  849. }
  850. this.$refs.followerModal.show();
  851. },
  852. followingLoadMore() {
  853. axios.get('/api/v1/accounts/'+this.profile.id+'/following', {
  854. params: {
  855. page: this.followingCursor
  856. }
  857. })
  858. .then(res => {
  859. if(res.data.length > 0) {
  860. this.following.push(...res.data);
  861. this.followingCursor++;
  862. }
  863. if(res.data.length < 10) {
  864. this.followingMore = false;
  865. }
  866. });
  867. },
  868. followersLoadMore() {
  869. axios.get('/api/v1/accounts/'+this.profile.id+'/followers', {
  870. params: {
  871. page: this.followerCursor
  872. }
  873. })
  874. .then(res => {
  875. if(res.data.length > 0) {
  876. this.followers.push(...res.data);
  877. this.followerCursor++;
  878. }
  879. if(res.data.length < 10) {
  880. this.followerMore = false;
  881. }
  882. });
  883. },
  884. lightbox(src) {
  885. this.lightboxMedia = src;
  886. this.$refs.lightboxModal.show();
  887. },
  888. expLc(status) {
  889. if(this.config.ab.lc == false) {
  890. return true;
  891. }
  892. if(this.statusOwner(status) == true) {
  893. return true;
  894. }
  895. return false;
  896. },
  897. expRec() {
  898. if(this.config.ab.rec == false) {
  899. return;
  900. }
  901. axios.get('/api/local/exp/rec')
  902. .then(res => {
  903. this.suggestions = res.data;
  904. })
  905. },
  906. expRecFollow(id, index) {
  907. if(this.config.ab.rec == false) {
  908. return;
  909. }
  910. axios.post('/i/follow', {
  911. item: id
  912. }).then(res => {
  913. this.suggestions.splice(index, 1);
  914. })
  915. },
  916. followModalAction(id, index, type = 'following') {
  917. axios.post('/i/follow', {
  918. item: id
  919. }).then(res => {
  920. if(type == 'following') {
  921. this.following.splice(index, 1);
  922. }
  923. })
  924. }
  925. }
  926. }
  927. </script>