PostComponent.vue 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041
  1. <template>
  2. <div>
  3. <div v-if="!loaded" style="height: 80vh;" class="d-flex justify-content-center align-items-center">
  4. <img src="/img/pixelfed-icon-grey.svg" class="">
  5. </div>
  6. <div v-if="loaded && warning" class="bg-white pt-3 border-bottom">
  7. <div class="container">
  8. <p class="text-center font-weight-bold">You are blocking this account</p>
  9. <p class="text-center font-weight-bold">Click <a href="#" class="cursor-pointer" @click.prevent="warning = false; fetchData()">here</a> to view this status</p>
  10. </div>
  11. </div>
  12. <div v-if="loaded && warning == false" class="postComponent">
  13. <div v-if="profileLayout == 'metro'" class="container px-0">
  14. <div class="card card-md-rounded-0 status-container orientation-unknown">
  15. <div class="row px-0 mx-0">
  16. <div class="d-flex d-md-none align-items-center justify-content-between card-header bg-white w-100">
  17. <a :href="statusProfileUrl" class="d-flex align-items-center status-username text-truncate" data-toggle="tooltip" data-placement="bottom" :title="statusUsername">
  18. <div class="status-avatar mr-2">
  19. <img :src="statusAvatar" width="24px" height="24px" style="border-radius:12px;">
  20. </div>
  21. <div class="username">
  22. <span class="username-link font-weight-bold text-dark">{{ statusUsername }}</span>
  23. </div>
  24. </a>
  25. <div v-if="user != false" class="float-right">
  26. <div class="post-actions">
  27. <div class="dropdown">
  28. <button class="btn btn-link text-dark no-caret dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" title="Post options">
  29. <span class="fas fa-ellipsis-v text-muted"></span>
  30. </button>
  31. <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuButton">
  32. <div v-if="!owner()">
  33. <a class="dropdown-item font-weight-bold" :href="reportUrl()">Report</a>
  34. <a class="dropdown-item font-weight-bold" v-on:click="muteProfile()">Mute Profile</a>
  35. <a class="dropdown-item font-weight-bold" v-on:click="blockProfile()">Block Profile</a>
  36. </div>
  37. <div v-if="ownerOrAdmin()">
  38. <a class="dropdown-item font-weight-bold" href="#" v-on:click.prevent="toggleCommentVisibility">{{ showComments ? 'Disable' : 'Enable'}} Comments</a>
  39. <a class="dropdown-item font-weight-bold" :href="editUrl()">Edit</a>
  40. <a class="dropdown-item font-weight-bold text-danger" v-on:click="deletePost(status)">Delete</a>
  41. </div>
  42. </div>
  43. </div>
  44. </div>
  45. </div>
  46. </div>
  47. <div class="col-12 col-md-8 px-0 mx-0">
  48. <div class="postPresenterContainer d-none d-flex justify-content-center align-items-center" v-on:dblclick="likeStatus">
  49. <div v-if="status.pf_type === 'photo'" class="w-100">
  50. <photo-presenter :status="status" v-on:lightbox="lightbox"></photo-presenter>
  51. </div>
  52. <div v-else-if="status.pf_type === 'video'" class="w-100">
  53. <video-presenter :status="status"></video-presenter>
  54. </div>
  55. <div v-else-if="status.pf_type === 'photo:album'" class="w-100">
  56. <photo-album-presenter :status="status" v-on:lightbox="lightbox"></photo-album-presenter>
  57. </div>
  58. <div v-else-if="status.pf_type === 'video:album'" class="w-100">
  59. <video-album-presenter :status="status"></video-album-presenter>
  60. </div>
  61. <div v-else-if="status.pf_type === 'photo:video:album'" class="w-100">
  62. <mixed-album-presenter :status="status" v-on:lightbox="lightbox"></mixed-album-presenter>
  63. </div>
  64. <div v-else class="w-100">
  65. <p class="text-center p-0 font-weight-bold text-white">Error: Problem rendering preview.</p>
  66. </div>
  67. </div>
  68. </div>
  69. <div class="col-12 col-md-4 px-0 d-flex flex-column border-left border-md-left-0">
  70. <div class="d-md-flex d-none align-items-center justify-content-between card-header py-3 bg-white">
  71. <a :href="statusProfileUrl" class="d-flex align-items-center status-username text-truncate" data-toggle="tooltip" data-placement="bottom" :title="statusUsername">
  72. <div class="status-avatar mr-2">
  73. <img :src="statusAvatar" width="24px" height="24px" style="border-radius:12px;">
  74. </div>
  75. <div class="username">
  76. <span class="username-link font-weight-bold text-dark">{{ statusUsername }}</span>
  77. </div>
  78. </a>
  79. <div class="float-right">
  80. <div class="post-actions">
  81. <div v-if="user != false" class="dropdown">
  82. <button class="btn btn-link text-dark no-caret dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" title="Post options">
  83. <span class="fas fa-ellipsis-v text-muted"></span>
  84. </button>
  85. <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuButton">
  86. <span v-if="!owner()">
  87. <a class="dropdown-item font-weight-bold" :href="reportUrl()">Report</a>
  88. <a class="dropdown-item font-weight-bold" v-on:click="muteProfile">Mute Profile</a>
  89. <a class="dropdown-item font-weight-bold" v-on:click="blockProfile">Block Profile</a>
  90. </span>
  91. <span v-if="ownerOrAdmin()">
  92. <a class="dropdown-item font-weight-bold" href="#" v-on:click.prevent="toggleCommentVisibility">{{ showComments ? 'Disable' : 'Enable'}} Comments</a>
  93. <a class="dropdown-item font-weight-bold" :href="editUrl()">Edit</a>
  94. <a class="dropdown-item font-weight-bold text-danger" v-on:click="deletePost">Delete</a>
  95. </span>
  96. </div>
  97. </div>
  98. </div>
  99. </div>
  100. </div>
  101. <div class="d-flex flex-md-column flex-column-reverse h-100">
  102. <div class="card-body status-comments pb-5">
  103. <div class="status-comment">
  104. <p :class="[status.content.length > 420 ? 'mb-1 read-more' : 'mb-1']" style="overflow: hidden;">
  105. <span class="font-weight-bold pr-1">{{statusUsername}}</span>
  106. <span class="comment-text" :id="status.id + '-status-readmore'" v-html="status.content"></span>
  107. </p>
  108. <div v-if="showComments">
  109. <div class="postCommentsLoader text-center">
  110. <div class="spinner-border" role="status">
  111. <span class="sr-only">Loading...</span>
  112. </div>
  113. </div>
  114. <div class="postCommentsContainer d-none pt-3">
  115. <p v-if="status.reply_count > 10"class="mb-1 text-center load-more-link d-none"><a href="#" class="text-muted" v-on:click="loadMore">Load more comments</a></p>
  116. <div class="comments">
  117. <div v-for="(reply, index) in results" class="pb-3" :key="'tl' + reply.id + '_' + index">
  118. <p class="d-flex justify-content-between align-items-top read-more" style="overflow-y: hidden;">
  119. <span>
  120. <a class="text-dark font-weight-bold mr-1" :href="reply.account.url" v-bind:title="reply.account.username">{{truncate(reply.account.username,15)}}</a>
  121. <span class="text-break" v-html="reply.content"></span>
  122. </span>
  123. <span class="pl-2" style="min-width:38px">
  124. <span v-on:click="likeReply(reply, $event)"><i v-bind:class="[reply.favourited ? 'fas fa-heart fa-sm text-danger':'far fa-heart fa-sm text-lighter']"></i></span>
  125. <post-menu :status="reply" :profile="user" :size="'sm'" :modal="'true'" class="d-inline-block pl-2" v-on:deletePost="deleteComment(reply.id, index)"></post-menu>
  126. </span>
  127. </p>
  128. <p class="">
  129. <a v-once class="text-muted mr-3 text-decoration-none small" style="width: 20px;" v-text="timeAgo(reply.created_at)" :href="reply.url"></a>
  130. <span v-if="reply.favourites_count" class="text-muted comment-reaction font-weight-bold mr-3">{{reply.favourites_count == 1 ? '1 like' : reply.favourites_count + ' likes'}}</span>
  131. <span class="text-muted comment-reaction font-weight-bold cursor-pointer" v-on:click="replyFocus(reply, index)">Reply</span>
  132. </p>
  133. <div v-if="reply.reply_count > 0" class="cursor-pointer" style="margin-left:30px;" v-on:click="toggleReplies(reply)">
  134. <span class="show-reply-bar"></span>
  135. <span class="comment-reaction font-weight-bold text-muted">{{reply.thread ? 'Hide' : 'View'}} Replies ({{reply.reply_count}})</span>
  136. </div>
  137. <div v-if="reply.thread == true" class="comment-thread">
  138. <div v-for="(s, sindex) in reply.replies" class="pb-3" :key="'cr' + s.id + '_' + index">
  139. <p class="d-flex justify-content-between align-items-top read-more" style="overflow-y: hidden;">
  140. <span>
  141. <a class="text-dark font-weight-bold mr-1" :href="s.account.url" :title="s.account.username">{{s.account.username}}</a>
  142. <span class="text-break" v-html="s.content"></span>
  143. </span>
  144. <span class="pl-2" style="min-width:38px">
  145. <span v-on:click="likeReply(s, $event)"><i v-bind:class="[s.favourited ? 'fas fa-heart fa-sm text-danger':'far fa-heart fa-sm text-lighter']"></i></span>
  146. <post-menu :status="s" :profile="user" :size="'sm'" :modal="'true'" class="d-inline-block pl-2" v-on:deletePost="deleteCommentReply(s.id, sindex, index) "></post-menu>
  147. </span>
  148. </p>
  149. <p class="">
  150. <a v-once class="text-muted mr-3 text-decoration-none small" style="width: 20px;" v-text="timeAgo(s.created_at)" :href="s.url"></a>
  151. <span v-if="s.favourites_count" class="text-muted comment-reaction font-weight-bold mr-3">{{s.favourites_count == 1 ? '1 like' : s.favourites_count + ' likes'}}</span>
  152. </p>
  153. </div>
  154. </div>
  155. </div>
  156. </div>
  157. </div>
  158. </div>
  159. </div>
  160. </div>
  161. <div class="card-body flex-grow-0 py-1">
  162. <div class="reactions my-1">
  163. <h3 v-bind:class="[reactions.liked ? '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"></h3>
  164. <h3 v-if="!status.comments_disabled" class="far fa-comment pr-3 m-0 cursor-pointer" title="Comment" v-on:click="replyFocus(status)"></h3>
  165. <h3 v-bind:class="[reactions.shared ? '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"></h3>
  166. <h3 v-bind:class="[reactions.bookmarked ? 'fas fa-bookmark text-warning m-0 float-right cursor-pointer' : 'far fa-bookmark m-0 float-right cursor-pointer']" title="Bookmark" v-on:click="bookmarkStatus"></h3>
  167. </div>
  168. <div class="reaction-counts font-weight-bold mb-0">
  169. <span style="cursor:pointer;" v-on:click="likesModal">
  170. <span class="like-count">{{status.favourites_count || 0}}</span> likes
  171. </span>
  172. <span class="float-right" style="cursor:pointer;" v-on:click="sharesModal">
  173. <span class="share-count pl-4">{{status.reblogs_count || 0}}</span> shares
  174. </span>
  175. </div>
  176. <div class="timestamp pt-2 d-flex align-items-bottom justify-content-between">
  177. <a v-bind:href="statusUrl" class="small text-muted">
  178. {{timestampFormat()}}
  179. </a>
  180. <span class="small text-muted text-capitalize cursor-pointer" v-on:click="visibilityModal">{{status.visibility}}</span>
  181. </div>
  182. </div>
  183. </div>
  184. <div v-if="showComments && user.length !== 0" class="card-footer bg-white px-2 py-0">
  185. <ul class="nav align-items-center emoji-reactions" style="overflow-x: scroll;flex-wrap: unset;">
  186. <li class="nav-item" v-on:click="emojiReaction">๐Ÿ˜‚</li>
  187. <li class="nav-item" v-on:click="emojiReaction">๐Ÿ’ฏ</li>
  188. <li class="nav-item" v-on:click="emojiReaction">โค๏ธ</li>
  189. <li class="nav-item" v-on:click="emojiReaction">๐Ÿ™Œ</li>
  190. <li class="nav-item" v-on:click="emojiReaction">๐Ÿ‘</li>
  191. <li class="nav-item" v-on:click="emojiReaction">๐Ÿ‘Œ</li>
  192. <li class="nav-item" v-on:click="emojiReaction">๐Ÿ˜</li>
  193. <li class="nav-item" v-on:click="emojiReaction">๐Ÿ˜ฏ</li>
  194. <li class="nav-item" v-on:click="emojiReaction">๐Ÿ˜ข</li>
  195. <li class="nav-item" v-on:click="emojiReaction">๐Ÿ˜…</li>
  196. <li class="nav-item" v-on:click="emojiReaction">๐Ÿ˜</li>
  197. <li class="nav-item" v-on:click="emojiReaction">๐Ÿ™‚</li>
  198. <li class="nav-item" v-on:click="emojiReaction">๐Ÿ˜Ž</li>
  199. <li class="nav-item" v-on:click="emojiReaction" v-for="e in emoji">{{e}}</li>
  200. </ul>
  201. </div>
  202. <div v-if="showComments" class="card-footer bg-white sticky-md-bottom p-0">
  203. <div v-if="user.length == 0" class="comment-form-guest p-3">
  204. <a href="/login">Login</a> to like or comment.
  205. </div>
  206. <form v-else class="border-0 rounded-0 align-middle" method="post" action="/i/comment" :data-id="statusId" data-truncate="false">
  207. <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>
  208. <input type="button" value="Post" class="d-inline-block btn btn-link font-weight-bold reply-btn text-decoration-none" v-on:click.prevent="postReply"/>
  209. </form>
  210. </div>
  211. </div>
  212. </div>
  213. </div>
  214. </div>
  215. <div v-if="profileLayout == 'moment'" class="momentui">
  216. <div class="bg-dark mt-md-n4">
  217. <div class="container" v-on:dblclick="likeStatus">
  218. <div class="postPresenterContainer d-none d-flex justify-content-center align-items-center bg-dark">
  219. <div v-if="status.pf_type === 'photo'" class="w-100">
  220. <photo-presenter :status="status" v-on:lightbox="lightbox"></photo-presenter>
  221. </div>
  222. <div v-else-if="status.pf_type === 'video'" class="w-100">
  223. <video-presenter :status="status"></video-presenter>
  224. </div>
  225. <div v-else-if="status.pf_type === 'photo:album'" class="w-100">
  226. <photo-album-presenter :status="status" v-on:lightbox="lightbox"></photo-album-presenter>
  227. </div>
  228. <div v-else-if="status.pf_type === 'video:album'" class="w-100">
  229. <video-album-presenter :status="status"></video-album-presenter>
  230. </div>
  231. <div v-else-if="status.pf_type === 'photo:video:album'" class="w-100">
  232. <mixed-album-presenter :status="status" v-on:lightbox="lightbox"></mixed-album-presenter>
  233. </div>
  234. <div v-else class="w-100">
  235. <p class="text-center p-0 font-weight-bold text-white">Error: Problem rendering preview.</p>
  236. </div>
  237. </div>
  238. </div>
  239. </div>
  240. <div class="bg-white">
  241. <div class="container">
  242. <div class="row py-5">
  243. <div class="col-12 col-md-8">
  244. <div class="reactions py-2">
  245. <h3 v-bind:class="[reactions.liked ? '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"></h3>
  246. <h3 v-if="!status.comments_disabled" class="far fa-comment pr-3 m-0 cursor-pointer" title="Comment" v-on:click="replyFocus(status)"></h3>
  247. <h3 v-bind:class="[reactions.shared ? 'far fa-share-square pr-3 m-0 text-primary float-right cursor-pointer' : 'far fa-share-square pr-3 m-0 share-btn float-right cursor-pointer']" title="Share" v-on:click="shareStatus"></h3>
  248. </div>
  249. <div class="reaction-counts font-weight-bold mb-0">
  250. <span style="cursor:pointer;" v-on:click="likesModal">
  251. <span class="like-count">{{status.favourites_count || 0}}</span> likes
  252. </span>
  253. <span class="float-right" style="cursor:pointer;" v-on:click="sharesModal">
  254. <span class="share-count pl-4">{{status.reblogs_count || 0}}</span> shares
  255. </span>
  256. </div>
  257. <hr>
  258. <div class="media align-items-center">
  259. <img :src="statusAvatar" class="rounded-circle shadow-lg mr-3" alt="avatar" width="72px" height="72px">
  260. <div class="media-body lead">
  261. by <a :href="statusProfileUrl">{{statusUsername}}</a>
  262. </div>
  263. </div>
  264. <hr>
  265. <div>
  266. <p class="lead"><i class="far fa-clock"></i> {{timestampFormat()}}</p>
  267. <div class="lead" v-html="status.content"></div>
  268. </div>
  269. </div>
  270. <div class="col-12 col-md-4">
  271. <div v-if="status.comments_disabled" class="bg-light p-5 text-center lead">
  272. <p class="mb-0">Comments have been disabled on this post.</p>
  273. </div>
  274. </div>
  275. </div>
  276. </div>
  277. </div>
  278. </div>
  279. </div>
  280. <b-modal ref="likesModal"
  281. id="l-modal"
  282. hide-footer
  283. centered
  284. title="Likes"
  285. body-class="list-group-flush p-0">
  286. <div class="list-group">
  287. <div class="list-group-item border-0" v-for="(user, index) in likes" :key="'modal_likes_'+index">
  288. <div class="media">
  289. <a :href="user.url">
  290. <img class="mr-3 rounded-circle box-shadow" :src="user.avatar" :alt="user.username + 'โ€™s avatar'" width="30px">
  291. </a>
  292. <div class="media-body">
  293. <p class="mb-0" style="font-size: 14px">
  294. <a :href="user.url" class="font-weight-bold text-dark">
  295. {{user.username}}
  296. </a>
  297. </p>
  298. <p class="text-muted mb-0" style="font-size: 14px">
  299. {{user.display_name}}
  300. </a>
  301. </p>
  302. </div>
  303. </div>
  304. </div>
  305. <infinite-loading @infinite="infiniteLikesHandler" spinner="spiral">
  306. <div slot="no-more"></div>
  307. <div slot="no-results"></div>
  308. </infinite-loading>
  309. </div>
  310. </b-modal>
  311. <b-modal ref="sharesModal"
  312. id="s-modal"
  313. hide-footer
  314. centered
  315. title="Shares"
  316. body-class="list-group-flush p-0">
  317. <div class="list-group">
  318. <div class="list-group-item border-0" v-for="(user, index) in shares" :key="'modal_shares_'+index">
  319. <div class="media">
  320. <a :href="user.url">
  321. <img class="mr-3 rounded-circle box-shadow" :src="user.avatar" :alt="user.username + 'โ€™s avatar'" width="30px">
  322. </a>
  323. <div class="media-body">
  324. <div class="d-inline-block">
  325. <p class="mb-0" style="font-size: 14px">
  326. <a :href="user.url" class="font-weight-bold text-dark">
  327. {{user.username}}
  328. </a>
  329. </p>
  330. <p class="text-muted mb-0" style="font-size: 14px">
  331. {{user.display_name}}
  332. </a>
  333. </p>
  334. </div>
  335. <p class="float-right"><!-- <a class="btn btn-primary font-weight-bold py-1" href="#">Follow</a> --></p>
  336. </div>
  337. </div>
  338. </div>
  339. <infinite-loading @infinite="infiniteSharesHandler" spinner="spiral">
  340. <div slot="no-more"></div>
  341. <div slot="no-results"></div>
  342. </infinite-loading>
  343. </div>
  344. </b-modal>
  345. <b-modal
  346. id="lightbox"
  347. ref="lightboxModal"
  348. :hide-header="true"
  349. :hide-footer="true"
  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. .status-comments,
  362. .reactions {
  363. background: #fff;
  364. }
  365. .postPresenterContainer {
  366. background: #fff;
  367. }
  368. @media(min-width: 720px) {
  369. .postPresenterContainer {
  370. min-height: 600px;
  371. }
  372. }
  373. ::-webkit-scrollbar {
  374. width: 0px;
  375. background: transparent;
  376. }
  377. .reply-btn {
  378. position: absolute;
  379. bottom: 12px;
  380. right: 20px;
  381. width: 60px;
  382. text-align: center;
  383. border-radius: 0 3px 3px 0;
  384. }
  385. .text-lighter {
  386. color:#B8C2CC !important;
  387. }
  388. .text-break {
  389. overflow-wrap: break-word;
  390. }
  391. .comments p {
  392. margin-bottom: 0;
  393. }
  394. .comment-reaction {
  395. font-size: 80%;
  396. }
  397. .show-reply-bar {
  398. display: inline-block;
  399. border-bottom: 1px solid #999;
  400. height: 0;
  401. margin-right: 16px;
  402. vertical-align: middle;
  403. width: 24px;
  404. }
  405. .comment-thread {
  406. margin: 4px 0 0 40px;
  407. width: calc(100% - 40px);
  408. }
  409. .emoji-reactions .nav-item {
  410. font-size: 1.2rem;
  411. padding: 9px;
  412. cursor: pointer;
  413. }
  414. .emoji-reactions::-webkit-scrollbar {
  415. width: 0px;
  416. height: 0px;
  417. background: transparent;
  418. }
  419. </style>
  420. <style type="text/css">
  421. .momentui .bg-dark {
  422. background: #000 !important;
  423. }
  424. .momentui .carousel.slide,
  425. .momentui .carousel-item {
  426. background: #000 !important;
  427. }
  428. </style>
  429. <script>
  430. pixelfed.postComponent = {};
  431. export default {
  432. props: [
  433. 'status-id',
  434. 'status-username',
  435. 'status-template',
  436. 'status-url',
  437. 'status-profile-url',
  438. 'status-avatar',
  439. 'status-profile-id',
  440. 'profile-layout'
  441. ],
  442. data() {
  443. return {
  444. status: false,
  445. media: {},
  446. user: false,
  447. reactions: {
  448. liked: false,
  449. shared: false
  450. },
  451. likes: [],
  452. likesPage: 1,
  453. shares: [],
  454. sharesPage: 1,
  455. lightboxMedia: false,
  456. replyText: '',
  457. relationship: {},
  458. results: [],
  459. pagination: {},
  460. min_id: 0,
  461. max_id: 0,
  462. reply_to_profile_id: 0,
  463. thread: false,
  464. showComments: false,
  465. warning: false,
  466. loaded: false,
  467. loading: null,
  468. replyingToId: this.statusId,
  469. replyToIndex: 0,
  470. emoji: ['๐Ÿ˜€','๐Ÿคฃ','๐Ÿ˜ƒ','๐Ÿ˜„','๐Ÿ˜†','๐Ÿ˜‰','๐Ÿ˜Š','๐Ÿ˜‹','๐Ÿ˜˜','๐Ÿ˜—','๐Ÿ˜™','๐Ÿ˜š','๐Ÿค—','๐Ÿคฉ','๐Ÿค”','๐Ÿคจ','๐Ÿ˜','๐Ÿ˜‘','๐Ÿ˜ถ','๐Ÿ™„','๐Ÿ˜','๐Ÿ˜ฃ','๐Ÿ˜ฅ','๐Ÿ˜ฎ','๐Ÿค','๐Ÿ˜ช','๐Ÿ˜ซ','๐Ÿ˜ด','๐Ÿ˜Œ','๐Ÿ˜›','๐Ÿ˜œ','๐Ÿ˜','๐Ÿคค','๐Ÿ˜’','๐Ÿ˜“','๐Ÿ˜”','๐Ÿ˜•','๐Ÿ™ƒ','๐Ÿค‘','๐Ÿ˜ฒ','๐Ÿ™','๐Ÿ˜–','๐Ÿ˜ž','๐Ÿ˜Ÿ','๐Ÿ˜ค','๐Ÿ˜ญ','๐Ÿ˜ฆ','๐Ÿ˜ง','๐Ÿ˜จ','๐Ÿ˜ฉ','๐Ÿคฏ','๐Ÿ˜ฌ','๐Ÿ˜ฐ','๐Ÿ˜ฑ','๐Ÿ˜ณ','๐Ÿคช','๐Ÿ˜ต','๐Ÿ˜ก','๐Ÿ˜ ','๐Ÿคฌ','๐Ÿ˜ท','๐Ÿค’','๐Ÿค•','๐Ÿคข','๐Ÿคฎ','๐Ÿคง','๐Ÿ˜‡','๐Ÿค ','๐Ÿคก','๐Ÿคฅ','๐Ÿคซ','๐Ÿคญ','๐Ÿง','๐Ÿค“','๐Ÿ˜ˆ','๐Ÿ‘ฟ','๐Ÿ‘น','๐Ÿ‘บ','๐Ÿ’€','๐Ÿ‘ป','๐Ÿ‘ฝ','๐Ÿค–','๐Ÿ’ฉ','๐Ÿ˜บ','๐Ÿ˜ธ','๐Ÿ˜น','๐Ÿ˜ป','๐Ÿ˜ผ','๐Ÿ˜ฝ','๐Ÿ™€','๐Ÿ˜ฟ','๐Ÿ˜พ','๐Ÿคฒ','๐Ÿ‘','๐Ÿค','๐Ÿ‘','๐Ÿ‘Ž','๐Ÿ‘Š','โœŠ','๐Ÿค›','๐Ÿคœ','๐Ÿคž','โœŒ๏ธ','๐ŸคŸ','๐Ÿค˜','๐Ÿ‘ˆ','๐Ÿ‘‰','๐Ÿ‘†','๐Ÿ‘‡','โ˜๏ธ','โœ‹','๐Ÿคš','๐Ÿ–','๐Ÿ––','๐Ÿ‘‹','๐Ÿค™','๐Ÿ’ช','๐Ÿ–•','โœ๏ธ','๐Ÿ™','๐Ÿ’','๐Ÿ’„','๐Ÿ’‹','๐Ÿ‘„','๐Ÿ‘…','๐Ÿ‘‚','๐Ÿ‘ƒ','๐Ÿ‘ฃ','๐Ÿ‘','๐Ÿ‘€','๐Ÿง ','๐Ÿ—ฃ','๐Ÿ‘ค','๐Ÿ‘ฅ'],
  471. }
  472. },
  473. beforeMount() {
  474. let u = new URLSearchParams(window.location.search);
  475. if(u.has('ui') && u.get('ui') == 'moment' && this.profileLayout != 'moment') {
  476. this.profileLayout = 'moment';
  477. }
  478. if(u.has('ui') && u.get('ui') == 'metro' && this.profileLayout != 'metro') {
  479. this.profileLayout = 'metro';
  480. }
  481. },
  482. mounted() {
  483. this.fetchRelationships();
  484. },
  485. updated() {
  486. $('.carousel').carousel();
  487. window.pixelfed.readmore();
  488. },
  489. methods: {
  490. showMuteBlock() {
  491. let sid = this.status.account.id;
  492. let uid = this.user.id;
  493. if(sid == uid) {
  494. $('.post-actions .menu-author').removeClass('d-none');
  495. } else {
  496. $('.post-actions .menu-user').removeClass('d-none');
  497. }
  498. },
  499. reportUrl() {
  500. return '/i/report?type=post&id=' + this.status.id;
  501. },
  502. editUrl() {
  503. return this.status.url + '/edit';
  504. },
  505. timestampFormat() {
  506. let ts = new Date(this.status.created_at);
  507. return ts.toDateString() + ' ' + ts.toLocaleTimeString();
  508. },
  509. fetchData() {
  510. axios.get('/api/v2/profile/'+this.statusUsername+'/status/'+this.statusId)
  511. .then(response => {
  512. let self = this;
  513. self.status = response.data.status;
  514. self.user = response.data.user;
  515. self.media = self.status.media_attachments;
  516. self.reactions = response.data.reactions;
  517. self.likes = response.data.likes;
  518. self.shares = response.data.shares;
  519. self.likesPage = 2;
  520. self.sharesPage = 2;
  521. this.showMuteBlock();
  522. if(self.status.comments_disabled == false) {
  523. self.showComments = true;
  524. this.fetchComments();
  525. }
  526. this.loaded = true;
  527. $('head title').text(this.status.account.username + ' posted a photo: ' + this.status.favourites_count + ' likes');
  528. }).catch(error => {
  529. if(!error.response) {
  530. } else {
  531. switch(error.response.status) {
  532. case 401:
  533. break;
  534. default:
  535. break;
  536. }
  537. }
  538. });
  539. },
  540. likesModal() {
  541. if(this.status.favourites_count == 0 || $('body').hasClass('loggedIn') == false) {
  542. return;
  543. }
  544. this.$refs.likesModal.show();
  545. },
  546. sharesModal() {
  547. if(this.status.reblogs_count == 0 || $('body').hasClass('loggedIn') == false) {
  548. return;
  549. }
  550. this.$refs.sharesModal.show();
  551. },
  552. infiniteLikesHandler($state) {
  553. let api = '/api/v2/likes/profile/'+this.statusUsername+'/status/'+this.statusId;
  554. axios.get(api, {
  555. params: {
  556. page: this.likesPage,
  557. },
  558. }).then(({ data }) => {
  559. if (data.data.length > 0) {
  560. this.likes.push(...data.data);
  561. this.likesPage++;
  562. $state.loaded();
  563. } else {
  564. $state.complete();
  565. }
  566. });
  567. },
  568. infiniteSharesHandler($state) {
  569. axios.get('/api/v2/shares/profile/'+this.statusUsername+'/status/'+this.statusId, {
  570. params: {
  571. page: this.sharesPage,
  572. },
  573. }).then(({ data }) => {
  574. if (data.data.length > 0) {
  575. this.shares.push(...data.data);
  576. this.sharesPage++;
  577. $state.loaded();
  578. } else {
  579. $state.complete();
  580. }
  581. });
  582. },
  583. likeStatus(event) {
  584. if($('body').hasClass('loggedIn') == false) {
  585. window.location.href = '/login?next=' + encodeURIComponent(window.location.pathname);
  586. return;
  587. }
  588. axios.post('/i/like', {
  589. item: this.status.id
  590. }).then(res => {
  591. this.status.favourites_count = res.data.count;
  592. if(this.reactions.liked == true) {
  593. this.reactions.liked = false;
  594. let user = this.user.id;
  595. this.likes = this.likes.filter(function(like) {
  596. return like.id !== user;
  597. });
  598. } else {
  599. this.reactions.liked = true;
  600. let user = this.user;
  601. this.likes.push(user);
  602. }
  603. }).catch(err => {
  604. console.error(err);
  605. swal('Error', 'Something went wrong, please try again later.', 'error');
  606. });
  607. },
  608. shareStatus() {
  609. if($('body').hasClass('loggedIn') == false) {
  610. window.location.href = '/login?next=' + encodeURIComponent(window.location.pathname);
  611. return;
  612. }
  613. axios.post('/i/share', {
  614. item: this.status.id
  615. }).then(res => {
  616. this.status.reblogs_count = res.data.count;
  617. if(this.reactions.shared == true) {
  618. this.reactions.shared = false;
  619. let user = this.user.id;
  620. this.shares = this.shares.filter(function(reaction) {
  621. return reaction.id !== user;
  622. });
  623. } else {
  624. this.reactions.shared = true;
  625. let user = this.user;
  626. this.shares.push(user);
  627. }
  628. }).catch(err => {
  629. console.error(err);
  630. swal('Error', 'Something went wrong, please try again later.', 'error');
  631. });
  632. },
  633. bookmarkStatus() {
  634. if($('body').hasClass('loggedIn') == false) {
  635. window.location.href = '/login?next=' + encodeURIComponent(window.location.pathname);
  636. return;
  637. }
  638. axios.post('/i/bookmark', {
  639. item: this.status.id
  640. }).then(res => {
  641. if(this.reactions.bookmarked == true) {
  642. this.reactions.bookmarked = false;
  643. } else {
  644. this.reactions.bookmarked = true;
  645. }
  646. }).catch(err => {
  647. swal('Error', 'Something went wrong, please try again later.', 'error');
  648. });
  649. },
  650. muteProfile() {
  651. if($('body').hasClass('loggedIn') == false) {
  652. return;
  653. }
  654. axios.post('/i/mute', {
  655. type: 'user',
  656. item: this.status.account.id
  657. }).then(res => {
  658. swal('Success', 'You have successfully muted ' + this.status.account.acct, 'success');
  659. }).catch(err => {
  660. swal('Error', 'Something went wrong. Please try again later.', 'error');
  661. });
  662. },
  663. blockProfile() {
  664. if($('body').hasClass('loggedIn') == false) {
  665. return;
  666. }
  667. axios.post('/i/block', {
  668. type: 'user',
  669. item: this.status.account.id
  670. }).then(res => {
  671. swal('Success', 'You have successfully blocked ' + this.status.account.acct, 'success');
  672. }).catch(err => {
  673. swal('Error', 'Something went wrong. Please try again later.', 'error');
  674. });
  675. },
  676. deletePost(status) {
  677. if(!this.ownerOrAdmin()) {
  678. return;
  679. }
  680. var result = confirm('Are you sure you want to delete this post?');
  681. if (result) {
  682. if($('body').hasClass('loggedIn') == false) {
  683. return;
  684. }
  685. axios.post('/i/delete', {
  686. type: 'status',
  687. item: this.status.id
  688. }).then(res => {
  689. setTimeout(function() {
  690. swal('Success', 'You have successfully deleted this post', 'success');
  691. window.location.href = '/';
  692. }, 2000);
  693. }).catch(err => {
  694. swal('Error', 'Something went wrong. Please try again later.', 'error');
  695. });
  696. }
  697. },
  698. owner() {
  699. return this.user.id === this.status.account.id;
  700. },
  701. admin() {
  702. return this.user.is_admin == true;
  703. },
  704. ownerOrAdmin() {
  705. return this.owner() || this.admin();
  706. },
  707. lightbox(src) {
  708. this.lightboxMedia = src;
  709. this.$refs.lightboxModal.show();
  710. },
  711. postReply() {
  712. let self = this;
  713. if(this.replyText.length == 0 ||
  714. this.replyText.trim() == '@'+this.status.account.acct) {
  715. self.replyText = null;
  716. $('textarea[name="comment"]').blur();
  717. return;
  718. }
  719. let data = {
  720. item: this.replyingToId,
  721. comment: this.replyText
  722. }
  723. axios.post('/i/comment', data)
  724. .then(function(res) {
  725. let entity = res.data.entity;
  726. if(entity.in_reply_to_id == self.status.id) {
  727. self.results.push(entity);
  728. let elem = $('.status-comments')[0];
  729. elem.scrollTop = elem.clientHeight;
  730. } else {
  731. if(self.replyToIndex >= 0) {
  732. let el = self.results[self.replyToIndex];
  733. el.replies.push(entity);
  734. el.reply_count = el.reply_count + 1;
  735. }
  736. }
  737. self.replyText = '';
  738. });
  739. },
  740. deleteComment(id, i) {
  741. axios.post('/i/delete', {
  742. type: 'comment',
  743. item: id
  744. }).then(res => {
  745. this.results.splice(i, 1);
  746. }).catch(err => {
  747. swal('Something went wrong!', 'Please try again later', 'error');
  748. });
  749. },
  750. deleteCommentReply(id, i, pi) {
  751. axios.post('/i/delete', {
  752. type: 'comment',
  753. item: id
  754. }).then(res => {
  755. this.results[pi].replies.splice(i, 1);
  756. --this.results[pi].reply_count;
  757. }).catch(err => {
  758. swal('Something went wrong!', 'Please try again later', 'error');
  759. });
  760. },
  761. l(e) {
  762. let len = e.length;
  763. if(len < 10) { return e; }
  764. return e.substr(0, 10)+'...';
  765. },
  766. replyFocus(e, index) {
  767. this.replyToIndex = index;
  768. this.replyingToId = e.id;
  769. this.reply_to_profile_id = e.account.id;
  770. this.replyText = '@' + e.account.username + ' ';
  771. $('textarea[name="comment"]').focus();
  772. },
  773. fetchComments() {
  774. let url = '/api/v2/comments/'+this.statusUsername+'/status/'+this.statusId;
  775. axios.get(url)
  776. .then(response => {
  777. let self = this;
  778. this.results = _.reverse(response.data.data);
  779. this.pagination = response.data.meta.pagination;
  780. if(this.results.length > 0) {
  781. $('.load-more-link').removeClass('d-none');
  782. }
  783. $('.postCommentsLoader').addClass('d-none');
  784. $('.postCommentsContainer').removeClass('d-none');
  785. }).catch(error => {
  786. if(!error.response) {
  787. $('.postCommentsLoader .lds-ring')
  788. .attr('style','width:100%')
  789. .addClass('pt-4 font-weight-bold text-muted')
  790. .text('An error occurred, cannot fetch comments. Please try again later.');
  791. } else {
  792. switch(error.response.status) {
  793. case 401:
  794. $('.postCommentsLoader .lds-ring')
  795. .attr('style','width:100%')
  796. .addClass('pt-4 font-weight-bold text-muted')
  797. .text('Please login to view.');
  798. break;
  799. default:
  800. $('.postCommentsLoader .lds-ring')
  801. .attr('style','width:100%')
  802. .addClass('pt-4 font-weight-bold text-muted')
  803. .text('An error occurred, cannot fetch comments. Please try again later.');
  804. break;
  805. }
  806. }
  807. });
  808. },
  809. loadMore(e) {
  810. e.preventDefault();
  811. if(this.pagination.total_pages == 1 || this.pagination.current_page == this.pagination.total_pages) {
  812. $('.load-more-link').addClass('d-none');
  813. return;
  814. }
  815. $('.postCommentsLoader').removeClass('d-none');
  816. let next = this.pagination.links.next;
  817. axios.get(next)
  818. .then(response => {
  819. let self = this;
  820. let res = response.data.data;
  821. $('.postCommentsLoader').addClass('d-none');
  822. for(let i=0; i < res.length; i++) {
  823. this.results.unshift(res[i]);
  824. }
  825. this.pagination = response.data.meta.pagination;
  826. });
  827. },
  828. likeReply(status, $event) {
  829. if($('body').hasClass('loggedIn') == false) {
  830. return;
  831. }
  832. axios.post('/i/like', {
  833. item: status.id
  834. }).then(res => {
  835. status.favourites_count = res.data.count;
  836. if(status.favourited == true) {
  837. status.favourited = false;
  838. } else {
  839. status.favourited = true;
  840. }
  841. }).catch(err => {
  842. swal('Error', 'Something went wrong, please try again later.', 'error');
  843. });
  844. },
  845. truncate(str,lim) {
  846. return _.truncate(str,{
  847. length: lim
  848. });
  849. },
  850. timeAgo(ts) {
  851. let date = Date.parse(ts);
  852. let seconds = Math.floor((new Date() - date) / 1000);
  853. let interval = Math.floor(seconds / 31536000);
  854. if (interval >= 1) {
  855. return interval + "y";
  856. }
  857. interval = Math.floor(seconds / 604800);
  858. if (interval >= 1) {
  859. return interval + "w";
  860. }
  861. interval = Math.floor(seconds / 86400);
  862. if (interval >= 1) {
  863. return interval + "d";
  864. }
  865. interval = Math.floor(seconds / 3600);
  866. if (interval >= 1) {
  867. return interval + "h";
  868. }
  869. interval = Math.floor(seconds / 60);
  870. if (interval >= 1) {
  871. return interval + "m";
  872. }
  873. return Math.floor(seconds) + "s";
  874. },
  875. emojiReaction() {
  876. let em = event.target.innerText;
  877. if(this.replyText.length == 0) {
  878. this.reply_to_profile_id = this.status.account.id;
  879. this.replyText = em + ' ';
  880. $('textarea[name="comment"]').focus();
  881. } else {
  882. this.reply_to_profile_id = this.status.account.id;
  883. this.replyText += em + ' ';
  884. $('textarea[name="comment"]').focus();
  885. }
  886. },
  887. toggleCommentVisibility() {
  888. if(this.ownerOrAdmin() == false) {
  889. return;
  890. }
  891. let state = this.status.comments_disabled;
  892. let self = this;
  893. if(state == true) {
  894. // re-enable comments
  895. axios.post('/i/visibility', {
  896. item: self.status.id,
  897. disableComments: false
  898. }).then(function(res) {
  899. window.location.href = self.status.url;
  900. }).catch(function(err) {
  901. return;
  902. });
  903. } else {
  904. // disable comments
  905. axios.post('/i/visibility', {
  906. item: self.status.id,
  907. disableComments: true
  908. }).then(function(res) {
  909. self.status.comments_disabled = false;
  910. self.showComments = false;
  911. }).catch(function(err) {
  912. return;
  913. });
  914. }
  915. },
  916. fetchRelationships() {
  917. if(document.querySelectorAll('body')[0].classList.contains('loggedIn') == false) {
  918. this.fetchData();
  919. return;
  920. } else {
  921. axios.get('/api/v1/accounts/relationships', {
  922. params: {
  923. 'id[]': this.statusProfileId
  924. }
  925. }).then(res => {
  926. if(res.data[0] == null) {
  927. this.fetchData();
  928. return;
  929. }
  930. this.relationship = res.data[0];
  931. if(res.data[0].blocking == true) {
  932. this.loaded = true;
  933. this.warning = true;
  934. return;
  935. } else {
  936. this.fetchData();
  937. return;
  938. }
  939. });
  940. }
  941. },
  942. visibilityModal() {
  943. switch(this.status.visibility) {
  944. case 'public':
  945. swal('Public Post', 'This post is visible to everyone.', 'info');
  946. break;
  947. case 'unlisted':
  948. swal('Unlisted Post', 'This post is visible on profiles and with a direct links. It is not displayed on timelines.', 'info');
  949. break;
  950. case 'private':
  951. swal('Private Post', 'This post is only visible to followers.', 'info');
  952. break;
  953. }
  954. },
  955. toggleReplies(reply) {
  956. if(reply.thread) {
  957. reply.thread = false;
  958. } else {
  959. if(reply.replies.length > 0) {
  960. reply.thread = true;
  961. return;
  962. }
  963. let url = '/api/v2/comments/'+reply.account.username+'/status/'+reply.id;
  964. axios.get(url)
  965. .then(response => {
  966. reply.replies = _.reverse(response.data.data);
  967. reply.thread = true;
  968. });
  969. }
  970. }
  971. },
  972. }
  973. </script>