Timeline.vue 37 KB

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