Timeline.vue 36 KB

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