Timeline.vue 36 KB

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