Timeline.vue 50 KB

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