RemotePost.vue 57 KB

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