Timeline.vue 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606
  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. :status="status"
  103. :reaction-bar="reactionBar"
  104. v-on:status-delete="deleteStatus"
  105. v-on:comment-focus="commentFocus"
  106. />
  107. </div>
  108. <div v-if="!loading && feed.length">
  109. <div class="card rounded-0 border-top-0 status-card card-md-rounded-0 shadow-none border">
  110. <div class="card-body py-5 my-5">
  111. <infinite-loading @infinite="infiniteTimeline" :distance="800">
  112. <div slot="no-more">
  113. <div v-if="recentFeed">
  114. <p class="text-center"><i class="far fa-check-circle fa-8x text-lighter"></i></p>
  115. <p class="text-center h3 font-weight-light">You're All Caught Up!</p>
  116. <p class="text-center text-muted font-weight-light">You've seen all the new posts from the accounts you follow.</p>
  117. <p class="text-center mb-0">
  118. <a class="btn btn-link font-weight-bold px-4" href="/?a=vop">View Older Posts</a>
  119. </p>
  120. <p class="text-center mb-0">
  121. <a class="btn btn-link font-weight-bold px-4" href="/" @click.prevent="alwaysViewOlderPosts()">Always show older posts on this device</a>
  122. </p>
  123. </div>
  124. <div v-else>
  125. <p class="text-center h3 font-weight-light">You've reached the end of this feed</p>
  126. <p class="text-center mb-0">
  127. <a class="btn btn-link font-weight-bold px-4" href="/discover">Discover new posts and people</a>
  128. </p>
  129. </div>
  130. </div>
  131. <div slot="no-results">
  132. <div v-if="recentFeed">
  133. <p class="text-center"><i class="far fa-check-circle fa-8x text-lighter"></i></p>
  134. <p class="text-center h3 font-weight-light">You're All Caught Up!</p>
  135. <p class="text-center text-muted font-weight-light">You've seen all the new posts from the accounts you follow.</p>
  136. <p class="text-center mb-0">
  137. <a class="btn btn-link font-weight-bold px-4" href="/?a=vop">View Older Posts</a>
  138. </p>
  139. <p class="text-center mb-0">
  140. <a class="btn btn-link font-weight-bold px-4" href="/" @click.prevent="alwaysViewOlderPosts()">Always show older posts on this device</a>
  141. </p>
  142. </div>
  143. <div v-else>
  144. <p class="text-center h3 font-weight-light">You've reached the end of this feed</p>
  145. <p class="text-center mb-0">
  146. <a class="btn btn-link font-weight-bold px-4" href="/discover">Discover new posts and people</a>
  147. </p>
  148. </div>
  149. </div>
  150. </infinite-loading>
  151. </div>
  152. </div>
  153. </div>
  154. <div v-if="!loading && scope == 'home' && feed.length == 0">
  155. <div class="card rounded-0 mt-4 status-card card-md-rounded-0 shadow-none border">
  156. <div v-if="profile.following_count != '0'" class="card-body py-5 my-5">
  157. <p class="text-center"><i class="far fa-check-circle fa-8x text-lighter"></i></p>
  158. <p class="text-center h3 font-weight-light">You're All Caught Up!</p>
  159. <p class="text-center text-muted font-weight-light">You've seen all the new posts from the accounts you follow.</p>
  160. <p class="text-center mb-0">
  161. <a class="btn btn-link font-weight-bold px-4" href="/?a=vop">View Older Posts</a>
  162. </p>
  163. <p class="text-center mb-0">
  164. <a class="btn btn-link font-weight-bold px-4" href="/" @click.prevent="alwaysViewOlderPosts()">Always show older posts on this device</a>
  165. </p>
  166. </div>
  167. <div v-else class="card-body py-5 my-5">
  168. <p class="text-center"><i class="far fa-smile fa-8x text-lighter"></i></p>
  169. <p class="text-center h3 font-weight-light">Hello {{profile.username}}</p>
  170. <p class="text-center text-muted font-weight-light">Accounts you follow will appear in this feed.</p>
  171. <p class="text-center mb-0">
  172. <a class="btn btn-link font-weight-bold px-4" href="/discover">Discover new posts and people</a>
  173. </p>
  174. </div>
  175. </div>
  176. </div>
  177. <div v-if="!loading && scope == 'home' && recentFeed && discover_feed.length" class="pt-3">
  178. <p class="h5 font-weight-bold py-3 d-flex justify-content-between align-items-center">
  179. <span>Suggested Posts</span>
  180. <a href="/?a=vop" class="small font-weight-bold">Older Posts</a>
  181. </p>
  182. </div>
  183. <div
  184. v-if="!loading && scope == 'home' && recentFeed && discover_feed.length"
  185. :data-status-id="status.id"
  186. v-for="(status, index) in discover_feed"
  187. :key="`discover_feed-${index}-${status.id}`">
  188. <div v-if="index == 2 && showSuggestions == true && suggestions.length" class="card mb-sm-4 status-card card-md-rounded-0 shadow-none border">
  189. <div class="card-header d-flex align-items-center justify-content-between bg-white border-0 pb-0">
  190. <h6 class="text-muted font-weight-bold mb-0">Suggestions For You</h6>
  191. <span class="cursor-pointer text-muted" v-on:click="hideSuggestions"><i class="fas fa-times"></i></span>
  192. </div>
  193. <div class="card-body row mx-0">
  194. <div class="col-12 col-md-4 mb-3" v-for="(rec, index) in suggestions">
  195. <div class="card">
  196. <div class="card-body text-center pt-3">
  197. <p class="mb-0">
  198. <a :href="'/'+rec.username">
  199. <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">
  200. </a>
  201. </p>
  202. <div class="py-3">
  203. <p class="font-weight-bold text-dark cursor-pointer mb-0">
  204. <a :href="'/'+rec.username" class="text-decoration-none text-dark">
  205. {{rec.username}}
  206. </a>
  207. </p>
  208. <p class="small text-muted mb-0">{{rec.message}}</p>
  209. </div>
  210. <p class="mb-0">
  211. <a class="btn btn-primary btn-block font-weight-bold py-0" href="#" @click.prevent="expRecFollow(rec.id, index)">Follow</a>
  212. </p>
  213. </div>
  214. </div>
  215. </div>
  216. </div>
  217. </div>
  218. <div v-if="index == 4 && showHashtagPosts && hashtagPosts.length" class="card status-card rounded-0 shadow-none border-top-0 border">
  219. <div class="card-header d-flex align-items-center justify-content-between bg-white border-0 pb-0">
  220. <span></span>
  221. <h6 class="text-muted font-weight-bold mb-0"><a :href="'/discover/tags/'+hashtagPostsName+'?src=tr'">#{{hashtagPostsName}}</a></h6>
  222. <span class="cursor-pointer text-muted" v-on:click="showHashtagPosts = false"><i class="fas fa-times"></i></span>
  223. </div>
  224. <div class="card-body row mx-0">
  225. <div v-for="(tag, index) in hashtagPosts" class="col-4 p-0 p-sm-2 p-md-3 hashtag-post-square">
  226. <a class="card info-overlay card-md-border-0" :href="tag.status.url">
  227. <div :class="[tag.status.filter ? 'square ' + tag.status.filter : 'square']">
  228. <div v-if="tag.status.sensitive" class="square-content">
  229. <div class="info-overlay-text-label">
  230. <h5 class="text-white m-auto font-weight-bold">
  231. <span>
  232. <span class="far fa-eye-slash fa-lg p-2 d-flex-inline"></span>
  233. </span>
  234. </h5>
  235. </div>
  236. <blur-hash-canvas
  237. width="32"
  238. height="32"
  239. :hash="tag.status.media_attachments[0].blurhash"
  240. />
  241. </div>
  242. <div v-else class="square-content">
  243. <blur-hash-image
  244. width="32"
  245. height="32"
  246. :hash="tag.status.media_attachments[0].blurhash"
  247. :src="tag.status.media_attachments[0].preview_url"
  248. />
  249. </div>
  250. <div class="info-overlay-text">
  251. <h5 class="text-white m-auto font-weight-bold">
  252. <span class="pr-4">
  253. <span class="far fa-heart fa-lg pr-1"></span> {{formatCount(tag.status.favourites_count)}}
  254. </span>
  255. <span>
  256. <span class="far fa-comment fa-lg pr-1"></span> {{formatCount(tag.status.reply_count)}}
  257. </span>
  258. </h5>
  259. </div>
  260. </div>
  261. </a>
  262. </div>
  263. </div>
  264. </div>
  265. <status-card :status="status" :recommended="true" />
  266. </div>
  267. </div>
  268. </div>
  269. <div class="col-md-4 col-lg-4 my-4 order-1 order-md-2 d-none d-md-block">
  270. <div>
  271. <!-- <div class="mb-4">
  272. <a class="btn btn-block btn-primary btn-sm font-weight-bold mb-3 border" href="/i/compose" data-toggle="modal" data-target="#composeModal">
  273. <i class="far fa-plus-square pr-3 fa-lg pt-1"></i> New Post
  274. </a>
  275. </div> -->
  276. <div class="mb-4">
  277. <div v-show="!loading" class="">
  278. <div class="pb-2">
  279. <div class="media d-flex align-items-center">
  280. <a :href="!userStory ? profile.url : '/stories/' + profile.acct" class="mr-3">
  281. <!-- <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'"> -->
  282. <div v-if="userStory" class="has-story cursor-pointer shadow-sm" @click="storyRedirect()">
  283. <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">
  284. </div>
  285. <div v-else>
  286. <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">
  287. </div>
  288. </a>
  289. <div class="media-body d-flex justify-content-between word-break" >
  290. <div>
  291. <p class="mb-0 px-0 font-weight-bold"><a :href="profile.url" class="text-dark">{{profile.username || 'loading...'}}</a></p>
  292. <p class="my-0 text-muted pb-0">{{profile.display_name || 'loading...'}}</p>
  293. </div>
  294. <div class="ml-2">
  295. <a class="text-muted" href="/settings/home">
  296. <i class="fas fa-cog fa-lg"></i>
  297. <span class="sr-only">User Settings</span>
  298. </a>
  299. </div>
  300. </div>
  301. </div>
  302. </div>
  303. <!-- <div class="card-footer bg-transparent border-top mt-2 py-1">
  304. <div class="d-flex justify-content-between text-center">
  305. <span class="cursor-pointer" @click="redirect(profile.url)">
  306. <p class="mb-0 font-weight-bold">{{formatCount(profile.statuses_count)}}</p>
  307. <p class="mb-0 small text-muted">Posts</p>
  308. </span>
  309. <span class="cursor-pointer" @click="redirect(profile.url+'?md=followers')">
  310. <p class="mb-0 font-weight-bold">{{formatCount(profile.followers_count)}}</p>
  311. <p class="mb-0 small text-muted">Followers</p>
  312. </span>
  313. <span class="cursor-pointer" @click="redirect(profile.url+'?md=following')">
  314. <p class="mb-0 font-weight-bold">{{formatCount(profile.following_count)}}</p>
  315. <p class="mb-0 small text-muted">Following</p>
  316. </span>
  317. </div>
  318. </div> -->
  319. </div>
  320. <div class="card-footer bg-transparent border-0 pt-0 pb-1">
  321. <div class="d-flex justify-content-between text-center">
  322. <span class="cursor-pointer" @click="redirect(profile.url)">
  323. <p class="mb-0 font-weight-bold">{{formatCount(profile.statuses_count)}}</p>
  324. <p class="mb-0 small text-muted">Posts</p>
  325. </span>
  326. <span class="cursor-pointer" @click="redirect(profile.url+'?md=followers')">
  327. <p class="mb-0 font-weight-bold">{{formatCount(profile.followers_count)}}</p>
  328. <p class="mb-0 small text-muted">Followers</p>
  329. </span>
  330. <span class="cursor-pointer" @click="redirect(profile.url+'?md=following')">
  331. <p class="mb-0 font-weight-bold">{{formatCount(profile.following_count)}}</p>
  332. <p class="mb-0 small text-muted">Following</p>
  333. </span>
  334. </div>
  335. </div>
  336. </div>
  337. <div v-show="modes.notify == true && !loading" class="mb-4">
  338. <notification-card></notification-card>
  339. </div>
  340. <div v-show="showSuggestions == true && suggestions.length && config.ab && config.ab.rec == true" class="mb-4">
  341. <div class="card shadow-none border">
  342. <div class="card-header bg-white d-flex align-items-center justify-content-between">
  343. <a class="small text-muted cursor-pointer" href="#" @click.prevent="refreshSuggestions" ref="suggestionRefresh"><i class="fas fa-sync-alt"></i></a>
  344. <div class="small text-dark text-uppercase font-weight-bold">Suggestions</div>
  345. <div class="small text-muted cursor-pointer" v-on:click="hideSuggestions"><i class="fas fa-times"></i></div>
  346. </div>
  347. <div class="card-body pt-0">
  348. <div v-for="(rec, index) in suggestions" class="media align-items-center mt-3">
  349. <a :href="'/'+rec.username">
  350. <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">
  351. </a>
  352. <div class="media-body">
  353. <p class="mb-0 font-weight-bold small">
  354. <a :href="'/'+rec.username" class="text-decoration-none text-dark">
  355. {{rec.username}}
  356. </a>
  357. </p>
  358. <p class="mb-0 small text-muted">{{rec.message}}</p>
  359. </div>
  360. <a class="font-weight-bold small" href="#" @click.prevent="expRecFollow(rec.id, index)">Follow</a>
  361. </div>
  362. </div>
  363. </div>
  364. </div>
  365. <footer>
  366. <div class="container px-0 pb-5">
  367. <p class="mb-2 small text-justify">
  368. <a href="/site/about" class="text-lighter pr-2">About</a>
  369. <a href="/site/help" class="text-lighter pr-2">Help</a>
  370. <a href="/site/language" class="text-lighter pr-2">Language</a>
  371. <a href="/discover/places" class="text-lighter pr-2">Places</a>
  372. <a href="/site/privacy" class="text-lighter pr-2">Privacy</a>
  373. <a href="/site/terms" class="text-lighter pr-2">Terms</a>
  374. </p>
  375. <p class="mb-0 text-uppercase text-muted small">
  376. <a href="http://pixelfed.org" class="text-lighter" rel="noopener" title="" data-toggle="tooltip">Powered by Pixelfed</a>
  377. </p>
  378. </div>
  379. </footer>
  380. </div>
  381. </div>
  382. </div>
  383. </div>
  384. <!-- <div v-if="currentLayout === 'comments'" class="container p-0 overflow-hidden">
  385. <div class="row">
  386. <div class="col-12 col-md-6 offset-md-3">
  387. <div class="card shadow-none border" style="height:100vh;">
  388. <div class="card-header d-flex justify-content-between align-items-center">
  389. <div
  390. @click="commentNavigateBack(status.id)"
  391. class="cursor-pointer"
  392. >
  393. <i class="fas fa-chevron-left fa-lg px-2"></i>
  394. </div>
  395. <div>
  396. <p class="font-weight-bold mb-0 h5">Comments</p>
  397. </div>
  398. <div>
  399. <i class="fas fa-cog fa-lg text-white"></i>
  400. </div>
  401. </div>
  402. <div class="card-body" style="overflow-y: auto !important">
  403. <div class="media">
  404. <img :src="status.account.avatar" class="rounded-circle border mr-3" width="32px" height="32px">
  405. <div class="media-body">
  406. <p class="d-flex justify-content-between align-items-top mb-0" style="overflow-y: hidden;">
  407. <span class="mr-2" style="font-size: 13px;">
  408. <a class="text-dark font-weight-bold mr-1 text-break" :href="status.account.url" v-bind:title="status.account.username">{{trimCaption(status.account.username,15)}}</a>
  409. <span class="text-break comment-body" style="word-break: break-all;" v-html="status.content"></span>
  410. </span>
  411. </p>
  412. </div>
  413. </div>
  414. <hr>
  415. <div class="postCommentsLoader text-center py-2">
  416. <div class="spinner-border" role="status">
  417. <span class="sr-only">Loading...</span>
  418. </div>
  419. </div>
  420. <div class="postCommentsContainer d-none">
  421. <p v-if="replies.length" class="mb-1 text-center load-more-link my-4">
  422. <a
  423. href="#"
  424. class="text-dark"
  425. title="Load more comments"
  426. @click.prevent="loadMoreComments"
  427. >
  428. <svg class="bi bi-plus-circle" width="1em" height="1em" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg" style="font-size:2em;"> <path fill-rule="evenodd" d="M8 3.5a.5.5 0 01.5.5v4a.5.5 0 01-.5.5H4a.5.5 0 010-1h3.5V4a.5.5 0 01.5-.5z" clip-rule="evenodd"/> <path fill-rule="evenodd" d="M7.5 8a.5.5 0 01.5-.5h4a.5.5 0 010 1H8.5V12a.5.5 0 01-1 0V8z" clip-rule="evenodd"/> <path fill-rule="evenodd" d="M8 15A7 7 0 108 1a7 7 0 000 14zm0 1A8 8 0 108 0a8 8 0 000 16z" clip-rule="evenodd"/></svg>
  429. </a>
  430. </p>
  431. <div v-for="(reply, index) in replies" class="pb-3 media" :key="'tl' + reply.id + '_' + index">
  432. <img :src="reply.account.avatar" class="rounded-circle border mr-3" width="32px" height="32px">
  433. <div class="media-body">
  434. <div v-if="reply.sensitive == true">
  435. <span class="py-3">
  436. <a class="text-dark font-weight-bold mr-3" style="font-size: 13px;" :href="reply.account.url" v-bind:title="reply.account.username">{{trimCaption(reply.account.username,15)}}</a>
  437. <span class="text-break" style="font-size: 13px;">
  438. <span class="font-italic text-muted">This comment may contain sensitive material</span>
  439. <span class="text-primary cursor-pointer pl-1" @click="reply.sensitive = false;">Show</span>
  440. </span>
  441. </span>
  442. </div>
  443. <div v-else>
  444. <p class="d-flex justify-content-between align-items-top read-more mb-0" style="overflow-y: hidden;">
  445. <span class="mr-3" style="font-size: 13px;">
  446. <a class="text-dark font-weight-bold mr-1 text-break" :href="reply.account.url" v-bind:title="reply.account.username">{{trimCaption(reply.account.username,15)}}</a>
  447. <span class="text-break comment-body" style="word-break: break-all;" v-html="reply.content"></span>
  448. </span>
  449. <span class="text-right" style="min-width: 30px;">
  450. <span v-on:click="likeReply(reply, $event)"><i v-bind:class="[reply.favourited ? 'fas fa-heart fa-sm text-danger':'far fa-heart fa-sm text-lighter']"></i></span>
  451. <span class="pl-2 text-lighter cursor-pointer" @click="ctxMenu(reply)">
  452. <span class="fas fa-ellipsis-v text-lighter"></span>
  453. </span>
  454. </span>
  455. </p>
  456. <p class="mb-0">
  457. <a v-once class="text-muted mr-3 text-decoration-none small" style="width: 20px;" v-text="timeAgo(reply.created_at)" :href="reply.url"></a>
  458. <span v-if="reply.favourites_count" class="text-muted comment-reaction font-weight-bold mr-3 small">{{reply.favourites_count == 1 ? '1 like' : reply.favourites_count + ' likes'}}</span>
  459. <span class="small text-muted comment-reaction font-weight-bold cursor-pointer" v-on:click="replyFocus(reply, index, true)">Reply</span>
  460. </p>
  461. <div v-if="reply.reply_count > 0" class="cursor-pointer pb-2" v-on:click="toggleReplies(reply)">
  462. <span class="show-reply-bar"></span>
  463. <span class="comment-reaction small font-weight-bold">{{reply.thread ? 'Hide' : 'View'}} Replies ({{reply.reply_count}})</span>
  464. </div>
  465. <div v-if="reply.thread == true" class="comment-thread">
  466. <div v-for="(s, sindex) in reply.replies" class="py-1 media" :key="'cr' + s.id + '_' + index">
  467. <img :src="s.account.avatar" class="rounded-circle border mr-3" width="25px" height="25px">
  468. <div class="media-body">
  469. <p class="d-flex justify-content-between align-items-top read-more mb-0" style="overflow-y: hidden;">
  470. <span class="mr-2" style="font-size: 13px;">
  471. <a class="text-dark font-weight-bold mr-1" :href="s.account.url" :title="s.account.username">{{s.account.username}}</a>
  472. <span class="text-break comment-body" style="word-break: break-all;" v-html="s.content"></span>
  473. </span>
  474. <span>
  475. <span v-on:click="likeReply(s, $event)"><i v-bind:class="[s.favourited ? 'fas fa-heart fa-sm text-danger':'far fa-heart fa-sm text-lighter']"></i></span>
  476. </span>
  477. </p>
  478. <p class="mb-0">
  479. <a v-once class="text-muted mr-3 text-decoration-none small" style="width: 20px;" v-text="timeAgo(s.created_at)" :href="s.url"></a>
  480. <span v-if="s.favourites_count" class="text-muted comment-reaction font-weight-bold mr-3">{{s.favourites_count == 1 ? '1 like' : s.favourites_count + ' likes'}}</span>
  481. </p>
  482. </div>
  483. </div>
  484. </div>
  485. </div>
  486. </div>
  487. </div>
  488. <div v-if="!replies.length">
  489. <p class="text-center text-muted font-weight-bold small">No comments yet</p>
  490. </div>
  491. </div>
  492. </div>
  493. <div class="card-footer mb-3">
  494. <div class="align-middle d-flex">
  495. <img
  496. :src="profile.avatar"
  497. width="36"
  498. height="36"
  499. class="rounded-circle border mr-3">
  500. <textarea
  501. class="form-control rounded-pill"
  502. name="comment"
  503. placeholder="Add a comment…"
  504. autocomplete="off"
  505. autocorrect="off"
  506. rows="1"
  507. maxlength="0"
  508. style="resize: none;overflow-y: hidden"
  509. @click="replyFocus(status)">
  510. </textarea>
  511. </div>
  512. </div>
  513. </div>
  514. </div>
  515. </div>
  516. </div> -->
  517. <comment-card
  518. v-if="replyStatus && replyStatus.hasOwnProperty('id')"
  519. :status="replyStatus"
  520. :profile="profile"
  521. v-on:current-layout="setCurrentLayout"
  522. />
  523. <div class="modal-stack">
  524. <b-modal ref="replyModal"
  525. id="ctx-reply-modal"
  526. hide-footer
  527. centered
  528. rounded
  529. :title-html="replyStatus.account ? 'Reply to <span class=text-dark>' + replyStatus.account.username + '</span>' : ''"
  530. title-tag="p"
  531. title-class="font-weight-bold text-muted"
  532. size="md"
  533. body-class="p-2 rounded">
  534. <div>
  535. <vue-tribute :options="tributeSettings">
  536. <textarea
  537. class="form-control replyModalTextarea"
  538. rows="4"
  539. v-model="replyText">
  540. </textarea>
  541. </vue-tribute>
  542. <div class="border-top border-bottom my-2">
  543. <ul class="nav align-items-center emoji-reactions" style="overflow-x: scroll;flex-wrap: unset;">
  544. <li class="nav-item" v-on:click="emojiReaction(status)" v-for="e in emoji">{{e}}</li>
  545. </ul>
  546. </div>
  547. <div class="d-flex justify-content-between align-items-center">
  548. <div>
  549. <span class="pl-2 small text-muted font-weight-bold text-monospace">
  550. <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}}
  551. </span>
  552. </div>
  553. <div class="d-flex align-items-center">
  554. <div class="custom-control custom-switch mr-3">
  555. <input type="checkbox" class="custom-control-input" id="replyModalCWSwitch" v-model="replyNsfw">
  556. <label :class="[replyNsfw ? 'custom-control-label font-weight-bold text-dark':'custom-control-label text-lighter']" for="replyModalCWSwitch">Mark as NSFW</label>
  557. </div>
  558. <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">
  559. {{replySending == true ? 'POSTING' : 'POST'}}
  560. </button>
  561. </div>
  562. </div>
  563. </div>
  564. </b-modal>
  565. <b-modal ref="ctxStatusModal"
  566. id="ctx-status-modal"
  567. hide-header
  568. hide-footer
  569. centered
  570. rounded
  571. size="xl"
  572. body-class="list-group-flush p-0 m-0 rounded">
  573. <!-- <post-component
  574. v-if="ctxMenuStatus"
  575. :status-template="ctxMenuStatus.pf_type"
  576. :status-id="ctxMenuStatus.id"
  577. :status-username="ctxMenuStatus.account.username"
  578. :status-url="ctxMenuStatus.url"
  579. :status-profile-url="ctxMenuStatus.account.url"
  580. :status-avatar="ctxMenuStatus.account.avatar"
  581. :status-profile-id="ctxMenuStatus.account.id"
  582. profile-layout="metro">
  583. </post-component> -->
  584. </b-modal>
  585. </div>
  586. </div>
  587. </template>
  588. <script type="text/javascript">
  589. import VueTribute from 'vue-tribute'
  590. import StatusCard from './partials/StatusCard.vue';
  591. import CommentCard from './partials/CommentCard.vue';
  592. export default {
  593. props: ['scope', 'layout'],
  594. components: {
  595. VueTribute,
  596. StatusCard,
  597. CommentCard
  598. },
  599. data() {
  600. return {
  601. ids: [],
  602. config: window.App.config,
  603. page: 2,
  604. feed: [],
  605. profile: {},
  606. min_id: 0,
  607. max_id: 0,
  608. suggestions: {},
  609. loading: true,
  610. replies: [],
  611. replyId: null,
  612. modes: {
  613. 'mod': false,
  614. 'dark': false,
  615. 'notify': true,
  616. 'distractionFree': false
  617. },
  618. followers: [],
  619. followerCursor: 1,
  620. followerMore: true,
  621. following: [],
  622. followingCursor: 1,
  623. followingMore: true,
  624. lightboxMedia: false,
  625. showSuggestions: true,
  626. showReadMore: true,
  627. replyStatus: {},
  628. replyText: '',
  629. replyNsfw: false,
  630. emoji: window.App.util.emoji,
  631. showHashtagPosts: false,
  632. hashtagPosts: [],
  633. hashtagPostsName: '',
  634. copiedEmbed: false,
  635. showTips: true,
  636. userStory: false,
  637. replySending: false,
  638. morePostsAvailable: false,
  639. mpCount: 0,
  640. mpData: false,
  641. mpInterval: 15000,
  642. mpEnabled: false,
  643. mpPoller: null,
  644. confirmModalTitle: 'Are you sure?',
  645. confirmModalIdentifer: null,
  646. confirmModalType: false,
  647. currentLayout: 'feed',
  648. pagination: {},
  649. tributeSettings: {
  650. collection: [
  651. {
  652. trigger: '@',
  653. menuShowMinLength: 2,
  654. values: (function (text, cb) {
  655. let url = '/api/compose/v0/search/mention';
  656. axios.get(url, { params: { q: text }})
  657. .then(res => {
  658. cb(res.data);
  659. })
  660. .catch(err => {
  661. console.log(err);
  662. })
  663. })
  664. },
  665. {
  666. trigger: '#',
  667. menuShowMinLength: 2,
  668. values: (function (text, cb) {
  669. let url = '/api/compose/v0/search/hashtag';
  670. axios.get(url, { params: { q: text }})
  671. .then(res => {
  672. cb(res.data);
  673. })
  674. .catch(err => {
  675. console.log(err);
  676. })
  677. })
  678. }
  679. ]
  680. },
  681. discover_min_id: 0,
  682. discover_max_id: 0,
  683. discover_feed: [],
  684. recentFeed: this.scope === 'home' ? true : false,
  685. recentFeedMin: null,
  686. recentFeedMax: null,
  687. reactionBar: this.scope === 'network' ? false : true
  688. }
  689. },
  690. beforeMount() {
  691. let avop = window.localStorage.getItem('pf.feed:avop') === 'always';
  692. let u = new URLSearchParams(window.location.search);
  693. if(u.has('a')) {
  694. switch(u.get('a')) {
  695. case 'recent_feed':
  696. if(this.scope === 'home') {
  697. this.recentFeed = true;
  698. }
  699. break;
  700. case 'vop':
  701. this.recentFeed = false;
  702. break;
  703. }
  704. }
  705. this.recentFeed = avop ? false : this.recentFeed;
  706. this.fetchProfile();
  707. this.fetchTimelineApi();
  708. },
  709. mounted() {
  710. // todo: release after dark mode updates
  711. /* if(window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches || $('link[data-stylesheet="dark"]').length != 0) {
  712. this.modes.dark = true;
  713. let el = document.querySelector('link[data-stylesheet="light"]');
  714. el.setAttribute('href', '/css/appdark.css?id=' + Date.now());
  715. el.setAttribute('data-stylesheet', 'dark');
  716. }*/
  717. if(localStorage.getItem('pf_metro_ui.exp.rec') == 'false') {
  718. this.showSuggestions = false;
  719. } else {
  720. this.showSuggestions = true;
  721. }
  722. if(localStorage.getItem('pf_metro_ui.exp.rm') == 'false') {
  723. this.showReadMore = false;
  724. } else {
  725. this.showReadMore = true;
  726. }
  727. if(localStorage.getItem('metro-tips') == 'false') {
  728. this.showTips = false;
  729. }
  730. this.$nextTick(function () {
  731. $('[data-toggle="tooltip"]').tooltip();
  732. let u = new URLSearchParams(window.location.search);
  733. if(u.has('a')) {
  734. switch(u.get('a')) {
  735. case 'co':
  736. $('#composeModal').modal('show');
  737. break;
  738. }
  739. }
  740. });
  741. },
  742. updated() {
  743. if(this.showReadMore == true) {
  744. pixelfed.readmore();
  745. }
  746. },
  747. methods: {
  748. fetchProfile() {
  749. axios.get('/api/pixelfed/v1/accounts/verify_credentials').then(res => {
  750. this.profile = res.data;
  751. if(this.profile.is_admin == true) {
  752. this.modes.mod = true;
  753. }
  754. window._sharedData.curUser = res.data;
  755. window.App.util.navatar();
  756. this.hasStory();
  757. // this.expRec();
  758. }).catch(err => {
  759. swal(
  760. 'Oops, something went wrong',
  761. 'Please reload the page.',
  762. 'error'
  763. );
  764. });
  765. },
  766. fetchTimelineApi() {
  767. let apiUrl = false;
  768. switch(this.scope) {
  769. case 'home':
  770. apiUrl = '/api/pixelfed/v1/timelines/home';
  771. break;
  772. case 'local':
  773. apiUrl = '/api/pixelfed/v1/timelines/public';
  774. break;
  775. case 'network':
  776. apiUrl = '/api/pixelfed/v1/timelines/network';
  777. break;
  778. }
  779. axios.get(apiUrl, {
  780. params: {
  781. max_id: this.max_id,
  782. limit: 3,
  783. recent_feed: this.recentFeed
  784. }
  785. }).then(res => {
  786. let data = res.data;
  787. this.feed.push(...data);
  788. let ids = data.map(status => status.id);
  789. this.ids = ids;
  790. this.min_id = Math.max(...ids).toString();
  791. this.max_id = Math.min(...ids).toString();
  792. this.loading = false;
  793. $('.timeline .pagination').removeClass('d-none');
  794. if(this.hashtagPosts.length == 0) {
  795. this.fetchHashtagPosts();
  796. }
  797. // this.fetchStories();
  798. // this.rtw();
  799. setTimeout(function() {
  800. document.querySelectorAll('.timeline .card-body .comments .comment-body a').forEach(function(i, e) {
  801. i.href = App.util.format.rewriteLinks(i);
  802. });
  803. }, 500);
  804. axios.get('/api/pixelfed/v2/discover/posts/trending', {
  805. params: {
  806. range: 'daily'
  807. }
  808. }).then(res => {
  809. let data = res.data.filter(post => this.ids.indexOf(post.id) === -1);
  810. this.discover_feed = data;
  811. });
  812. }).catch(err => {
  813. swal(
  814. 'Oops, something went wrong',
  815. 'Please reload the page.',
  816. 'error'
  817. );
  818. });
  819. },
  820. infiniteTimeline($state) {
  821. if(this.loading) {
  822. $state.complete();
  823. return;
  824. }
  825. if(this.page > 40) {
  826. this.loading = false;
  827. $state.complete();
  828. }
  829. let apiUrl = false;
  830. switch(this.scope) {
  831. case 'home':
  832. apiUrl = '/api/pixelfed/v1/timelines/home';
  833. break;
  834. case 'local':
  835. apiUrl = '/api/pixelfed/v1/timelines/public';
  836. break;
  837. case 'network':
  838. apiUrl = '/api/pixelfed/v1/timelines/network';
  839. break;
  840. }
  841. axios.get(apiUrl, {
  842. params: {
  843. max_id: this.max_id,
  844. limit: 6,
  845. recent_feed: this.recentFeed
  846. },
  847. }).then(res => {
  848. if (res.data.length && this.loading == false) {
  849. let data = res.data;
  850. let self = this;
  851. let vids = [];
  852. if(self.recentFeed && self.ids.indexOf(data[0].id) != -1) {
  853. this.loading = false;
  854. $state.complete();
  855. return;
  856. }
  857. data.forEach((d, index) => {
  858. if(self.ids.indexOf(d.id) == -1) {
  859. self.feed.push(d);
  860. self.ids.push(d.id);
  861. // vids.push({
  862. // sid: d.id,
  863. // pid: d.account.id
  864. // });
  865. }
  866. });
  867. this.min_id = Math.max(...this.ids).toString();
  868. this.max_id = Math.min(...this.ids).toString();
  869. this.page += 1;
  870. $state.loaded();
  871. this.loading = false;
  872. // axios.post('/api/status/view', {
  873. // '_v': vids,
  874. // });
  875. } else {
  876. $state.complete();
  877. }
  878. }).catch(err => {
  879. this.loading = false;
  880. $state.complete();
  881. });
  882. },
  883. reportUrl(status) {
  884. let type = status.in_reply_to ? 'comment' : 'post';
  885. let id = status.id;
  886. return '/i/report?type=' + type + '&id=' + id;
  887. },
  888. commentFocus(status, $event) {
  889. if(status.comments_disabled) {
  890. return;
  891. }
  892. // if(this.status && this.status.id == status.id) {
  893. // this.$refs.replyModal.show();
  894. // return;
  895. // }
  896. this.status = status;
  897. this.replies = {};
  898. this.replyStatus = {};
  899. this.replyText = '';
  900. this.replyId = status.id;
  901. this.replyStatus = status;
  902. // this.$refs.replyModal.show();
  903. this.fetchStatusComments(status, '');
  904. $('nav').hide();
  905. $('footer').hide();
  906. $('.mobile-footer-spacer').attr('style', 'display:none !important');
  907. $('.mobile-footer').attr('style', 'display:none !important');
  908. this.currentLayout = 'comments';
  909. window.history.pushState({}, '', this.statusUrl(status));
  910. return;
  911. },
  912. commentNavigateBack(id) {
  913. $('nav').show();
  914. $('footer').show();
  915. $('.mobile-footer-spacer').attr('style', 'display:block');
  916. $('.mobile-footer').attr('style', 'display:block');
  917. this.currentLayout = 'feed';
  918. let path = this.scope == 'home' ? '/' : '/timeline/public';
  919. window.history.pushState({}, '', path);
  920. },
  921. likeStatus(status, event) {
  922. if($('body').hasClass('loggedIn') == false) {
  923. return;
  924. }
  925. let count = status.favourites_count;
  926. status.favourited = !status.favourited;
  927. axios.post('/i/like', {
  928. item: status.id
  929. }).then(res => {
  930. status.favourites_count = res.data.count;
  931. }).catch(err => {
  932. status.favourited = !status.favourited;
  933. status.favourites_count = count;
  934. swal('Error', 'Something went wrong, please try again later.', 'error');
  935. });
  936. window.navigator.vibrate(200);
  937. if(status.favourited) {
  938. setTimeout(function() {
  939. event.target.classList.add('animate__animated', 'animate__bounce');
  940. },100);
  941. }
  942. },
  943. shareStatus(status, $event) {
  944. if($('body').hasClass('loggedIn') == false) {
  945. return;
  946. }
  947. this.closeModals();
  948. axios.post('/i/share', {
  949. item: status.id
  950. }).then(res => {
  951. status.reblogs_count = res.data.count;
  952. status.reblogged = !status.reblogged;
  953. if(status.reblogged) {
  954. swal('Success', 'You shared this post', 'success');
  955. } else {
  956. swal('Success', 'You unshared this post', 'success');
  957. }
  958. }).catch(err => {
  959. swal('Error', 'Something went wrong, please try again later.', 'error');
  960. });
  961. },
  962. timestampFormat(timestamp) {
  963. let ts = new Date(timestamp);
  964. return ts.toDateString() + ' ' + ts.toLocaleTimeString();
  965. },
  966. redirect(url) {
  967. window.location.href = url;
  968. return;
  969. },
  970. statusOwner(status) {
  971. let sid = status.account.id;
  972. let uid = this.profile.id;
  973. if(sid == uid) {
  974. return true;
  975. } else {
  976. return false;
  977. }
  978. },
  979. fetchStatusComments(status, card) {
  980. // axios.get('/api/v2/status/'+status.id+'/replies',
  981. // {
  982. // params: {
  983. // limit: 6
  984. // }
  985. // })
  986. // .then(res => {
  987. // let data = res.data.filter(res => {
  988. // return res.sensitive == false;
  989. // });
  990. // this.replies = _.reverse(data);
  991. // setTimeout(function() {
  992. // document.querySelectorAll('.timeline .card-body .comments .comment-body a').forEach(function(i, e) {
  993. // i.href = App.util.format.rewriteLinks(i);
  994. // });
  995. // }, 500);
  996. // }).catch(err => {
  997. // })
  998. let url = '/api/v2/comments/'+status.account.id+'/status/'+status.id;
  999. axios.get(url)
  1000. .then(response => {
  1001. let self = this;
  1002. // this.results = this.layout == 'metro' ?
  1003. // _.reverse(response.data.data) :
  1004. // response.data.data;
  1005. this.replies = _.reverse(response.data.data);
  1006. this.pagination = response.data.meta.pagination;
  1007. if(this.replies.length > 0) {
  1008. $('.load-more-link').removeClass('d-none');
  1009. }
  1010. $('.postCommentsLoader').addClass('d-none');
  1011. $('.postCommentsContainer').removeClass('d-none');
  1012. // setTimeout(function() {
  1013. // document.querySelectorAll('.status-comment .postCommentsContainer .comment-body a').forEach(function(i, e) {
  1014. // i.href = App.util.format.rewriteLinks(i);
  1015. // });
  1016. // }, 500);
  1017. }).catch(error => {
  1018. if(!error.response) {
  1019. $('.postCommentsLoader .lds-ring')
  1020. .attr('style','width:100%')
  1021. .addClass('pt-4 font-weight-bold text-muted')
  1022. .text('An error occurred, cannot fetch comments. Please try again later.');
  1023. } else {
  1024. switch(error.response.status) {
  1025. case 401:
  1026. $('.postCommentsLoader .lds-ring')
  1027. .attr('style','width:100%')
  1028. .addClass('pt-4 font-weight-bold text-muted')
  1029. .text('Please login to view.');
  1030. break;
  1031. default:
  1032. $('.postCommentsLoader .lds-ring')
  1033. .attr('style','width:100%')
  1034. .addClass('pt-4 font-weight-bold text-muted')
  1035. .text('An error occurred, cannot fetch comments. Please try again later.');
  1036. break;
  1037. }
  1038. }
  1039. });
  1040. },
  1041. followingModal() {
  1042. if(this.following.length > 0) {
  1043. this.$refs.followingModal.show();
  1044. return;
  1045. }
  1046. axios.get('/api/pixelfed/v1/accounts/'+this.profile.id+'/following', {
  1047. params: {
  1048. page: this.followingCursor
  1049. }
  1050. })
  1051. .then(res => {
  1052. this.following = res.data;
  1053. this.followingCursor++;
  1054. });
  1055. if(res.data.length < 10) {
  1056. this.followingMore = false;
  1057. }
  1058. this.$refs.followingModal.show();
  1059. },
  1060. followersModal() {
  1061. if(this.followers.length > 0) {
  1062. this.$refs.followerModal.show();
  1063. return;
  1064. }
  1065. axios.get('/api/pixelfed/v1/accounts/'+this.profile.id+'/followers', {
  1066. params: {
  1067. page: this.followerCursor
  1068. }
  1069. })
  1070. .then(res => {
  1071. this.followers = res.data;
  1072. this.followerCursor++;
  1073. })
  1074. if(res.data.length < 10) {
  1075. this.followerMore = false;
  1076. }
  1077. this.$refs.followerModal.show();
  1078. },
  1079. followingLoadMore() {
  1080. axios.get('/api/pixelfed/v1/accounts/'+this.profile.id+'/following', {
  1081. params: {
  1082. page: this.followingCursor
  1083. }
  1084. })
  1085. .then(res => {
  1086. if(res.data.length > 0) {
  1087. this.following.push(...res.data);
  1088. this.followingCursor++;
  1089. }
  1090. if(res.data.length < 10) {
  1091. this.followingMore = false;
  1092. }
  1093. });
  1094. },
  1095. followersLoadMore() {
  1096. axios.get('/api/pixelfed/v1/accounts/'+this.profile.id+'/followers', {
  1097. params: {
  1098. page: this.followerCursor
  1099. }
  1100. })
  1101. .then(res => {
  1102. if(res.data.length > 0) {
  1103. this.followers.push(...res.data);
  1104. this.followerCursor++;
  1105. }
  1106. if(res.data.length < 10) {
  1107. this.followerMore = false;
  1108. }
  1109. });
  1110. },
  1111. lightbox(status) {
  1112. window.location.href = status.media_attachments[0].url;
  1113. return;
  1114. this.lightboxMedia = status.media_attachments[0];
  1115. this.$refs.lightboxModal.show();
  1116. },
  1117. expLc(status) {
  1118. if(this.config.ab.lc == false) {
  1119. return true;
  1120. }
  1121. if(this.statusOwner(status) == true) {
  1122. return true;
  1123. }
  1124. return false;
  1125. },
  1126. expRec() {
  1127. //return;
  1128. if(this.config.ab.rec == false) {
  1129. return;
  1130. }
  1131. axios.get('/api/local/exp/rec')
  1132. .then(res => {
  1133. this.suggestions = res.data;
  1134. })
  1135. },
  1136. expRecFollow(id, index) {
  1137. return;
  1138. if(this.config.ab.rec == false) {
  1139. return;
  1140. }
  1141. axios.post('/i/follow', {
  1142. item: id
  1143. }).then(res => {
  1144. this.suggestions.splice(index, 1);
  1145. }).catch(err => {
  1146. if(err.response.data.message) {
  1147. swal('Error', err.response.data.message, 'error');
  1148. }
  1149. });
  1150. },
  1151. followAction(status) {
  1152. let id = status.account.id;
  1153. axios.post('/i/follow', {
  1154. item: id
  1155. }).then(res => {
  1156. this.feed.forEach(s => {
  1157. if(s.account.id == id) {
  1158. s.account.relationship.following = !s.account.relationship.following;
  1159. }
  1160. });
  1161. let username = status.account.acct;
  1162. if(status.account.relationship.following) {
  1163. swal('Follow successful!', 'You are now following ' + username, 'success');
  1164. } else {
  1165. swal('Unfollow successful!', 'You are no longer following ' + username, 'success');
  1166. }
  1167. }).catch(err => {
  1168. if(err.response.data.message) {
  1169. swal('Error', err.response.data.message, 'error');
  1170. }
  1171. });
  1172. },
  1173. owner(status) {
  1174. return this.profile.id === status.account.id;
  1175. },
  1176. admin() {
  1177. return this.profile.is_admin == true;
  1178. },
  1179. ownerOrAdmin(status) {
  1180. return this.owner(status) || this.admin();
  1181. },
  1182. hideSuggestions() {
  1183. localStorage.setItem('pf_metro_ui.exp.rec', false);
  1184. this.showSuggestions = false;
  1185. },
  1186. emojiReaction(status) {
  1187. let em = event.target.innerText;
  1188. if(this.replyText.length == 0) {
  1189. this.replyText = em + ' ';
  1190. $('textarea[name="comment"]').focus();
  1191. } else {
  1192. this.replyText += em + ' ';
  1193. $('textarea[name="comment"]').focus();
  1194. }
  1195. },
  1196. refreshSuggestions() {
  1197. return;
  1198. let el = event.target.parentNode;
  1199. if(el.classList.contains('disabled') == true) {
  1200. return;
  1201. }
  1202. axios.get('/api/local/exp/rec', {
  1203. params: {
  1204. refresh: true
  1205. }
  1206. })
  1207. .then(res => {
  1208. this.suggestions = res.data;
  1209. if (el.classList) {
  1210. el.classList.add('disabled');
  1211. el.classList.add('text-light');
  1212. }
  1213. else {
  1214. el.className += ' ' + 'disabled text-light';
  1215. }
  1216. setTimeout(function() {
  1217. el.setAttribute('href', '#');
  1218. if (el.classList) {
  1219. el.classList.remove('disabled');
  1220. el.classList.remove('text-light');
  1221. }
  1222. else {
  1223. el.className = el.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), 'disabled text-light');
  1224. }
  1225. }, 10000);
  1226. });
  1227. },
  1228. fetchHashtagPosts() {
  1229. axios.get('/api/local/discover/tag/list')
  1230. .then(res => {
  1231. let tags = res.data;
  1232. if(tags.length == 0) {
  1233. return;
  1234. }
  1235. let hashtag = tags[Math.floor(Math.random(), tags.length)];
  1236. this.hashtagPostsName = hashtag;
  1237. axios.get('/api/v2/discover/tag', {
  1238. params: {
  1239. hashtag: hashtag
  1240. }
  1241. }).then(res => {
  1242. if(res.data.tags.length > 3) {
  1243. this.showHashtagPosts = true;
  1244. this.hashtagPosts = res.data.tags.splice(0,3);
  1245. }
  1246. })
  1247. })
  1248. },
  1249. ctxCopyEmbed() {
  1250. navigator.clipboard.writeText(this.ctxEmbedPayload);
  1251. this.ctxEmbedShowCaption = true;
  1252. this.ctxEmbedShowLikes = false;
  1253. this.ctxEmbedCompactMode = false;
  1254. this.$refs.ctxEmbedModal.hide();
  1255. },
  1256. formatCount(count) {
  1257. return App.util.format.count(count);
  1258. },
  1259. statusUrl(status) {
  1260. if(status.local == true) {
  1261. return status.url;
  1262. }
  1263. return '/i/web/post/_/' + status.account.id + '/' + status.id;
  1264. },
  1265. profileUrl(status) {
  1266. if(status.local == true) {
  1267. return status.account.url;
  1268. }
  1269. return '/i/web/profile/_/' + status.account.id;
  1270. },
  1271. statusCardUsernameFormat(status) {
  1272. if(status.account.local == true) {
  1273. return status.account.username;
  1274. }
  1275. let fmt = window.App.config.username.remote.format;
  1276. let txt = window.App.config.username.remote.custom;
  1277. let usr = status.account.username;
  1278. let dom = document.createElement('a');
  1279. dom.href = status.account.url;
  1280. dom = dom.hostname;
  1281. switch(fmt) {
  1282. case '@':
  1283. return usr + '<span class="text-lighter font-weight-bold">@' + dom + '</span>';
  1284. break;
  1285. case 'from':
  1286. return usr + '<span class="text-lighter font-weight-bold"> <span class="font-weight-normal">from</span> ' + dom + '</span>';
  1287. break;
  1288. case 'custom':
  1289. return usr + '<span class="text-lighter font-weight-bold"> ' + txt + ' ' + dom + '</span>';
  1290. break;
  1291. default:
  1292. return usr + '<span class="text-lighter font-weight-bold">@' + dom + '</span>';
  1293. break;
  1294. }
  1295. },
  1296. previewUrl(status) {
  1297. return status.sensitive ? '/storage/no-preview.png?v=' + new Date().getTime() : status.media_attachments[0].preview_url;
  1298. },
  1299. previewBackground(status) {
  1300. let preview = this.previewUrl(status);
  1301. return 'background-image: url(' + preview + ');';
  1302. },
  1303. trimCaption(caption, len = 60) {
  1304. return _.truncate(caption, {
  1305. length: len
  1306. });
  1307. },
  1308. hasStory() {
  1309. axios.get('/api/stories/v0/exists/'+this.profile.id)
  1310. .then(res => {
  1311. this.userStory = res.data;
  1312. })
  1313. },
  1314. // real time watcher
  1315. rtw() {
  1316. this.mpPoller = setInterval(() => {
  1317. let apiUrl = false;
  1318. this.mpCount++;
  1319. if(this.mpCount > 10) {
  1320. this.mpInterval = 30000;
  1321. }
  1322. if(this.mpCount > 50) {
  1323. this.mpInterval = (5 * 60 * 1000);
  1324. }
  1325. switch(this.scope) {
  1326. case 'home':
  1327. apiUrl = '/api/pixelfed/v1/timelines/home';
  1328. break;
  1329. case 'local':
  1330. apiUrl = '/api/pixelfed/v1/timelines/public';
  1331. break;
  1332. case 'network':
  1333. apiUrl = '/api/pixelfed/v1/timelines/network';
  1334. break;
  1335. }
  1336. axios.get(apiUrl, {
  1337. params: {
  1338. max_id: 0,
  1339. limit: 20,
  1340. recent_feed: this.recentFeed
  1341. }
  1342. }).then(res => {
  1343. let self = this;
  1344. let tids = this.feed.map(status => status.id);
  1345. let data = res.data.filter(d => {
  1346. return d.id > self.min_id && tids.indexOf(d.id) == -1;
  1347. });
  1348. let ids = data.map(status => status.id);
  1349. let max = Math.max(...ids).toString();
  1350. let newer = max > this.min_id;
  1351. if(newer) {
  1352. this.morePostsAvailable = true;
  1353. this.mpData = data;
  1354. }
  1355. });
  1356. }, this.mpInterval);
  1357. },
  1358. syncNewPosts() {
  1359. let self = this;
  1360. let data = this.mpData;
  1361. let ids = data.map(s => s.id);
  1362. this.min_id = Math.max(...ids).toString();
  1363. this.max_id = Math.min(...ids).toString();
  1364. this.feed.unshift(...data);
  1365. this.morePostsAvailable = false;
  1366. this.mpData = null;
  1367. },
  1368. toggleReplies(reply) {
  1369. if(reply.thread) {
  1370. reply.thread = false;
  1371. } else {
  1372. if(reply.replies.length > 0) {
  1373. reply.thread = true;
  1374. return;
  1375. }
  1376. let url = '/api/v2/comments/'+reply.account.id+'/status/'+reply.id;
  1377. axios.get(url)
  1378. .then(response => {
  1379. reply.replies = _.reverse(response.data.data);
  1380. reply.thread = true;
  1381. });
  1382. }
  1383. },
  1384. replyFocus(e, index, prependUsername = false) {
  1385. if($('body').hasClass('loggedIn') == false) {
  1386. this.redirect('/login?next=' + encodeURIComponent(window.location.pathname));
  1387. return;
  1388. }
  1389. if(this.status.comments_disabled) {
  1390. return;
  1391. }
  1392. this.replyToIndex = index;
  1393. this.replyingToId = e.id;
  1394. this.replyingToUsername = e.account.username;
  1395. this.reply_to_profile_id = e.account.id;
  1396. let username = e.account.local ? '@' + e.account.username + ' '
  1397. : '@' + e.account.acct + ' ';
  1398. if(prependUsername == true) {
  1399. this.replyText = username;
  1400. }
  1401. this.$refs.replyModal.show();
  1402. setTimeout(function() {
  1403. $('.replyModalTextarea').focus();
  1404. }, 500);
  1405. },
  1406. alwaysViewOlderPosts() {
  1407. // Set Feed:Always View Older Posts
  1408. window.localStorage.setItem('pf.feed:avop', 'always');
  1409. window.location.href = '/';
  1410. },
  1411. setCurrentLayout(layout) {
  1412. this.currentLayout = layout;
  1413. },
  1414. deleteStatus(status) {
  1415. this.feed = this.feed.filter(s => {
  1416. return s.id != status;
  1417. });
  1418. }
  1419. },
  1420. beforeDestroy () {
  1421. clearInterval(this.mpInterval);
  1422. }
  1423. }
  1424. </script>
  1425. <style type="text/css" scoped>
  1426. .postPresenterContainer {
  1427. display: flex;
  1428. align-items: center;
  1429. background: #fff;
  1430. }
  1431. .word-break {
  1432. word-break: break-all;
  1433. }
  1434. .small .custom-control-label {
  1435. padding-top: 3px;
  1436. }
  1437. /*.reply-btn {
  1438. position: absolute;
  1439. bottom: 30px;
  1440. right: 20px;
  1441. width: 60px;
  1442. text-align: center;
  1443. font-size: 13px;
  1444. border-radius: 0 3px 3px 0;
  1445. }*/
  1446. .reply-btn[disabled] {
  1447. opacity: .3;
  1448. color: #3897f0;
  1449. }
  1450. .replyModalTextarea {
  1451. border: none;
  1452. font-size: 18px;
  1453. resize: none;
  1454. white-space: pre-wrap;
  1455. outline: none;
  1456. }
  1457. .has-story {
  1458. width: 64px;
  1459. height: 64px;
  1460. border-radius: 50%;
  1461. padding: 2px;
  1462. background: radial-gradient(ellipse at 70% 70%, #ee583f 8%, #d92d77 42%, #bd3381 58%);
  1463. }
  1464. .has-story img {
  1465. width: 60px;
  1466. height: 60px;
  1467. border-radius: 50%;
  1468. padding: 3px;
  1469. background: #fff;
  1470. }
  1471. .has-story.has-story-sm {
  1472. width: 32px;
  1473. height: 32px;
  1474. border-radius: 50%;
  1475. padding: 2px;
  1476. background: radial-gradient(ellipse at 70% 70%, #ee583f 8%, #d92d77 42%, #bd3381 58%);
  1477. }
  1478. .has-story.has-story-sm img {
  1479. width: 28px;
  1480. height: 28px;
  1481. border-radius: 50%;
  1482. padding: 3px;
  1483. background: #fff;
  1484. }
  1485. #ctx-reply-modal .form-control:focus {
  1486. border: none;
  1487. outline: 0;
  1488. box-shadow: none;
  1489. }
  1490. </style>