Timeline.vue 32 KB

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