Timeline.vue 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102
  1. <template>
  2. <div class="container" style="">
  3. <div class="row">
  4. <div :class="[modes.distractionFree ? 'col-md-8 col-lg-8 offset-md-2 pt-sm-2 px-0 my-sm-3 timeline order-2 order-md-1':'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 v-if="!modes.distractionFree" 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 v-if="!modes.distractionFree" 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 && !modes.distractionFree">
  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. <a v-if="modes.distractionFree" class="float-right" :href="status.url">
  143. <i class="fas fa-ellipsis-h fa-lg text-muted"></i>
  144. </a>
  145. </p>
  146. </div>
  147. </div>
  148. <div v-if="status.id == replyId && !status.comments_disabled" class="card-footer bg-white px-2 py-0">
  149. <ul class="nav align-items-center emoji-reactions" style="overflow-x: scroll;flex-wrap: unset;">
  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. <li class="nav-item" v-on:click="emojiReaction(status)">๐Ÿ˜…</li>
  160. <li class="nav-item" v-on:click="emojiReaction(status)">๐Ÿ˜</li>
  161. <li class="nav-item" v-on:click="emojiReaction(status)">๐Ÿ™‚</li>
  162. <li class="nav-item" v-on:click="emojiReaction(status)">๐Ÿ˜Ž</li>
  163. <li class="nav-item" v-on:click="emojiReaction(status)" v-for="e in emoji">{{e}}</li>
  164. </ul>
  165. </div>
  166. <div v-if="status.id == replyId && !status.comments_disabled" class="card-footer bg-white sticky-md-bottom p-0">
  167. <form class="border-0 rounded-0 align-middle" method="post" action="/i/comment" :data-id="status.id" data-truncate="false">
  168. <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>
  169. <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)"/>
  170. </form>
  171. </div>
  172. </div>
  173. </div>
  174. <div v-if="modes.infinite == true && !loading && feed.length > 0">
  175. <div class="card">
  176. <div class="card-body">
  177. <infinite-loading @infinite="infiniteTimeline" :distance="800">
  178. <div slot="no-more" class="font-weight-bold">No more posts to load</div>
  179. <div slot="no-results" class="font-weight-bold">No posts found</div>
  180. </infinite-loading>
  181. </div>
  182. </div>
  183. </div>
  184. <div v-if="modes.infinite == false && !loading && feed.length > 0" class="pagination">
  185. <p class="btn btn-outline-secondary font-weight-bold btn-block" v-on:click="loadMore">Load more posts</p>
  186. </div>
  187. <div v-if="!loading && scope == 'home' && feed.length == 0">
  188. <div class="card">
  189. <div class="card-body text-center">
  190. <p class="h2 font-weight-lighter p-5">Hello, {{profile.acct}}</p>
  191. <p class="text-lighter"><i class="fas fa-camera-retro fa-5x"></i></p>
  192. <p class="h3 font-weight-lighter p-5">Start following people to build your timeline.</p>
  193. <p><a href="/discover" class="btn btn-primary font-weight-bold py-0">Discover new people and posts</a></p>
  194. </div>
  195. </div>
  196. </div>
  197. </div>
  198. </div>
  199. <div v-if="!modes.distractionFree" class="col-md-4 col-lg-4 pt-2 my-3 order-1 order-md-2 d-none d-md-block">
  200. <div class="position-sticky" style="top:68px;">
  201. <div class="mb-4">
  202. <div class="">
  203. <div class="">
  204. <div class="media d-flex align-items-center">
  205. <a :href="profile.url">
  206. <img class="mr-3 rounded-circle box-shadow" :src="profile.avatar || '/storage/avatars/default.png'" alt="avatar" width="64px" height="64px">
  207. </a>
  208. <div class="media-body d-flex justify-content-between word-break" >
  209. <div>
  210. <p class="mb-0 px-0 font-weight-bold"><a :href="profile.url" class="text-dark">{{profile.username || 'loading...'}}</a></p>
  211. <p class="my-0 text-muted pb-0">{{profile.display_name || 'loading...'}}</p>
  212. </div>
  213. <div class="ml-2">
  214. <a class="text-muted" href="/settings/home"><i class="fas fa-cog fa-lg"></i></a>
  215. </div>
  216. </div>
  217. </div>
  218. </div>
  219. <!-- <div class="card-footer bg-white py-1 d-none">
  220. <div class="d-flex justify-content-between text-center">
  221. <span class="pl-3 cursor-pointer" v-on:click="redirect(profile.url)">
  222. <p class="mb-0 font-weight-bold">{{profile.statuses_count}}</p>
  223. <p class="mb-0 small text-muted">Posts</p>
  224. </span>
  225. <span class="cursor-pointer" v-on:click="followersModal()">
  226. <p class="mb-0 font-weight-bold">{{profile.followers_count}}</p>
  227. <p class="mb-0 small text-muted">Followers</p>
  228. </span>
  229. <span class="pr-3 cursor-pointer" v-on:click="followingModal()">
  230. <p class="mb-0 font-weight-bold">{{profile.following_count}}</p>
  231. <p class="mb-0 small text-muted">Following</p>
  232. </span>
  233. </div>
  234. </div> -->
  235. </div>
  236. </div>
  237. <div v-show="modes.notify == true" class="mb-4">
  238. <notification-card></notification-card>
  239. </div>
  240. <div v-show="showSuggestions == true && suggestions.length && config.ab && config.ab.rec == true" class="mb-4">
  241. <div class="card">
  242. <div class="card-header bg-white d-flex align-items-center justify-content-between">
  243. <a class="small text-muted cursor-pointer" href="#" @click.prevent="refreshSuggestions" ref="suggestionRefresh"><i class="fas fa-sync-alt"></i></a>
  244. <div class="small text-dark text-uppercase font-weight-bold">Suggestions</div>
  245. <div class="small text-muted cursor-pointer" v-on:click="hideSuggestions"><i class="fas fa-times"></i></div>
  246. </div>
  247. <div class="card-body pt-0">
  248. <div v-for="(rec, index) in suggestions" class="media align-items-center mt-3">
  249. <a :href="'/'+rec.username">
  250. <img :src="rec.avatar" width="32px" height="32px" class="rounded-circle mr-3">
  251. </a>
  252. <div class="media-body">
  253. <p class="mb-0 font-weight-bold small">
  254. <a :href="'/'+rec.username" class="text-decoration-none text-dark">
  255. {{rec.username}}
  256. </a>
  257. </p>
  258. <p class="mb-0 small text-muted">{{rec.message}}</p>
  259. </div>
  260. <a class="font-weight-bold small" href="#" @click.prevent="expRecFollow(rec.id, index)">Follow</a>
  261. </div>
  262. </div>
  263. </div>
  264. </div>
  265. <footer>
  266. <div class="container pb-5">
  267. <p class="mb-0 text-uppercase font-weight-bold text-muted small">
  268. <a href="/site/about" class="text-dark pr-2">About Us</a>
  269. <a href="/site/help" class="text-dark pr-2">Help</a>
  270. <a href="/site/open-source" class="text-dark pr-2">Open Source</a>
  271. <a href="/site/language" class="text-dark pr-2">Language</a>
  272. <a href="/site/terms" class="text-dark pr-2">Terms</a>
  273. <a href="/site/privacy" class="text-dark pr-2">Privacy</a>
  274. <a href="/site/platform" class="text-dark pr-2">API</a>
  275. </p>
  276. <p class="mb-0 text-uppercase font-weight-bold text-muted small">
  277. <a href="http://pixelfed.org" class="text-muted" rel="noopener" title="" data-toggle="tooltip">Powered by Pixelfed</a>
  278. </p>
  279. </div>
  280. </footer>
  281. </div>
  282. </div>
  283. </div>
  284. <!-- <b-modal ref="followingModal"
  285. id="following-modal"
  286. hide-footer
  287. centered
  288. title="Following"
  289. body-class="list-group-flush p-0">
  290. <div class="list-group">
  291. <div class="list-group-item border-0" v-for="(user, index) in following" :key="'following_'+index">
  292. <div class="media">
  293. <a :href="user.url">
  294. <img class="mr-3 rounded-circle box-shadow" :src="user.avatar" :alt="user.username + 'โ€™s avatar'" width="30px">
  295. </a>
  296. <div class="media-body">
  297. <p class="mb-0" style="font-size: 14px">
  298. <a :href="user.url" class="font-weight-bold text-dark">
  299. {{user.username}}
  300. </a>
  301. </p>
  302. <p class="text-muted mb-0" style="font-size: 14px">
  303. {{user.display_name}}
  304. </p>
  305. </div>
  306. <a class="btn btn-outline-secondary btn-sm" href="#" @click.prevent="followModalAction(user.id, index, 'following')">Unfollow</a>
  307. </div>
  308. </div>
  309. <div v-if="following.length == 0" class="list-group-item border-0">
  310. <div class="list-group-item border-0">
  311. <p class="p-3 text-center mb-0 lead">You are not following anyone.</p>
  312. </div>
  313. </div>
  314. <div v-if="following.length != 0 && followingMore" class="list-group-item text-center" v-on:click="followingLoadMore()">
  315. <p class="mb-0 small text-muted font-weight-light cursor-pointer">Load more</p>
  316. </div>
  317. </div>
  318. </b-modal>
  319. <b-modal ref="followerModal"
  320. id="follower-modal"
  321. hide-footer
  322. centered
  323. title="Followers"
  324. body-class="list-group-flush p-0">
  325. <div class="list-group">
  326. <div class="list-group-item border-0" v-for="(user, index) in followers" :key="'follower_'+index">
  327. <div class="media">
  328. <a :href="user.url">
  329. <img class="mr-3 rounded-circle box-shadow" :src="user.avatar" :alt="user.username + 'โ€™s avatar'" width="30px">
  330. </a>
  331. <div class="media-body">
  332. <p class="mb-0" style="font-size: 14px">
  333. <a :href="user.url" class="font-weight-bold text-dark">
  334. {{user.username}}
  335. </a>
  336. </p>
  337. <p class="text-muted mb-0" style="font-size: 14px">
  338. {{user.display_name}}
  339. </p>
  340. </div>
  341. </div>
  342. </div>
  343. <div v-if="followerMore" class="list-group-item text-center" v-on:click="followersLoadMore()">
  344. <p class="mb-0 small text-muted font-weight-light cursor-pointer">Load more</p>
  345. </div>
  346. </div>
  347. </b-modal> -->
  348. <b-modal
  349. id="lightbox"
  350. ref="lightboxModal"
  351. hide-header
  352. hide-footer
  353. centered
  354. size="lg"
  355. body-class="p-0"
  356. >
  357. <div v-if="lightboxMedia" :class="lightboxMedia.filter_class">
  358. <img :src="lightboxMedia.url" class="img-fluid" style="min-height: 100%; min-width: 100%">
  359. </div>
  360. </b-modal>
  361. </div>
  362. </template>
  363. <style type="text/css" scoped>
  364. .postPresenterContainer {
  365. display: flex;
  366. align-items: center;
  367. background: #fff;
  368. }
  369. .word-break {
  370. word-break: break-all;
  371. }
  372. .small .custom-control-label {
  373. padding-top: 3px;
  374. }
  375. .reply-btn {
  376. position: absolute;
  377. bottom: 12px;
  378. right: 20px;
  379. width: 60px;
  380. text-align: center;
  381. border-radius: 0 3px 3px 0;
  382. }
  383. .emoji-reactions .nav-item {
  384. font-size: 1.2rem;
  385. padding: 9px;
  386. cursor: pointer;
  387. }
  388. .emoji-reactions::-webkit-scrollbar {
  389. width: 0px;
  390. height: 0px;
  391. background: transparent;
  392. }
  393. </style>
  394. <script type="text/javascript">
  395. export default {
  396. props: ['scope'],
  397. data() {
  398. return {
  399. ids: [],
  400. config: {},
  401. page: 2,
  402. feed: [],
  403. profile: {},
  404. min_id: 0,
  405. max_id: 0,
  406. stories: {},
  407. suggestions: {},
  408. loading: true,
  409. replies: [],
  410. replyId: null,
  411. modes: {
  412. 'mod': false,
  413. 'dark': false,
  414. 'notify': true,
  415. 'distractionFree': false
  416. },
  417. followers: [],
  418. followerCursor: 1,
  419. followerMore: true,
  420. following: [],
  421. followingCursor: 1,
  422. followingMore: true,
  423. lightboxMedia: false,
  424. showSuggestions: false,
  425. showReadMore: true,
  426. replyStatus: {},
  427. replyText: '',
  428. emoji: ['๐Ÿ˜€','๐Ÿคฃ','๐Ÿ˜ƒ','๐Ÿ˜„','๐Ÿ˜†','๐Ÿ˜‰','๐Ÿ˜Š','๐Ÿ˜‹','๐Ÿ˜˜','๐Ÿ˜—','๐Ÿ˜™','๐Ÿ˜š','๐Ÿค—','๐Ÿคฉ','๐Ÿค”','๐Ÿคจ','๐Ÿ˜','๐Ÿ˜‘','๐Ÿ˜ถ','๐Ÿ™„','๐Ÿ˜','๐Ÿ˜ฃ','๐Ÿ˜ฅ','๐Ÿ˜ฎ','๐Ÿค','๐Ÿ˜ช','๐Ÿ˜ซ','๐Ÿ˜ด','๐Ÿ˜Œ','๐Ÿ˜›','๐Ÿ˜œ','๐Ÿ˜','๐Ÿคค','๐Ÿ˜’','๐Ÿ˜“','๐Ÿ˜”','๐Ÿ˜•','๐Ÿ™ƒ','๐Ÿค‘','๐Ÿ˜ฒ','๐Ÿ™','๐Ÿ˜–','๐Ÿ˜ž','๐Ÿ˜Ÿ','๐Ÿ˜ค','๐Ÿ˜ญ','๐Ÿ˜ฆ','๐Ÿ˜ง','๐Ÿ˜จ','๐Ÿ˜ฉ','๐Ÿคฏ','๐Ÿ˜ฌ','๐Ÿ˜ฐ','๐Ÿ˜ฑ','๐Ÿ˜ณ','๐Ÿคช','๐Ÿ˜ต','๐Ÿ˜ก','๐Ÿ˜ ','๐Ÿคฌ','๐Ÿ˜ท','๐Ÿค’','๐Ÿค•','๐Ÿคข','๐Ÿคฎ','๐Ÿคง','๐Ÿ˜‡','๐Ÿค ','๐Ÿคก','๐Ÿคฅ','๐Ÿคซ','๐Ÿคญ','๐Ÿง','๐Ÿค“','๐Ÿ˜ˆ','๐Ÿ‘ฟ','๐Ÿ‘น','๐Ÿ‘บ','๐Ÿ’€','๐Ÿ‘ป','๐Ÿ‘ฝ','๐Ÿค–','๐Ÿ’ฉ','๐Ÿ˜บ','๐Ÿ˜ธ','๐Ÿ˜น','๐Ÿ˜ป','๐Ÿ˜ผ','๐Ÿ˜ฝ','๐Ÿ™€','๐Ÿ˜ฟ','๐Ÿ˜พ','๐Ÿคฒ','๐Ÿ‘','๐Ÿค','๐Ÿ‘','๐Ÿ‘Ž','๐Ÿ‘Š','โœŠ','๐Ÿค›','๐Ÿคœ','๐Ÿคž','โœŒ๏ธ','๐ŸคŸ','๐Ÿค˜','๐Ÿ‘ˆ','๐Ÿ‘‰','๐Ÿ‘†','๐Ÿ‘‡','โ˜๏ธ','โœ‹','๐Ÿคš','๐Ÿ–','๐Ÿ––','๐Ÿ‘‹','๐Ÿค™','๐Ÿ’ช','๐Ÿ–•','โœ๏ธ','๐Ÿ™','๐Ÿ’','๐Ÿ’„','๐Ÿ’‹','๐Ÿ‘„','๐Ÿ‘…','๐Ÿ‘‚','๐Ÿ‘ƒ','๐Ÿ‘ฃ','๐Ÿ‘','๐Ÿ‘€','๐Ÿง ','๐Ÿ—ฃ','๐Ÿ‘ค','๐Ÿ‘ฅ']
  429. }
  430. },
  431. beforeMount() {
  432. axios.get('/api/v2/config')
  433. .then(res => {
  434. this.config = res.data;
  435. this.fetchProfile();
  436. this.fetchTimelineApi();
  437. });
  438. },
  439. mounted() {
  440. if($('link[data-stylesheet="dark"]').length != 0) {
  441. this.modes.dark = true;
  442. }
  443. if(localStorage.getItem('pf_metro_ui.exp.rec') == 'false') {
  444. this.showSuggestions = false;
  445. } else {
  446. this.showSuggestions = true;
  447. }
  448. if(localStorage.getItem('pf_metro_ui.exp.rm') == 'false') {
  449. this.showReadMore = false;
  450. } else {
  451. this.showReadMore = true;
  452. }
  453. if(localStorage.getItem('pf_metro_ui.exp.df') == 'true') {
  454. this.modes.distractionFree = true;
  455. } else {
  456. this.modes.distractionFree = false;
  457. }
  458. this.$nextTick(function () {
  459. $('[data-toggle="tooltip"]').tooltip()
  460. });
  461. },
  462. updated() {
  463. if(this.showReadMore == true) {
  464. pixelfed.readmore();
  465. }
  466. },
  467. methods: {
  468. fetchProfile() {
  469. axios.get('/api/v1/accounts/verify_credentials').then(res => {
  470. this.profile = res.data;
  471. if(this.profile.is_admin == true) {
  472. this.modes.mod = true;
  473. }
  474. $('.profile-card .loader').addClass('d-none');
  475. $('.profile-card .contents').removeClass('d-none');
  476. $('.profile-card .card-footer').removeClass('d-none');
  477. this.expRec();
  478. }).catch(err => {
  479. swal(
  480. 'Oops, something went wrong',
  481. 'Please reload the page.',
  482. 'error'
  483. );
  484. });
  485. },
  486. fetchTimelineApi() {
  487. let apiUrl = false;
  488. switch(this.scope) {
  489. case 'home':
  490. apiUrl = '/api/v1/timelines/home';
  491. break;
  492. case 'local':
  493. apiUrl = '/api/v1/timelines/public';
  494. break;
  495. case 'network':
  496. apiUrl = '/api/v1/timelines/network';
  497. break;
  498. }
  499. axios.get(apiUrl, {
  500. params: {
  501. max_id: this.max_id,
  502. limit: 6
  503. }
  504. }).then(res => {
  505. let data = res.data;
  506. this.feed.push(...data);
  507. let ids = data.map(status => status.id);
  508. this.ids = ids;
  509. this.min_id = Math.max(...ids);
  510. this.max_id = Math.min(...ids);
  511. $('.timeline .pagination').removeClass('d-none');
  512. this.loading = false;
  513. }).catch(err => {
  514. });
  515. },
  516. infiniteTimeline($state) {
  517. if(this.loading) {
  518. return;
  519. }
  520. let apiUrl = false;
  521. switch(this.scope) {
  522. case 'home':
  523. apiUrl = '/api/v1/timelines/home';
  524. break;
  525. case 'local':
  526. apiUrl = '/api/v1/timelines/public';
  527. break;
  528. case 'network':
  529. apiUrl = '/api/v1/timelines/network';
  530. break;
  531. }
  532. axios.get(apiUrl, {
  533. params: {
  534. max_id: this.max_id,
  535. limit: 6
  536. },
  537. }).then(res => {
  538. if (res.data.length && this.loading == false) {
  539. let data = res.data;
  540. let self = this;
  541. data.forEach(d => {
  542. if(self.ids.indexOf(d.id) == -1) {
  543. self.feed.push(d);
  544. self.ids.push(d.id);
  545. }
  546. });
  547. this.min_id = Math.max(...this.ids);
  548. this.max_id = Math.min(...this.ids);
  549. this.page += 1;
  550. $state.loaded();
  551. this.loading = false;
  552. } else {
  553. $state.complete();
  554. }
  555. });
  556. },
  557. loadMore(event) {
  558. let homeTimeline = '/api/v1/timelines/home';
  559. let localTimeline = '/api/v1/timelines/public';
  560. let apiUrl = this.scope == 'home' ? homeTimeline : localTimeline;
  561. event.target.innerText = 'Loading...';
  562. axios.get(apiUrl, {
  563. params: {
  564. page: this.page,
  565. },
  566. }).then(res => {
  567. if (res.data.length && this.loading == false) {
  568. let data = res.data;
  569. let ids = data.map(status => status.id);
  570. this.min_id = Math.min(...ids);
  571. if(this.page == 1) {
  572. this.max_id = Math.max(...ids);
  573. }
  574. this.feed.push(...data);
  575. this.page += 1;
  576. this.loading = false;
  577. event.target.innerText = 'Load more posts';
  578. } else {
  579. }
  580. });
  581. },
  582. reportUrl(status) {
  583. let type = status.in_reply_to ? 'comment' : 'post';
  584. let id = status.id;
  585. return '/i/report?type=' + type + '&id=' + id;
  586. },
  587. commentFocus(status, $event) {
  588. if(this.replyId == status.id || status.comments_disabled) {
  589. return;
  590. }
  591. this.replies = {};
  592. this.replyStatus = {};
  593. this.replyText = '';
  594. this.replyId = status.id;
  595. this.replyStatus = status;
  596. this.fetchStatusComments(status, '');
  597. },
  598. likeStatus(status) {
  599. if($('body').hasClass('loggedIn') == false) {
  600. return;
  601. }
  602. axios.post('/i/like', {
  603. item: status.id
  604. }).then(res => {
  605. status.favourites_count = res.data.count;
  606. status.favourited = !status.favourited;
  607. }).catch(err => {
  608. swal('Error', 'Something went wrong, please try again later.', 'error');
  609. });
  610. },
  611. shareStatus(status, $event) {
  612. if($('body').hasClass('loggedIn') == false) {
  613. return;
  614. }
  615. axios.post('/i/share', {
  616. item: status.id
  617. }).then(res => {
  618. status.reblogs_count = res.data.count;
  619. status.reblogged = !status.reblogged;
  620. }).catch(err => {
  621. swal('Error', 'Something went wrong, please try again later.', 'error');
  622. });
  623. },
  624. timestampFormat(timestamp) {
  625. let ts = new Date(timestamp);
  626. return ts.toDateString() + ' ' + ts.toLocaleTimeString();
  627. },
  628. editUrl(status) {
  629. return status.url + '/edit';
  630. },
  631. redirect(url) {
  632. window.location.href = url;
  633. return;
  634. },
  635. replyUrl(status) {
  636. let username = this.profile.username;
  637. let id = status.account.id == this.profile.id ? status.id : status.in_reply_to_id;
  638. return '/p/' + username + '/' + id;
  639. },
  640. mentionUrl(status) {
  641. let username = status.account.username;
  642. let id = status.id;
  643. return '/p/' + username + '/' + id;
  644. },
  645. statusOwner(status) {
  646. let sid = status.account.id;
  647. let uid = this.profile.id;
  648. if(sid == uid) {
  649. return true;
  650. } else {
  651. return false;
  652. }
  653. },
  654. fetchStatusComments(status, card) {
  655. axios.get('/api/v2/status/'+status.id+'/replies')
  656. .then(res => {
  657. let data = res.data;
  658. this.replies = _.reverse(data);
  659. }).catch(err => {
  660. })
  661. },
  662. muteProfile(status) {
  663. if($('body').hasClass('loggedIn') == false) {
  664. return;
  665. }
  666. axios.post('/i/mute', {
  667. type: 'user',
  668. item: status.account.id
  669. }).then(res => {
  670. this.feed = this.feed.filter(s => s.account.id !== status.account.id);
  671. swal('Success', 'You have successfully muted ' + status.account.acct, 'success');
  672. }).catch(err => {
  673. swal('Error', 'Something went wrong. Please try again later.', 'error');
  674. });
  675. },
  676. blockProfile(status) {
  677. if($('body').hasClass('loggedIn') == false) {
  678. return;
  679. }
  680. axios.post('/i/block', {
  681. type: 'user',
  682. item: status.account.id
  683. }).then(res => {
  684. this.feed = this.feed.filter(s => s.account.id !== status.account.id);
  685. swal('Success', 'You have successfully blocked ' + status.account.acct, 'success');
  686. }).catch(err => {
  687. swal('Error', 'Something went wrong. Please try again later.', 'error');
  688. });
  689. },
  690. deletePost(status, index) {
  691. if($('body').hasClass('loggedIn') == false || this.ownerOrAdmin(status) == false) {
  692. return;
  693. }
  694. if(window.confirm('Are you sure you want to delete this post?') == false) {
  695. return;
  696. }
  697. axios.post('/i/delete', {
  698. type: 'status',
  699. item: status.id
  700. }).then(res => {
  701. this.feed.splice(index,1);
  702. swal('Success', 'You have successfully deleted this post', 'success');
  703. }).catch(err => {
  704. swal('Error', 'Something went wrong. Please try again later.', 'error');
  705. });
  706. },
  707. commentSubmit(status, $event) {
  708. let id = status.id;
  709. let comment = this.replyText;
  710. axios.post('/i/comment', {
  711. item: id,
  712. comment: comment
  713. }).then(res => {
  714. this.replyText = '';
  715. this.replies.push(res.data.entity);
  716. });
  717. },
  718. moderatePost(status, action, $event) {
  719. let username = status.account.username;
  720. console.log('action: ' + action + ' status id' + status.id);
  721. switch(action) {
  722. case 'autocw':
  723. let msg = 'Are you sure you want to enforce CW for ' + username + ' ?';
  724. swal({
  725. title: 'Confirm',
  726. text: msg,
  727. icon: 'warning',
  728. buttons: true,
  729. dangerMode: true
  730. }).then(res => {
  731. if(res) {
  732. axios.post('/api/v2/moderator/action', {
  733. action: action,
  734. item_id: status.id,
  735. item_type: 'status'
  736. }).then(res => {
  737. swal('Success', 'Successfully enforced CW for ' + username, 'success');
  738. }).catch(err => {
  739. swal(
  740. 'Error',
  741. 'Something went wrong, please try again later.',
  742. 'error'
  743. );
  744. });
  745. }
  746. });
  747. break;
  748. case 'noautolink':
  749. msg = 'Are you sure you want to disable auto linking for ' + username + ' ?';
  750. swal({
  751. title: 'Confirm',
  752. text: msg,
  753. icon: 'warning',
  754. buttons: true,
  755. dangerMode: true
  756. }).then(res => {
  757. if(res) {
  758. axios.post('/api/v2/moderator/action', {
  759. action: action,
  760. item_id: status.id,
  761. item_type: 'status'
  762. }).then(res => {
  763. swal('Success', 'Successfully disabled autolinking for ' + username, 'success');
  764. }).catch(err => {
  765. swal(
  766. 'Error',
  767. 'Something went wrong, please try again later.',
  768. 'error'
  769. );
  770. });
  771. }
  772. });
  773. break;
  774. case 'unlisted':
  775. msg = 'Are you sure you want to unlist from timelines for ' + username + ' ?';
  776. swal({
  777. title: 'Confirm',
  778. text: msg,
  779. icon: 'warning',
  780. buttons: true,
  781. dangerMode: true
  782. }).then(res => {
  783. if(res) {
  784. axios.post('/api/v2/moderator/action', {
  785. action: action,
  786. item_id: status.id,
  787. item_type: 'status'
  788. }).then(res => {
  789. swal('Success', 'Successfully unlisted for ' + username, 'success');
  790. }).catch(err => {
  791. swal(
  792. 'Error',
  793. 'Something went wrong, please try again later.',
  794. 'error'
  795. );
  796. });
  797. }
  798. });
  799. break;
  800. case 'disable':
  801. msg = 'Are you sure you want to disable ' + username + 'โ€™s account ?';
  802. swal({
  803. title: 'Confirm',
  804. text: msg,
  805. icon: 'warning',
  806. buttons: true,
  807. dangerMode: true
  808. }).then(res => {
  809. if(res) {
  810. axios.post('/api/v2/moderator/action', {
  811. action: action,
  812. item_id: status.id,
  813. item_type: 'status'
  814. }).then(res => {
  815. swal('Success', 'Successfully disabled ' + username + 'โ€™s account', 'success');
  816. }).catch(err => {
  817. swal(
  818. 'Error',
  819. 'Something went wrong, please try again later.',
  820. 'error'
  821. );
  822. });
  823. }
  824. });
  825. break;
  826. case 'suspend':
  827. msg = 'Are you sure you want to suspend ' + username + 'โ€™s account ?';
  828. swal({
  829. title: 'Confirm',
  830. text: msg,
  831. icon: 'warning',
  832. buttons: true,
  833. dangerMode: true
  834. }).then(res => {
  835. if(res) {
  836. axios.post('/api/v2/moderator/action', {
  837. action: action,
  838. item_id: status.id,
  839. item_type: 'status'
  840. }).then(res => {
  841. swal('Success', 'Successfully suspend ' + username + 'โ€™s account', 'success');
  842. }).catch(err => {
  843. swal(
  844. 'Error',
  845. 'Something went wrong, please try again later.',
  846. 'error'
  847. );
  848. });
  849. }
  850. });
  851. break;
  852. }
  853. },
  854. followingModal() {
  855. if(this.following.length > 0) {
  856. this.$refs.followingModal.show();
  857. return;
  858. }
  859. axios.get('/api/v1/accounts/'+this.profile.id+'/following', {
  860. params: {
  861. page: this.followingCursor
  862. }
  863. })
  864. .then(res => {
  865. this.following = res.data;
  866. this.followingCursor++;
  867. });
  868. if(res.data.length < 10) {
  869. this.followingMore = false;
  870. }
  871. this.$refs.followingModal.show();
  872. },
  873. followersModal() {
  874. if(this.followers.length > 0) {
  875. this.$refs.followerModal.show();
  876. return;
  877. }
  878. axios.get('/api/v1/accounts/'+this.profile.id+'/followers', {
  879. params: {
  880. page: this.followerCursor
  881. }
  882. })
  883. .then(res => {
  884. this.followers = res.data;
  885. this.followerCursor++;
  886. })
  887. if(res.data.length < 10) {
  888. this.followerMore = false;
  889. }
  890. this.$refs.followerModal.show();
  891. },
  892. followingLoadMore() {
  893. axios.get('/api/v1/accounts/'+this.profile.id+'/following', {
  894. params: {
  895. page: this.followingCursor
  896. }
  897. })
  898. .then(res => {
  899. if(res.data.length > 0) {
  900. this.following.push(...res.data);
  901. this.followingCursor++;
  902. }
  903. if(res.data.length < 10) {
  904. this.followingMore = false;
  905. }
  906. });
  907. },
  908. followersLoadMore() {
  909. axios.get('/api/v1/accounts/'+this.profile.id+'/followers', {
  910. params: {
  911. page: this.followerCursor
  912. }
  913. })
  914. .then(res => {
  915. if(res.data.length > 0) {
  916. this.followers.push(...res.data);
  917. this.followerCursor++;
  918. }
  919. if(res.data.length < 10) {
  920. this.followerMore = false;
  921. }
  922. });
  923. },
  924. lightbox(src) {
  925. this.lightboxMedia = src;
  926. this.$refs.lightboxModal.show();
  927. },
  928. expLc(status) {
  929. if(this.config.ab.lc == false) {
  930. return true;
  931. }
  932. if(this.statusOwner(status) == true) {
  933. return true;
  934. }
  935. return false;
  936. },
  937. expRec() {
  938. if(this.config.ab.rec == false) {
  939. return;
  940. }
  941. axios.get('/api/local/exp/rec')
  942. .then(res => {
  943. this.suggestions = res.data;
  944. })
  945. },
  946. expRecFollow(id, index) {
  947. if(this.config.ab.rec == false) {
  948. return;
  949. }
  950. axios.post('/i/follow', {
  951. item: id
  952. }).then(res => {
  953. this.suggestions.splice(index, 1);
  954. }).catch(err => {
  955. if(err.response.data.message) {
  956. swal('Error', err.response.data.message, 'error');
  957. }
  958. });
  959. },
  960. followModalAction(id, index, type = 'following') {
  961. axios.post('/i/follow', {
  962. item: id
  963. }).then(res => {
  964. if(type == 'following') {
  965. this.following.splice(index, 1);
  966. }
  967. }).catch(err => {
  968. if(err.response.data.message) {
  969. swal('Error', err.response.data.message, 'error');
  970. }
  971. });
  972. },
  973. owner(status) {
  974. return this.profile.id === status.account.id;
  975. },
  976. admin() {
  977. return this.profile.is_admin == true;
  978. },
  979. ownerOrAdmin(status) {
  980. return this.owner(status) || this.admin();
  981. },
  982. hideSuggestions() {
  983. localStorage.setItem('pf_metro_ui.exp.rec', false);
  984. this.showSuggestions = false;
  985. },
  986. emojiReaction(status) {
  987. let em = event.target.innerText;
  988. if(this.replyText.length == 0) {
  989. this.replyText = em + ' ';
  990. $('textarea[name="comment"]').focus();
  991. } else {
  992. this.replyText += em + ' ';
  993. $('textarea[name="comment"]').focus();
  994. }
  995. },
  996. refreshSuggestions() {
  997. let el = event.target.parentNode;
  998. if(el.classList.contains('disabled') == true) {
  999. return;
  1000. }
  1001. axios.get('/api/local/exp/rec', {
  1002. params: {
  1003. refresh: true
  1004. }
  1005. })
  1006. .then(res => {
  1007. this.suggestions = res.data;
  1008. if (el.classList) {
  1009. el.classList.add('disabled');
  1010. el.classList.add('text-light');
  1011. }
  1012. else {
  1013. el.className += ' ' + 'disabled text-light';
  1014. }
  1015. setTimeout(function() {
  1016. el.setAttribute('href', '#');
  1017. if (el.classList) {
  1018. el.classList.remove('disabled');
  1019. el.classList.remove('text-light');
  1020. }
  1021. else {
  1022. el.className = el.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), 'disabled text-light');
  1023. }
  1024. }, 10000);
  1025. });
  1026. }
  1027. }
  1028. }
  1029. </script>