Timeline.vue 36 KB

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