Timeline.vue 37 KB

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