Timeline.vue 36 KB

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