Timeline.vue 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144
  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="https://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: 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. },
  507. mounted() {
  508. // todo: release after dark mode updates
  509. /* if(window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches || $('link[data-stylesheet="dark"]').length != 0) {
  510. this.modes.dark = true;
  511. let el = document.querySelector('link[data-stylesheet="light"]');
  512. el.setAttribute('href', '/css/appdark.css?id=' + Date.now());
  513. el.setAttribute('data-stylesheet', 'dark');
  514. }*/
  515. if(localStorage.getItem('pf_metro_ui.exp.rec') == 'false') {
  516. this.showSuggestions = false;
  517. } else {
  518. this.showSuggestions = true;
  519. }
  520. if(localStorage.getItem('pf_metro_ui.exp.rm') == 'false') {
  521. this.showReadMore = false;
  522. } else {
  523. this.showReadMore = true;
  524. }
  525. if(localStorage.getItem('metro-tips') == 'false') {
  526. this.showTips = false;
  527. }
  528. this.$nextTick(() => {
  529. $('[data-toggle="tooltip"]').tooltip();
  530. let u = new URLSearchParams(window.location.search);
  531. if(u.has('a')) {
  532. switch(u.get('a')) {
  533. case 'co':
  534. $('#composeModal').modal('show');
  535. break;
  536. }
  537. }
  538. this.fetchTimelineApi();
  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.$nextTick(() => {
  556. // this.hasStory();
  557. // });
  558. // this.expRec();
  559. }).catch(err => {
  560. swal(
  561. 'Oops, something went wrong',
  562. 'Please reload the page.',
  563. 'error'
  564. );
  565. });
  566. },
  567. fetchTimelineApi() {
  568. let apiUrl = false;
  569. switch(this.scope) {
  570. case 'home':
  571. apiUrl = '/api/pixelfed/v1/timelines/home';
  572. break;
  573. case 'local':
  574. apiUrl = '/api/pixelfed/v1/timelines/public';
  575. break;
  576. case 'network':
  577. apiUrl = '/api/pixelfed/v1/timelines/network';
  578. break;
  579. }
  580. axios.get(apiUrl, {
  581. params: {
  582. max_id: this.max_id,
  583. limit: 12,
  584. recent_feed: this.recentFeed
  585. }
  586. }).then(res => {
  587. let data = res.data;
  588. if(!data.length) {
  589. this.loading = false;
  590. this.emptyFeed = true;
  591. return;
  592. }
  593. this.feed.push(...data);
  594. let ids = data.map(status => status.id);
  595. this.ids = ids;
  596. this.min_id = Math.max(...ids).toString();
  597. this.max_id = Math.min(...ids).toString();
  598. this.loading = false;
  599. // $('.timeline .pagination').removeClass('d-none');
  600. // if(this.hashtagPosts.length == 0) {
  601. // this.fetchHashtagPosts();
  602. // }
  603. this.$nextTick(() => {
  604. this.hasStory();
  605. });
  606. // this.fetchStories();
  607. // this.rtw();
  608. setTimeout(function() {
  609. document.querySelectorAll('.timeline .card-body .comments .comment-body a').forEach(function(i, e) {
  610. i.href = App.util.format.rewriteLinks(i);
  611. });
  612. }, 500);
  613. // axios.get('/api/pixelfed/v2/discover/posts/trending', {
  614. // params: {
  615. // range: 'daily'
  616. // }
  617. // }).then(res => {
  618. // let data = res.data.filter(post => this.ids.indexOf(post.id) === -1);
  619. // this.discover_feed = data;
  620. // });
  621. }).catch(err => {
  622. swal(
  623. 'Oops, something went wrong',
  624. 'Please reload the page.',
  625. 'error'
  626. );
  627. });
  628. },
  629. infiniteTimeline($state) {
  630. if(this.loading) {
  631. $state.complete();
  632. return;
  633. }
  634. if(this.page > 40) {
  635. this.loading = false;
  636. $state.complete();
  637. }
  638. let apiUrl = false;
  639. switch(this.scope) {
  640. case 'home':
  641. apiUrl = '/api/pixelfed/v1/timelines/home';
  642. break;
  643. case 'local':
  644. apiUrl = '/api/pixelfed/v1/timelines/public';
  645. break;
  646. case 'network':
  647. apiUrl = '/api/pixelfed/v1/timelines/network';
  648. break;
  649. }
  650. axios.get(apiUrl, {
  651. params: {
  652. max_id: this.max_id,
  653. limit: 6,
  654. recent_feed: this.recentFeed
  655. },
  656. }).then(res => {
  657. if (res.data.length && this.loading == false) {
  658. let data = res.data;
  659. let self = this;
  660. let vids = [];
  661. if(self.recentFeed && self.ids.indexOf(data[0].id) != -1) {
  662. this.loading = false;
  663. $state.complete();
  664. return;
  665. }
  666. data.forEach((d, index) => {
  667. if(self.ids.indexOf(d.id) == -1) {
  668. self.feed.push(d);
  669. self.ids.push(d.id);
  670. // vids.push({
  671. // sid: d.id,
  672. // pid: d.account.id
  673. // });
  674. }
  675. });
  676. this.min_id = Math.max(...this.ids).toString();
  677. this.max_id = Math.min(...this.ids).toString();
  678. this.page += 1;
  679. $state.loaded();
  680. this.loading = false;
  681. // axios.post('/api/status/view', {
  682. // '_v': vids,
  683. // });
  684. } else {
  685. $state.complete();
  686. }
  687. }).catch(err => {
  688. this.loading = false;
  689. $state.complete();
  690. });
  691. },
  692. redirect(url) {
  693. window.location.href = url;
  694. return;
  695. },
  696. expRec() {
  697. //return;
  698. if(this.config.ab.rec == false) {
  699. return;
  700. }
  701. axios.get('/api/local/exp/rec')
  702. .then(res => {
  703. this.suggestions = res.data;
  704. })
  705. },
  706. expRecFollow(id, index) {
  707. return;
  708. if(this.config.ab.rec == false) {
  709. return;
  710. }
  711. axios.post('/i/follow', {
  712. item: id
  713. }).then(res => {
  714. this.suggestions.splice(index, 1);
  715. }).catch(err => {
  716. if(err.response.data.message) {
  717. swal('Error', err.response.data.message, 'error');
  718. }
  719. });
  720. },
  721. owner(status) {
  722. return this.profile.id === status.account.id;
  723. },
  724. admin() {
  725. return this.profile.is_admin == true;
  726. },
  727. ownerOrAdmin(status) {
  728. return this.owner(status) || this.admin();
  729. },
  730. hideSuggestions() {
  731. localStorage.setItem('pf_metro_ui.exp.rec', false);
  732. this.showSuggestions = false;
  733. },
  734. emojiReaction(status) {
  735. let em = event.target.innerText;
  736. if(this.replyText.length == 0) {
  737. this.replyText = em + ' ';
  738. $('textarea[name="comment"]').focus();
  739. } else {
  740. this.replyText += em + ' ';
  741. $('textarea[name="comment"]').focus();
  742. }
  743. },
  744. refreshSuggestions() {
  745. return;
  746. let el = event.target.parentNode;
  747. if(el.classList.contains('disabled') == true) {
  748. return;
  749. }
  750. axios.get('/api/local/exp/rec', {
  751. params: {
  752. refresh: true
  753. }
  754. })
  755. .then(res => {
  756. this.suggestions = res.data;
  757. if (el.classList) {
  758. el.classList.add('disabled');
  759. el.classList.add('text-light');
  760. }
  761. else {
  762. el.className += ' ' + 'disabled text-light';
  763. }
  764. setTimeout(function() {
  765. el.setAttribute('href', '#');
  766. if (el.classList) {
  767. el.classList.remove('disabled');
  768. el.classList.remove('text-light');
  769. }
  770. else {
  771. el.className = el.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), 'disabled text-light');
  772. }
  773. }, 10000);
  774. });
  775. },
  776. fetchHashtagPosts() {
  777. axios.get('/api/local/discover/tag/list')
  778. .then(res => {
  779. let tags = res.data;
  780. if(tags.length == 0) {
  781. return;
  782. }
  783. let hashtag = tags[Math.floor(Math.random(), tags.length)];
  784. this.hashtagPostsName = hashtag;
  785. axios.get('/api/v2/discover/tag', {
  786. params: {
  787. hashtag: hashtag
  788. }
  789. }).then(res => {
  790. if(res.data.tags.length > 3) {
  791. this.showHashtagPosts = true;
  792. this.hashtagPosts = res.data.tags.splice(0,9);
  793. }
  794. })
  795. })
  796. },
  797. commentFocus(status, $event) {
  798. if(status.comments_disabled) {
  799. return;
  800. }
  801. // if(this.status && this.status.id == status.id) {
  802. // this.$refs.replyModal.show();
  803. // return;
  804. // }
  805. this.status = status;
  806. this.replies = {};
  807. this.replyStatus = {};
  808. this.replyText = '';
  809. this.replyId = status.id;
  810. this.replyStatus = status;
  811. // this.$refs.replyModal.show();
  812. this.fetchStatusComments(status, '');
  813. $('nav').hide();
  814. $('footer').hide();
  815. $('.mobile-footer-spacer').attr('style', 'display:none !important');
  816. $('.mobile-footer').attr('style', 'display:none !important');
  817. this.currentLayout = 'comments';
  818. window.history.pushState({}, '', this.statusUrl(status));
  819. return;
  820. },
  821. fetchStatusComments(status, card) {
  822. let url = '/api/v2/comments/'+status.account.id+'/status/'+status.id;
  823. axios.get(url)
  824. .then(response => {
  825. let self = this;
  826. this.replies = _.reverse(response.data.data);
  827. this.pagination = response.data.meta.pagination;
  828. if(this.replies.length > 0) {
  829. $('.load-more-link').removeClass('d-none');
  830. }
  831. $('.postCommentsLoader').addClass('d-none');
  832. $('.postCommentsContainer').removeClass('d-none');
  833. // setTimeout(function() {
  834. // document.querySelectorAll('.status-comment .postCommentsContainer .comment-body a').forEach(function(i, e) {
  835. // i.href = App.util.format.rewriteLinks(i);
  836. // });
  837. // }, 500);
  838. }).catch(error => {
  839. if(!error.response) {
  840. $('.postCommentsLoader .lds-ring')
  841. .attr('style','width:100%')
  842. .addClass('pt-4 font-weight-bold text-muted')
  843. .text('An error occurred, cannot fetch comments. Please try again later.');
  844. } else {
  845. switch(error.response.status) {
  846. case 401:
  847. $('.postCommentsLoader .lds-ring')
  848. .attr('style','width:100%')
  849. .addClass('pt-4 font-weight-bold text-muted')
  850. .text('Please login to view.');
  851. break;
  852. default:
  853. $('.postCommentsLoader .lds-ring')
  854. .attr('style','width:100%')
  855. .addClass('pt-4 font-weight-bold text-muted')
  856. .text('An error occurred, cannot fetch comments. Please try again later.');
  857. break;
  858. }
  859. }
  860. });
  861. },
  862. statusUrl(status) {
  863. if(status.local == true) {
  864. return status.url;
  865. }
  866. return '/i/web/post/_/' + status.account.id + '/' + status.id;
  867. },
  868. profileUrl(status) {
  869. if(status.local == true) {
  870. return status.account.url;
  871. }
  872. return '/i/web/profile/_/' + status.account.id;
  873. },
  874. formatCount(count) {
  875. return App.util.format.count(count);
  876. },
  877. hasStory() {
  878. axios.get('/api/web/stories/v1/exists/'+this.profile.id)
  879. .then(res => {
  880. this.userStory = res.data;
  881. })
  882. },
  883. // real time watcher
  884. rtw() {
  885. this.mpPoller = setInterval(() => {
  886. let apiUrl = false;
  887. this.mpCount++;
  888. if(this.mpCount > 10) {
  889. this.mpInterval = 30000;
  890. }
  891. if(this.mpCount > 50) {
  892. this.mpInterval = (5 * 60 * 1000);
  893. }
  894. switch(this.scope) {
  895. case 'home':
  896. apiUrl = '/api/pixelfed/v1/timelines/home';
  897. break;
  898. case 'local':
  899. apiUrl = '/api/pixelfed/v1/timelines/public';
  900. break;
  901. case 'network':
  902. apiUrl = '/api/pixelfed/v1/timelines/network';
  903. break;
  904. }
  905. axios.get(apiUrl, {
  906. params: {
  907. max_id: 0,
  908. limit: 20,
  909. recent_feed: this.recentFeed
  910. }
  911. }).then(res => {
  912. let self = this;
  913. let tids = this.feed.map(status => status.id);
  914. let data = res.data.filter(d => {
  915. return d.id > self.min_id && tids.indexOf(d.id) == -1;
  916. });
  917. let ids = data.map(status => status.id);
  918. let max = Math.max(...ids).toString();
  919. let newer = max > this.min_id;
  920. if(newer) {
  921. this.morePostsAvailable = true;
  922. this.mpData = data;
  923. }
  924. });
  925. }, this.mpInterval);
  926. },
  927. syncNewPosts() {
  928. let self = this;
  929. let data = this.mpData;
  930. let ids = data.map(s => s.id);
  931. this.min_id = Math.max(...ids).toString();
  932. this.max_id = Math.min(...ids).toString();
  933. this.feed.unshift(...data);
  934. this.morePostsAvailable = false;
  935. this.mpData = null;
  936. },
  937. toggleReplies(reply) {
  938. if(reply.thread) {
  939. reply.thread = false;
  940. } else {
  941. if(reply.replies.length > 0) {
  942. reply.thread = true;
  943. return;
  944. }
  945. let url = '/api/v2/comments/'+reply.account.id+'/status/'+reply.id;
  946. axios.get(url)
  947. .then(response => {
  948. reply.replies = _.reverse(response.data.data);
  949. reply.thread = true;
  950. });
  951. }
  952. },
  953. replyFocus(e, index, prependUsername = false) {
  954. if($('body').hasClass('loggedIn') == false) {
  955. this.redirect('/login?next=' + encodeURIComponent(window.location.pathname));
  956. return;
  957. }
  958. if(this.status.comments_disabled) {
  959. return;
  960. }
  961. this.replyToIndex = index;
  962. this.replyingToId = e.id;
  963. this.replyingToUsername = e.account.username;
  964. this.reply_to_profile_id = e.account.id;
  965. let username = e.account.local ? '@' + e.account.username + ' '
  966. : '@' + e.account.acct + ' ';
  967. if(prependUsername == true) {
  968. this.replyText = username;
  969. }
  970. this.$refs.replyModal.show();
  971. setTimeout(function() {
  972. $('.replyModalTextarea').focus();
  973. }, 500);
  974. },
  975. alwaysViewOlderPosts() {
  976. // Set Feed:Always View Older Posts
  977. window.localStorage.setItem('pf.feed:avop', 'always');
  978. window.location.href = '/';
  979. },
  980. setCurrentLayout(layout) {
  981. this.currentLayout = layout;
  982. },
  983. deleteStatus(status) {
  984. this.feed = this.feed.filter(s => {
  985. return s.id != status;
  986. });
  987. }
  988. },
  989. beforeDestroy () {
  990. clearInterval(this.mpInterval);
  991. }
  992. }
  993. </script>
  994. <style type="text/css" scoped>
  995. .postPresenterContainer {
  996. display: flex;
  997. align-items: center;
  998. background: #fff;
  999. }
  1000. .word-break {
  1001. word-break: break-all;
  1002. }
  1003. .small .custom-control-label {
  1004. padding-top: 3px;
  1005. }
  1006. /*.reply-btn {
  1007. position: absolute;
  1008. bottom: 30px;
  1009. right: 20px;
  1010. width: 60px;
  1011. text-align: center;
  1012. font-size: 13px;
  1013. border-radius: 0 3px 3px 0;
  1014. }*/
  1015. .reply-btn[disabled] {
  1016. opacity: .3;
  1017. color: #3897f0;
  1018. }
  1019. .replyModalTextarea {
  1020. border: none;
  1021. font-size: 18px;
  1022. resize: none;
  1023. white-space: pre-wrap;
  1024. outline: none;
  1025. }
  1026. .has-story {
  1027. width: 64px;
  1028. height: 64px;
  1029. border-radius: 50%;
  1030. padding: 2px;
  1031. background: radial-gradient(ellipse at 70% 70%, #ee583f 8%, #d92d77 42%, #bd3381 58%);
  1032. }
  1033. .has-story img {
  1034. width: 60px;
  1035. height: 60px;
  1036. border-radius: 50%;
  1037. padding: 3px;
  1038. background: #fff;
  1039. }
  1040. .has-story.has-story-sm {
  1041. width: 32px;
  1042. height: 32px;
  1043. border-radius: 50%;
  1044. padding: 2px;
  1045. background: radial-gradient(ellipse at 70% 70%, #ee583f 8%, #d92d77 42%, #bd3381 58%);
  1046. }
  1047. .has-story.has-story-sm img {
  1048. width: 28px;
  1049. height: 28px;
  1050. border-radius: 50%;
  1051. padding: 3px;
  1052. background: #fff;
  1053. }
  1054. #ctx-reply-modal .form-control:focus {
  1055. border: none;
  1056. outline: 0;
  1057. box-shadow: none;
  1058. }
  1059. </style>