Timeline.vue 47 KB

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