Timeline.vue 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064
  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" 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">
  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">
  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 class="card-footer bg-white" v-if="status.id == replyId">
  146. <form class="" v-on:submit.prevent="commentSubmit(status, $event)">
  147. <input type="hidden" name="item" value="">
  148. <input class="form-control status-reply-input" name="comment" placeholder="Add a comment…" autocomplete="off">
  149. </form>
  150. </div>
  151. </div>
  152. </div>
  153. <div v-if="modes.infinite == true && !loading && feed.length > 0">
  154. <div class="card">
  155. <div class="card-body">
  156. <infinite-loading @infinite="infiniteTimeline" :distance="800">
  157. <div slot="no-more" class="font-weight-bold">No more posts to load</div>
  158. <div slot="no-results" class="font-weight-bold">No posts found</div>
  159. </infinite-loading>
  160. </div>
  161. </div>
  162. </div>
  163. <div v-if="modes.infinite == false && !loading && feed.length > 0" class="pagination">
  164. <p class="btn btn-outline-secondary font-weight-bold btn-block" v-on:click="loadMore">Load more posts</p>
  165. </div>
  166. <div v-if="!loading && scope == 'home' && feed.length == 0">
  167. <div class="card">
  168. <div class="card-body text-center">
  169. <p class="h2 font-weight-lighter p-5">Hello, {{profile.acct}}</p>
  170. <p class="text-lighter"><i class="fas fa-camera-retro fa-5x"></i></p>
  171. <p class="h3 font-weight-lighter p-5">Start following people to build your timeline.</p>
  172. <p><a href="/discover" class="btn btn-primary font-weight-bold py-0">Discover new people and posts</a></p>
  173. </div>
  174. </div>
  175. </div>
  176. </div>
  177. </div>
  178. <div class="col-md-4 col-lg-4 pt-2 my-3 order-1 order-md-2 d-none d-md-block">
  179. <div class="position-sticky" style="top:68px;">
  180. <div class="mb-4">
  181. <div class="">
  182. <div class="">
  183. <div class="media d-flex align-items-center">
  184. <a :href="profile.url">
  185. <img class="mr-3 rounded-circle box-shadow" :src="profile.avatar || '/storage/avatars/default.png'" alt="avatar" width="64px" height="64px">
  186. </a>
  187. <div class="media-body d-flex justify-content-between word-break" >
  188. <div>
  189. <p class="mb-0 px-0 font-weight-bold"><a :href="profile.url" class="text-dark">{{profile.username || 'loading...'}}</a></p>
  190. <p class="my-0 text-muted pb-0">{{profile.display_name || 'loading...'}}</p>
  191. </div>
  192. <div class="ml-2">
  193. <a :class="[optionMenuState == true ? 'text-primary' :'text-muted']" v-on:click="toggleOptionsMenu()"><i class="fas fa-cog fa-lg"></i></a>
  194. </div>
  195. </div>
  196. </div>
  197. </div>
  198. <!-- <div class="card-footer bg-white py-1 d-none">
  199. <div class="d-flex justify-content-between text-center">
  200. <span class="pl-3 cursor-pointer" v-on:click="redirect(profile.url)">
  201. <p class="mb-0 font-weight-bold">{{profile.statuses_count}}</p>
  202. <p class="mb-0 small text-muted">Posts</p>
  203. </span>
  204. <span class="cursor-pointer" v-on:click="followersModal()">
  205. <p class="mb-0 font-weight-bold">{{profile.followers_count}}</p>
  206. <p class="mb-0 small text-muted">Followers</p>
  207. </span>
  208. <span class="pr-3 cursor-pointer" v-on:click="followingModal()">
  209. <p class="mb-0 font-weight-bold">{{profile.following_count}}</p>
  210. <p class="mb-0 small text-muted">Following</p>
  211. </span>
  212. </div>
  213. </div> -->
  214. </div>
  215. </div>
  216. <div v-if="optionMenuState == true" class="mb-4">
  217. <div class="card options-card">
  218. <div class="card-body small">
  219. <div v-if="profile.is_admin" class="custom-control custom-switch mb-3">
  220. <input type="checkbox" class="custom-control-input" id="mode-mod" v-on:click="modeModToggle()" v-model="modes.mod">
  221. <label class="custom-control-label font-weight-bold" for="mode-mod">Moderator Mode</label>
  222. </div>
  223. <!-- <div class="custom-control custom-switch mb-3">
  224. <input type="checkbox" class="custom-control-input" id="mode-notify" v-on:click="modeNotifyToggle()" v-model="!modes.notify">
  225. <label class="custom-control-label font-weight-bold" for="mode-notify">Disable Notifications</label>
  226. </div> -->
  227. <div class="custom-control custom-switch">
  228. <input type="checkbox" class="custom-control-input" id="mode-infinite" v-on:click="modeInfiniteToggle()" v-model="modes.infinite">
  229. <label class="custom-control-label font-weight-bold" for="mode-infinite">Enable Infinite Scroll</label>
  230. </div>
  231. <hr>
  232. <p class="font-weight-bold">BETA FEATURES</p>
  233. <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>
  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. <div></div>
  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. </style>
  376. <script type="text/javascript">
  377. export default {
  378. props: ['scope'],
  379. data() {
  380. return {
  381. config: {},
  382. page: 2,
  383. feed: [],
  384. profile: {},
  385. min_id: 0,
  386. max_id: 0,
  387. stories: {},
  388. suggestions: {},
  389. loading: true,
  390. replies: [],
  391. replyId: null,
  392. optionMenuState: false,
  393. modes: {
  394. 'mod': false,
  395. 'dark': false,
  396. 'notify': true,
  397. 'infinite': true
  398. },
  399. followers: [],
  400. followerCursor: 1,
  401. followerMore: true,
  402. following: [],
  403. followingCursor: 1,
  404. followingMore: true,
  405. lightboxMedia: false,
  406. showSuggestions: false,
  407. showReadMore: true,
  408. }
  409. },
  410. beforeMount() {
  411. axios.get('/api/v2/config')
  412. .then(res => {
  413. this.config = res.data;
  414. this.fetchTimelineApi();
  415. if(window.outerWidth > 767) {
  416. this.fetchProfile();
  417. }
  418. });
  419. },
  420. mounted() {
  421. if($('link[data-stylesheet="dark"]').length != 0) {
  422. this.modes.dark = true;
  423. }
  424. if(localStorage.getItem('pf_metro_ui.exp.rec') == 'false') {
  425. this.showSuggestions = false;
  426. } else {
  427. this.showSuggestions = true;
  428. }
  429. if(localStorage.getItem('pf_metro_ui.exp.rm') == 'false') {
  430. this.showReadMore = false;
  431. } else {
  432. this.showReadMore = true;
  433. }
  434. this.$nextTick(function () {
  435. $('[data-toggle="tooltip"]').tooltip()
  436. });
  437. },
  438. updated() {
  439. if(this.showReadMore == true) {
  440. pixelfed.readmore();
  441. }
  442. },
  443. methods: {
  444. fetchProfile() {
  445. axios.get('/api/v1/accounts/verify_credentials').then(res => {
  446. this.profile = res.data;
  447. if(this.profile.is_admin == true) {
  448. this.modes.mod = true;
  449. }
  450. $('.profile-card .loader').addClass('d-none');
  451. $('.profile-card .contents').removeClass('d-none');
  452. $('.profile-card .card-footer').removeClass('d-none');
  453. }).catch(err => {
  454. swal(
  455. 'Oops, something went wrong',
  456. 'Please reload the page.',
  457. 'error'
  458. );
  459. });
  460. },
  461. fetchTimelineApi() {
  462. let apiUrl = false;
  463. switch(this.scope) {
  464. case 'home':
  465. apiUrl = '/api/v1/timelines/home';
  466. break;
  467. case 'local':
  468. apiUrl = '/api/v1/timelines/public';
  469. break;
  470. case 'network':
  471. apiUrl = '/api/v1/timelines/network';
  472. break;
  473. }
  474. axios.get(apiUrl, {
  475. params: {
  476. max_id: this.max_id,
  477. limit: 6
  478. }
  479. }).then(res => {
  480. let data = res.data;
  481. this.feed.push(...data);
  482. let ids = data.map(status => status.id);
  483. this.min_id = Math.max(...ids);
  484. this.max_id = Math.min(...ids);
  485. $('.timeline .pagination').removeClass('d-none');
  486. this.loading = false;
  487. this.expRec();
  488. }).catch(err => {
  489. });
  490. },
  491. infiniteTimeline($state) {
  492. if(this.loading) {
  493. return;
  494. }
  495. let apiUrl = false;
  496. switch(this.scope) {
  497. case 'home':
  498. apiUrl = '/api/v1/timelines/home';
  499. break;
  500. case 'local':
  501. apiUrl = '/api/v1/timelines/public';
  502. break;
  503. case 'network':
  504. apiUrl = '/api/v1/timelines/network';
  505. break;
  506. }
  507. axios.get(apiUrl, {
  508. params: {
  509. max_id: this.max_id,
  510. limit: 6
  511. },
  512. }).then(res => {
  513. if (res.data.length && this.loading == false) {
  514. let data = res.data;
  515. this.feed.push(...data);
  516. let ids = data.map(status => status.id);
  517. this.min_id = Math.max(...ids);
  518. this.max_id = Math.min(...ids);
  519. this.page += 1;
  520. $state.loaded();
  521. this.loading = false;
  522. } else {
  523. $state.complete();
  524. }
  525. });
  526. },
  527. loadMore(event) {
  528. let homeTimeline = '/api/v1/timelines/home';
  529. let localTimeline = '/api/v1/timelines/public';
  530. let apiUrl = this.scope == 'home' ? homeTimeline : localTimeline;
  531. event.target.innerText = 'Loading...';
  532. axios.get(apiUrl, {
  533. params: {
  534. page: this.page,
  535. },
  536. }).then(res => {
  537. if (res.data.length && this.loading == false) {
  538. let data = res.data;
  539. let ids = data.map(status => status.id);
  540. this.min_id = Math.min(...ids);
  541. if(this.page == 1) {
  542. this.max_id = Math.max(...ids);
  543. }
  544. this.feed.push(...data);
  545. this.page += 1;
  546. this.loading = false;
  547. event.target.innerText = 'Load more posts';
  548. } else {
  549. }
  550. });
  551. },
  552. reportUrl(status) {
  553. let type = status.in_reply_to ? 'comment' : 'post';
  554. let id = status.id;
  555. return '/i/report?type=' + type + '&id=' + id;
  556. },
  557. commentFocus(status, $event) {
  558. if(this.replyId == status.id || status.comments_disabled) {
  559. return;
  560. }
  561. this.replies = {};
  562. this.replyId = status.id;
  563. this.fetchStatusComments(status, '');
  564. },
  565. likeStatus(status, $event) {
  566. if($('body').hasClass('loggedIn') == false) {
  567. return;
  568. }
  569. axios.post('/i/like', {
  570. item: status.id
  571. }).then(res => {
  572. status.favourites_count = res.data.count;
  573. status.favourited = !status.favourited;
  574. }).catch(err => {
  575. swal('Error', 'Something went wrong, please try again later.', 'error');
  576. });
  577. },
  578. shareStatus(status, $event) {
  579. if($('body').hasClass('loggedIn') == false) {
  580. return;
  581. }
  582. axios.post('/i/share', {
  583. item: status.id
  584. }).then(res => {
  585. status.reblogs_count = res.data.count;
  586. status.reblogged = !status.reblogged;
  587. }).catch(err => {
  588. swal('Error', 'Something went wrong, please try again later.', 'error');
  589. });
  590. },
  591. timestampFormat(timestamp) {
  592. let ts = new Date(timestamp);
  593. return ts.toDateString() + ' ' + ts.toLocaleTimeString();
  594. },
  595. editUrl(status) {
  596. return status.url + '/edit';
  597. },
  598. redirect(url) {
  599. window.location.href = url;
  600. return;
  601. },
  602. replyUrl(status) {
  603. let username = this.profile.username;
  604. let id = status.account.id == this.profile.id ? status.id : status.in_reply_to_id;
  605. return '/p/' + username + '/' + id;
  606. },
  607. mentionUrl(status) {
  608. let username = status.account.username;
  609. let id = status.id;
  610. return '/p/' + username + '/' + id;
  611. },
  612. statusOwner(status) {
  613. let sid = status.account.id;
  614. let uid = this.profile.id;
  615. if(sid == uid) {
  616. return true;
  617. } else {
  618. return false;
  619. }
  620. },
  621. fetchStatusComments(status, card) {
  622. axios.get('/api/v2/status/'+status.id+'/replies')
  623. .then(res => {
  624. let data = res.data;
  625. this.replies = _.reverse(data);
  626. }).catch(err => {
  627. })
  628. },
  629. muteProfile(status) {
  630. if($('body').hasClass('loggedIn') == false) {
  631. return;
  632. }
  633. axios.post('/i/mute', {
  634. type: 'user',
  635. item: status.account.id
  636. }).then(res => {
  637. this.feed = this.feed.filter(s => s.account.id !== status.account.id);
  638. swal('Success', 'You have successfully muted ' + status.account.acct, 'success');
  639. }).catch(err => {
  640. swal('Error', 'Something went wrong. Please try again later.', 'error');
  641. });
  642. },
  643. blockProfile(status) {
  644. if($('body').hasClass('loggedIn') == false) {
  645. return;
  646. }
  647. axios.post('/i/block', {
  648. type: 'user',
  649. item: status.account.id
  650. }).then(res => {
  651. this.feed = this.feed.filter(s => s.account.id !== status.account.id);
  652. swal('Success', 'You have successfully blocked ' + status.account.acct, 'success');
  653. }).catch(err => {
  654. swal('Error', 'Something went wrong. Please try again later.', 'error');
  655. });
  656. },
  657. deletePost(status, index) {
  658. if($('body').hasClass('loggedIn') == false || this.ownerOrAdmin(status) == false) {
  659. return;
  660. }
  661. if(window.confirm('Are you sure you want to delete this post?') == false) {
  662. return;
  663. }
  664. axios.post('/i/delete', {
  665. type: 'status',
  666. item: status.id
  667. }).then(res => {
  668. this.feed.splice(index,1);
  669. swal('Success', 'You have successfully deleted this post', 'success');
  670. }).catch(err => {
  671. swal('Error', 'Something went wrong. Please try again later.', 'error');
  672. });
  673. },
  674. commentSubmit(status, $event) {
  675. let id = status.id;
  676. let form = $event.target;
  677. let input = $(form).find('input[name="comment"]');
  678. let comment = input.val();
  679. let comments = form.parentElement.parentElement.getElementsByClassName('comments')[0];
  680. axios.post('/i/comment', {
  681. item: id,
  682. comment: comment
  683. }).then(res => {
  684. form.reset();
  685. form.blur();
  686. this.replies.push(res.data.entity);
  687. });
  688. },
  689. moderatePost(status, action, $event) {
  690. let username = status.account.username;
  691. console.log('action: ' + action + ' status id' + status.id);
  692. switch(action) {
  693. case 'autocw':
  694. let msg = 'Are you sure you want to enforce CW for ' + username + ' ?';
  695. swal({
  696. title: 'Confirm',
  697. text: msg,
  698. icon: 'warning',
  699. buttons: true,
  700. dangerMode: true
  701. }).then(res => {
  702. if(res) {
  703. axios.post('/api/v2/moderator/action', {
  704. action: action,
  705. item_id: status.id,
  706. item_type: 'status'
  707. }).then(res => {
  708. swal('Success', 'Successfully enforced CW for ' + username, 'success');
  709. }).catch(err => {
  710. swal(
  711. 'Error',
  712. 'Something went wrong, please try again later.',
  713. 'error'
  714. );
  715. });
  716. }
  717. });
  718. break;
  719. case 'noautolink':
  720. msg = 'Are you sure you want to disable auto linking for ' + username + ' ?';
  721. swal({
  722. title: 'Confirm',
  723. text: msg,
  724. icon: 'warning',
  725. buttons: true,
  726. dangerMode: true
  727. }).then(res => {
  728. if(res) {
  729. axios.post('/api/v2/moderator/action', {
  730. action: action,
  731. item_id: status.id,
  732. item_type: 'status'
  733. }).then(res => {
  734. swal('Success', 'Successfully disabled autolinking for ' + username, 'success');
  735. }).catch(err => {
  736. swal(
  737. 'Error',
  738. 'Something went wrong, please try again later.',
  739. 'error'
  740. );
  741. });
  742. }
  743. });
  744. break;
  745. case 'unlisted':
  746. msg = 'Are you sure you want to unlist from timelines for ' + username + ' ?';
  747. swal({
  748. title: 'Confirm',
  749. text: msg,
  750. icon: 'warning',
  751. buttons: true,
  752. dangerMode: true
  753. }).then(res => {
  754. if(res) {
  755. axios.post('/api/v2/moderator/action', {
  756. action: action,
  757. item_id: status.id,
  758. item_type: 'status'
  759. }).then(res => {
  760. swal('Success', 'Successfully unlisted for ' + username, 'success');
  761. }).catch(err => {
  762. swal(
  763. 'Error',
  764. 'Something went wrong, please try again later.',
  765. 'error'
  766. );
  767. });
  768. }
  769. });
  770. break;
  771. case 'disable':
  772. msg = 'Are you sure you want to disable ' + username + '’s account ?';
  773. swal({
  774. title: 'Confirm',
  775. text: msg,
  776. icon: 'warning',
  777. buttons: true,
  778. dangerMode: true
  779. }).then(res => {
  780. if(res) {
  781. axios.post('/api/v2/moderator/action', {
  782. action: action,
  783. item_id: status.id,
  784. item_type: 'status'
  785. }).then(res => {
  786. swal('Success', 'Successfully disabled ' + username + '’s account', 'success');
  787. }).catch(err => {
  788. swal(
  789. 'Error',
  790. 'Something went wrong, please try again later.',
  791. 'error'
  792. );
  793. });
  794. }
  795. });
  796. break;
  797. case 'suspend':
  798. msg = 'Are you sure you want to suspend ' + username + '’s account ?';
  799. swal({
  800. title: 'Confirm',
  801. text: msg,
  802. icon: 'warning',
  803. buttons: true,
  804. dangerMode: true
  805. }).then(res => {
  806. if(res) {
  807. axios.post('/api/v2/moderator/action', {
  808. action: action,
  809. item_id: status.id,
  810. item_type: 'status'
  811. }).then(res => {
  812. swal('Success', 'Successfully suspend ' + username + '’s account', 'success');
  813. }).catch(err => {
  814. swal(
  815. 'Error',
  816. 'Something went wrong, please try again later.',
  817. 'error'
  818. );
  819. });
  820. }
  821. });
  822. break;
  823. }
  824. },
  825. toggleOptionsMenu() {
  826. this.optionMenuState = !this.optionMenuState;
  827. },
  828. modeModToggle() {
  829. this.modes.mod = !this.modes.mod;
  830. //window.ls.set('pixelfed-classicui-settings', this.modes);
  831. },
  832. modeNotifyToggle() {
  833. this.modes.notify = !this.modes.notify;
  834. //window.ls.set('pixelfed-classicui-settings', this.modes);
  835. },
  836. modeDarkToggle() {
  837. // todo: more graceful stylesheet change
  838. if(this.modes.dark == true) {
  839. axios.post('/i/metro/dark-mode', {
  840. mode: 'light'
  841. }).then(res => {
  842. $('link[data-stylesheet=dark]')
  843. .attr('data-stylesheet', 'light')
  844. .attr('href', '/css/app.css?v=' + Date.now());
  845. this.modes.dark = false;
  846. });
  847. } else {
  848. axios.post('/i/metro/dark-mode', {
  849. mode: 'dark'
  850. }).then(res => {
  851. $('link[data-stylesheet=light]')
  852. .attr('data-stylesheet', 'dark')
  853. .attr('href', '/css/appdark.css?v=' + Date.now());
  854. this.modes.dark = true;
  855. });
  856. }
  857. //window.ls.set('pixelfed-classicui-settings', this.modes);
  858. },
  859. modeInfiniteToggle() {
  860. this.modes.infinite = !this.modes.infinite
  861. //window.ls.set('pixelfed-classicui-settings', this.modes);
  862. },
  863. followingModal() {
  864. if(this.following.length > 0) {
  865. this.$refs.followingModal.show();
  866. return;
  867. }
  868. axios.get('/api/v1/accounts/'+this.profile.id+'/following', {
  869. params: {
  870. page: this.followingCursor
  871. }
  872. })
  873. .then(res => {
  874. this.following = res.data;
  875. this.followingCursor++;
  876. });
  877. if(res.data.length < 10) {
  878. this.followingMore = false;
  879. }
  880. this.$refs.followingModal.show();
  881. },
  882. followersModal() {
  883. if(this.followers.length > 0) {
  884. this.$refs.followerModal.show();
  885. return;
  886. }
  887. axios.get('/api/v1/accounts/'+this.profile.id+'/followers', {
  888. params: {
  889. page: this.followerCursor
  890. }
  891. })
  892. .then(res => {
  893. this.followers = res.data;
  894. this.followerCursor++;
  895. })
  896. if(res.data.length < 10) {
  897. this.followerMore = false;
  898. }
  899. this.$refs.followerModal.show();
  900. },
  901. followingLoadMore() {
  902. axios.get('/api/v1/accounts/'+this.profile.id+'/following', {
  903. params: {
  904. page: this.followingCursor
  905. }
  906. })
  907. .then(res => {
  908. if(res.data.length > 0) {
  909. this.following.push(...res.data);
  910. this.followingCursor++;
  911. }
  912. if(res.data.length < 10) {
  913. this.followingMore = false;
  914. }
  915. });
  916. },
  917. followersLoadMore() {
  918. axios.get('/api/v1/accounts/'+this.profile.id+'/followers', {
  919. params: {
  920. page: this.followerCursor
  921. }
  922. })
  923. .then(res => {
  924. if(res.data.length > 0) {
  925. this.followers.push(...res.data);
  926. this.followerCursor++;
  927. }
  928. if(res.data.length < 10) {
  929. this.followerMore = false;
  930. }
  931. });
  932. },
  933. lightbox(src) {
  934. this.lightboxMedia = src;
  935. this.$refs.lightboxModal.show();
  936. },
  937. expLc(status) {
  938. if(this.config.ab.lc == false) {
  939. return true;
  940. }
  941. if(this.statusOwner(status) == true) {
  942. return true;
  943. }
  944. return false;
  945. },
  946. expRec() {
  947. if(this.config.ab.rec == false) {
  948. return;
  949. }
  950. axios.get('/api/local/exp/rec')
  951. .then(res => {
  952. this.suggestions = res.data;
  953. })
  954. },
  955. expRecFollow(id, index) {
  956. if(this.config.ab.rec == false) {
  957. return;
  958. }
  959. axios.post('/i/follow', {
  960. item: id
  961. }).then(res => {
  962. this.suggestions.splice(index, 1);
  963. })
  964. },
  965. followModalAction(id, index, type = 'following') {
  966. axios.post('/i/follow', {
  967. item: id
  968. }).then(res => {
  969. if(type == 'following') {
  970. this.following.splice(index, 1);
  971. }
  972. })
  973. },
  974. owner(status) {
  975. return this.profile.id === status.account.id;
  976. },
  977. admin() {
  978. return this.profile.is_admin == true;
  979. },
  980. ownerOrAdmin(status) {
  981. return this.owner(status) || this.admin();
  982. },
  983. hideSuggestions() {
  984. localStorage.setItem('pf_metro_ui.exp.rec', false);
  985. this.showSuggestions = false;
  986. }
  987. }
  988. }
  989. </script>