Timeline.vue 54 KB

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