Timeline.vue 37 KB

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