Timeline.vue 56 KB

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