Timeline.vue 30 KB

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