Timeline.vue 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154
  1. <template>
  2. <div>
  3. <div v-if="currentLayout === 'feed'" class="container">
  4. <div class="row">
  5. <div v-if="morePostsAvailable == true" class="col-12 mt-5 pt-3 mb-3 fixed-top">
  6. <p class="text-center">
  7. <button class="btn btn-dark px-4 rounded-pill font-weight-bold shadow" @click="syncNewPosts">Load New Posts</button>
  8. </p>
  9. </div>
  10. <div class="col-md-8 col-lg-8 px-0 mb-sm-3 timeline order-2 order-md-1">
  11. <div style="margin-top:-2px;">
  12. <story-component v-if="config.features.stories" :scope="scope"></story-component>
  13. </div>
  14. <div class="pt-4">
  15. <div v-if="loading" class="text-center" style="padding-top:10px;">
  16. <div class="spinner-border" role="status">
  17. <span class="sr-only">Loading...</span>
  18. </div>
  19. </div>
  20. <div :data-status-id="status.id" v-for="(status, index) in feed" :key="`feed-${index}-${status.id}`">
  21. <div v-if="index == 1 && !loading && showPromo" class="">
  22. <div class="card rounded-0 shadow-none border border-top-0 py-5">
  23. <div class="card-body p-5 my-5">
  24. <h1>A New Experience Awaits</h1>
  25. <p class="lead">Try out an early release of our new design</p>
  26. <p class="mb-0 d-flex align-items-center">
  27. <a class="btn btn-primary font-weight-bold py-1 px-4 rounded-pill mr-4" href="/i/web">Try new UI</a>
  28. <a class="font-weight-bold text-muted" href="/" @click.prevent="hidePromo()">Hide</a>
  29. </p>
  30. </div>
  31. </div>
  32. </div>
  33. <!-- <div v-if="index == 0 && showTips && !loading" class="my-4 card-tips">
  34. <announcements-card v-on:show-tips="showTips = $event"></announcements-card>
  35. </div> -->
  36. <!-- <div v-if="index == 2 && showSuggestions == true && suggestions.length" class="card status-card rounded-0 shadow-none border">
  37. <div class="card-header d-flex align-items-center justify-content-between bg-white border-0 pb-0">
  38. <h6 class="text-muted font-weight-bold mb-0">Suggestions For You</h6>
  39. <span class="cursor-pointer text-muted" v-on:click="hideSuggestions"><i class="fas fa-times"></i></span>
  40. </div>
  41. <div class="card-body row mx-0">
  42. <div class="col-12 col-md-4 mb-3" v-for="(rec, index) in suggestions">
  43. <div class="card">
  44. <div class="card-body text-center pt-3">
  45. <p class="mb-0">
  46. <a :href="'/'+rec.username">
  47. <img :src="rec.avatar" class="img-fluid rounded-circle cursor-pointer" width="45px" height="45px" onerror="this.onerror=null;this.src='/storage/avatars/default.png?v=2'" alt="avatar">
  48. </a>
  49. </p>
  50. <div class="py-3">
  51. <p class="font-weight-bold text-dark cursor-pointer mb-0">
  52. <a :href="'/'+rec.username" class="text-decoration-none text-dark">
  53. {{rec.username}}
  54. </a>
  55. </p>
  56. <p class="small text-muted mb-0">{{rec.message}}</p>
  57. </div>
  58. <p class="mb-0">
  59. <a class="btn btn-primary btn-block font-weight-bold py-0" href="#" @click.prevent="expRecFollow(rec.id, index)">Follow</a>
  60. </p>
  61. </div>
  62. </div>
  63. </div>
  64. </div>
  65. </div> -->
  66. <!-- <div v-if="index == 4 && showHashtagPosts && hashtagPosts.length" class="card status-card rounded-0 shadow-none border border-top-0">
  67. <div class="card-header bg-white border-0 mb-0">
  68. <div class="d-flex align-items-center justify-content-between pt-2">
  69. <div></div>
  70. <div>
  71. <h6 class="text-muted lead font-weight-bold mb-0"><a :href="'/discover/tags/'+hashtagPostsName+'?src=tr'">#{{hashtagPostsName}}</a></h6>
  72. </div>
  73. <div class="cursor-pointer text-muted" v-on:click="showHashtagPosts = false"><i class="fas fa-times"></i></div>
  74. </div>
  75. <p class="small text-muted text-center mb-0">You follow this hashtag. <a href="/site/kb/hashtags">Learn more</a></p>
  76. </div>
  77. <div class="card-body row mx-0">
  78. <div v-for="(tag, index) in hashtagPosts" class="col-4 p-1 hashtag-post-square">
  79. <a class="card info-overlay card-md-border-0" :href="tag.status.url">
  80. <div class="square">
  81. <div v-if="tag.status.sensitive" class="square-content">
  82. <div class="info-overlay-text-label">
  83. <h5 class="text-white m-auto font-weight-bold">
  84. <span>
  85. <span class="far fa-eye-slash fa-lg p-2 d-flex-inline"></span>
  86. </span>
  87. </h5>
  88. </div>
  89. <blur-hash-canvas
  90. width="32"
  91. height="32"
  92. :hash="tag.status.media_attachments[0].blurhash"
  93. />
  94. </div>
  95. <div v-else class="square-content">
  96. <blur-hash-image
  97. width="32"
  98. height="32"
  99. :hash="tag.status.media_attachments[0].blurhash"
  100. :src="tag.status.media_attachments[0].preview_url"
  101. onerror="this.onerror=null;this.src='/storage/no-preview.png'"
  102. />
  103. </div>
  104. </div>
  105. </a>
  106. </div>
  107. </div>
  108. </div> -->
  109. <status-card
  110. :class="{ 'border-top': index === 0 }"
  111. :status="status"
  112. :reaction-bar="reactionBar"
  113. size="small"
  114. v-on:status-delete="deleteStatus"
  115. v-on:comment-focus="commentFocus"
  116. v-on:followed="followedAccount"
  117. v-on:unfollowed="unfollowedAccount"
  118. />
  119. </div>
  120. <div v-if="!loading && feed.length">
  121. <div class="card rounded-0 border-top-0 status-card rounded-0 shadow-none border">
  122. <div class="card-body py-5 my-5">
  123. <infinite-loading @infinite="infiniteTimeline" :distance="800">
  124. <div slot="no-more">
  125. <div v-if="recentFeed">
  126. <p class="text-center"><i class="far fa-check-circle fa-8x text-lighter"></i></p>
  127. <p class="text-center h3 font-weight-light">You're All Caught Up!</p>
  128. <p class="text-center text-muted font-weight-light">You've seen all the new posts from the accounts you follow.</p>
  129. <p class="text-center mb-0">
  130. <a class="btn btn-link font-weight-bold px-4" href="/?a=vop">View Older Posts</a>
  131. </p>
  132. <p class="text-center mb-0">
  133. <a class="btn btn-link font-weight-bold px-4" href="/" @click.prevent="alwaysViewOlderPosts()">Always show older posts on this device</a>
  134. </p>
  135. </div>
  136. <div v-else>
  137. <p class="text-center h3 font-weight-light">You've reached the end of this feed</p>
  138. <p class="text-center mb-0">
  139. <a class="btn btn-link font-weight-bold px-4" href="/discover">Discover new posts and people</a>
  140. </p>
  141. </div>
  142. </div>
  143. <div slot="no-results">
  144. <div v-if="recentFeed">
  145. <p class="text-center"><i class="far fa-check-circle fa-8x text-lighter"></i></p>
  146. <p class="text-center h3 font-weight-light">You're All Caught Up!</p>
  147. <p class="text-center text-muted font-weight-light">You've seen all the new posts from the accounts you follow.</p>
  148. <p class="text-center mb-0">
  149. <a class="btn btn-link font-weight-bold px-4" href="/?a=vop">View Older Posts</a>
  150. </p>
  151. <p class="text-center mb-0">
  152. <a class="btn btn-link font-weight-bold px-4" href="/" @click.prevent="alwaysViewOlderPosts()">Always show older posts on this device</a>
  153. </p>
  154. </div>
  155. <div v-else>
  156. <p class="text-center h3 font-weight-light">You've reached the end of this feed</p>
  157. <p class="text-center mb-0">
  158. <a class="btn btn-link font-weight-bold px-4" href="/discover">Discover new posts and people</a>
  159. </p>
  160. </div>
  161. </div>
  162. </infinite-loading>
  163. </div>
  164. </div>
  165. </div>
  166. <div v-if="!loading && scope == 'home' && feed.length == 0">
  167. <div class="card rounded-0 mt-4 status-card rounded-0 shadow-none border">
  168. <div v-if="profile.following_count != '0'" class="card-body py-5 my-5">
  169. <p class="text-center"><i class="far fa-check-circle fa-8x text-lighter"></i></p>
  170. <p class="text-center h3 font-weight-light">You're All Caught Up!</p>
  171. <p class="text-center text-muted font-weight-light">You've seen all the new posts from the accounts you follow.</p>
  172. <p class="text-center mb-0">
  173. <a class="btn btn-link font-weight-bold px-4" href="/?a=vop">View Older Posts</a>
  174. </p>
  175. <p class="text-center mb-0">
  176. <a class="btn btn-link font-weight-bold px-4" href="/" @click.prevent="alwaysViewOlderPosts()">Always show older posts on this device</a>
  177. </p>
  178. </div>
  179. <div v-else class="card-body py-5 my-5">
  180. <p class="text-center"><i class="far fa-smile fa-8x text-lighter"></i></p>
  181. <p class="text-center h3 font-weight-light">Hello {{profile.username}}</p>
  182. <p class="text-center text-muted font-weight-light">Accounts you follow will appear in this feed.</p>
  183. <p class="text-center mb-0">
  184. <a class="btn btn-link font-weight-bold px-4" href="/discover">Discover new posts and people</a>
  185. </p>
  186. <hr>
  187. <div class="text-center pt-5">
  188. <h1>A New Experience Awaits</h1>
  189. <p class="lead">Try out an early release of our new design</p>
  190. <p class="mb-0 d-flex align-items-center justify-content-center">
  191. <a class="btn btn-primary font-weight-bold py-1 px-4 rounded-pill mr-4" href="/i/web">Try new UI</a>
  192. </p>
  193. </div>
  194. </div>
  195. </div>
  196. </div>
  197. <div v-if="!loading && scope == 'home' && recentFeed && discover_feed.length" class="pt-3">
  198. <p class="h5 font-weight-bold py-3 d-flex justify-content-between align-items-center">
  199. <span>Suggested Posts</span>
  200. <a href="/?a=vop" class="small font-weight-bold">Older Posts</a>
  201. </p>
  202. </div>
  203. <div
  204. v-if="!loading && scope == 'home' && recentFeed && discover_feed.length"
  205. :data-status-id="status.id"
  206. v-for="(status, index) in discover_feed"
  207. :key="`discover_feed-${index}-${status.id}`">
  208. <status-card
  209. :class="{'border-top': index === 0}"
  210. :status="status"
  211. :recommended="true" />
  212. </div>
  213. <div v-if="!loading && emptyFeed && scope !== 'home'">
  214. <div class="card rounded-0 mt-3 status-card rounded-0 shadow-none border">
  215. <div class="card-body py-5 my-5">
  216. <p class="text-center"><i class="fas fa-battery-empty fa-8x text-lighter"></i></p>
  217. <p class="text-center h3 font-weight-light">empty_timeline.jpg</p>
  218. <p class="text-center text-muted font-weight-light">We cannot find any posts for this timeline.</p>
  219. <p class="text-center mb-0">
  220. <a class="btn btn-link font-weight-bold px-4" href="/discover">Discover new posts and people</a>
  221. </p>
  222. </div>
  223. </div>
  224. </div>
  225. </div>
  226. </div>
  227. <div class="col-md-4 col-lg-4 my-4 order-1 order-md-2 d-none d-md-block">
  228. <div>
  229. <div class="mb-4">
  230. <div v-show="!loading" class="">
  231. <div class="pb-2">
  232. <div class="media d-flex align-items-center">
  233. <a :href="!userStory ? profile.url : '/stories/' + profile.acct" class="mr-3">
  234. <!-- <img class="mr-3 rounded-circle box-shadow" :src="profile.avatar || '/storage/avatars/default.png'" alt="avatar" width="64px" height="64px" onerror="this.onerror=null;this.src='/storage/avatars/default.png?v=2'"> -->
  235. <div v-if="userStory" class="has-story cursor-pointer shadow-sm" @click="storyRedirect()">
  236. <img class="rounded-circle box-shadow" :src="profile.avatar" width="64px" height="64px" onerror="this.onerror=null;this.src='/storage/avatars/default.png?v=2'" alt="avatar">
  237. </div>
  238. <div v-else>
  239. <img class="rounded-circle box-shadow" :src="profile.avatar" width="64px" height="64px" onerror="this.onerror=null;this.src='/storage/avatars/default.png?v=2'" alt="avatar">
  240. </div>
  241. </a>
  242. <div class="media-body d-flex justify-content-between word-break" >
  243. <div>
  244. <p class="mb-0 px-0 font-weight-bold"><a :href="profile.url" class="text-dark">{{profile.username || 'loading...'}}</a></p>
  245. <p class="my-0 text-muted pb-0">{{profile.display_name || 'loading...'}}</p>
  246. </div>
  247. <div class="ml-2">
  248. <a class="text-muted" href="/settings/home">
  249. <i class="fas fa-cog fa-lg"></i>
  250. <span class="sr-only">User Settings</span>
  251. </a>
  252. </div>
  253. </div>
  254. </div>
  255. </div>
  256. <!-- <div class="card-footer bg-transparent border-top mt-2 py-1">
  257. <div class="d-flex justify-content-between text-center">
  258. <span class="cursor-pointer" @click="redirect(profile.url)">
  259. <p class="mb-0 font-weight-bold">{{formatCount(profile.statuses_count)}}</p>
  260. <p class="mb-0 small text-muted">Posts</p>
  261. </span>
  262. <span class="cursor-pointer" @click="redirect(profile.url+'?md=followers')">
  263. <p class="mb-0 font-weight-bold">{{formatCount(profile.followers_count)}}</p>
  264. <p class="mb-0 small text-muted">Followers</p>
  265. </span>
  266. <span class="cursor-pointer" @click="redirect(profile.url+'?md=following')">
  267. <p class="mb-0 font-weight-bold">{{formatCount(profile.following_count)}}</p>
  268. <p class="mb-0 small text-muted">Following</p>
  269. </span>
  270. </div>
  271. </div> -->
  272. </div>
  273. <div class="card-footer bg-transparent border-0 pt-0 pb-1">
  274. <div class="d-flex justify-content-between text-center">
  275. <span class="cursor-pointer" @click="redirect(profile.url)">
  276. <p class="mb-0 font-weight-bold">{{formatCount(profile.statuses_count)}}</p>
  277. <p class="mb-0 small text-muted">Posts</p>
  278. </span>
  279. <span class="cursor-pointer" @click="redirect(profile.url+'?md=followers')">
  280. <p class="mb-0 font-weight-bold">{{formatCount(profile.followers_count)}}</p>
  281. <p class="mb-0 small text-muted">Followers</p>
  282. </span>
  283. <span class="cursor-pointer" @click="redirect(profile.url+'?md=following')">
  284. <p class="mb-0 font-weight-bold">{{formatCount(profile.following_count)}}</p>
  285. <p class="mb-0 small text-muted">Following</p>
  286. </span>
  287. </div>
  288. </div>
  289. </div>
  290. <div v-show="modes.notify == true && !loading" class="mb-4">
  291. <notification-card></notification-card>
  292. </div>
  293. <div v-show="showSuggestions == true && suggestions.length && config.ab && config.ab.rec == true" class="mb-4">
  294. <div class="card shadow-none border">
  295. <div class="card-header bg-white d-flex align-items-center justify-content-between">
  296. <a class="small text-muted cursor-pointer" href="#" @click.prevent="refreshSuggestions" ref="suggestionRefresh"><i class="fas fa-sync-alt"></i></a>
  297. <div class="small text-dark text-uppercase font-weight-bold">Suggestions</div>
  298. <div class="small text-muted cursor-pointer" v-on:click="hideSuggestions"><i class="fas fa-times"></i></div>
  299. </div>
  300. <div class="card-body pt-0">
  301. <div v-for="(rec, index) in suggestions" class="media align-items-center mt-3">
  302. <a :href="'/'+rec.username">
  303. <img :src="rec.avatar" width="32px" height="32px" class="rounded-circle mr-3" onerror="this.onerror=null;this.src='/storage/avatars/default.png?v=2'" alt="avatar">
  304. </a>
  305. <div class="media-body">
  306. <p class="mb-0 font-weight-bold small">
  307. <a :href="'/'+rec.username" class="text-decoration-none text-dark">
  308. {{rec.username}}
  309. </a>
  310. </p>
  311. <p class="mb-0 small text-muted">{{rec.message}}</p>
  312. </div>
  313. </div>
  314. </div>
  315. </div>
  316. </div>
  317. <footer>
  318. <div class="container px-0 pb-5">
  319. <p class="mb-2 small text-justify">
  320. <a href="/site/about" class="text-lighter pr-2">About</a>
  321. <a href="/site/help" class="text-lighter pr-2">Help</a>
  322. <a href="/site/language" class="text-lighter pr-2">Language</a>
  323. <a href="/discover/places" class="text-lighter pr-2">Places</a>
  324. <a href="/site/privacy" class="text-lighter pr-2">Privacy</a>
  325. <a href="/site/terms" class="text-lighter pr-2">Terms</a>
  326. </p>
  327. <p class="mb-0 text-uppercase text-muted small">
  328. <a href="https://pixelfed.org" class="text-lighter" rel="noopener" title="" data-toggle="tooltip">Powered by Pixelfed</a>
  329. </p>
  330. </div>
  331. </footer>
  332. </div>
  333. </div>
  334. </div>
  335. </div>
  336. <comment-card
  337. v-if="replyStatus && replyStatus.hasOwnProperty('id')"
  338. :status="replyStatus"
  339. :profile="profile"
  340. v-on:current-layout="setCurrentLayout"
  341. />
  342. <div class="modal-stack">
  343. <b-modal ref="replyModal"
  344. id="ctx-reply-modal"
  345. hide-footer
  346. centered
  347. rounded
  348. :title-html="replyStatus.account ? 'Reply to <span class=text-dark>' + replyStatus.account.username + '</span>' : ''"
  349. title-tag="p"
  350. title-class="font-weight-bold text-muted"
  351. size="md"
  352. body-class="p-2 rounded">
  353. <div>
  354. <vue-tribute :options="tributeSettings">
  355. <textarea
  356. class="form-control replyModalTextarea"
  357. rows="4"
  358. v-model="replyText">
  359. </textarea>
  360. </vue-tribute>
  361. <div class="border-top border-bottom my-2">
  362. <ul class="nav align-items-center emoji-reactions" style="overflow-x: scroll;flex-wrap: unset;">
  363. <li class="nav-item" v-on:click="emojiReaction(status)" v-for="e in emoji">{{e}}</li>
  364. </ul>
  365. </div>
  366. <div class="d-flex justify-content-between align-items-center">
  367. <div>
  368. <span class="pl-2 small text-muted font-weight-bold text-monospace">
  369. <span :class="[replyText.length > config.uploader.max_caption_length ? 'text-danger':'text-dark']">{{replyText.length > config.uploader.max_caption_length ? config.uploader.max_caption_length - replyText.length : replyText.length}}</span>/{{config.uploader.max_caption_length}}
  370. </span>
  371. </div>
  372. <div class="d-flex align-items-center">
  373. <div class="custom-control custom-switch mr-3">
  374. <input type="checkbox" class="custom-control-input" id="replyModalCWSwitch" v-model="replyNsfw">
  375. <label :class="[replyNsfw ? 'custom-control-label font-weight-bold text-dark':'custom-control-label text-lighter']" for="replyModalCWSwitch">Mark as NSFW</label>
  376. </div>
  377. <button class="btn btn-primary btn-sm py-2 px-4 lead text-uppercase font-weight-bold" v-on:click.prevent="commentSubmit(status, $event)" :disabled="replyText.length == 0">
  378. {{replySending == true ? 'POSTING' : 'POST'}}
  379. </button>
  380. </div>
  381. </div>
  382. </div>
  383. </b-modal>
  384. <b-modal ref="ctxStatusModal"
  385. id="ctx-status-modal"
  386. hide-header
  387. hide-footer
  388. centered
  389. rounded
  390. size="xl"
  391. body-class="list-group-flush p-0 m-0 rounded">
  392. <!-- <post-component
  393. v-if="ctxMenuStatus"
  394. :status-template="ctxMenuStatus.pf_type"
  395. :status-id="ctxMenuStatus.id"
  396. :status-username="ctxMenuStatus.account.username"
  397. :status-url="ctxMenuStatus.url"
  398. :status-profile-url="ctxMenuStatus.account.url"
  399. :status-avatar="ctxMenuStatus.account.avatar"
  400. :status-profile-id="ctxMenuStatus.account.id"
  401. profile-layout="metro">
  402. </post-component> -->
  403. </b-modal>
  404. </div>
  405. </div>
  406. </template>
  407. <script type="text/javascript">
  408. import VueTribute from 'vue-tribute'
  409. import StatusCard from './partials/StatusCard.vue';
  410. import CommentCard from './partials/CommentCard.vue';
  411. export default {
  412. props: ['scope', 'layout'],
  413. components: {
  414. VueTribute,
  415. StatusCard,
  416. CommentCard
  417. },
  418. data() {
  419. return {
  420. ids: [],
  421. config: window.App.config,
  422. page: 2,
  423. feed: [],
  424. profile: {},
  425. min_id: 0,
  426. max_id: 0,
  427. suggestions: {},
  428. loading: true,
  429. replies: [],
  430. replyId: null,
  431. modes: {
  432. 'mod': false,
  433. 'dark': false,
  434. 'notify': true,
  435. 'distractionFree': false
  436. },
  437. followers: [],
  438. followerCursor: 1,
  439. followerMore: true,
  440. following: [],
  441. followingCursor: 1,
  442. followingMore: true,
  443. lightboxMedia: false,
  444. showSuggestions: true,
  445. showReadMore: true,
  446. replyStatus: {},
  447. replyText: '',
  448. replyNsfw: false,
  449. emoji: [],
  450. showHashtagPosts: false,
  451. hashtagPosts: [],
  452. hashtagPostsName: '',
  453. copiedEmbed: false,
  454. showTips: true,
  455. userStory: false,
  456. replySending: false,
  457. morePostsAvailable: false,
  458. mpCount: 0,
  459. mpData: false,
  460. mpInterval: 15000,
  461. mpEnabled: false,
  462. mpPoller: null,
  463. confirmModalTitle: 'Are you sure?',
  464. confirmModalIdentifer: null,
  465. confirmModalType: false,
  466. currentLayout: 'feed',
  467. pagination: {},
  468. tributeSettings: {
  469. collection: [
  470. {
  471. trigger: '@',
  472. menuShowMinLength: 2,
  473. values: (function (text, cb) {
  474. let url = '/api/compose/v0/search/mention';
  475. axios.get(url, { params: { q: text }})
  476. .then(res => {
  477. cb(res.data);
  478. })
  479. .catch(err => {
  480. console.log(err);
  481. })
  482. })
  483. },
  484. {
  485. trigger: '#',
  486. menuShowMinLength: 2,
  487. values: (function (text, cb) {
  488. let url = '/api/compose/v0/search/hashtag';
  489. axios.get(url, { params: { q: text }})
  490. .then(res => {
  491. cb(res.data);
  492. })
  493. .catch(err => {
  494. console.log(err);
  495. })
  496. })
  497. }
  498. ]
  499. },
  500. discover_min_id: 0,
  501. discover_max_id: 0,
  502. discover_feed: [],
  503. recentFeed: false,
  504. recentFeedMin: null,
  505. recentFeedMax: null,
  506. reactionBar: true,
  507. emptyFeed: false,
  508. filters: [],
  509. showPromo: false,
  510. }
  511. },
  512. beforeMount() {
  513. this.fetchProfile();
  514. },
  515. mounted() {
  516. // todo: release after dark mode updates
  517. /* if(window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches || $('link[data-stylesheet="dark"]').length != 0) {
  518. this.modes.dark = true;
  519. let el = document.querySelector('link[data-stylesheet="light"]');
  520. el.setAttribute('href', '/css/appdark.css?id=' + Date.now());
  521. el.setAttribute('data-stylesheet', 'dark');
  522. }*/
  523. if(this.config.ab.spa === true) {
  524. this.showPromo = localStorage.getItem('pf_metro_ui.exp.spa' + new Date().getMonth()) == 'false' ? false : true;
  525. }
  526. if(localStorage.getItem('pf_metro_ui.exp.rec') == 'false') {
  527. this.showSuggestions = false;
  528. } else {
  529. this.showSuggestions = true;
  530. }
  531. if(localStorage.getItem('pf_metro_ui.exp.rm') == 'false') {
  532. this.showReadMore = false;
  533. } else {
  534. this.showReadMore = true;
  535. }
  536. if(localStorage.getItem('metro-tips') == 'false') {
  537. this.showTips = false;
  538. }
  539. this.$nextTick(() => {
  540. $('[data-toggle="tooltip"]').tooltip();
  541. let u = new URLSearchParams(window.location.search);
  542. if(u.has('a')) {
  543. switch(u.get('a')) {
  544. case 'co':
  545. $('#composeModal').modal('show');
  546. break;
  547. }
  548. }
  549. if(this.scope != 'home') {
  550. axios.get('/api/pixelfed/v2/filters')
  551. .then(res => {
  552. this.filters = res.data;
  553. this.fetchTimelineApi();
  554. });
  555. } else {
  556. this.fetchTimelineApi();
  557. }
  558. });
  559. },
  560. updated() {
  561. if(this.showReadMore == true) {
  562. pixelfed.readmore();
  563. }
  564. },
  565. methods: {
  566. fetchProfile() {
  567. axios.get('/api/pixelfed/v1/accounts/verify_credentials').then(res => {
  568. this.profile = res.data;
  569. if(this.profile.is_admin == true) {
  570. this.modes.mod = true;
  571. }
  572. window._sharedData.curUser = res.data;
  573. window.App.util.navatar();
  574. }).catch(err => {
  575. swal(
  576. 'Oops, something went wrong',
  577. 'Please reload the page.',
  578. 'error'
  579. );
  580. });
  581. },
  582. fetchTimelineApi() {
  583. let apiUrl = false;
  584. switch(this.scope) {
  585. case 'home':
  586. apiUrl = '/api/pixelfed/v1/timelines/home';
  587. break;
  588. case 'local':
  589. apiUrl = '/api/pixelfed/v1/timelines/public';
  590. break;
  591. case 'network':
  592. apiUrl = '/api/pixelfed/v1/timelines/network';
  593. break;
  594. }
  595. axios.get(apiUrl, {
  596. params: {
  597. max_id: this.max_id,
  598. limit: 12,
  599. recent_feed: this.recentFeed
  600. }
  601. }).then(res => {
  602. let data = res.data;
  603. if(!data || !data.length) {
  604. this.loading = false;
  605. this.emptyFeed = true;
  606. return;
  607. }
  608. if(this.filters.length) {
  609. data = data.filter(d => {
  610. return this.filters.includes(d.account.id) == false;
  611. });
  612. }
  613. this.feed.push(...data);
  614. let ids = data.map(status => status.id);
  615. this.ids = ids;
  616. this.min_id = Math.max(...ids).toString();
  617. this.max_id = Math.min(...ids).toString();
  618. this.loading = false;
  619. this.$nextTick(() => {
  620. this.hasStory();
  621. });
  622. setTimeout(function() {
  623. document.querySelectorAll('.timeline .card-body .comments .comment-body a').forEach(function(i, e) {
  624. i.href = App.util.format.rewriteLinks(i);
  625. });
  626. }, 500);
  627. }).catch(err => {
  628. swal(
  629. 'Oops, something went wrong',
  630. 'Please reload the page.',
  631. 'error'
  632. );
  633. });
  634. },
  635. infiniteTimeline($state) {
  636. if(this.loading) {
  637. $state.complete();
  638. return;
  639. }
  640. if(this.page > 40) {
  641. this.loading = false;
  642. $state.complete();
  643. }
  644. let apiUrl = false;
  645. switch(this.scope) {
  646. case 'home':
  647. apiUrl = '/api/pixelfed/v1/timelines/home';
  648. break;
  649. case 'local':
  650. apiUrl = '/api/pixelfed/v1/timelines/public';
  651. break;
  652. case 'network':
  653. apiUrl = '/api/pixelfed/v1/timelines/network';
  654. break;
  655. }
  656. axios.get(apiUrl, {
  657. params: {
  658. max_id: this.max_id,
  659. limit: 6,
  660. recent_feed: this.recentFeed
  661. },
  662. }).then(res => {
  663. if (res.data.length && this.loading == false) {
  664. let data = res.data;
  665. let self = this;
  666. let vids = [];
  667. if(self.recentFeed && self.ids.indexOf(data[0].id) != -1) {
  668. this.loading = false;
  669. $state.complete();
  670. return;
  671. }
  672. data.forEach((d, index) => {
  673. if(self.ids.indexOf(d.id) == -1) {
  674. self.feed.push(d);
  675. self.ids.push(d.id);
  676. // vids.push({
  677. // sid: d.id,
  678. // pid: d.account.id
  679. // });
  680. }
  681. });
  682. this.min_id = Math.max(...this.ids).toString();
  683. this.max_id = Math.min(...this.ids).toString();
  684. this.page += 1;
  685. $state.loaded();
  686. this.loading = false;
  687. // axios.post('/api/status/view', {
  688. // '_v': vids,
  689. // });
  690. } else {
  691. $state.complete();
  692. }
  693. }).catch(err => {
  694. this.loading = false;
  695. $state.complete();
  696. });
  697. },
  698. redirect(url) {
  699. window.location.href = url;
  700. return;
  701. },
  702. expRec() {
  703. //return;
  704. if(this.config.ab.rec == false) {
  705. return;
  706. }
  707. axios.get('/api/local/exp/rec')
  708. .then(res => {
  709. this.suggestions = res.data;
  710. })
  711. },
  712. owner(status) {
  713. return this.profile.id === status.account.id;
  714. },
  715. admin() {
  716. return this.profile.is_admin == true;
  717. },
  718. ownerOrAdmin(status) {
  719. return this.owner(status) || this.admin();
  720. },
  721. hideSuggestions() {
  722. localStorage.setItem('pf_metro_ui.exp.rec', false);
  723. this.showSuggestions = false;
  724. },
  725. emojiReaction(status) {
  726. let em = event.target.innerText;
  727. if(this.replyText.length == 0) {
  728. this.replyText = em + ' ';
  729. $('textarea[name="comment"]').focus();
  730. } else {
  731. this.replyText += em + ' ';
  732. $('textarea[name="comment"]').focus();
  733. }
  734. },
  735. refreshSuggestions() {
  736. return;
  737. let el = event.target.parentNode;
  738. if(el.classList.contains('disabled') == true) {
  739. return;
  740. }
  741. axios.get('/api/local/exp/rec', {
  742. params: {
  743. refresh: true
  744. }
  745. })
  746. .then(res => {
  747. this.suggestions = res.data;
  748. if (el.classList) {
  749. el.classList.add('disabled');
  750. el.classList.add('text-light');
  751. }
  752. else {
  753. el.className += ' ' + 'disabled text-light';
  754. }
  755. setTimeout(function() {
  756. el.setAttribute('href', '#');
  757. if (el.classList) {
  758. el.classList.remove('disabled');
  759. el.classList.remove('text-light');
  760. }
  761. else {
  762. el.className = el.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), 'disabled text-light');
  763. }
  764. }, 10000);
  765. });
  766. },
  767. fetchHashtagPosts() {
  768. axios.get('/api/local/discover/tag/list')
  769. .then(res => {
  770. let tags = res.data;
  771. if(tags.length == 0) {
  772. return;
  773. }
  774. let hashtag = tags[Math.floor(Math.random(), tags.length)];
  775. this.hashtagPostsName = hashtag;
  776. axios.get('/api/v2/discover/tag', {
  777. params: {
  778. hashtag: hashtag
  779. }
  780. }).then(res => {
  781. if(res.data.tags.length > 3) {
  782. this.showHashtagPosts = true;
  783. this.hashtagPosts = res.data.tags.splice(0,9);
  784. }
  785. })
  786. })
  787. },
  788. commentFocus(status, $event) {
  789. if(status.comments_disabled) {
  790. return;
  791. }
  792. // if(this.status && this.status.id == status.id) {
  793. // this.$refs.replyModal.show();
  794. // return;
  795. // }
  796. this.status = status;
  797. this.replies = {};
  798. this.replyStatus = {};
  799. this.replyText = '';
  800. this.replyId = status.id;
  801. this.replyStatus = status;
  802. // this.$refs.replyModal.show();
  803. this.fetchStatusComments(status, '');
  804. $('nav').hide();
  805. $('footer').hide();
  806. $('.mobile-footer-spacer').attr('style', 'display:none !important');
  807. $('.mobile-footer').attr('style', 'display:none !important');
  808. this.currentLayout = 'comments';
  809. window.history.pushState({}, '', this.statusUrl(status));
  810. return;
  811. },
  812. fetchStatusComments(status, card) {
  813. let url = '/api/v2/comments/'+status.account.id+'/status/'+status.id;
  814. axios.get(url)
  815. .then(response => {
  816. let self = this;
  817. this.replies = _.reverse(response.data.data);
  818. this.pagination = response.data.meta.pagination;
  819. if(this.replies.length > 0) {
  820. $('.load-more-link').removeClass('d-none');
  821. }
  822. $('.postCommentsLoader').addClass('d-none');
  823. $('.postCommentsContainer').removeClass('d-none');
  824. }).catch(error => {
  825. if(!error.response) {
  826. $('.postCommentsLoader .lds-ring')
  827. .attr('style','width:100%')
  828. .addClass('pt-4 font-weight-bold text-muted')
  829. .text('An error occurred, cannot fetch comments. Please try again later.');
  830. } else {
  831. switch(error.response.status) {
  832. case 401:
  833. $('.postCommentsLoader .lds-ring')
  834. .attr('style','width:100%')
  835. .addClass('pt-4 font-weight-bold text-muted')
  836. .text('Please login to view.');
  837. break;
  838. default:
  839. $('.postCommentsLoader .lds-ring')
  840. .attr('style','width:100%')
  841. .addClass('pt-4 font-weight-bold text-muted')
  842. .text('An error occurred, cannot fetch comments. Please try again later.');
  843. break;
  844. }
  845. }
  846. });
  847. },
  848. statusUrl(status) {
  849. if(status.local == true) {
  850. return status.url;
  851. }
  852. return '/i/web/post/_/' + status.account.id + '/' + status.id;
  853. },
  854. profileUrl(status) {
  855. if(status.local == true) {
  856. return status.account.url;
  857. }
  858. return '/i/web/profile/_/' + status.account.id;
  859. },
  860. formatCount(count) {
  861. return App.util.format.count(count);
  862. },
  863. hasStory() {
  864. axios.get('/api/web/stories/v1/exists/'+this.profile.id)
  865. .then(res => {
  866. this.userStory = res.data;
  867. })
  868. },
  869. // real time watcher
  870. rtw() {
  871. this.mpPoller = setInterval(() => {
  872. let apiUrl = false;
  873. this.mpCount++;
  874. if(this.mpCount > 10) {
  875. this.mpInterval = 30000;
  876. }
  877. if(this.mpCount > 50) {
  878. this.mpInterval = (5 * 60 * 1000);
  879. }
  880. switch(this.scope) {
  881. case 'home':
  882. apiUrl = '/api/pixelfed/v1/timelines/home';
  883. break;
  884. case 'local':
  885. apiUrl = '/api/pixelfed/v1/timelines/public';
  886. break;
  887. case 'network':
  888. apiUrl = '/api/pixelfed/v1/timelines/network';
  889. break;
  890. }
  891. axios.get(apiUrl, {
  892. params: {
  893. max_id: 0,
  894. limit: 20,
  895. recent_feed: this.recentFeed
  896. }
  897. }).then(res => {
  898. let self = this;
  899. let tids = this.feed.map(status => status.id);
  900. let data = res.data.filter(d => {
  901. return d.id > self.min_id && tids.indexOf(d.id) == -1;
  902. });
  903. let ids = data.map(status => status.id);
  904. let max = Math.max(...ids).toString();
  905. let newer = max > this.min_id;
  906. if(newer) {
  907. this.morePostsAvailable = true;
  908. this.mpData = data;
  909. }
  910. });
  911. }, this.mpInterval);
  912. },
  913. syncNewPosts() {
  914. let self = this;
  915. let data = this.mpData;
  916. let ids = data.map(s => s.id);
  917. this.min_id = Math.max(...ids).toString();
  918. this.max_id = Math.min(...ids).toString();
  919. this.feed.unshift(...data);
  920. this.morePostsAvailable = false;
  921. this.mpData = null;
  922. },
  923. toggleReplies(reply) {
  924. if(reply.thread) {
  925. reply.thread = false;
  926. } else {
  927. if(reply.replies.length > 0) {
  928. reply.thread = true;
  929. return;
  930. }
  931. let url = '/api/v2/comments/'+reply.account.id+'/status/'+reply.id;
  932. axios.get(url)
  933. .then(response => {
  934. reply.replies = _.reverse(response.data.data);
  935. reply.thread = true;
  936. });
  937. }
  938. },
  939. replyFocus(e, index, prependUsername = false) {
  940. if($('body').hasClass('loggedIn') == false) {
  941. this.redirect('/login?next=' + encodeURIComponent(window.location.pathname));
  942. return;
  943. }
  944. if(this.status.comments_disabled) {
  945. return;
  946. }
  947. this.replyToIndex = index;
  948. this.replyingToId = e.id;
  949. this.replyingToUsername = e.account.username;
  950. this.reply_to_profile_id = e.account.id;
  951. let username = e.account.local ? '@' + e.account.username + ' '
  952. : '@' + e.account.acct + ' ';
  953. if(prependUsername == true) {
  954. this.replyText = username;
  955. }
  956. this.$refs.replyModal.show();
  957. setTimeout(function() {
  958. $('.replyModalTextarea').focus();
  959. }, 500);
  960. },
  961. alwaysViewOlderPosts() {
  962. // Set Feed:Always View Older Posts
  963. window.localStorage.setItem('pf.feed:avop', 'always');
  964. window.location.href = '/';
  965. },
  966. setCurrentLayout(layout) {
  967. this.currentLayout = layout;
  968. },
  969. deleteStatus(status) {
  970. this.feed = this.feed.filter(s => {
  971. return s.id != status;
  972. });
  973. },
  974. followedAccount(id) {
  975. this.feed = this.feed.map(s => {
  976. if(s.account.id == id) {
  977. if(s.hasOwnProperty('relationship') && s.relationship.following == false) {
  978. s.relationship.following = true;
  979. }
  980. }
  981. return s;
  982. });
  983. },
  984. unfollowedAccount(id) {
  985. this.feed = this.feed.map(s => {
  986. if(s.account.id == id) {
  987. if(s.hasOwnProperty('relationship') && s.relationship.following == true) {
  988. s.relationship.following = false;
  989. }
  990. }
  991. return s;
  992. });
  993. },
  994. hidePromo() {
  995. localStorage.setItem('pf_metro_ui.exp.spa' + new Date().getMonth(), 'false');
  996. this.showPromo = false;
  997. }
  998. },
  999. beforeDestroy () {
  1000. clearInterval(this.mpInterval);
  1001. }
  1002. }
  1003. </script>
  1004. <style type="text/css" scoped>
  1005. .postPresenterContainer {
  1006. display: flex;
  1007. align-items: center;
  1008. background: #fff;
  1009. }
  1010. .word-break {
  1011. word-break: break-all;
  1012. }
  1013. .small .custom-control-label {
  1014. padding-top: 3px;
  1015. }
  1016. /*.reply-btn {
  1017. position: absolute;
  1018. bottom: 30px;
  1019. right: 20px;
  1020. width: 60px;
  1021. text-align: center;
  1022. font-size: 13px;
  1023. border-radius: 0 3px 3px 0;
  1024. }*/
  1025. .reply-btn[disabled] {
  1026. opacity: .3;
  1027. color: #3897f0;
  1028. }
  1029. .replyModalTextarea {
  1030. border: none;
  1031. font-size: 18px;
  1032. resize: none;
  1033. white-space: pre-wrap;
  1034. outline: none;
  1035. }
  1036. .has-story {
  1037. width: 64px;
  1038. height: 64px;
  1039. border-radius: 50%;
  1040. padding: 2px;
  1041. background: radial-gradient(ellipse at 70% 70%, #ee583f 8%, #d92d77 42%, #bd3381 58%);
  1042. }
  1043. .has-story img {
  1044. width: 60px;
  1045. height: 60px;
  1046. border-radius: 50%;
  1047. padding: 3px;
  1048. background: #fff;
  1049. }
  1050. .has-story.has-story-sm {
  1051. width: 32px;
  1052. height: 32px;
  1053. border-radius: 50%;
  1054. padding: 2px;
  1055. background: radial-gradient(ellipse at 70% 70%, #ee583f 8%, #d92d77 42%, #bd3381 58%);
  1056. }
  1057. .has-story.has-story-sm img {
  1058. width: 28px;
  1059. height: 28px;
  1060. border-radius: 50%;
  1061. padding: 3px;
  1062. background: #fff;
  1063. }
  1064. #ctx-reply-modal .form-control:focus {
  1065. border: none;
  1066. outline: 0;
  1067. box-shadow: none;
  1068. }
  1069. </style>