Timeline.vue 51 KB

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