Timeline.vue 46 KB

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