Timeline.vue 57 KB

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