Timeline.vue 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118
  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. ids: [],
  416. config: {},
  417. page: 2,
  418. feed: [],
  419. profile: {},
  420. min_id: 0,
  421. max_id: 0,
  422. stories: {},
  423. suggestions: {},
  424. loading: true,
  425. replies: [],
  426. replyId: null,
  427. optionMenuState: false,
  428. modes: {
  429. 'mod': false,
  430. 'dark': false,
  431. 'notify': true,
  432. 'infinite': true
  433. },
  434. followers: [],
  435. followerCursor: 1,
  436. followerMore: true,
  437. following: [],
  438. followingCursor: 1,
  439. followingMore: true,
  440. lightboxMedia: false,
  441. showSuggestions: false,
  442. showReadMore: true,
  443. replyStatus: {},
  444. replyText: '',
  445. }
  446. },
  447. beforeMount() {
  448. axios.get('/api/v2/config')
  449. .then(res => {
  450. this.config = res.data;
  451. this.fetchTimelineApi();
  452. if(window.outerWidth > 767) {
  453. this.fetchProfile();
  454. }
  455. });
  456. },
  457. mounted() {
  458. if($('link[data-stylesheet="dark"]').length != 0) {
  459. this.modes.dark = true;
  460. }
  461. if(localStorage.getItem('pf_metro_ui.exp.rec') == 'false') {
  462. this.showSuggestions = false;
  463. } else {
  464. this.showSuggestions = true;
  465. }
  466. if(localStorage.getItem('pf_metro_ui.exp.rm') == 'false') {
  467. this.showReadMore = false;
  468. } else {
  469. this.showReadMore = true;
  470. }
  471. this.$nextTick(function () {
  472. $('[data-toggle="tooltip"]').tooltip()
  473. });
  474. },
  475. updated() {
  476. if(this.showReadMore == true) {
  477. pixelfed.readmore();
  478. }
  479. },
  480. methods: {
  481. fetchProfile() {
  482. axios.get('/api/v1/accounts/verify_credentials').then(res => {
  483. this.profile = res.data;
  484. if(this.profile.is_admin == true) {
  485. this.modes.mod = true;
  486. }
  487. $('.profile-card .loader').addClass('d-none');
  488. $('.profile-card .contents').removeClass('d-none');
  489. $('.profile-card .card-footer').removeClass('d-none');
  490. }).catch(err => {
  491. swal(
  492. 'Oops, something went wrong',
  493. 'Please reload the page.',
  494. 'error'
  495. );
  496. });
  497. },
  498. fetchTimelineApi() {
  499. let apiUrl = false;
  500. switch(this.scope) {
  501. case 'home':
  502. apiUrl = '/api/v1/timelines/home';
  503. break;
  504. case 'local':
  505. apiUrl = '/api/v1/timelines/public';
  506. break;
  507. case 'network':
  508. apiUrl = '/api/v1/timelines/network';
  509. break;
  510. }
  511. axios.get(apiUrl, {
  512. params: {
  513. max_id: this.max_id,
  514. limit: 6
  515. }
  516. }).then(res => {
  517. let data = res.data;
  518. this.feed.push(...data);
  519. let ids = data.map(status => status.id);
  520. this.ids = ids;
  521. this.min_id = Math.max(...ids);
  522. this.max_id = Math.min(...ids);
  523. $('.timeline .pagination').removeClass('d-none');
  524. this.loading = false;
  525. this.expRec();
  526. }).catch(err => {
  527. });
  528. },
  529. infiniteTimeline($state) {
  530. if(this.loading) {
  531. return;
  532. }
  533. let apiUrl = false;
  534. switch(this.scope) {
  535. case 'home':
  536. apiUrl = '/api/v1/timelines/home';
  537. break;
  538. case 'local':
  539. apiUrl = '/api/v1/timelines/public';
  540. break;
  541. case 'network':
  542. apiUrl = '/api/v1/timelines/network';
  543. break;
  544. }
  545. axios.get(apiUrl, {
  546. params: {
  547. max_id: this.max_id,
  548. limit: 6
  549. },
  550. }).then(res => {
  551. if (res.data.length && this.loading == false) {
  552. let data = res.data;
  553. let self = this;
  554. data.forEach(d => {
  555. if(self.ids.indexOf(d.id) == -1) {
  556. self.feed.push(d);
  557. self.ids.push(d.id);
  558. }
  559. });
  560. this.min_id = Math.max(...this.ids);
  561. this.max_id = Math.min(...this.ids);
  562. this.page += 1;
  563. $state.loaded();
  564. this.loading = false;
  565. } else {
  566. $state.complete();
  567. }
  568. });
  569. },
  570. loadMore(event) {
  571. let homeTimeline = '/api/v1/timelines/home';
  572. let localTimeline = '/api/v1/timelines/public';
  573. let apiUrl = this.scope == 'home' ? homeTimeline : localTimeline;
  574. event.target.innerText = 'Loading...';
  575. axios.get(apiUrl, {
  576. params: {
  577. page: this.page,
  578. },
  579. }).then(res => {
  580. if (res.data.length && this.loading == false) {
  581. let data = res.data;
  582. let ids = data.map(status => status.id);
  583. this.min_id = Math.min(...ids);
  584. if(this.page == 1) {
  585. this.max_id = Math.max(...ids);
  586. }
  587. this.feed.push(...data);
  588. this.page += 1;
  589. this.loading = false;
  590. event.target.innerText = 'Load more posts';
  591. } else {
  592. }
  593. });
  594. },
  595. reportUrl(status) {
  596. let type = status.in_reply_to ? 'comment' : 'post';
  597. let id = status.id;
  598. return '/i/report?type=' + type + '&id=' + id;
  599. },
  600. commentFocus(status, $event) {
  601. if(this.replyId == status.id || status.comments_disabled) {
  602. return;
  603. }
  604. this.replies = {};
  605. this.replyStatus = {};
  606. this.replyText = '';
  607. this.replyId = status.id;
  608. this.replyStatus = status;
  609. this.fetchStatusComments(status, '');
  610. },
  611. likeStatus(status) {
  612. if($('body').hasClass('loggedIn') == false) {
  613. return;
  614. }
  615. axios.post('/i/like', {
  616. item: status.id
  617. }).then(res => {
  618. status.favourites_count = res.data.count;
  619. status.favourited = !status.favourited;
  620. }).catch(err => {
  621. swal('Error', 'Something went wrong, please try again later.', 'error');
  622. });
  623. },
  624. shareStatus(status, $event) {
  625. if($('body').hasClass('loggedIn') == false) {
  626. return;
  627. }
  628. axios.post('/i/share', {
  629. item: status.id
  630. }).then(res => {
  631. status.reblogs_count = res.data.count;
  632. status.reblogged = !status.reblogged;
  633. }).catch(err => {
  634. swal('Error', 'Something went wrong, please try again later.', 'error');
  635. });
  636. },
  637. timestampFormat(timestamp) {
  638. let ts = new Date(timestamp);
  639. return ts.toDateString() + ' ' + ts.toLocaleTimeString();
  640. },
  641. editUrl(status) {
  642. return status.url + '/edit';
  643. },
  644. redirect(url) {
  645. window.location.href = url;
  646. return;
  647. },
  648. replyUrl(status) {
  649. let username = this.profile.username;
  650. let id = status.account.id == this.profile.id ? status.id : status.in_reply_to_id;
  651. return '/p/' + username + '/' + id;
  652. },
  653. mentionUrl(status) {
  654. let username = status.account.username;
  655. let id = status.id;
  656. return '/p/' + username + '/' + id;
  657. },
  658. statusOwner(status) {
  659. let sid = status.account.id;
  660. let uid = this.profile.id;
  661. if(sid == uid) {
  662. return true;
  663. } else {
  664. return false;
  665. }
  666. },
  667. fetchStatusComments(status, card) {
  668. axios.get('/api/v2/status/'+status.id+'/replies')
  669. .then(res => {
  670. let data = res.data;
  671. this.replies = _.reverse(data);
  672. }).catch(err => {
  673. })
  674. },
  675. muteProfile(status) {
  676. if($('body').hasClass('loggedIn') == false) {
  677. return;
  678. }
  679. axios.post('/i/mute', {
  680. type: 'user',
  681. item: status.account.id
  682. }).then(res => {
  683. this.feed = this.feed.filter(s => s.account.id !== status.account.id);
  684. swal('Success', 'You have successfully muted ' + status.account.acct, 'success');
  685. }).catch(err => {
  686. swal('Error', 'Something went wrong. Please try again later.', 'error');
  687. });
  688. },
  689. blockProfile(status) {
  690. if($('body').hasClass('loggedIn') == false) {
  691. return;
  692. }
  693. axios.post('/i/block', {
  694. type: 'user',
  695. item: status.account.id
  696. }).then(res => {
  697. this.feed = this.feed.filter(s => s.account.id !== status.account.id);
  698. swal('Success', 'You have successfully blocked ' + status.account.acct, 'success');
  699. }).catch(err => {
  700. swal('Error', 'Something went wrong. Please try again later.', 'error');
  701. });
  702. },
  703. deletePost(status, index) {
  704. if($('body').hasClass('loggedIn') == false || this.ownerOrAdmin(status) == false) {
  705. return;
  706. }
  707. if(window.confirm('Are you sure you want to delete this post?') == false) {
  708. return;
  709. }
  710. axios.post('/i/delete', {
  711. type: 'status',
  712. item: status.id
  713. }).then(res => {
  714. this.feed.splice(index,1);
  715. swal('Success', 'You have successfully deleted this post', 'success');
  716. }).catch(err => {
  717. swal('Error', 'Something went wrong. Please try again later.', 'error');
  718. });
  719. },
  720. commentSubmit(status, $event) {
  721. let id = status.id;
  722. let comment = this.replyText;
  723. axios.post('/i/comment', {
  724. item: id,
  725. comment: comment
  726. }).then(res => {
  727. this.replyText = '';
  728. this.replies.push(res.data.entity);
  729. });
  730. },
  731. moderatePost(status, action, $event) {
  732. let username = status.account.username;
  733. console.log('action: ' + action + ' status id' + status.id);
  734. switch(action) {
  735. case 'autocw':
  736. let msg = 'Are you sure you want to enforce CW for ' + username + ' ?';
  737. swal({
  738. title: 'Confirm',
  739. text: msg,
  740. icon: 'warning',
  741. buttons: true,
  742. dangerMode: true
  743. }).then(res => {
  744. if(res) {
  745. axios.post('/api/v2/moderator/action', {
  746. action: action,
  747. item_id: status.id,
  748. item_type: 'status'
  749. }).then(res => {
  750. swal('Success', 'Successfully enforced CW for ' + username, 'success');
  751. }).catch(err => {
  752. swal(
  753. 'Error',
  754. 'Something went wrong, please try again later.',
  755. 'error'
  756. );
  757. });
  758. }
  759. });
  760. break;
  761. case 'noautolink':
  762. msg = 'Are you sure you want to disable auto linking for ' + username + ' ?';
  763. swal({
  764. title: 'Confirm',
  765. text: msg,
  766. icon: 'warning',
  767. buttons: true,
  768. dangerMode: true
  769. }).then(res => {
  770. if(res) {
  771. axios.post('/api/v2/moderator/action', {
  772. action: action,
  773. item_id: status.id,
  774. item_type: 'status'
  775. }).then(res => {
  776. swal('Success', 'Successfully disabled autolinking for ' + username, 'success');
  777. }).catch(err => {
  778. swal(
  779. 'Error',
  780. 'Something went wrong, please try again later.',
  781. 'error'
  782. );
  783. });
  784. }
  785. });
  786. break;
  787. case 'unlisted':
  788. msg = 'Are you sure you want to unlist from timelines for ' + username + ' ?';
  789. swal({
  790. title: 'Confirm',
  791. text: msg,
  792. icon: 'warning',
  793. buttons: true,
  794. dangerMode: true
  795. }).then(res => {
  796. if(res) {
  797. axios.post('/api/v2/moderator/action', {
  798. action: action,
  799. item_id: status.id,
  800. item_type: 'status'
  801. }).then(res => {
  802. swal('Success', 'Successfully unlisted for ' + username, 'success');
  803. }).catch(err => {
  804. swal(
  805. 'Error',
  806. 'Something went wrong, please try again later.',
  807. 'error'
  808. );
  809. });
  810. }
  811. });
  812. break;
  813. case 'disable':
  814. msg = 'Are you sure you want to disable ' + username + '’s account ?';
  815. swal({
  816. title: 'Confirm',
  817. text: msg,
  818. icon: 'warning',
  819. buttons: true,
  820. dangerMode: true
  821. }).then(res => {
  822. if(res) {
  823. axios.post('/api/v2/moderator/action', {
  824. action: action,
  825. item_id: status.id,
  826. item_type: 'status'
  827. }).then(res => {
  828. swal('Success', 'Successfully disabled ' + username + '’s account', 'success');
  829. }).catch(err => {
  830. swal(
  831. 'Error',
  832. 'Something went wrong, please try again later.',
  833. 'error'
  834. );
  835. });
  836. }
  837. });
  838. break;
  839. case 'suspend':
  840. msg = 'Are you sure you want to suspend ' + username + '’s account ?';
  841. swal({
  842. title: 'Confirm',
  843. text: msg,
  844. icon: 'warning',
  845. buttons: true,
  846. dangerMode: true
  847. }).then(res => {
  848. if(res) {
  849. axios.post('/api/v2/moderator/action', {
  850. action: action,
  851. item_id: status.id,
  852. item_type: 'status'
  853. }).then(res => {
  854. swal('Success', 'Successfully suspend ' + username + '’s account', 'success');
  855. }).catch(err => {
  856. swal(
  857. 'Error',
  858. 'Something went wrong, please try again later.',
  859. 'error'
  860. );
  861. });
  862. }
  863. });
  864. break;
  865. }
  866. },
  867. toggleOptionsMenu() {
  868. this.optionMenuState = !this.optionMenuState;
  869. },
  870. modeModToggle() {
  871. this.modes.mod = !this.modes.mod;
  872. //window.ls.set('pixelfed-classicui-settings', this.modes);
  873. },
  874. modeNotifyToggle() {
  875. this.modes.notify = !this.modes.notify;
  876. //window.ls.set('pixelfed-classicui-settings', this.modes);
  877. },
  878. modeDarkToggle() {
  879. // todo: more graceful stylesheet change
  880. if(this.modes.dark == true) {
  881. axios.post('/i/metro/dark-mode', {
  882. mode: 'light'
  883. }).then(res => {
  884. $('link[data-stylesheet=dark]')
  885. .attr('data-stylesheet', 'light')
  886. .attr('href', '/css/app.css?v=' + Date.now());
  887. this.modes.dark = false;
  888. });
  889. } else {
  890. axios.post('/i/metro/dark-mode', {
  891. mode: 'dark'
  892. }).then(res => {
  893. $('link[data-stylesheet=light]')
  894. .attr('data-stylesheet', 'dark')
  895. .attr('href', '/css/appdark.css?v=' + Date.now());
  896. this.modes.dark = true;
  897. });
  898. }
  899. //window.ls.set('pixelfed-classicui-settings', this.modes);
  900. },
  901. modeInfiniteToggle() {
  902. this.modes.infinite = !this.modes.infinite
  903. //window.ls.set('pixelfed-classicui-settings', this.modes);
  904. },
  905. followingModal() {
  906. if(this.following.length > 0) {
  907. this.$refs.followingModal.show();
  908. return;
  909. }
  910. axios.get('/api/v1/accounts/'+this.profile.id+'/following', {
  911. params: {
  912. page: this.followingCursor
  913. }
  914. })
  915. .then(res => {
  916. this.following = res.data;
  917. this.followingCursor++;
  918. });
  919. if(res.data.length < 10) {
  920. this.followingMore = false;
  921. }
  922. this.$refs.followingModal.show();
  923. },
  924. followersModal() {
  925. if(this.followers.length > 0) {
  926. this.$refs.followerModal.show();
  927. return;
  928. }
  929. axios.get('/api/v1/accounts/'+this.profile.id+'/followers', {
  930. params: {
  931. page: this.followerCursor
  932. }
  933. })
  934. .then(res => {
  935. this.followers = res.data;
  936. this.followerCursor++;
  937. })
  938. if(res.data.length < 10) {
  939. this.followerMore = false;
  940. }
  941. this.$refs.followerModal.show();
  942. },
  943. followingLoadMore() {
  944. axios.get('/api/v1/accounts/'+this.profile.id+'/following', {
  945. params: {
  946. page: this.followingCursor
  947. }
  948. })
  949. .then(res => {
  950. if(res.data.length > 0) {
  951. this.following.push(...res.data);
  952. this.followingCursor++;
  953. }
  954. if(res.data.length < 10) {
  955. this.followingMore = false;
  956. }
  957. });
  958. },
  959. followersLoadMore() {
  960. axios.get('/api/v1/accounts/'+this.profile.id+'/followers', {
  961. params: {
  962. page: this.followerCursor
  963. }
  964. })
  965. .then(res => {
  966. if(res.data.length > 0) {
  967. this.followers.push(...res.data);
  968. this.followerCursor++;
  969. }
  970. if(res.data.length < 10) {
  971. this.followerMore = false;
  972. }
  973. });
  974. },
  975. lightbox(src) {
  976. this.lightboxMedia = src;
  977. this.$refs.lightboxModal.show();
  978. },
  979. expLc(status) {
  980. if(this.config.ab.lc == false) {
  981. return true;
  982. }
  983. if(this.statusOwner(status) == true) {
  984. return true;
  985. }
  986. return false;
  987. },
  988. expRec() {
  989. if(this.config.ab.rec == false) {
  990. return;
  991. }
  992. axios.get('/api/local/exp/rec')
  993. .then(res => {
  994. this.suggestions = res.data;
  995. })
  996. },
  997. expRecFollow(id, index) {
  998. if(this.config.ab.rec == false) {
  999. return;
  1000. }
  1001. axios.post('/i/follow', {
  1002. item: id
  1003. }).then(res => {
  1004. this.suggestions.splice(index, 1);
  1005. })
  1006. },
  1007. followModalAction(id, index, type = 'following') {
  1008. axios.post('/i/follow', {
  1009. item: id
  1010. }).then(res => {
  1011. if(type == 'following') {
  1012. this.following.splice(index, 1);
  1013. }
  1014. })
  1015. },
  1016. owner(status) {
  1017. return this.profile.id === status.account.id;
  1018. },
  1019. admin() {
  1020. return this.profile.is_admin == true;
  1021. },
  1022. ownerOrAdmin(status) {
  1023. return this.owner(status) || this.admin();
  1024. },
  1025. hideSuggestions() {
  1026. localStorage.setItem('pf_metro_ui.exp.rec', false);
  1027. this.showSuggestions = false;
  1028. },
  1029. emojiReaction(status) {
  1030. let em = event.target.innerText;
  1031. if(this.replyText.length == 0) {
  1032. this.replyText = em + ' ';
  1033. $('textarea[name="comment"]').focus();
  1034. } else {
  1035. this.replyText += em + ' ';
  1036. $('textarea[name="comment"]').focus();
  1037. }
  1038. },
  1039. }
  1040. }
  1041. </script>