Timeline.vue 39 KB

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