Timeline.vue 31 KB

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