RemotePost.vue 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512
  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 mt-n4 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"><a href="#" class="btn btn-primary font-weight-bold px-5" @click.prevent="warning = false; fetchData()">View Status</a></p>
  10. </div>
  11. </div>
  12. <div v-if="loaded && warning == false && currentLayout === 'status'" class="postComponent">
  13. <div class="container px-0">
  14. <div v-if="status.pf_type === 'text'" class="col-12 col-md-6 offset-md-3">
  15. <status-card
  16. class="border-top"
  17. :status="status"
  18. :recommended="false"
  19. v-on:comment-focus="commentFocus" />
  20. </div>
  21. <div v-else class="card card-md-rounded-0 status-container orientation-unknown shadow-none border">
  22. <div class="row px-0 mx-0">
  23. <div class="d-flex d-md-none align-items-center justify-content-between card-header bg-white w-100">
  24. <div class="d-flex">
  25. <div class="status-avatar mr-2" @click="redirect(profileUrl)">
  26. <img :src="statusAvatar" width="24px" height="24px" style="border-radius:12px;" class="cursor-pointer">
  27. </div>
  28. <div class="username">
  29. <span class="username-link font-weight-bold text-dark cursor-pointer" @click="redirect(profileUrl)">{{ statusUsername }}</span>
  30. <span v-if="status.account.is_admin" class="fa-stack" title="Admin Account" data-toggle="tooltip" style="height:1em; line-height:1em; max-width:19px;">
  31. <i class="fas fa-certificate text-danger fa-stack-1x"></i>
  32. <i class="fas fa-crown text-white fa-sm fa-stack-1x" style="font-size:7px;"></i>
  33. </span>
  34. <p class="mb-0" style="font-size: 10px;">
  35. <span v-if="loaded && status.taggedPeople.length" class="mb-0">
  36. <span class="font-weight-light cursor-pointer" style="color:#718096" title="Tagged People" data-toggle="tooltip" data-placement="bottom" @click="showTaggedPeopleModal()"><i class="fas fa-tag text-lighter"></i> <span class="font-weight-bold">{{status.taggedPeople.length}} Tagged People</span></span>
  37. </span>
  38. <span v-if="loaded && status.place != null && status.taggedPeople.length" class="px-2 font-weight-bold text-lighter">&#8226;</span>
  39. <span v-if="loaded && status.place != null" class="mb-0 cursor-pointer text-truncate" style="color:#718096" @click="redirect('/discover/places/' + status.place.id + '/' + status.place.slug)"><i class="fas fa-map-marked-alt text-lighter"></i> <span class="font-weight-bold">{{status.place.name}}, {{status.place.country}}</span></span>
  40. </p>
  41. </div>
  42. </div>
  43. <div v-if="user != false" class="float-right">
  44. <div class="post-actions">
  45. <div>
  46. <button class="btn btn-link text-dark no-caret" title="Post options" @click="ctxMenu()">
  47. <span class="fas fa-ellipsis-v text-muted"></span>
  48. </button>
  49. </div>
  50. </div>
  51. </div>
  52. </div>
  53. <div class="col-12 col-md-8 px-0 mx-0">
  54. <div class="postPresenterContainer d-none d-flex justify-content-center align-items-center" style="background: #000;">
  55. <div v-if="status.pf_type === 'photo'" class="w-100">
  56. <photo-presenter :status="status" v-on:togglecw="status.sensitive = false"></photo-presenter>
  57. </div>
  58. <div v-else-if="status.pf_type === 'video'" class="w-100">
  59. <video-presenter :status="status" v-on:togglecw="status.sensitive = false"></video-presenter>
  60. </div>
  61. <div v-else-if="status.pf_type === 'photo:album'" class="w-100">
  62. <photo-album-presenter :status="status" v-on:togglecw="status.sensitive = false"></photo-album-presenter>
  63. </div>
  64. <div v-else-if="status.pf_type === 'video:album'" class="w-100">
  65. <video-album-presenter :status="status" v-on:togglecw="status.sensitive = false"></video-album-presenter>
  66. </div>
  67. <div v-else-if="status.pf_type === 'photo:video:album'" class="w-100">
  68. <mixed-album-presenter :status="status" v-on:togglecw="status.sensitive = false"></mixed-album-presenter>
  69. </div>
  70. <div v-else class="w-100">
  71. <p class="text-center p-0 font-weight-bold text-white">Error: Problem rendering preview.</p>
  72. </div>
  73. </div>
  74. </div>
  75. <div class="col-12 col-md-4 px-0 d-flex flex-column border-left border-md-left-0">
  76. <div class="d-md-flex d-none align-items-center justify-content-between card-header py-3 bg-white">
  77. <div class="d-flex align-items-center status-username text-truncate">
  78. <div class="status-avatar mr-2" @click="redirect(profileUrl)">
  79. <img :src="statusAvatar" width="24px" height="24px" style="border-radius:12px;" class="cursor-pointer">
  80. </div>
  81. <div class="username">
  82. <span class="username-link font-weight-bold text-dark cursor-pointer" @click="redirect(profileUrl)">{{ statusUsername }}</span>
  83. <span v-if="status.account.is_admin" class="fa-stack" title="Admin Account" data-toggle="tooltip" style="height:1em; line-height:1em; max-width:19px;">
  84. <i class="fas fa-certificate text-danger fa-stack-1x"></i>
  85. <i class="fas fa-crown text-white fa-sm fa-stack-1x" style="font-size:7px;"></i>
  86. </span>
  87. <p class="mb-0" style="font-size: 10px;">
  88. <span v-if="loaded && status.taggedPeople.length" class="mb-0">
  89. <span class="font-weight-light cursor-pointer" style="color:#718096" title="Tagged People" data-toggle="tooltip" data-placement="bottom" @click="showTaggedPeopleModal()"><i class="fas fa-tag text-lighter"></i> <span class="font-weight-bold">{{status.taggedPeople.length}} Tagged People</span></span>
  90. </span>
  91. <span v-if="loaded && status.place != null && status.taggedPeople.length" class="px-2 font-weight-bold text-lighter">&#8226;</span>
  92. <span v-if="loaded && status.place != null" class="mb-0 cursor-pointer text-truncate" style="color:#718096" @click="redirect('/discover/places/' + status.place.id + '/' + status.place.slug)"><i class="fas fa-map-marked-alt text-lighter"></i> <span class="font-weight-bold">{{status.place.name}}, {{status.place.country}}</span></span>
  93. </p>
  94. </div>
  95. </div>
  96. <div class="float-right">
  97. <div class="post-actions">
  98. <div v-if="user != false">
  99. <button class="btn btn-link text-dark no-caret" title="Post options" @click="ctxMenu()">
  100. <span class="fas fa-ellipsis-v text-muted"></span>
  101. </button>
  102. </div>
  103. </div>
  104. </div>
  105. </div>
  106. <div class="d-flex flex-md-column flex-column-reverse h-100" style="overflow-y: auto;">
  107. <div class="card-body status-comments pt-0">
  108. <div class="status-comment">
  109. <div v-if="status.content.length" class="pt-3">
  110. <div v-if="status.sensitive">
  111. <span class="py-3">
  112. <a class="text-dark font-weight-bold mr-1" :href="profileUrl" v-bind:title="status.account.username">{{truncate(status.account.username,15)}}</a>
  113. <span class="text-break">
  114. <span class="font-italic text-muted">This comment may contain sensitive material</span>
  115. <span class="text-primary cursor-pointer pl-1" @click="status.sensitive = false">Show</span>
  116. </span>
  117. </span>
  118. </div>
  119. <div v-else>
  120. <p :class="[status.content.length > 620 ? 'mb-1 read-more' : 'mb-1']" style="overflow: hidden;">
  121. <a class="font-weight-bold pr-1 text-dark text-decoration-none" :href="profileUrl">{{statusUsername}}</a>
  122. <span class="comment-text" :id="status.id + '-status-readmore'" v-html="status.content"></span>
  123. </p>
  124. </div>
  125. <hr>
  126. </div>
  127. <div v-if="showComments">
  128. <div class="postCommentsLoader text-center py-2">
  129. <div class="spinner-border" role="status">
  130. <span class="sr-only">Loading...</span>
  131. </div>
  132. </div>
  133. <div class="postCommentsContainer d-none">
  134. <p class="mb-1 text-center load-more-link d-none my-4">
  135. <a href="#" class="text-dark" v-on:click="loadMore" title="Load more comments" data-toggle="tooltip" data-placement="bottom">
  136. <svg class="bi bi-plus-circle" width="1em" height="1em" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg" style="font-size:2em;"> <path fill-rule="evenodd" d="M8 3.5a.5.5 0 01.5.5v4a.5.5 0 01-.5.5H4a.5.5 0 010-1h3.5V4a.5.5 0 01.5-.5z" clip-rule="evenodd"/> <path fill-rule="evenodd" d="M7.5 8a.5.5 0 01.5-.5h4a.5.5 0 010 1H8.5V12a.5.5 0 01-1 0V8z" clip-rule="evenodd"/> <path fill-rule="evenodd" d="M8 15A7 7 0 108 1a7 7 0 000 14zm0 1A8 8 0 108 0a8 8 0 000 16z" clip-rule="evenodd"/></svg>
  137. </a>
  138. </p>
  139. <div class="comments mt-3">
  140. <div v-for="(reply, index) in results" class="pb-4 media" :key="'tl' + reply.id + '_' + index">
  141. <img :src="reply.account.avatar" class="rounded-circle border mr-3" width="42px" height="42px">
  142. <div class="media-body">
  143. <div v-if="reply.sensitive == true">
  144. <span class="py-3">
  145. <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>
  146. <span class="text-break">
  147. <span class="font-italic text-muted">This comment may contain sensitive material</span>
  148. <span class="text-primary cursor-pointer pl-1" @click="reply.sensitive = false;">Show</span>
  149. </span>
  150. </span>
  151. </div>
  152. <div v-else>
  153. <p class="d-flex justify-content-between align-items-top read-more" style="overflow-y: hidden;">
  154. <span>
  155. <a class="text-dark font-weight-bold mr-1 text-break" :href="reply.account.url" v-bind:title="reply.account.username">{{truncate(reply.account.username,15)}}</a>
  156. <span class="text-break comment-body" style="word-break: break-all;" v-html="reply.content"></span>
  157. </span>
  158. <span style="min-width:38px;">
  159. <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>
  160. <post-menu :status="reply" :profile="user" :size="'sm'" :modal="'true'" class="d-inline-block px-2" v-on:deletePost="deleteComment(reply.id, index)"></post-menu>
  161. </span>
  162. </p>
  163. <p class="">
  164. <a v-once class="text-muted mr-3 text-decoration-none small" style="width: 20px;" v-text="timeAgo(reply.created_at)" :href="permalinkUrl(reply)"></a>
  165. <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>
  166. <span class="text-muted comment-reaction font-weight-bold cursor-pointer" v-on:click="replyFocus(reply, index, true)">Reply</span>
  167. </p>
  168. <div v-if="reply.reply_count > 0" class="cursor-pointer" v-on:click="toggleReplies(reply)">
  169. <span class="show-reply-bar"></span>
  170. <span class="comment-reaction font-weight-bold text-muted">{{reply.thread ? 'Hide' : 'View'}} Replies ({{reply.reply_count}})</span>
  171. </div>
  172. <div v-if="reply.thread == true" class="comment-thread">
  173. <div v-for="(s, sindex) in reply.replies" class="pb-3 media" :key="'cr' + s.id + '_' + index">
  174. <img :src="s.account.avatar" class="rounded-circle border mr-3" width="25px" height="25px">
  175. <div class="media-body">
  176. <p class="d-flex justify-content-between align-items-top read-more" style="overflow-y: hidden;">
  177. <span>
  178. <a class="text-dark font-weight-bold mr-1" :href="s.account.url" :title="s.account.username">{{s.account.username}}</a>
  179. <span class="text-break comment-body" style="word-break: break-all;" v-html="s.content"></span>
  180. </span>
  181. <span class="pl-2" style="min-width:38px">
  182. <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>
  183. <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>
  184. </span>
  185. </p>
  186. <p class="">
  187. <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>
  188. <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>
  189. </p>
  190. </div>
  191. </div>
  192. </div>
  193. </div>
  194. </div>
  195. </div>
  196. </div>
  197. </div>
  198. </div>
  199. </div>
  200. </div>
  201. <div v-if="reactionBarLoading" class="card-body flex-grow-0 py-4 text-center">
  202. <div class="spinner-border" role="status">
  203. <span class="sr-only">Loading...</span>
  204. </div>
  205. </div>
  206. <div v-else class="card-body flex-grow-0 py-1">
  207. <div v-if="loaded && user.hasOwnProperty('id')" class="reactions my-2 pb-1 d-flex justify-content-between">
  208. <h3 v-bind:class="[reactions.liked ? 'fas fa-heart text-danger mr-3 m-0 cursor-pointer' : 'far fa-heart pr-3 m-0 like-btn cursor-pointer']" title="Like" v-on:click="likeStatus"></h3>
  209. <h3 v-if="!status.comments_disabled" class="far fa-comment mr-3 m-0 cursor-pointer" title="Comment" v-on:click="replyFocus(status)"></h3>
  210. <h3 @click="redirect(status.media_attachments[0].url)" class="fas fa-expand m-0 mr-3 cursor-pointer"></h3>
  211. <!-- <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> -->
  212. <h3 v-if="status.visibility == 'public'" v-bind:class="[reactions.bookmarked ? 'fas fa-bookmark text-warning m-0 mr-3 cursor-pointer' : 'far fa-bookmark m-0 mr-3 cursor-pointer']" title="Bookmark" v-on:click="bookmarkStatus"></h3>
  213. <h3 v-if="status.visibility == 'public'" v-bind:class="[reactions.shared ? 'fas fa-retweet m-0 text-primary cursor-pointer' : 'fas fa-retweet m-0 share-btn cursor-pointer']" title="Share" v-on:click="shareStatus"></h3>
  214. </div>
  215. <div class="reaction-counts mb-0">
  216. <div v-if="status.liked_by.username && status.liked_by.username !== user.username" class="likes mb-1">
  217. <span class="like-count">Liked by
  218. <a class="font-weight-bold text-dark" :href="status.liked_by.url">{{status.liked_by.username}}</a>
  219. <span v-if="status.liked_by.others == true">
  220. and <span class="font-weight-bold text-dark cursor-pointer" @click="likesModal"><span v-if="status.liked_by.total_count_pretty">{{status.liked_by.total_count_pretty}}</span> others</span>
  221. </span>
  222. </span>
  223. </div>
  224. </div>
  225. <div class="timestamp pt-2 d-flex align-items-bottom justify-content-between">
  226. <a v-bind:href="statusUrl" class="small text-muted" :title="status.created_at">
  227. {{timestampFormat()}}
  228. </a>
  229. <span class="small text-muted text-capitalize cursor-pointer" v-on:click="visibilityModal">{{status.visibility}}</span>
  230. </div>
  231. </div>
  232. </div>
  233. <div v-if="showComments" class="card-footer bg-white sticky-md-bottom p-0">
  234. <div v-if="user.length == 0" class="comment-form-guest p-3">
  235. <a href="/login">Login</a> to like or comment.
  236. </div>
  237. <form v-else class="border-0 rounded-0 align-middle" method="post" action="/i/comment" :data-id="statusId" data-truncate="false">
  238. <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;" @click="replyFocus(status)"></textarea>
  239. <input type="button" value="Post" class="d-inline-block btn btn-link font-weight-bold reply-btn text-decoration-none" disabled/>
  240. </form>
  241. </div>
  242. </div>
  243. </div>
  244. </div>
  245. <div class="container" v-if="showProfileMorePosts">
  246. <p class="text-lighter px-3 mt-5" style="font-weight: 600;font-size: 15px;">More posts from <a :href="profileUrl" class="text-dark">{{this.statusUsername}}</a></p>
  247. <div class="profile-timeline mt-md-4">
  248. <div class="row">
  249. <div class="col-4 p-1 p-md-3" v-for="(s, index) in profileMorePosts" :key="'tlob:'+index">
  250. <a class="card info-overlay card-md-border-0" :href="getStatusUrl(s)" v-once>
  251. <div :class="[s.sensitive ? 'square' : 'square ' + s.media_attachments[0].filter_class]">
  252. <span v-if="s.pf_type == 'photo:album'" class="float-right mr-3 post-icon"><i class="fas fa-images fa-2x"></i></span>
  253. <span v-if="s.pf_type == 'video'" class="float-right mr-3 post-icon"><i class="fas fa-video fa-2x"></i></span>
  254. <span v-if="s.pf_type == 'video:album'" class="float-right mr-3 post-icon"><i class="fas fa-film fa-2x"></i></span>
  255. <div class="square-content" v-bind:style="previewBackground(s)">
  256. </div>
  257. <div class="info-overlay-text">
  258. <h5 class="text-white m-auto font-weight-bold">
  259. <span>
  260. <span class="far fa-heart fa-lg p-2 d-flex-inline"></span>
  261. <span class="d-flex-inline">{{s.favourites_count}}</span>
  262. </span>
  263. <span>
  264. <span class="fas fa-retweet fa-lg p-2 d-flex-inline"></span>
  265. <span class="d-flex-inline">{{s.reblogs_count}}</span>
  266. </span>
  267. </h5>
  268. </div>
  269. </div>
  270. </a>
  271. </div>
  272. </div>
  273. </div>
  274. </div>
  275. </div>
  276. </div>
  277. <comment-card
  278. v-if="currentLayout === 'comments'"
  279. :status="status"
  280. :profile="profile"
  281. v-on:current-layout="setCurrentLayout"
  282. :backToStatus="true"
  283. />
  284. <b-modal ref="likesModal"
  285. id="l-modal"
  286. hide-footer
  287. centered
  288. title="Likes"
  289. body-class="list-group-flush py-3 px-0">
  290. <div class="list-group">
  291. <div class="list-group-item border-0 py-1" v-for="(user, index) in likes" :key="'modal_likes_'+index">
  292. <div class="media">
  293. <a :href="user.url">
  294. <img class="mr-3 rounded-circle box-shadow" :src="user.avatar" :alt="user.username + '’s avatar'" width="30px">
  295. </a>
  296. <div class="media-body">
  297. <p class="mb-0" style="font-size: 14px">
  298. <a :href="user.url" class="font-weight-bold text-dark">
  299. {{user.username}}
  300. </a>
  301. </p>
  302. <p v-if="!user.local" class="text-muted mb-0 text-truncate mr-3" style="font-size: 14px" :title="user.acct" data-toggle="dropdown" data-placement="bottom">
  303. <span class="font-weight-bold">{{user.acct.split('@')[0]}}</span><span class="text-lighter">&commat;{{user.acct.split('@')[1]}}</span>
  304. </p>
  305. <p v-else class="text-muted mb-0 text-truncate" style="font-size: 14px">
  306. {{user.display_name}}
  307. </p>
  308. </div>
  309. </div>
  310. </div>
  311. <infinite-loading @infinite="infiniteLikesHandler" spinner="spiral">
  312. <div slot="no-more"></div>
  313. <div slot="no-results"></div>
  314. </infinite-loading>
  315. </div>
  316. </b-modal>
  317. <b-modal ref="sharesModal"
  318. id="s-modal"
  319. hide-footer
  320. centered
  321. title="Shares"
  322. body-class="list-group-flush py-3 px-0">
  323. <div class="list-group">
  324. <div class="list-group-item border-0 py-1" v-for="(user, index) in shares" :key="'modal_shares_'+index">
  325. <div class="media">
  326. <a :href="user.url">
  327. <img class="mr-3 rounded-circle box-shadow" :src="user.avatar" :alt="user.username + '’s avatar'" width="30px">
  328. </a>
  329. <div class="media-body">
  330. <div class="d-inline-block">
  331. <p class="mb-0" style="font-size: 14px">
  332. <a :href="user.url" class="font-weight-bold text-dark">
  333. {{user.username}}
  334. </a>
  335. </p>
  336. <p class="text-muted mb-0" style="font-size: 14px">
  337. {{user.display_name}}
  338. </a>
  339. </p>
  340. </div>
  341. <p class="float-right"><!-- <a class="btn btn-primary font-weight-bold py-1" href="#">Follow</a> --></p>
  342. </div>
  343. </div>
  344. </div>
  345. <infinite-loading @infinite="infiniteSharesHandler" spinner="spiral">
  346. <div slot="no-more"></div>
  347. <div slot="no-results"></div>
  348. </infinite-loading>
  349. </div>
  350. </b-modal>
  351. <b-modal ref="taggedModal"
  352. id="tagged-modal"
  353. hide-footer
  354. centered
  355. title="Tagged People"
  356. body-class="list-group-flush py-3 px-0">
  357. <div class="list-group">
  358. <div class="list-group-item border-0 py-1" v-for="(taguser, index) in status.taggedPeople" :key="'modal_taggedpeople_'+index">
  359. <div class="media">
  360. <a :href="'/'+taguser.username">
  361. <img class="mr-3 rounded-circle box-shadow" :src="taguser.avatar" :alt="taguser.username + '’s avatar'" width="30px">
  362. </a>
  363. <div class="media-body">
  364. <p class="pt-1 d-flex justify-content-between" style="font-size: 14px">
  365. <a :href="'/'+taguser.username" class="font-weight-bold text-dark">
  366. {{taguser.username}}
  367. </a>
  368. <button v-if="taguser.id == user.id" class="btn btn-outline-primary btn-sm py-1 px-3" @click="untagMe()">Untag Me</button>
  369. </p>
  370. </div>
  371. </div>
  372. </div>
  373. </div>
  374. <p class="mb-0 text-center small text-muted font-weight-bold"><a href="/site/kb/tagging-people">Learn more</a> about Tagging People.</p>
  375. </b-modal>
  376. <b-modal ref="ctxModal"
  377. id="ctx-modal"
  378. hide-header
  379. hide-footer
  380. centered
  381. rounded
  382. size="sm"
  383. body-class="list-group-flush p-0 rounded">
  384. <div class="list-group text-center">
  385. <div v-if="user && user.id != status.account.id && relationship && relationship.following" class="list-group-item rounded cursor-pointer font-weight-bold text-danger" @click="ctxMenuUnfollow()">Unfollow</div>
  386. <div v-if="user && user.id != status.account.id && relationship && !relationship.following" class="list-group-item rounded cursor-pointer font-weight-bold text-primary" @click="ctxMenuFollow()">Follow</div>
  387. <div class="list-group-item rounded cursor-pointer" @click="ctxMenuCopyLink()">Copy Link</div>
  388. <div v-if="status && user.id == status.account.id" class="list-group-item rounded cursor-pointer" @click="toggleCommentVisibility">{{ showComments ? 'Disable' : 'Enable'}} Comments</div>
  389. <a v-if="status && user.id == status.account.id" class="list-group-item rounded cursor-pointer text-dark text-decoration-none" :href="editUrl()">Edit</a>
  390. <div v-if="user && user.is_admin == true" class="list-group-item rounded cursor-pointer" @click="ctxModMenu()">ModTools</div>
  391. <div v-if="status && user.id != status.account.id && !relationship.blocking && !user.is_admin" class="list-group-item rounded cursor-pointer font-weight-bold text-danger" @click="blockProfile()">Block</div>
  392. <div v-if="status && user.id != status.account.id && relationship.blocking && !user.is_admin" class="list-group-item rounded cursor-pointer font-weight-bold text-danger" @click="unblockProfile()">Unblock</div>
  393. <a v-if="user && user.id != status.account.id && !user.is_admin" class="list-group-item rounded cursor-pointer font-weight-bold text-danger text-decoration-none" :href="reportUrl()">Report</a>
  394. <div v-if="status && (user.is_admin || user.id == status.account.id)" class="list-group-item rounded cursor-pointer font-weight-bold text-danger" @click="deletePost(ctxMenuStatus)">Delete</div>
  395. <div class="list-group-item rounded cursor-pointer text-lighter" @click="closeCtxMenu()">Cancel</div>
  396. </div>
  397. </b-modal>
  398. <b-modal ref="ctxModModal"
  399. id="ctx-mod-modal"
  400. hide-header
  401. hide-footer
  402. centered
  403. rounded
  404. size="sm"
  405. body-class="list-group-flush p-0 rounded">
  406. <div class="list-group text-center">
  407. <div class="list-group-item rounded cursor-pointer" @click="toggleCommentVisibility">{{ showComments ? 'Disable' : 'Enable'}} Comments</div>
  408. <div class="list-group-item rounded cursor-pointer" @click="moderatePost('unlist')">Unlist from Timelines</div>
  409. <div v-if="status.sensitive" class="list-group-item rounded cursor-pointer" @click="moderatePost('remcw')">Remove Content Warning</div>
  410. <div v-else class="list-group-item rounded cursor-pointer" @click="moderatePost('addcw')">Add Content Warning</div>
  411. <div class="list-group-item rounded cursor-pointer text-lighter" @click="ctxModMenuClose()">Cancel</div>
  412. </div>
  413. </b-modal>
  414. <b-modal ref="replyModal"
  415. id="ctx-reply-modal"
  416. hide-footer
  417. centered
  418. rounded
  419. :title-html="replyingToUsername ? 'Reply to <span class=text-dark>' + replyingToUsername + '</span>' : ''"
  420. title-tag="p"
  421. title-class="font-weight-bold text-muted"
  422. size="md"
  423. body-class="p-2 rounded">
  424. <div>
  425. <textarea class="form-control" rows="4" style="border: none; font-size: 18px; resize: none; white-space: pre-wrap;outline: none;" placeholder="Reply here ..." v-model="replyText">
  426. </textarea>
  427. <div class="border-top border-bottom my-2">
  428. <ul class="nav align-items-center emoji-reactions" style="overflow-x: scroll;flex-wrap: unset;">
  429. <li class="nav-item" v-on:click="emojiReaction(status)" v-for="e in emoji">{{e}}</li>
  430. </ul>
  431. </div>
  432. <div class="d-flex justify-content-between align-items-center">
  433. <div>
  434. <span class="pl-2 small text-muted font-weight-bold text-monospace">
  435. <span :class="[replyText.length > config.uploader.max_caption_length ? 'text-danger':'text-dark']">{{replyText.length > config.uploader.max_caption_length ? config.uploader.max_caption_length - replyText.length : replyText.length}}</span>/{{config.uploader.max_caption_length}}
  436. </span>
  437. </div>
  438. <div class="d-flex align-items-center">
  439. <div class="custom-control custom-switch mr-3">
  440. <input type="checkbox" class="custom-control-input" id="replyModalCWSwitch" v-model="replySensitive">
  441. <label :class="[replySensitive ? 'custom-control-label font-weight-bold text-dark':'custom-control-label text-lighter']" for="replyModalCWSwitch">Mark as NSFW</label>
  442. </div>
  443. <!-- <select class="custom-select custom-select-sm my-0 mr-2">
  444. <option value="public" selected="">Public</option>
  445. <option value="unlisted">Unlisted</option>
  446. <option value="followers">Followers Only</option>
  447. </select> -->
  448. <button class="btn btn-primary btn-sm py-2 px-4 lead text-uppercase font-weight-bold" v-on:click.prevent="postReply()" :disabled="replyText.length == 0">
  449. {{replySending == true ? 'POSTING' : 'POST'}}
  450. </button>
  451. </div>
  452. </div>
  453. </div>
  454. </b-modal>
  455. </div>
  456. </template>
  457. <style type="text/css" scoped>
  458. .status-comments,
  459. .reactions {
  460. background: #fff;
  461. }
  462. .postPresenterContainer {
  463. background: #fff;
  464. }
  465. @media(min-width: 720px) {
  466. .postPresenterContainer {
  467. min-height: 600px;
  468. }
  469. }
  470. ::-webkit-scrollbar {
  471. width: 0px;
  472. background: transparent;
  473. }
  474. .reply-btn {
  475. position: absolute;
  476. bottom: 12px;
  477. right: 20px;
  478. width: 60px;
  479. text-align: center;
  480. border-radius: 0 3px 3px 0;
  481. }
  482. .text-lighter {
  483. color:#B8C2CC !important;
  484. }
  485. .text-break {
  486. overflow-wrap: break-word;
  487. }
  488. .comments p {
  489. margin-bottom: 0;
  490. }
  491. .comment-reaction {
  492. font-size: 80%;
  493. }
  494. .show-reply-bar {
  495. display: inline-block;
  496. border-bottom: 1px solid #999;
  497. height: 0;
  498. margin-right: 16px;
  499. vertical-align: middle;
  500. width: 24px;
  501. }
  502. .comment-thread {
  503. margin-top: 1rem;
  504. }
  505. .emoji-reactions .nav-item {
  506. font-size: 1.2rem;
  507. padding: 9px;
  508. cursor: pointer;
  509. }
  510. .emoji-reactions::-webkit-scrollbar {
  511. width: 0px;
  512. height: 0px;
  513. background: transparent;
  514. }
  515. @media (min-width: 1200px) {
  516. .container {
  517. max-width: 1100px;
  518. }
  519. }
  520. </style>
  521. <script>
  522. pixelfed.postComponent = {};
  523. import StatusCard from './partials/StatusCard.vue';
  524. import CommentCard from './partials/CommentCard.vue';
  525. export default {
  526. props: [
  527. 'status-id',
  528. 'status-username',
  529. 'status-template',
  530. 'status-url',
  531. 'status-profile-url',
  532. 'status-avatar',
  533. 'status-profile-id',
  534. 'profile-layout'
  535. ],
  536. components: {
  537. StatusCard,
  538. CommentCard
  539. },
  540. data() {
  541. return {
  542. config: window.App.config,
  543. status: false,
  544. media: {},
  545. user: false,
  546. profile: false,
  547. reactions: {
  548. liked: false,
  549. shared: false
  550. },
  551. likes: [],
  552. likesPage: 1,
  553. shares: [],
  554. sharesPage: 1,
  555. replyText: '',
  556. replyStatus: {},
  557. replySensitive: false,
  558. relationship: {},
  559. results: [],
  560. pagination: {},
  561. min_id: 0,
  562. max_id: 0,
  563. reply_to_profile_id: 0,
  564. thread: false,
  565. showComments: false,
  566. warning: false,
  567. loaded: false,
  568. loading: null,
  569. replyingToId: this.statusId,
  570. replyingToUsername: this.statusUsername,
  571. replyToIndex: 0,
  572. replySending: false,
  573. emoji: window.App.util.emoji,
  574. showReadMore: true,
  575. showCaption: true,
  576. layout: this.profileLayout,
  577. showProfileMorePosts: false,
  578. profileMorePosts: [],
  579. replySending: false,
  580. reactionBarLoading: true,
  581. profileUrl: null,
  582. currentLayout: 'status'
  583. }
  584. },
  585. mounted() {
  586. axios.get('/api/pixelfed/v1/accounts/verify_credentials').then(res => {
  587. this.profile = res.data;
  588. });
  589. this.fetchRelationships();
  590. if(localStorage.getItem('pf_metro_ui.exp.rm') == 'false') {
  591. this.showReadMore = false;
  592. } else {
  593. this.showReadMore = true;
  594. }
  595. },
  596. updated() {
  597. $('.carousel').carousel();
  598. $('[data-toggle="tooltip"]').tooltip();
  599. if(this.showReadMore == true) {
  600. window.pixelfed.readmore();
  601. }
  602. document.querySelectorAll('.hashtag').forEach(function(i, e) {
  603. i.href = App.util.format.rewriteLinks(i);
  604. });
  605. },
  606. methods: {
  607. reportUrl() {
  608. return '/i/report?type=post&id=' + this.status.id;
  609. },
  610. editUrl() {
  611. return this.status.url + '/edit';
  612. },
  613. timestampFormat() {
  614. let ts = new Date(this.status.created_at);
  615. return ts.toDateString() + ' · ' + ts.toLocaleTimeString();
  616. },
  617. fetchData() {
  618. let self = this;
  619. axios.get('/api/v2/profile/'+this.statusUsername+'/status/'+this.statusId)
  620. .then(response => {
  621. self.status = response.data.status;
  622. self.media = self.status.media_attachments;
  623. self.likesPage = 2;
  624. self.sharesPage = 2;
  625. self.showCaption = !response.data.status.sensitive;
  626. if(self.status.comments_disabled == false) {
  627. self.showComments = true;
  628. this.fetchComments();
  629. }
  630. self.profileUrl = '/i/web/profile/_/' + response.data.status.account.id;
  631. this.loaded = true;
  632. // setTimeout(function() {
  633. // self.fetchProfilePosts();
  634. // }, 3000);
  635. setTimeout(function() {
  636. self.fetchState();
  637. document.querySelectorAll('.status-comment .postCommentsContainer .comment-body a').forEach(function(i, e) {
  638. i.href = App.util.format.rewriteLinks(i);
  639. });
  640. }, 500);
  641. }).catch(error => {
  642. swal('Oops!', 'An error occured, please try refreshing the page.', 'error');
  643. });
  644. },
  645. fetchState() {
  646. let self = this;
  647. axios.get('/api/v2/profile/'+this.statusUsername+'/status/'+this.statusId+'/state')
  648. .then(res => {
  649. self.user = res.data.user;
  650. window._sharedData.curUser = self.user;
  651. window.App.util.navatar();
  652. self.likes = res.data.likes;
  653. self.shares = res.data.shares;
  654. self.reactions = res.data.reactions;
  655. self.reactionBarLoading = false;
  656. });
  657. },
  658. likesModal() {
  659. if($('body').hasClass('loggedIn') == false) {
  660. window.location.href = '/login?next=' + encodeURIComponent('/p/' + this.status.shortcode);
  661. return;
  662. }
  663. if(this.likes.length) {
  664. this.$refs.likesModal.show();
  665. return;
  666. }
  667. axios.get('/api/v2/likes/profile/'+this.statusUsername+'/status/'+this.statusId)
  668. .then(res => {
  669. this.likes = res.data.data;
  670. this.$refs.likesModal.show();
  671. });
  672. },
  673. sharesModal() {
  674. if(this.status.reblogs_count == 0 || $('body').hasClass('loggedIn') == false) {
  675. window.location.href = '/login?next=' + encodeURIComponent('/p/' + this.status.shortcode);
  676. return;
  677. }
  678. if(this.shares.length) {
  679. this.$refs.sharesModal.show();
  680. return;
  681. }
  682. axios.get('/api/v2/shares/profile/'+this.statusUsername+'/status/'+this.statusId)
  683. .then(res => {
  684. this.shares = res.data.data;
  685. this.$refs.sharesModal.show();
  686. });
  687. },
  688. infiniteLikesHandler($state) {
  689. let api = '/api/v2/likes/profile/'+this.statusUsername+'/status/'+this.statusId;
  690. axios.get(api, {
  691. params: {
  692. page: this.likesPage,
  693. },
  694. }).then(({ data }) => {
  695. if (data.data.length > 0) {
  696. this.likes.push(...data.data);
  697. this.likesPage++;
  698. $state.loaded();
  699. } else {
  700. $state.complete();
  701. }
  702. });
  703. },
  704. infiniteSharesHandler($state) {
  705. axios.get('/api/v2/shares/profile/'+this.statusUsername+'/status/'+this.statusId, {
  706. params: {
  707. page: this.sharesPage,
  708. },
  709. }).then(({ data }) => {
  710. if (data.data.length > 0) {
  711. this.shares.push(...data.data);
  712. this.sharesPage++;
  713. $state.loaded();
  714. } else {
  715. $state.complete();
  716. }
  717. });
  718. },
  719. likeStatus(event) {
  720. if($('body').hasClass('loggedIn') == false) {
  721. window.location.href = '/login?next=' + encodeURIComponent(window.location.pathname);
  722. return;
  723. }
  724. axios.post('/i/like', {
  725. item: this.status.id
  726. }).then(res => {
  727. this.status.favourites_count = res.data.count;
  728. if(this.reactions.liked == true) {
  729. this.reactions.liked = false;
  730. let user = this.user.id;
  731. this.likes = this.likes.filter(function(like) {
  732. return like.id !== user;
  733. });
  734. } else {
  735. this.reactions.liked = true;
  736. let user = this.user;
  737. this.likes.unshift(user);
  738. setTimeout(function() {
  739. event.target.classList.add('animate__animated', 'animate__bounce');
  740. },100);
  741. }
  742. }).catch(err => {
  743. console.error(err);
  744. swal('Error', 'Something went wrong, please try again later.', 'error');
  745. });
  746. window.navigator.vibrate(200);
  747. },
  748. shareStatus() {
  749. if($('body').hasClass('loggedIn') == false) {
  750. window.location.href = '/login?next=' + encodeURIComponent(window.location.pathname);
  751. return;
  752. }
  753. axios.post('/i/share', {
  754. item: this.status.id
  755. }).then(res => {
  756. this.status.reblogs_count = res.data.count;
  757. if(this.reactions.shared == true) {
  758. this.reactions.shared = false;
  759. let user = this.user.id;
  760. this.shares = this.shares.filter(function(reaction) {
  761. return reaction.id !== user;
  762. });
  763. } else {
  764. this.reactions.shared = true;
  765. let user = this.user;
  766. this.shares.push(user);
  767. }
  768. }).catch(err => {
  769. console.error(err);
  770. swal('Error', 'Something went wrong, please try again later.', 'error');
  771. });
  772. },
  773. bookmarkStatus() {
  774. if($('body').hasClass('loggedIn') == false) {
  775. window.location.href = '/login?next=' + encodeURIComponent(window.location.pathname);
  776. return;
  777. }
  778. axios.post('/i/bookmark', {
  779. item: this.status.id
  780. }).then(res => {
  781. if(this.reactions.bookmarked == true) {
  782. this.reactions.bookmarked = false;
  783. } else {
  784. this.reactions.bookmarked = true;
  785. }
  786. }).catch(err => {
  787. swal('Error', 'Something went wrong, please try again later.', 'error');
  788. });
  789. },
  790. blockProfile() {
  791. if($('body').hasClass('loggedIn') == false) {
  792. return;
  793. }
  794. axios.post('/i/block', {
  795. type: 'user',
  796. item: this.status.account.id
  797. }).then(res => {
  798. this.$refs.ctxModal.hide();
  799. this.relationship.blocking = true;
  800. swal('Success', 'You have successfully blocked ' + this.status.account.acct, 'success');
  801. }).catch(err => {
  802. swal('Error', 'Something went wrong. Please try again later.', 'error');
  803. });
  804. },
  805. unblockProfile() {
  806. if($('body').hasClass('loggedIn') == false) {
  807. return;
  808. }
  809. axios.post('/i/unblock', {
  810. type: 'user',
  811. item: this.status.account.id
  812. }).then(res => {
  813. this.relationship.blocking = false;
  814. this.$refs.ctxModal.hide();
  815. swal('Success', 'You have successfully unblocked ' + this.status.account.acct, 'success');
  816. }).catch(err => {
  817. swal('Error', 'Something went wrong. Please try again later.', 'error');
  818. });
  819. },
  820. deletePost(status) {
  821. if(!this.ownerOrAdmin()) {
  822. return;
  823. }
  824. var result = confirm('Are you sure you want to delete this post?');
  825. if (result) {
  826. if($('body').hasClass('loggedIn') == false) {
  827. return;
  828. }
  829. axios.post('/i/delete', {
  830. type: 'status',
  831. item: this.status.id
  832. }).then(res => {
  833. swal('Success', 'You have successfully deleted this post', 'success');
  834. setTimeout(function() {
  835. window.location.href = '/';
  836. }, 3000);
  837. }).catch(err => {
  838. swal('Error', 'Something went wrong. Please try again later.', 'error');
  839. });
  840. }
  841. },
  842. owner() {
  843. return this.user.id === this.status.account.id;
  844. },
  845. admin() {
  846. return this.user.is_admin == true;
  847. },
  848. ownerOrAdmin() {
  849. return this.owner() || this.admin();
  850. },
  851. postReply() {
  852. let self = this;
  853. this.replySending = true;
  854. if(this.replyText.length == 0 ||
  855. this.replyText.trim() == '@'+this.status.account.acct) {
  856. self.replyText = null;
  857. $('textarea[name="comment"]').blur();
  858. return;
  859. }
  860. let data = {
  861. item: this.replyingToId,
  862. comment: this.replyText,
  863. sensitive: this.replySensitive
  864. }
  865. this.replyText = '';
  866. axios.post('/i/comment', data)
  867. .then(function(res) {
  868. let entity = res.data.entity;
  869. if(entity.in_reply_to_id == self.status.id) {
  870. if(self.layout == 'metro') {
  871. self.results.push(entity);
  872. } else {
  873. self.results.unshift(entity);
  874. }
  875. let elem = $('.status-comments')[0];
  876. elem.scrollTop = elem.clientHeight * 2;
  877. } else {
  878. if(self.replyToIndex >= 0) {
  879. let el = self.results[self.replyToIndex];
  880. el.replies.push(entity);
  881. el.reply_count = el.reply_count + 1;
  882. }
  883. }
  884. self.$refs.replyModal.hide();
  885. self.replySending = false;
  886. });
  887. },
  888. deleteComment(id, i) {
  889. axios.post('/i/delete', {
  890. type: 'comment',
  891. item: id
  892. }).then(res => {
  893. this.results.splice(i, 1);
  894. }).catch(err => {
  895. swal('Something went wrong!', 'Please try again later', 'error');
  896. });
  897. },
  898. deleteCommentReply(id, i, pi) {
  899. axios.post('/i/delete', {
  900. type: 'comment',
  901. item: id
  902. }).then(res => {
  903. this.results[pi].replies.splice(i, 1);
  904. --this.results[pi].reply_count;
  905. }).catch(err => {
  906. swal('Something went wrong!', 'Please try again later', 'error');
  907. });
  908. },
  909. l(e) {
  910. let len = e.length;
  911. if(len < 10) { return e; }
  912. return e.substr(0, 10)+'...';
  913. },
  914. replyFocus(e, index, prependUsername = false) {
  915. if($('body').hasClass('loggedIn') == false) {
  916. this.redirect('/login?next=' + encodeURIComponent(window.location.pathname));
  917. return;
  918. }
  919. if(this.status.comments_disabled) {
  920. return;
  921. }
  922. this.replyToIndex = index;
  923. this.replyingToId = e.id;
  924. this.replyingToUsername = e.account.username;
  925. this.reply_to_profile_id = e.account.id;
  926. let username = e.account.local ? '@' + e.account.username + ' '
  927. : '@' + e.account.acct + ' ';
  928. if(prependUsername == true) {
  929. this.replyText = username;
  930. }
  931. this.$refs.replyModal.show();
  932. },
  933. fetchComments() {
  934. let url = '/api/v2/comments/'+this.statusProfileId+'/status/'+this.statusId;
  935. axios.get(url)
  936. .then(response => {
  937. let self = this;
  938. this.results = this.layout == 'metro' ?
  939. _.reverse(response.data.data) :
  940. response.data.data;
  941. this.pagination = response.data.meta.pagination;
  942. if(this.results.length > 0) {
  943. $('.load-more-link').removeClass('d-none');
  944. }
  945. $('.postCommentsLoader').addClass('d-none');
  946. $('.postCommentsContainer').removeClass('d-none');
  947. setTimeout(function() {
  948. document.querySelectorAll('.status-comment .postCommentsContainer .comment-body a').forEach(function(i, e) {
  949. i.href = App.util.format.rewriteLinks(i);
  950. });
  951. }, 500);
  952. }).catch(error => {
  953. if(!error.response) {
  954. $('.postCommentsLoader .lds-ring')
  955. .attr('style','width:100%')
  956. .addClass('pt-4 font-weight-bold text-muted')
  957. .text('An error occurred, cannot fetch comments. Please try again later.');
  958. } else {
  959. switch(error.response.status) {
  960. case 401:
  961. $('.postCommentsLoader .lds-ring')
  962. .attr('style','width:100%')
  963. .addClass('pt-4 font-weight-bold text-muted')
  964. .text('Please login to view.');
  965. break;
  966. default:
  967. $('.postCommentsLoader .lds-ring')
  968. .attr('style','width:100%')
  969. .addClass('pt-4 font-weight-bold text-muted')
  970. .text('An error occurred, cannot fetch comments. Please try again later.');
  971. break;
  972. }
  973. }
  974. });
  975. },
  976. loadMore(e) {
  977. e.preventDefault();
  978. if(this.pagination.total_pages == 1 || this.pagination.current_page == this.pagination.total_pages) {
  979. $('.load-more-link').addClass('d-none');
  980. return;
  981. }
  982. $('.load-more-link').addClass('d-none');
  983. $('.postCommentsLoader').removeClass('d-none');
  984. let next = this.pagination.links.next;
  985. axios.get(next)
  986. .then(response => {
  987. let self = this;
  988. let res = response.data.data;
  989. $('.postCommentsLoader').addClass('d-none');
  990. for(let i=0; i < res.length; i++) {
  991. this.results.unshift(res[i]);
  992. }
  993. this.pagination = response.data.meta.pagination;
  994. $('.load-more-link').removeClass('d-none');
  995. });
  996. },
  997. likeReply(status, $event) {
  998. if($('body').hasClass('loggedIn') == false) {
  999. swal('Login', 'Please login to perform this action.', 'info');
  1000. return;
  1001. }
  1002. axios.post('/i/like', {
  1003. item: status.id
  1004. }).then(res => {
  1005. status.favourites_count = res.data.count;
  1006. if(status.favourited == true) {
  1007. status.favourited = false;
  1008. } else {
  1009. status.favourited = true;
  1010. }
  1011. }).catch(err => {
  1012. swal('Error', 'Something went wrong, please try again later.', 'error');
  1013. });
  1014. },
  1015. truncate(str,lim) {
  1016. return _.truncate(str,{
  1017. length: lim
  1018. });
  1019. },
  1020. timeAgo(ts) {
  1021. return App.util.format.timeAgo(ts);
  1022. },
  1023. emojiReaction() {
  1024. let em = event.target.innerText;
  1025. if(this.replyText.length == 0) {
  1026. this.reply_to_profile_id = this.status.account.id;
  1027. this.replyText = em + ' ';
  1028. $('textarea[name="comment"]').focus();
  1029. } else {
  1030. this.reply_to_profile_id = this.status.account.id;
  1031. this.replyText += em + ' ';
  1032. $('textarea[name="comment"]').focus();
  1033. }
  1034. },
  1035. toggleCommentVisibility() {
  1036. if(this.ownerOrAdmin() == false) {
  1037. return;
  1038. }
  1039. let state = this.status.comments_disabled;
  1040. let self = this;
  1041. if(state == true) {
  1042. // re-enable comments
  1043. axios.post('/i/visibility', {
  1044. item: self.status.id,
  1045. disableComments: false
  1046. }).then(function(res) {
  1047. self.status.comments_disabled = false;
  1048. self.$refs.ctxModal.hide();
  1049. window.location.reload();
  1050. }).catch(function(err) {
  1051. return;
  1052. });
  1053. } else {
  1054. // disable comments
  1055. axios.post('/i/visibility', {
  1056. item: self.status.id,
  1057. disableComments: true
  1058. }).then(function(res) {
  1059. self.status.comments_disabled = true;
  1060. self.showComments = false;
  1061. self.$refs.ctxModal.hide();
  1062. }).catch(function(err) {
  1063. return;
  1064. });
  1065. }
  1066. },
  1067. fetchRelationships() {
  1068. if(document.querySelectorAll('body')[0].classList.contains('loggedIn') == false) {
  1069. this.fetchData();
  1070. return;
  1071. } else {
  1072. axios.get('/api/pixelfed/v1/accounts/relationships', {
  1073. params: {
  1074. 'id[]': this.statusProfileId
  1075. }
  1076. }).then(res => {
  1077. if(res.data[0] == null) {
  1078. this.fetchData();
  1079. return;
  1080. }
  1081. this.relationship = res.data[0];
  1082. if(res.data[0].blocking == true) {
  1083. this.loaded = true;
  1084. this.warning = true;
  1085. return;
  1086. } else {
  1087. this.fetchData();
  1088. return;
  1089. }
  1090. });
  1091. }
  1092. },
  1093. visibilityModal() {
  1094. switch(this.status.visibility) {
  1095. case 'public':
  1096. swal('Public Post', 'This post is visible to everyone.', 'info');
  1097. break;
  1098. case 'unlisted':
  1099. swal('Unlisted Post', 'This post is visible on profiles and with a direct links. It is not displayed on timelines.', 'info');
  1100. break;
  1101. case 'private':
  1102. swal('Private Post', 'This post is only visible to followers.', 'info');
  1103. break;
  1104. }
  1105. },
  1106. toggleReplies(reply) {
  1107. if(reply.thread) {
  1108. reply.thread = false;
  1109. } else {
  1110. if(reply.replies.length > 0) {
  1111. reply.thread = true;
  1112. return;
  1113. }
  1114. let url = '/api/v2/comments/'+reply.account.id+'/status/'+reply.id;
  1115. axios.get(url)
  1116. .then(response => {
  1117. reply.replies = _.reverse(response.data.data);
  1118. reply.thread = true;
  1119. });
  1120. }
  1121. },
  1122. redirect(url) {
  1123. window.location.href = url;
  1124. },
  1125. permalinkUrl(reply, showOrigin = false) {
  1126. let profile = reply.account;
  1127. if(profile.local == true) {
  1128. return reply.url;
  1129. } else {
  1130. return showOrigin ?
  1131. reply.url :
  1132. '/i/web/post/_/' + profile.id + '/' + reply.id;
  1133. }
  1134. },
  1135. fetchProfilePosts() {
  1136. if(!$('body').hasClass('loggedIn') && this.loaded) {
  1137. return;
  1138. }
  1139. let self = this;
  1140. let apiUrl = '/api/pixelfed/v1/accounts/' + this.statusProfileId + '/statuses';
  1141. axios.get(apiUrl, {
  1142. params: {
  1143. only_media: true,
  1144. min_id: 1,
  1145. limit: 9
  1146. }
  1147. })
  1148. .then(res => {
  1149. let data = res.data.filter(function(status) {
  1150. return status.media_attachments.length > 0 &&
  1151. status.id != self.statusId &&
  1152. status.sensitive == false
  1153. });
  1154. let ids = data.map(status => status.id);
  1155. // if(data.length >= 3) {
  1156. // self.showProfileMorePosts = true;
  1157. // }
  1158. self.profileMorePosts = data.slice(0,6);
  1159. })
  1160. },
  1161. previewUrl(status) {
  1162. return status.sensitive ? '/storage/no-preview.png?v=' + new Date().getTime() : status.media_attachments[0].preview_url;
  1163. },
  1164. previewBackground(status) {
  1165. let preview = this.previewUrl(status);
  1166. return 'background-image: url(' + preview + ');';
  1167. },
  1168. getStatusUrl(status, showOrigin = false) {
  1169. if(status.local == true || showOrigin == true) {
  1170. return status.url;
  1171. }
  1172. return '/i/web/post/_/' + status.account.id + '/' + status.id;
  1173. },
  1174. showTaggedPeopleModal() {
  1175. if(!$('body').hasClass('loggedIn') && this.loaded) {
  1176. return;
  1177. }
  1178. this.$refs.taggedModal.show();
  1179. },
  1180. untagMe() {
  1181. this.$refs.taggedModal.hide();
  1182. let id = this.user.id;
  1183. axios.post('/api/local/compose/tag/untagme', {
  1184. status_id: this.statusId,
  1185. profile_id: id
  1186. }).then(res => {
  1187. this.status.taggedPeople = this.status.taggedPeople.filter(t => {
  1188. return t.id != id;
  1189. });
  1190. swal('Untagged', 'You have been untagged from this post.', 'success');
  1191. }).catch(err => {
  1192. swal('An Error Occurred', 'Please try again later.', 'error');
  1193. });
  1194. },
  1195. copyPostUrl() {
  1196. navigator.clipboard.writeText(this.statusUrl);
  1197. return;
  1198. },
  1199. moderatePost(action, $event) {
  1200. let status = this.status;
  1201. let username = status.account.username;
  1202. let msg = '';
  1203. let self = this;
  1204. switch(action) {
  1205. case 'addcw':
  1206. msg = 'Are you sure you want to add a content warning to this post?';
  1207. swal({
  1208. title: 'Confirm',
  1209. text: msg,
  1210. icon: 'warning',
  1211. buttons: true,
  1212. dangerMode: true
  1213. }).then(res => {
  1214. if(res) {
  1215. axios.post('/api/v2/moderator/action', {
  1216. action: action,
  1217. item_id: status.id,
  1218. item_type: 'status'
  1219. }).then(res => {
  1220. swal('Success', 'Successfully added content warning', 'success');
  1221. status.sensitive = true;
  1222. self.ctxModMenuClose();
  1223. }).catch(err => {
  1224. swal(
  1225. 'Error',
  1226. 'Something went wrong, please try again later.',
  1227. 'error'
  1228. );
  1229. self.ctxModMenuClose();
  1230. });
  1231. }
  1232. });
  1233. break;
  1234. case 'remcw':
  1235. msg = 'Are you sure you want to remove the content warning on this post?';
  1236. swal({
  1237. title: 'Confirm',
  1238. text: msg,
  1239. icon: 'warning',
  1240. buttons: true,
  1241. dangerMode: true
  1242. }).then(res => {
  1243. if(res) {
  1244. axios.post('/api/v2/moderator/action', {
  1245. action: action,
  1246. item_id: status.id,
  1247. item_type: 'status'
  1248. }).then(res => {
  1249. swal('Success', 'Successfully added content warning', 'success');
  1250. status.sensitive = false;
  1251. self.ctxModMenuClose();
  1252. }).catch(err => {
  1253. swal(
  1254. 'Error',
  1255. 'Something went wrong, please try again later.',
  1256. 'error'
  1257. );
  1258. self.ctxModMenuClose();
  1259. });
  1260. }
  1261. });
  1262. break;
  1263. case 'unlist':
  1264. msg = 'Are you sure you want to unlist this post?';
  1265. swal({
  1266. title: 'Confirm',
  1267. text: msg,
  1268. icon: 'warning',
  1269. buttons: true,
  1270. dangerMode: true
  1271. }).then(res => {
  1272. if(res) {
  1273. axios.post('/api/v2/moderator/action', {
  1274. action: action,
  1275. item_id: status.id,
  1276. item_type: 'status'
  1277. }).then(res => {
  1278. // this.feed = this.feed.filter(f => {
  1279. // return f.id != status.id;
  1280. // });
  1281. swal('Success', 'Successfully unlisted post', 'success');
  1282. self.ctxModMenuClose();
  1283. }).catch(err => {
  1284. self.ctxModMenuClose();
  1285. swal(
  1286. 'Error',
  1287. 'Something went wrong, please try again later.',
  1288. 'error'
  1289. );
  1290. });
  1291. }
  1292. });
  1293. break;
  1294. }
  1295. },
  1296. ctxMenu() {
  1297. this.$refs.ctxModal.show();
  1298. return;
  1299. },
  1300. closeCtxMenu(truncate) {
  1301. this.$refs.ctxModal.hide();
  1302. },
  1303. ctxModMenu() {
  1304. this.$refs.ctxModal.hide();
  1305. this.$refs.ctxModModal.show();
  1306. },
  1307. ctxModMenuClose() {
  1308. this.$refs.ctxModal.hide();
  1309. this.$refs.ctxModModal.hide();
  1310. },
  1311. ctxMenuCopyLink() {
  1312. let status = this.status;
  1313. navigator.clipboard.writeText(status.url);
  1314. this.closeCtxMenu();
  1315. return;
  1316. },
  1317. ctxMenuFollow() {
  1318. let id = this.status.account.id;
  1319. axios.post('/i/follow', {
  1320. item: id
  1321. }).then(res => {
  1322. let username = this.status.account.acct;
  1323. this.relationship.following = true;
  1324. this.$refs.ctxModal.hide();
  1325. setTimeout(function() {
  1326. swal('Follow successful!', 'You are now following ' + username, 'success');
  1327. }, 500);
  1328. });
  1329. },
  1330. ctxMenuUnfollow() {
  1331. let id = this.status.account.id;
  1332. axios.post('/i/follow', {
  1333. item: id
  1334. }).then(res => {
  1335. let username = this.status.account.acct;
  1336. this.relationship.following = false;
  1337. this.$refs.ctxModal.hide();
  1338. setTimeout(function() {
  1339. swal('Unfollow successful!', 'You are no longer following ' + username, 'success');
  1340. }, 500);
  1341. });
  1342. },
  1343. setCurrentLayout(layout) {
  1344. this.currentLayout = layout;
  1345. },
  1346. commentFocus(status, $event) {
  1347. if(status.comments_disabled) {
  1348. return;
  1349. }
  1350. this.replies = {};
  1351. this.replyStatus = {};
  1352. this.replyText = '';
  1353. this.replyId = status.id;
  1354. this.replyStatus = status;
  1355. // this.$refs.replyModal.show();
  1356. this.fetchStatusComments(status, '');
  1357. $('nav').hide();
  1358. $('footer').hide();
  1359. $('.mobile-footer-spacer').attr('style', 'display:none !important');
  1360. $('.mobile-footer').attr('style', 'display:none !important');
  1361. $('.mt-md-4').hide();
  1362. this.currentLayout = 'comments';
  1363. window.history.pushState({}, '', this.getStatusUrl(status));
  1364. return;
  1365. },
  1366. fetchStatusComments(status, card) {
  1367. let url = '/api/v2/comments/'+status.account.id+'/status/'+status.id;
  1368. axios.get(url)
  1369. .then(response => {
  1370. let self = this;
  1371. this.replies = _.reverse(response.data.data);
  1372. this.pagination = response.data.meta.pagination;
  1373. if(this.replies.length > 0) {
  1374. $('.load-more-link').removeClass('d-none');
  1375. }
  1376. $('.postCommentsLoader').addClass('d-none');
  1377. $('.postCommentsContainer').removeClass('d-none');
  1378. // setTimeout(function() {
  1379. // document.querySelectorAll('.status-comment .postCommentsContainer .comment-body a').forEach(function(i, e) {
  1380. // i.href = App.util.format.rewriteLinks(i);
  1381. // });
  1382. // }, 500);
  1383. }).catch(error => {
  1384. if(!error.response) {
  1385. $('.postCommentsLoader .lds-ring')
  1386. .attr('style','width:100%')
  1387. .addClass('pt-4 font-weight-bold text-muted')
  1388. .text('An error occurred, cannot fetch comments. Please try again later.');
  1389. } else {
  1390. switch(error.response.status) {
  1391. case 401:
  1392. $('.postCommentsLoader .lds-ring')
  1393. .attr('style','width:100%')
  1394. .addClass('pt-4 font-weight-bold text-muted')
  1395. .text('Please login to view.');
  1396. break;
  1397. default:
  1398. $('.postCommentsLoader .lds-ring')
  1399. .attr('style','width:100%')
  1400. .addClass('pt-4 font-weight-bold text-muted')
  1401. .text('An error occurred, cannot fetch comments. Please try again later.');
  1402. break;
  1403. }
  1404. }
  1405. });
  1406. },
  1407. },
  1408. }
  1409. </script>