PostComponent.vue 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050
  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" style="overflow-y: auto;">
  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. <hr>
  110. <div class="postCommentsLoader text-center">
  111. <div class="spinner-border" role="status">
  112. <span class="sr-only">Loading...</span>
  113. </div>
  114. </div>
  115. <div class="postCommentsContainer d-none">
  116. <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>
  117. <div class="comments">
  118. <div v-for="(reply, index) in results" class="pb-3" :key="'tl' + reply.id + '_' + index">
  119. <div v-if="reply.sensitive == true">
  120. <div class="card card-body shadow-none border border-left-blue py-3 px-1 text-center small">
  121. <p class="mb-0">This comment may contain sensitive material</p>
  122. <p class="font-weight-bold text-primary cursor-pointer mb-0" @click="reply.sensitive = false;">Show</p>
  123. </div>
  124. </div>
  125. <div v-else>
  126. <p class="d-flex justify-content-between align-items-top read-more" style="overflow-y: hidden;">
  127. <span>
  128. <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>
  129. <span class="text-break" v-html="reply.content"></span>
  130. </span>
  131. <span class="pl-2" style="min-width:38px">
  132. <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>
  133. <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>
  134. </span>
  135. </p>
  136. <p class="">
  137. <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>
  138. <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>
  139. <span class="text-muted comment-reaction font-weight-bold cursor-pointer" v-on:click="replyFocus(reply, index)">Reply</span>
  140. </p>
  141. <div v-if="reply.reply_count > 0" class="cursor-pointer" style="margin-left:30px;" v-on:click="toggleReplies(reply)">
  142. <span class="show-reply-bar"></span>
  143. <span class="comment-reaction font-weight-bold text-muted">{{reply.thread ? 'Hide' : 'View'}} Replies ({{reply.reply_count}})</span>
  144. </div>
  145. <div v-if="reply.thread == true" class="comment-thread">
  146. <div v-for="(s, sindex) in reply.replies" class="pb-3" :key="'cr' + s.id + '_' + index">
  147. <p class="d-flex justify-content-between align-items-top read-more" style="overflow-y: hidden;">
  148. <span>
  149. <a class="text-dark font-weight-bold mr-1" :href="s.account.url" :title="s.account.username">{{s.account.username}}</a>
  150. <span class="text-break" v-html="s.content"></span>
  151. </span>
  152. <span class="pl-2" style="min-width:38px">
  153. <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>
  154. <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>
  155. </span>
  156. </p>
  157. <p class="">
  158. <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>
  159. <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>
  160. </p>
  161. </div>
  162. </div>
  163. </div>
  164. </div>
  165. </div>
  166. </div>
  167. </div>
  168. </div>
  169. </div>
  170. <div class="card-body flex-grow-0 py-1">
  171. <div class="reactions my-1">
  172. <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>
  173. <h3 v-if="!status.comments_disabled" class="far fa-comment pr-3 m-0 cursor-pointer" title="Comment" v-on:click="replyFocus(status)"></h3>
  174. <h3 v-if="status.visibility == 'public'" 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>
  175. <h3 v-if="status.visibility == 'public'" 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>
  176. </div>
  177. <div class="reaction-counts font-weight-bold mb-0">
  178. <span style="cursor:pointer;" v-on:click="likesModal">
  179. <span class="like-count">{{status.favourites_count || 0}}</span> likes
  180. </span>
  181. <span v-if="status.visibility == 'public'" class="float-right" style="cursor:pointer;" v-on:click="sharesModal">
  182. <span class="share-count pl-4">{{status.reblogs_count || 0}}</span> shares
  183. </span>
  184. </div>
  185. <div class="timestamp pt-2 d-flex align-items-bottom justify-content-between">
  186. <a v-bind:href="statusUrl" class="small text-muted">
  187. {{timestampFormat()}}
  188. </a>
  189. <span class="small text-muted text-capitalize cursor-pointer" v-on:click="visibilityModal">{{status.visibility}}</span>
  190. </div>
  191. </div>
  192. </div>
  193. <div v-if="showComments && user.length !== 0" class="card-footer bg-white px-2 py-0">
  194. <ul class="nav align-items-center emoji-reactions" style="overflow-x: scroll;flex-wrap: unset;">
  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">👏</li>
  200. <li class="nav-item" v-on:click="emojiReaction">👌</li>
  201. <li class="nav-item" v-on:click="emojiReaction">😍</li>
  202. <li class="nav-item" v-on:click="emojiReaction">😯</li>
  203. <li class="nav-item" v-on:click="emojiReaction">😢</li>
  204. <li class="nav-item" v-on:click="emojiReaction">😅</li>
  205. <li class="nav-item" v-on:click="emojiReaction">😁</li>
  206. <li class="nav-item" v-on:click="emojiReaction">🙂</li>
  207. <li class="nav-item" v-on:click="emojiReaction">😎</li>
  208. <li class="nav-item" v-on:click="emojiReaction" v-for="e in emoji">{{e}}</li>
  209. </ul>
  210. </div>
  211. <div v-if="showComments" class="card-footer bg-white sticky-md-bottom p-0">
  212. <div v-if="user.length == 0" class="comment-form-guest p-3">
  213. <a href="/login">Login</a> to like or comment.
  214. </div>
  215. <form v-else class="border-0 rounded-0 align-middle" method="post" action="/i/comment" :data-id="statusId" data-truncate="false">
  216. <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>
  217. <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"/>
  218. </form>
  219. </div>
  220. </div>
  221. </div>
  222. </div>
  223. </div>
  224. <div v-if="profileLayout == 'moment'" class="momentui">
  225. <div class="bg-dark mt-md-n4">
  226. <div class="container" v-on:dblclick="likeStatus">
  227. <div class="postPresenterContainer d-none d-flex justify-content-center align-items-center bg-dark">
  228. <div v-if="status.pf_type === 'photo'" class="w-100">
  229. <photo-presenter :status="status" v-on:lightbox="lightbox"></photo-presenter>
  230. </div>
  231. <div v-else-if="status.pf_type === 'video'" class="w-100">
  232. <video-presenter :status="status"></video-presenter>
  233. </div>
  234. <div v-else-if="status.pf_type === 'photo:album'" class="w-100">
  235. <photo-album-presenter :status="status" v-on:lightbox="lightbox"></photo-album-presenter>
  236. </div>
  237. <div v-else-if="status.pf_type === 'video:album'" class="w-100">
  238. <video-album-presenter :status="status"></video-album-presenter>
  239. </div>
  240. <div v-else-if="status.pf_type === 'photo:video:album'" class="w-100">
  241. <mixed-album-presenter :status="status" v-on:lightbox="lightbox"></mixed-album-presenter>
  242. </div>
  243. <div v-else class="w-100">
  244. <p class="text-center p-0 font-weight-bold text-white">Error: Problem rendering preview.</p>
  245. </div>
  246. </div>
  247. </div>
  248. </div>
  249. <div class="bg-white">
  250. <div class="container">
  251. <div class="row py-5">
  252. <div class="col-12 col-md-8">
  253. <div class="reactions py-2">
  254. <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>
  255. <h3 v-if="!status.comments_disabled" class="far fa-comment pr-3 m-0 cursor-pointer" title="Comment" v-on:click="replyFocus(status)"></h3>
  256. <h3 v-if="status.visibility == 'public'" 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>
  257. </div>
  258. <div class="reaction-counts font-weight-bold mb-0">
  259. <span style="cursor:pointer;" v-on:click="likesModal">
  260. <span class="like-count">{{status.favourites_count || 0}}</span> likes
  261. </span>
  262. <span v-if="status.visibility == 'public'" class="float-right" style="cursor:pointer;" v-on:click="sharesModal">
  263. <span class="share-count pl-4">{{status.reblogs_count || 0}}</span> shares
  264. </span>
  265. </div>
  266. <hr>
  267. <div class="media align-items-center">
  268. <img :src="statusAvatar" class="rounded-circle shadow-lg mr-3" alt="avatar" width="72px" height="72px">
  269. <div class="media-body lead">
  270. by <a :href="statusProfileUrl">{{statusUsername}}</a>
  271. </div>
  272. </div>
  273. <hr>
  274. <div>
  275. <p class="lead"><i class="far fa-clock"></i> {{timestampFormat()}}</p>
  276. <div class="lead" v-html="status.content"></div>
  277. </div>
  278. </div>
  279. <div class="col-12 col-md-4">
  280. <div v-if="status.comments_disabled" class="bg-light p-5 text-center lead">
  281. <p class="mb-0">Comments have been disabled on this post.</p>
  282. </div>
  283. </div>
  284. </div>
  285. </div>
  286. </div>
  287. </div>
  288. </div>
  289. <b-modal ref="likesModal"
  290. id="l-modal"
  291. hide-footer
  292. centered
  293. title="Likes"
  294. body-class="list-group-flush p-0">
  295. <div class="list-group">
  296. <div class="list-group-item border-0" v-for="(user, index) in likes" :key="'modal_likes_'+index">
  297. <div class="media">
  298. <a :href="user.url">
  299. <img class="mr-3 rounded-circle box-shadow" :src="user.avatar" :alt="user.username + '’s avatar'" width="30px">
  300. </a>
  301. <div class="media-body">
  302. <p class="mb-0" style="font-size: 14px">
  303. <a :href="user.url" class="font-weight-bold text-dark">
  304. {{user.username}}
  305. </a>
  306. </p>
  307. <p class="text-muted mb-0" style="font-size: 14px">
  308. {{user.display_name}}
  309. </a>
  310. </p>
  311. </div>
  312. </div>
  313. </div>
  314. <infinite-loading @infinite="infiniteLikesHandler" spinner="spiral">
  315. <div slot="no-more"></div>
  316. <div slot="no-results"></div>
  317. </infinite-loading>
  318. </div>
  319. </b-modal>
  320. <b-modal ref="sharesModal"
  321. id="s-modal"
  322. hide-footer
  323. centered
  324. title="Shares"
  325. body-class="list-group-flush p-0">
  326. <div class="list-group">
  327. <div class="list-group-item border-0" v-for="(user, index) in shares" :key="'modal_shares_'+index">
  328. <div class="media">
  329. <a :href="user.url">
  330. <img class="mr-3 rounded-circle box-shadow" :src="user.avatar" :alt="user.username + '’s avatar'" width="30px">
  331. </a>
  332. <div class="media-body">
  333. <div class="d-inline-block">
  334. <p class="mb-0" style="font-size: 14px">
  335. <a :href="user.url" class="font-weight-bold text-dark">
  336. {{user.username}}
  337. </a>
  338. </p>
  339. <p class="text-muted mb-0" style="font-size: 14px">
  340. {{user.display_name}}
  341. </a>
  342. </p>
  343. </div>
  344. <p class="float-right"><!-- <a class="btn btn-primary font-weight-bold py-1" href="#">Follow</a> --></p>
  345. </div>
  346. </div>
  347. </div>
  348. <infinite-loading @infinite="infiniteSharesHandler" spinner="spiral">
  349. <div slot="no-more"></div>
  350. <div slot="no-results"></div>
  351. </infinite-loading>
  352. </div>
  353. </b-modal>
  354. <b-modal
  355. id="lightbox"
  356. ref="lightboxModal"
  357. :hide-header="true"
  358. :hide-footer="true"
  359. centered
  360. size="lg"
  361. body-class="p-0"
  362. >
  363. <div v-if="lightboxMedia" :class="lightboxMedia.filter_class">
  364. <img :src="lightboxMedia.url" class="img-fluid" style="min-height: 100%; min-width: 100%">
  365. </div>
  366. </b-modal>
  367. </div>
  368. </template>
  369. <style type="text/css" scoped>
  370. .status-comments,
  371. .reactions {
  372. background: #fff;
  373. }
  374. .postPresenterContainer {
  375. background: #fff;
  376. }
  377. @media(min-width: 720px) {
  378. .postPresenterContainer {
  379. min-height: 600px;
  380. }
  381. }
  382. ::-webkit-scrollbar {
  383. width: 0px;
  384. background: transparent;
  385. }
  386. .reply-btn {
  387. position: absolute;
  388. bottom: 12px;
  389. right: 20px;
  390. width: 60px;
  391. text-align: center;
  392. border-radius: 0 3px 3px 0;
  393. }
  394. .text-lighter {
  395. color:#B8C2CC !important;
  396. }
  397. .text-break {
  398. overflow-wrap: break-word;
  399. }
  400. .comments p {
  401. margin-bottom: 0;
  402. }
  403. .comment-reaction {
  404. font-size: 80%;
  405. }
  406. .show-reply-bar {
  407. display: inline-block;
  408. border-bottom: 1px solid #999;
  409. height: 0;
  410. margin-right: 16px;
  411. vertical-align: middle;
  412. width: 24px;
  413. }
  414. .comment-thread {
  415. margin: 4px 0 0 40px;
  416. width: calc(100% - 40px);
  417. }
  418. .emoji-reactions .nav-item {
  419. font-size: 1.2rem;
  420. padding: 9px;
  421. cursor: pointer;
  422. }
  423. .emoji-reactions::-webkit-scrollbar {
  424. width: 0px;
  425. height: 0px;
  426. background: transparent;
  427. }
  428. </style>
  429. <style type="text/css" scoped>
  430. .momentui .bg-dark {
  431. background: #000 !important;
  432. }
  433. .momentui .carousel.slide,
  434. .momentui .carousel-item {
  435. background: #000 !important;
  436. }
  437. </style>
  438. <script>
  439. pixelfed.postComponent = {};
  440. export default {
  441. props: [
  442. 'status-id',
  443. 'status-username',
  444. 'status-template',
  445. 'status-url',
  446. 'status-profile-url',
  447. 'status-avatar',
  448. 'status-profile-id',
  449. 'profile-layout'
  450. ],
  451. data() {
  452. return {
  453. status: false,
  454. media: {},
  455. user: false,
  456. reactions: {
  457. liked: false,
  458. shared: false
  459. },
  460. likes: [],
  461. likesPage: 1,
  462. shares: [],
  463. sharesPage: 1,
  464. lightboxMedia: false,
  465. replyText: '',
  466. relationship: {},
  467. results: [],
  468. pagination: {},
  469. min_id: 0,
  470. max_id: 0,
  471. reply_to_profile_id: 0,
  472. thread: false,
  473. showComments: false,
  474. warning: false,
  475. loaded: false,
  476. loading: null,
  477. replyingToId: this.statusId,
  478. replyToIndex: 0,
  479. emoji: ['😀','🤣','😃','😄','😆','😉','😊','😋','😘','😗','😙','😚','🤗','🤩','🤔','🤨','😐','😑','😶','🙄','😏','😣','😥','😮','🤐','😪','😫','😴','😌','😛','😜','😝','🤤','😒','😓','😔','😕','🙃','🤑','😲','🙁','😖','😞','😟','😤','😭','😦','😧','😨','😩','🤯','😬','😰','😱','😳','🤪','😵','😡','😠','🤬','😷','🤒','🤕','🤢','🤮','🤧','😇','🤠','🤡','🤥','🤫','🤭','🧐','🤓','😈','👿','👹','👺','💀','👻','👽','🤖','💩','😺','😸','😹','😻','😼','😽','🙀','😿','😾','🤲','👐','🤝','👍','👎','👊','✊','🤛','🤜','🤞','✌️','🤟','🤘','👈','👉','👆','👇','☝️','✋','🤚','🖐','🖖','👋','🤙','💪','🖕','✍️','🙏','💍','💄','💋','👄','👅','👂','👃','👣','👁','👀','🧠','🗣','👤','👥'],
  480. }
  481. },
  482. beforeMount() {
  483. let u = new URLSearchParams(window.location.search);
  484. if(u.has('ui') && u.get('ui') == 'moment' && this.profileLayout != 'moment') {
  485. this.profileLayout = 'moment';
  486. }
  487. if(u.has('ui') && u.get('ui') == 'metro' && this.profileLayout != 'metro') {
  488. this.profileLayout = 'metro';
  489. }
  490. },
  491. mounted() {
  492. this.fetchRelationships();
  493. },
  494. updated() {
  495. $('.carousel').carousel();
  496. window.pixelfed.readmore();
  497. },
  498. methods: {
  499. showMuteBlock() {
  500. let sid = this.status.account.id;
  501. let uid = this.user.id;
  502. if(sid == uid) {
  503. $('.post-actions .menu-author').removeClass('d-none');
  504. } else {
  505. $('.post-actions .menu-user').removeClass('d-none');
  506. }
  507. },
  508. reportUrl() {
  509. return '/i/report?type=post&id=' + this.status.id;
  510. },
  511. editUrl() {
  512. return this.status.url + '/edit';
  513. },
  514. timestampFormat() {
  515. let ts = new Date(this.status.created_at);
  516. return ts.toDateString() + ' ' + ts.toLocaleTimeString();
  517. },
  518. fetchData() {
  519. axios.get('/api/v2/profile/'+this.statusUsername+'/status/'+this.statusId)
  520. .then(response => {
  521. let self = this;
  522. self.status = response.data.status;
  523. self.user = response.data.user;
  524. self.media = self.status.media_attachments;
  525. self.reactions = response.data.reactions;
  526. self.likes = response.data.likes;
  527. self.shares = response.data.shares;
  528. self.likesPage = 2;
  529. self.sharesPage = 2;
  530. this.showMuteBlock();
  531. if(self.status.comments_disabled == false) {
  532. self.showComments = true;
  533. this.fetchComments();
  534. }
  535. this.loaded = true;
  536. $('head title').text(this.status.account.username + ' posted a photo: ' + this.status.favourites_count + ' likes');
  537. }).catch(error => {
  538. if(!error.response) {
  539. } else {
  540. switch(error.response.status) {
  541. case 401:
  542. break;
  543. default:
  544. break;
  545. }
  546. }
  547. });
  548. },
  549. likesModal() {
  550. if(this.status.favourites_count == 0 || $('body').hasClass('loggedIn') == false) {
  551. return;
  552. }
  553. this.$refs.likesModal.show();
  554. },
  555. sharesModal() {
  556. if(this.status.reblogs_count == 0 || $('body').hasClass('loggedIn') == false) {
  557. return;
  558. }
  559. this.$refs.sharesModal.show();
  560. },
  561. infiniteLikesHandler($state) {
  562. let api = '/api/v2/likes/profile/'+this.statusUsername+'/status/'+this.statusId;
  563. axios.get(api, {
  564. params: {
  565. page: this.likesPage,
  566. },
  567. }).then(({ data }) => {
  568. if (data.data.length > 0) {
  569. this.likes.push(...data.data);
  570. this.likesPage++;
  571. $state.loaded();
  572. } else {
  573. $state.complete();
  574. }
  575. });
  576. },
  577. infiniteSharesHandler($state) {
  578. axios.get('/api/v2/shares/profile/'+this.statusUsername+'/status/'+this.statusId, {
  579. params: {
  580. page: this.sharesPage,
  581. },
  582. }).then(({ data }) => {
  583. if (data.data.length > 0) {
  584. this.shares.push(...data.data);
  585. this.sharesPage++;
  586. $state.loaded();
  587. } else {
  588. $state.complete();
  589. }
  590. });
  591. },
  592. likeStatus(event) {
  593. if($('body').hasClass('loggedIn') == false) {
  594. window.location.href = '/login?next=' + encodeURIComponent(window.location.pathname);
  595. return;
  596. }
  597. axios.post('/i/like', {
  598. item: this.status.id
  599. }).then(res => {
  600. this.status.favourites_count = res.data.count;
  601. if(this.reactions.liked == true) {
  602. this.reactions.liked = false;
  603. let user = this.user.id;
  604. this.likes = this.likes.filter(function(like) {
  605. return like.id !== user;
  606. });
  607. } else {
  608. this.reactions.liked = true;
  609. let user = this.user;
  610. this.likes.push(user);
  611. }
  612. }).catch(err => {
  613. console.error(err);
  614. swal('Error', 'Something went wrong, please try again later.', 'error');
  615. });
  616. },
  617. shareStatus() {
  618. if($('body').hasClass('loggedIn') == false) {
  619. window.location.href = '/login?next=' + encodeURIComponent(window.location.pathname);
  620. return;
  621. }
  622. axios.post('/i/share', {
  623. item: this.status.id
  624. }).then(res => {
  625. this.status.reblogs_count = res.data.count;
  626. if(this.reactions.shared == true) {
  627. this.reactions.shared = false;
  628. let user = this.user.id;
  629. this.shares = this.shares.filter(function(reaction) {
  630. return reaction.id !== user;
  631. });
  632. } else {
  633. this.reactions.shared = true;
  634. let user = this.user;
  635. this.shares.push(user);
  636. }
  637. }).catch(err => {
  638. console.error(err);
  639. swal('Error', 'Something went wrong, please try again later.', 'error');
  640. });
  641. },
  642. bookmarkStatus() {
  643. if($('body').hasClass('loggedIn') == false) {
  644. window.location.href = '/login?next=' + encodeURIComponent(window.location.pathname);
  645. return;
  646. }
  647. axios.post('/i/bookmark', {
  648. item: this.status.id
  649. }).then(res => {
  650. if(this.reactions.bookmarked == true) {
  651. this.reactions.bookmarked = false;
  652. } else {
  653. this.reactions.bookmarked = true;
  654. }
  655. }).catch(err => {
  656. swal('Error', 'Something went wrong, please try again later.', 'error');
  657. });
  658. },
  659. muteProfile() {
  660. if($('body').hasClass('loggedIn') == false) {
  661. return;
  662. }
  663. axios.post('/i/mute', {
  664. type: 'user',
  665. item: this.status.account.id
  666. }).then(res => {
  667. swal('Success', 'You have successfully muted ' + this.status.account.acct, 'success');
  668. }).catch(err => {
  669. swal('Error', 'Something went wrong. Please try again later.', 'error');
  670. });
  671. },
  672. blockProfile() {
  673. if($('body').hasClass('loggedIn') == false) {
  674. return;
  675. }
  676. axios.post('/i/block', {
  677. type: 'user',
  678. item: this.status.account.id
  679. }).then(res => {
  680. swal('Success', 'You have successfully blocked ' + this.status.account.acct, 'success');
  681. }).catch(err => {
  682. swal('Error', 'Something went wrong. Please try again later.', 'error');
  683. });
  684. },
  685. deletePost(status) {
  686. if(!this.ownerOrAdmin()) {
  687. return;
  688. }
  689. var result = confirm('Are you sure you want to delete this post?');
  690. if (result) {
  691. if($('body').hasClass('loggedIn') == false) {
  692. return;
  693. }
  694. axios.post('/i/delete', {
  695. type: 'status',
  696. item: this.status.id
  697. }).then(res => {
  698. swal('Success', 'You have successfully deleted this post', 'success');
  699. setTimeout(function() {
  700. window.location.href = '/';
  701. }, 3000);
  702. }).catch(err => {
  703. swal('Error', 'Something went wrong. Please try again later.', 'error');
  704. });
  705. }
  706. },
  707. owner() {
  708. return this.user.id === this.status.account.id;
  709. },
  710. admin() {
  711. return this.user.is_admin == true;
  712. },
  713. ownerOrAdmin() {
  714. return this.owner() || this.admin();
  715. },
  716. lightbox(src) {
  717. this.lightboxMedia = src;
  718. this.$refs.lightboxModal.show();
  719. },
  720. postReply() {
  721. let self = this;
  722. if(this.replyText.length == 0 ||
  723. this.replyText.trim() == '@'+this.status.account.acct) {
  724. self.replyText = null;
  725. $('textarea[name="comment"]').blur();
  726. return;
  727. }
  728. let data = {
  729. item: this.replyingToId,
  730. comment: this.replyText
  731. }
  732. axios.post('/i/comment', data)
  733. .then(function(res) {
  734. let entity = res.data.entity;
  735. if(entity.in_reply_to_id == self.status.id) {
  736. self.results.push(entity);
  737. let elem = $('.status-comments')[0];
  738. elem.scrollTop = elem.clientHeight;
  739. } else {
  740. if(self.replyToIndex >= 0) {
  741. let el = self.results[self.replyToIndex];
  742. el.replies.push(entity);
  743. el.reply_count = el.reply_count + 1;
  744. }
  745. }
  746. self.replyText = '';
  747. });
  748. },
  749. deleteComment(id, i) {
  750. axios.post('/i/delete', {
  751. type: 'comment',
  752. item: id
  753. }).then(res => {
  754. this.results.splice(i, 1);
  755. }).catch(err => {
  756. swal('Something went wrong!', 'Please try again later', 'error');
  757. });
  758. },
  759. deleteCommentReply(id, i, pi) {
  760. axios.post('/i/delete', {
  761. type: 'comment',
  762. item: id
  763. }).then(res => {
  764. this.results[pi].replies.splice(i, 1);
  765. --this.results[pi].reply_count;
  766. }).catch(err => {
  767. swal('Something went wrong!', 'Please try again later', 'error');
  768. });
  769. },
  770. l(e) {
  771. let len = e.length;
  772. if(len < 10) { return e; }
  773. return e.substr(0, 10)+'...';
  774. },
  775. replyFocus(e, index) {
  776. this.replyToIndex = index;
  777. this.replyingToId = e.id;
  778. this.reply_to_profile_id = e.account.id;
  779. this.replyText = '@' + e.account.username + ' ';
  780. $('textarea[name="comment"]').focus();
  781. },
  782. fetchComments() {
  783. let url = '/api/v2/comments/'+this.statusUsername+'/status/'+this.statusId;
  784. axios.get(url)
  785. .then(response => {
  786. let self = this;
  787. this.results = _.reverse(response.data.data);
  788. this.pagination = response.data.meta.pagination;
  789. if(this.results.length > 0) {
  790. $('.load-more-link').removeClass('d-none');
  791. }
  792. $('.postCommentsLoader').addClass('d-none');
  793. $('.postCommentsContainer').removeClass('d-none');
  794. }).catch(error => {
  795. if(!error.response) {
  796. $('.postCommentsLoader .lds-ring')
  797. .attr('style','width:100%')
  798. .addClass('pt-4 font-weight-bold text-muted')
  799. .text('An error occurred, cannot fetch comments. Please try again later.');
  800. } else {
  801. switch(error.response.status) {
  802. case 401:
  803. $('.postCommentsLoader .lds-ring')
  804. .attr('style','width:100%')
  805. .addClass('pt-4 font-weight-bold text-muted')
  806. .text('Please login to view.');
  807. break;
  808. default:
  809. $('.postCommentsLoader .lds-ring')
  810. .attr('style','width:100%')
  811. .addClass('pt-4 font-weight-bold text-muted')
  812. .text('An error occurred, cannot fetch comments. Please try again later.');
  813. break;
  814. }
  815. }
  816. });
  817. },
  818. loadMore(e) {
  819. e.preventDefault();
  820. if(this.pagination.total_pages == 1 || this.pagination.current_page == this.pagination.total_pages) {
  821. $('.load-more-link').addClass('d-none');
  822. return;
  823. }
  824. $('.postCommentsLoader').removeClass('d-none');
  825. let next = this.pagination.links.next;
  826. axios.get(next)
  827. .then(response => {
  828. let self = this;
  829. let res = response.data.data;
  830. $('.postCommentsLoader').addClass('d-none');
  831. for(let i=0; i < res.length; i++) {
  832. this.results.unshift(res[i]);
  833. }
  834. this.pagination = response.data.meta.pagination;
  835. });
  836. },
  837. likeReply(status, $event) {
  838. if($('body').hasClass('loggedIn') == false) {
  839. return;
  840. }
  841. axios.post('/i/like', {
  842. item: status.id
  843. }).then(res => {
  844. status.favourites_count = res.data.count;
  845. if(status.favourited == true) {
  846. status.favourited = false;
  847. } else {
  848. status.favourited = true;
  849. }
  850. }).catch(err => {
  851. swal('Error', 'Something went wrong, please try again later.', 'error');
  852. });
  853. },
  854. truncate(str,lim) {
  855. return _.truncate(str,{
  856. length: lim
  857. });
  858. },
  859. timeAgo(ts) {
  860. let date = Date.parse(ts);
  861. let seconds = Math.floor((new Date() - date) / 1000);
  862. let interval = Math.floor(seconds / 31536000);
  863. if (interval >= 1) {
  864. return interval + "y";
  865. }
  866. interval = Math.floor(seconds / 604800);
  867. if (interval >= 1) {
  868. return interval + "w";
  869. }
  870. interval = Math.floor(seconds / 86400);
  871. if (interval >= 1) {
  872. return interval + "d";
  873. }
  874. interval = Math.floor(seconds / 3600);
  875. if (interval >= 1) {
  876. return interval + "h";
  877. }
  878. interval = Math.floor(seconds / 60);
  879. if (interval >= 1) {
  880. return interval + "m";
  881. }
  882. return Math.floor(seconds) + "s";
  883. },
  884. emojiReaction() {
  885. let em = event.target.innerText;
  886. if(this.replyText.length == 0) {
  887. this.reply_to_profile_id = this.status.account.id;
  888. this.replyText = em + ' ';
  889. $('textarea[name="comment"]').focus();
  890. } else {
  891. this.reply_to_profile_id = this.status.account.id;
  892. this.replyText += em + ' ';
  893. $('textarea[name="comment"]').focus();
  894. }
  895. },
  896. toggleCommentVisibility() {
  897. if(this.ownerOrAdmin() == false) {
  898. return;
  899. }
  900. let state = this.status.comments_disabled;
  901. let self = this;
  902. if(state == true) {
  903. // re-enable comments
  904. axios.post('/i/visibility', {
  905. item: self.status.id,
  906. disableComments: false
  907. }).then(function(res) {
  908. window.location.href = self.status.url;
  909. }).catch(function(err) {
  910. return;
  911. });
  912. } else {
  913. // disable comments
  914. axios.post('/i/visibility', {
  915. item: self.status.id,
  916. disableComments: true
  917. }).then(function(res) {
  918. self.status.comments_disabled = false;
  919. self.showComments = false;
  920. }).catch(function(err) {
  921. return;
  922. });
  923. }
  924. },
  925. fetchRelationships() {
  926. if(document.querySelectorAll('body')[0].classList.contains('loggedIn') == false) {
  927. this.fetchData();
  928. return;
  929. } else {
  930. axios.get('/api/v1/accounts/relationships', {
  931. params: {
  932. 'id[]': this.statusProfileId
  933. }
  934. }).then(res => {
  935. if(res.data[0] == null) {
  936. this.fetchData();
  937. return;
  938. }
  939. this.relationship = res.data[0];
  940. if(res.data[0].blocking == true) {
  941. this.loaded = true;
  942. this.warning = true;
  943. return;
  944. } else {
  945. this.fetchData();
  946. return;
  947. }
  948. });
  949. }
  950. },
  951. visibilityModal() {
  952. switch(this.status.visibility) {
  953. case 'public':
  954. swal('Public Post', 'This post is visible to everyone.', 'info');
  955. break;
  956. case 'unlisted':
  957. swal('Unlisted Post', 'This post is visible on profiles and with a direct links. It is not displayed on timelines.', 'info');
  958. break;
  959. case 'private':
  960. swal('Private Post', 'This post is only visible to followers.', 'info');
  961. break;
  962. }
  963. },
  964. toggleReplies(reply) {
  965. if(reply.thread) {
  966. reply.thread = false;
  967. } else {
  968. if(reply.replies.length > 0) {
  969. reply.thread = true;
  970. return;
  971. }
  972. let url = '/api/v2/comments/'+reply.account.username+'/status/'+reply.id;
  973. axios.get(url)
  974. .then(response => {
  975. reply.replies = _.reverse(response.data.data);
  976. reply.thread = true;
  977. });
  978. }
  979. }
  980. },
  981. }
  982. </script>