Timeline.vue 49 KB

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