Timeline.vue 45 KB

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