Timeline.vue 32 KB

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