Timeline.vue 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443
  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. <textarea class="form-control disabled" rows="1" style="border: 1px solid #efefef; font-size: 14px; line-height: 12px; height: 37px; margin: 0 0 7px; resize: none; white-space: nowrap;" v-model="ctxEmbedPayload"></textarea>
  417. <hr>
  418. <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>
  419. <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>
  420. </div>
  421. </b-modal>
  422. <b-modal
  423. id="lightbox"
  424. ref="lightboxModal"
  425. hide-header
  426. hide-footer
  427. centered
  428. size="lg"
  429. body-class="p-0"
  430. >
  431. <div v-if="lightboxMedia" :class="lightboxMedia.filter_class" class="w-100 h-100">
  432. <img :src="lightboxMedia.url" style="max-height: 100%; max-width: 100%">
  433. </div>
  434. </b-modal>
  435. <b-modal ref="replyModal"
  436. id="ctx-reply-modal"
  437. hide-footer
  438. centered
  439. rounded
  440. :title-html="replyStatus.account ? 'Reply to <span class=text-dark>' + replyStatus.account.username + '</span>' : ''"
  441. title-tag="p"
  442. title-class="font-weight-bold text-muted"
  443. size="md"
  444. body-class="p-2 rounded">
  445. <div>
  446. <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">
  447. </textarea>
  448. <div class="border-top border-bottom my-2">
  449. <ul class="nav align-items-center emoji-reactions" style="overflow-x: scroll;flex-wrap: unset;">
  450. <li class="nav-item" v-on:click="emojiReaction(status)" v-for="e in emoji">{{e}}</li>
  451. </ul>
  452. </div>
  453. <div class="d-flex justify-content-between align-items-center">
  454. <div>
  455. <span class="pl-2 small text-muted font-weight-bold text-monospace">
  456. {{replyText.length}}/600
  457. </span>
  458. </div>
  459. <div class="d-flex align-items-center">
  460. <!-- <select class="custom-select custom-select-sm my-0 mr-2">
  461. <option value="public" selected="">Public</option>
  462. <option value="unlisted">Unlisted</option>
  463. <option value="followers">Followers Only</option>
  464. </select> -->
  465. <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">
  466. {{replySending == true ? 'POSTING' : 'POST'}}
  467. </button>
  468. </div>
  469. </div>
  470. </div>
  471. </b-modal>
  472. </div>
  473. </template>
  474. <style type="text/css" scoped>
  475. .postPresenterContainer {
  476. display: flex;
  477. align-items: center;
  478. background: #fff;
  479. }
  480. .word-break {
  481. word-break: break-all;
  482. }
  483. .small .custom-control-label {
  484. padding-top: 3px;
  485. }
  486. .reply-btn {
  487. position: absolute;
  488. bottom: 12px;
  489. right: 20px;
  490. width: 60px;
  491. text-align: center;
  492. border-radius: 0 3px 3px 0;
  493. }
  494. .emoji-reactions .nav-item {
  495. font-size: 1.2rem;
  496. padding: 9px;
  497. cursor: pointer;
  498. }
  499. .emoji-reactions::-webkit-scrollbar {
  500. width: 0px;
  501. height: 0px;
  502. background: transparent;
  503. }
  504. .reply-btn[disabled] {
  505. opacity: .3;
  506. color: #3897f0;
  507. }
  508. .has-story {
  509. width: 64px;
  510. height: 64px;
  511. border-radius: 50%;
  512. padding: 2px;
  513. background: radial-gradient(ellipse at 70% 70%, #ee583f 8%, #d92d77 42%, #bd3381 58%);
  514. }
  515. .has-story img {
  516. width: 60px;
  517. height: 60px;
  518. border-radius: 50%;
  519. padding: 3px;
  520. background: #fff;
  521. }
  522. .has-story.has-story-sm {
  523. width: 32px;
  524. height: 32px;
  525. border-radius: 50%;
  526. padding: 2px;
  527. background: radial-gradient(ellipse at 70% 70%, #ee583f 8%, #d92d77 42%, #bd3381 58%);
  528. }
  529. .has-story.has-story-sm img {
  530. width: 28px;
  531. height: 28px;
  532. border-radius: 50%;
  533. padding: 3px;
  534. background: #fff;
  535. }
  536. #ctx-reply-modal .form-control:focus {
  537. border: none;
  538. outline: 0;
  539. box-shadow: none;
  540. }
  541. </style>
  542. <script type="text/javascript">
  543. export default {
  544. props: ['scope', 'layout'],
  545. data() {
  546. return {
  547. ids: [],
  548. config: window.App.config,
  549. page: 2,
  550. feed: [],
  551. profile: {},
  552. min_id: 0,
  553. max_id: 0,
  554. suggestions: {},
  555. loading: true,
  556. replies: [],
  557. replyId: null,
  558. modes: {
  559. 'mod': false,
  560. 'dark': false,
  561. 'notify': true,
  562. 'distractionFree': false
  563. },
  564. followers: [],
  565. followerCursor: 1,
  566. followerMore: true,
  567. following: [],
  568. followingCursor: 1,
  569. followingMore: true,
  570. lightboxMedia: false,
  571. showSuggestions: true,
  572. showReadMore: true,
  573. replyStatus: {},
  574. replyText: '',
  575. emoji: window.App.util.emoji,
  576. showHashtagPosts: false,
  577. hashtagPosts: [],
  578. hashtagPostsName: '',
  579. ctxMenuStatus: false,
  580. ctxMenuRelationship: false,
  581. ctxEmbedPayload: false,
  582. copiedEmbed: false,
  583. showTips: true,
  584. userStory: false,
  585. replySending: false,
  586. }
  587. },
  588. beforeMount() {
  589. this.fetchProfile();
  590. this.fetchTimelineApi();
  591. },
  592. mounted() {
  593. if(window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches || $('link[data-stylesheet="dark"]').length != 0) {
  594. this.modes.dark = true;
  595. // todo: release after dark mode updates
  596. /* let el = document.querySelector('link[data-stylesheet="light"]');
  597. el.setAttribute('href', '/css/appdark.css?id=' + Date.now());
  598. el.setAttribute('data-stylesheet', 'dark'); */
  599. }
  600. if(localStorage.getItem('pf_metro_ui.exp.rec') == 'false') {
  601. this.showSuggestions = false;
  602. } else {
  603. this.showSuggestions = true;
  604. }
  605. if(localStorage.getItem('pf_metro_ui.exp.rm') == 'false') {
  606. this.showReadMore = false;
  607. } else {
  608. this.showReadMore = true;
  609. }
  610. if(localStorage.getItem('pf_metro_ui.exp.df') == 'true') {
  611. this.modes.distractionFree = true;
  612. } else {
  613. this.modes.distractionFree = false;
  614. }
  615. if(localStorage.getItem('metro-tips') == 'false') {
  616. this.showTips = false;
  617. }
  618. this.$nextTick(function () {
  619. $('[data-toggle="tooltip"]').tooltip();
  620. let u = new URLSearchParams(window.location.search);
  621. if(u.has('a') && u.get('a') == 'co') {
  622. $('#composeModal').modal('show');
  623. }
  624. });
  625. },
  626. updated() {
  627. if(this.showReadMore == true) {
  628. pixelfed.readmore();
  629. }
  630. },
  631. methods: {
  632. fetchProfile() {
  633. axios.get('/api/pixelfed/v1/accounts/verify_credentials').then(res => {
  634. this.profile = res.data;
  635. if(this.profile.is_admin == true) {
  636. this.modes.mod = true;
  637. }
  638. window._sharedData.curUser = res.data;
  639. this.hasStory();
  640. // this.expRec();
  641. }).catch(err => {
  642. swal(
  643. 'Oops, something went wrong',
  644. 'Please reload the page.',
  645. 'error'
  646. );
  647. });
  648. },
  649. fetchTimelineApi() {
  650. let apiUrl = false;
  651. switch(this.scope) {
  652. case 'home':
  653. apiUrl = '/api/pixelfed/v1/timelines/home';
  654. break;
  655. case 'local':
  656. apiUrl = '/api/pixelfed/v1/timelines/public';
  657. break;
  658. case 'network':
  659. apiUrl = '/api/pixelfed/v1/timelines/network';
  660. break;
  661. }
  662. axios.get(apiUrl, {
  663. params: {
  664. max_id: this.max_id,
  665. limit: 3
  666. }
  667. }).then(res => {
  668. let data = res.data;
  669. this.feed.push(...data);
  670. let ids = data.map(status => status.id);
  671. this.ids = ids;
  672. this.min_id = Math.max(...ids).toString();
  673. this.max_id = Math.min(...ids).toString();
  674. this.loading = false;
  675. $('.timeline .pagination').removeClass('d-none');
  676. // if(this.feed.length == 4) {
  677. // this.fetchTimelineApi();
  678. // }
  679. if(this.hashtagPosts.length == 0) {
  680. this.fetchHashtagPosts();
  681. }
  682. // this.fetchStories();
  683. }).catch(err => {
  684. swal(
  685. 'Oops, something went wrong',
  686. 'Please reload the page.',
  687. 'error'
  688. );
  689. });
  690. },
  691. infiniteTimeline($state) {
  692. if(this.loading) {
  693. $state.complete();
  694. return;
  695. }
  696. if(this.page > 40) {
  697. this.loading = false;
  698. $state.complete();
  699. }
  700. let apiUrl = false;
  701. switch(this.scope) {
  702. case 'home':
  703. apiUrl = '/api/pixelfed/v1/timelines/home';
  704. break;
  705. case 'local':
  706. apiUrl = '/api/pixelfed/v1/timelines/public';
  707. break;
  708. case 'network':
  709. apiUrl = '/api/pixelfed/v1/timelines/network';
  710. break;
  711. }
  712. axios.get(apiUrl, {
  713. params: {
  714. max_id: this.max_id,
  715. limit: 6
  716. },
  717. }).then(res => {
  718. if (res.data.length && this.loading == false) {
  719. let data = res.data;
  720. let self = this;
  721. data.forEach((d, index) => {
  722. if(self.ids.indexOf(d.id) == -1) {
  723. self.feed.push(d);
  724. self.ids.push(d.id);
  725. }
  726. });
  727. this.min_id = Math.max(...this.ids).toString();
  728. this.max_id = Math.min(...this.ids).toString();
  729. this.page += 1;
  730. $state.loaded();
  731. this.loading = false;
  732. } else {
  733. $state.complete();
  734. }
  735. }).catch(err => {
  736. this.loading = false;
  737. $state.complete();
  738. });
  739. },
  740. reportUrl(status) {
  741. let type = status.in_reply_to ? 'comment' : 'post';
  742. let id = status.id;
  743. return '/i/report?type=' + type + '&id=' + id;
  744. },
  745. commentFocus(status, $event) {
  746. if(status.comments_disabled) {
  747. return;
  748. }
  749. this.status = status;
  750. this.replies = {};
  751. this.replyStatus = {};
  752. this.replyText = '';
  753. this.replyId = status.id;
  754. this.replyStatus = status;
  755. this.$refs.replyModal.show();
  756. this.fetchStatusComments(status, '');
  757. return;
  758. },
  759. likeStatus(status) {
  760. if($('body').hasClass('loggedIn') == false) {
  761. return;
  762. }
  763. let count = status.favourites_count;
  764. status.favourited = !status.favourited;
  765. axios.post('/i/like', {
  766. item: status.id
  767. }).then(res => {
  768. status.favourites_count = res.data.count;
  769. }).catch(err => {
  770. status.favourited = !status.favourited;
  771. status.favourites_count = count;
  772. swal('Error', 'Something went wrong, please try again later.', 'error');
  773. });
  774. },
  775. shareStatus(status, $event) {
  776. if($('body').hasClass('loggedIn') == false) {
  777. return;
  778. }
  779. axios.post('/i/share', {
  780. item: status.id
  781. }).then(res => {
  782. status.reblogs_count = res.data.count;
  783. status.reblogged = !status.reblogged;
  784. }).catch(err => {
  785. swal('Error', 'Something went wrong, please try again later.', 'error');
  786. });
  787. },
  788. timestampFormat(timestamp) {
  789. let ts = new Date(timestamp);
  790. return ts.toDateString() + ' ' + ts.toLocaleTimeString();
  791. },
  792. redirect(url) {
  793. window.location.href = url;
  794. return;
  795. },
  796. statusOwner(status) {
  797. let sid = status.account.id;
  798. let uid = this.profile.id;
  799. if(sid == uid) {
  800. return true;
  801. } else {
  802. return false;
  803. }
  804. },
  805. fetchStatusComments(status, card) {
  806. axios.get('/api/v2/status/'+status.id+'/replies')
  807. .then(res => {
  808. let data = res.data.filter(res => {
  809. return res.sensitive == false;
  810. });
  811. this.replies = _.reverse(data);
  812. }).catch(err => {
  813. })
  814. },
  815. muteProfile(status) {
  816. if($('body').hasClass('loggedIn') == false) {
  817. return;
  818. }
  819. axios.post('/i/mute', {
  820. type: 'user',
  821. item: status.account.id
  822. }).then(res => {
  823. this.feed = this.feed.filter(s => s.account.id !== status.account.id);
  824. swal('Success', 'You have successfully muted ' + status.account.acct, 'success');
  825. }).catch(err => {
  826. swal('Error', 'Something went wrong. Please try again later.', 'error');
  827. });
  828. },
  829. blockProfile(status) {
  830. if($('body').hasClass('loggedIn') == false) {
  831. return;
  832. }
  833. axios.post('/i/block', {
  834. type: 'user',
  835. item: status.account.id
  836. }).then(res => {
  837. this.feed = this.feed.filter(s => s.account.id !== status.account.id);
  838. swal('Success', 'You have successfully blocked ' + status.account.acct, 'success');
  839. }).catch(err => {
  840. swal('Error', 'Something went wrong. Please try again later.', 'error');
  841. });
  842. },
  843. deletePost(status) {
  844. if($('body').hasClass('loggedIn') == false || this.ownerOrAdmin(status) == false) {
  845. return;
  846. }
  847. if(window.confirm('Are you sure you want to delete this post?') == false) {
  848. return;
  849. }
  850. axios.post('/i/delete', {
  851. type: 'status',
  852. item: status.id
  853. }).then(res => {
  854. this.feed = this.feed.filter(s => {
  855. return s.id != status.id;
  856. });
  857. this.$refs.ctxModal.hide();
  858. }).catch(err => {
  859. swal('Error', 'Something went wrong. Please try again later.', 'error');
  860. });
  861. },
  862. commentSubmit(status, $event) {
  863. this.replySending = true;
  864. let id = status.id;
  865. let comment = this.replyText;
  866. axios.post('/i/comment', {
  867. item: id,
  868. comment: comment
  869. }).then(res => {
  870. this.replyText = '';
  871. this.replies.unshift(res.data.entity);
  872. this.$refs.replyModal.hide();
  873. });
  874. this.replySending = false;
  875. },
  876. moderatePost(status, action, $event) {
  877. let username = status.account.username;
  878. let msg = '';
  879. let self = this;
  880. switch(action) {
  881. case 'addcw':
  882. msg = 'Are you sure you want to add a content warning to this post?';
  883. swal({
  884. title: 'Confirm',
  885. text: msg,
  886. icon: 'warning',
  887. buttons: true,
  888. dangerMode: true
  889. }).then(res => {
  890. if(res) {
  891. axios.post('/api/v2/moderator/action', {
  892. action: action,
  893. item_id: status.id,
  894. item_type: 'status'
  895. }).then(res => {
  896. swal('Success', 'Successfully added content warning', 'success');
  897. status.sensitive = true;
  898. self.ctxModMenuClose();
  899. }).catch(err => {
  900. swal(
  901. 'Error',
  902. 'Something went wrong, please try again later.',
  903. 'error'
  904. );
  905. self.ctxModMenuClose();
  906. });
  907. }
  908. });
  909. break;
  910. case 'remcw':
  911. msg = 'Are you sure you want to remove the content warning on this post?';
  912. swal({
  913. title: 'Confirm',
  914. text: msg,
  915. icon: 'warning',
  916. buttons: true,
  917. dangerMode: true
  918. }).then(res => {
  919. if(res) {
  920. axios.post('/api/v2/moderator/action', {
  921. action: action,
  922. item_id: status.id,
  923. item_type: 'status'
  924. }).then(res => {
  925. swal('Success', 'Successfully added content warning', 'success');
  926. status.sensitive = false;
  927. self.ctxModMenuClose();
  928. }).catch(err => {
  929. swal(
  930. 'Error',
  931. 'Something went wrong, please try again later.',
  932. 'error'
  933. );
  934. self.ctxModMenuClose();
  935. });
  936. }
  937. });
  938. break;
  939. case 'unlist':
  940. msg = 'Are you sure you want to unlist this post?';
  941. swal({
  942. title: 'Confirm',
  943. text: msg,
  944. icon: 'warning',
  945. buttons: true,
  946. dangerMode: true
  947. }).then(res => {
  948. if(res) {
  949. axios.post('/api/v2/moderator/action', {
  950. action: action,
  951. item_id: status.id,
  952. item_type: 'status'
  953. }).then(res => {
  954. this.feed = this.feed.filter(f => {
  955. return f.id != status.id;
  956. });
  957. swal('Success', 'Successfully unlisted post', 'success');
  958. self.ctxModMenuClose();
  959. }).catch(err => {
  960. self.ctxModMenuClose();
  961. swal(
  962. 'Error',
  963. 'Something went wrong, please try again later.',
  964. 'error'
  965. );
  966. });
  967. }
  968. });
  969. break;
  970. }
  971. },
  972. followingModal() {
  973. if(this.following.length > 0) {
  974. this.$refs.followingModal.show();
  975. return;
  976. }
  977. axios.get('/api/pixelfed/v1/accounts/'+this.profile.id+'/following', {
  978. params: {
  979. page: this.followingCursor
  980. }
  981. })
  982. .then(res => {
  983. this.following = res.data;
  984. this.followingCursor++;
  985. });
  986. if(res.data.length < 10) {
  987. this.followingMore = false;
  988. }
  989. this.$refs.followingModal.show();
  990. },
  991. followersModal() {
  992. if(this.followers.length > 0) {
  993. this.$refs.followerModal.show();
  994. return;
  995. }
  996. axios.get('/api/pixelfed/v1/accounts/'+this.profile.id+'/followers', {
  997. params: {
  998. page: this.followerCursor
  999. }
  1000. })
  1001. .then(res => {
  1002. this.followers = res.data;
  1003. this.followerCursor++;
  1004. })
  1005. if(res.data.length < 10) {
  1006. this.followerMore = false;
  1007. }
  1008. this.$refs.followerModal.show();
  1009. },
  1010. followingLoadMore() {
  1011. axios.get('/api/pixelfed/v1/accounts/'+this.profile.id+'/following', {
  1012. params: {
  1013. page: this.followingCursor
  1014. }
  1015. })
  1016. .then(res => {
  1017. if(res.data.length > 0) {
  1018. this.following.push(...res.data);
  1019. this.followingCursor++;
  1020. }
  1021. if(res.data.length < 10) {
  1022. this.followingMore = false;
  1023. }
  1024. });
  1025. },
  1026. followersLoadMore() {
  1027. axios.get('/api/pixelfed/v1/accounts/'+this.profile.id+'/followers', {
  1028. params: {
  1029. page: this.followerCursor
  1030. }
  1031. })
  1032. .then(res => {
  1033. if(res.data.length > 0) {
  1034. this.followers.push(...res.data);
  1035. this.followerCursor++;
  1036. }
  1037. if(res.data.length < 10) {
  1038. this.followerMore = false;
  1039. }
  1040. });
  1041. },
  1042. lightbox(status) {
  1043. this.lightboxMedia = status.media_attachments[0];
  1044. this.$refs.lightboxModal.show();
  1045. },
  1046. expLc(status) {
  1047. if(this.config.ab.lc == false) {
  1048. return true;
  1049. }
  1050. if(this.statusOwner(status) == true) {
  1051. return true;
  1052. }
  1053. return false;
  1054. },
  1055. expRec() {
  1056. //return;
  1057. if(this.config.ab.rec == false) {
  1058. return;
  1059. }
  1060. axios.get('/api/local/exp/rec')
  1061. .then(res => {
  1062. this.suggestions = res.data;
  1063. })
  1064. },
  1065. expRecFollow(id, index) {
  1066. return;
  1067. if(this.config.ab.rec == false) {
  1068. return;
  1069. }
  1070. axios.post('/i/follow', {
  1071. item: id
  1072. }).then(res => {
  1073. this.suggestions.splice(index, 1);
  1074. }).catch(err => {
  1075. if(err.response.data.message) {
  1076. swal('Error', err.response.data.message, 'error');
  1077. }
  1078. });
  1079. },
  1080. followAction(status) {
  1081. let id = status.account.id;
  1082. axios.post('/i/follow', {
  1083. item: id
  1084. }).then(res => {
  1085. this.feed.forEach(s => {
  1086. if(s.account.id == id) {
  1087. s.account.relationship.following = !s.account.relationship.following;
  1088. }
  1089. });
  1090. let username = status.account.acct;
  1091. if(status.account.relationship.following) {
  1092. swal('Follow successful!', 'You are now following ' + username, 'success');
  1093. } else {
  1094. swal('Unfollow successful!', 'You are no longer following ' + username, 'success');
  1095. }
  1096. }).catch(err => {
  1097. if(err.response.data.message) {
  1098. swal('Error', err.response.data.message, 'error');
  1099. }
  1100. });
  1101. },
  1102. owner(status) {
  1103. return this.profile.id === status.account.id;
  1104. },
  1105. admin() {
  1106. return this.profile.is_admin == true;
  1107. },
  1108. ownerOrAdmin(status) {
  1109. return this.owner(status) || this.admin();
  1110. },
  1111. hideSuggestions() {
  1112. localStorage.setItem('pf_metro_ui.exp.rec', false);
  1113. this.showSuggestions = false;
  1114. },
  1115. emojiReaction(status) {
  1116. let em = event.target.innerText;
  1117. if(this.replyText.length == 0) {
  1118. this.replyText = em + ' ';
  1119. $('textarea[name="comment"]').focus();
  1120. } else {
  1121. this.replyText += em + ' ';
  1122. $('textarea[name="comment"]').focus();
  1123. }
  1124. },
  1125. refreshSuggestions() {
  1126. return;
  1127. let el = event.target.parentNode;
  1128. if(el.classList.contains('disabled') == true) {
  1129. return;
  1130. }
  1131. axios.get('/api/local/exp/rec', {
  1132. params: {
  1133. refresh: true
  1134. }
  1135. })
  1136. .then(res => {
  1137. this.suggestions = res.data;
  1138. if (el.classList) {
  1139. el.classList.add('disabled');
  1140. el.classList.add('text-light');
  1141. }
  1142. else {
  1143. el.className += ' ' + 'disabled text-light';
  1144. }
  1145. setTimeout(function() {
  1146. el.setAttribute('href', '#');
  1147. if (el.classList) {
  1148. el.classList.remove('disabled');
  1149. el.classList.remove('text-light');
  1150. }
  1151. else {
  1152. el.className = el.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), 'disabled text-light');
  1153. }
  1154. }, 10000);
  1155. });
  1156. },
  1157. fetchHashtagPosts() {
  1158. axios.get('/api/local/discover/tag/list')
  1159. .then(res => {
  1160. let tags = res.data;
  1161. if(tags.length == 0) {
  1162. return;
  1163. }
  1164. let hashtag = tags[Math.floor(Math.random(), tags.length)];
  1165. this.hashtagPostsName = hashtag;
  1166. axios.get('/api/v2/discover/tag', {
  1167. params: {
  1168. hashtag: hashtag
  1169. }
  1170. }).then(res => {
  1171. if(res.data.tags.length > 3) {
  1172. this.showHashtagPosts = true;
  1173. this.hashtagPosts = res.data.tags.splice(0,3);
  1174. }
  1175. })
  1176. })
  1177. },
  1178. ctxMenu(status) {
  1179. this.ctxMenuStatus = status;
  1180. this.ctxEmbedPayload = window.App.util.embed.post(status.url);
  1181. if(status.account.id == this.profile.id) {
  1182. this.ctxMenuRelationship = false;
  1183. this.$refs.ctxModal.show();
  1184. } else {
  1185. axios.get('/api/pixelfed/v1/accounts/relationships', {
  1186. params: {
  1187. 'id[]': status.account.id
  1188. }
  1189. }).then(res => {
  1190. this.ctxMenuRelationship = res.data[0];
  1191. this.$refs.ctxModal.show();
  1192. });
  1193. }
  1194. },
  1195. closeCtxMenu(truncate) {
  1196. this.copiedEmbed = false;
  1197. this.ctxMenuStatus = false;
  1198. this.ctxMenuRelationship = false;
  1199. this.$refs.ctxModal.hide();
  1200. },
  1201. ctxMenuCopyLink() {
  1202. let status = this.ctxMenuStatus;
  1203. navigator.clipboard.writeText(status.url);
  1204. this.closeCtxMenu();
  1205. return;
  1206. },
  1207. ctxMenuGoToPost() {
  1208. let status = this.ctxMenuStatus;
  1209. window.location.href = this.statusUrl(status);
  1210. this.closeCtxMenu();
  1211. return;
  1212. },
  1213. ctxMenuFollow() {
  1214. let id = this.ctxMenuStatus.account.id;
  1215. axios.post('/i/follow', {
  1216. item: id
  1217. }).then(res => {
  1218. let username = this.ctxMenuStatus.account.acct;
  1219. this.closeCtxMenu();
  1220. setTimeout(function() {
  1221. swal('Follow successful!', 'You are now following ' + username, 'success');
  1222. }, 500);
  1223. });
  1224. },
  1225. ctxMenuUnfollow() {
  1226. let id = this.ctxMenuStatus.account.id;
  1227. axios.post('/i/follow', {
  1228. item: id
  1229. }).then(res => {
  1230. let username = this.ctxMenuStatus.account.acct;
  1231. if(this.scope == 'home') {
  1232. this.feed = this.feed.filter(s => {
  1233. return s.account.id != this.ctxMenuStatus.account.id;
  1234. });
  1235. }
  1236. this.closeCtxMenu();
  1237. setTimeout(function() {
  1238. swal('Unfollow successful!', 'You are no longer following ' + username, 'success');
  1239. }, 500);
  1240. });
  1241. },
  1242. ctxMenuReportPost() {
  1243. window.location.href = '/i/report?type=post&id=' + this.ctxMenuStatus.id;
  1244. },
  1245. ctxMenuEmbed() {
  1246. this.$refs.ctxModal.hide();
  1247. this.$refs.ctxEmbedModal.show();
  1248. },
  1249. ctxMenuShare() {
  1250. this.$refs.ctxModal.hide();
  1251. this.$refs.ctxShareModal.show();
  1252. },
  1253. closeCtxShareMenu() {
  1254. this.$refs.ctxShareModal.hide();
  1255. this.$refs.ctxModal.show();
  1256. },
  1257. ctxCopyEmbed() {
  1258. navigator.clipboard.writeText(this.ctxEmbedPayload);
  1259. this.$refs.ctxEmbedModal.hide();
  1260. },
  1261. ctxModMenuShow() {
  1262. this.$refs.ctxModal.hide();
  1263. this.$refs.ctxModModal.show();
  1264. },
  1265. ctxModMenu() {
  1266. this.$refs.ctxModal.hide();
  1267. },
  1268. ctxModMenuClose() {
  1269. this.$refs.ctxModal.hide();
  1270. this.$refs.ctxModModal.hide();
  1271. },
  1272. formatCount(count) {
  1273. return App.util.format.count(count);
  1274. },
  1275. statusUrl(status) {
  1276. if(status.local == true) {
  1277. return status.url;
  1278. }
  1279. return '/i/web/post/_/' + status.account.id + '/' + status.id;
  1280. },
  1281. profileUrl(status) {
  1282. if(status.local == true) {
  1283. return status.account.url;
  1284. }
  1285. return '/i/web/profile/_/' + status.account.id;
  1286. },
  1287. statusCardUsernameFormat(status) {
  1288. if(status.account.local == true) {
  1289. return status.account.username;
  1290. }
  1291. let fmt = window.App.config.username.remote.format;
  1292. let txt = window.App.config.username.remote.custom;
  1293. let usr = status.account.username;
  1294. let dom = document.createElement('a');
  1295. dom.href = status.account.url;
  1296. dom = dom.hostname;
  1297. switch(fmt) {
  1298. case '@':
  1299. return usr + '<span class="text-lighter font-weight-bold">@' + dom + '</span>';
  1300. break;
  1301. case 'from':
  1302. return usr + '<span class="text-lighter font-weight-bold"> <span class="font-weight-normal">from</span> ' + dom + '</span>';
  1303. break;
  1304. case 'custom':
  1305. return usr + '<span class="text-lighter font-weight-bold"> ' + txt + ' ' + dom + '</span>';
  1306. break;
  1307. default:
  1308. return usr + '<span class="text-lighter font-weight-bold">@' + dom + '</span>';
  1309. break;
  1310. }
  1311. },
  1312. previewUrl(status) {
  1313. return status.sensitive ? '/storage/no-preview.png?v=' + new Date().getTime() : status.media_attachments[0].preview_url;
  1314. },
  1315. previewBackground(status) {
  1316. let preview = this.previewUrl(status);
  1317. return 'background-image: url(' + preview + ');';
  1318. },
  1319. trimCaption(caption, len = 60) {
  1320. return _.truncate(caption, {
  1321. length: len
  1322. });
  1323. },
  1324. hasStory() {
  1325. axios.get('/api/stories/v0/exists/'+this.profile.id)
  1326. .then(res => {
  1327. this.userStory = res.data;
  1328. })
  1329. }
  1330. }
  1331. }
  1332. </script>