Timeline.vue 53 KB

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