Timeline.vue 36 KB

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