Timeline.vue 39 KB

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