Timeline.vue 47 KB

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