StatusCard.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. <template>
  2. <div>
  3. <div v-if="status.pf_type === 'text'" class="card shadow-none border border-top-0 rounded-0">
  4. <div class="card-body">
  5. <div class="media">
  6. <img class="rounded-circle box-shadow mr-2" :src="status.account.avatar" width="32px" height="32px" onerror="this.onerror=null;this.src='/storage/avatars/default.png?v=2'" alt="avatar">
  7. <div class="media-body">
  8. <div class="pl-2 d-flex align-items-top">
  9. <a class="username font-weight-bold text-dark text-decoration-none text-break" v-bind:href="profileUrl(status)" v-html="statusCardUsernameFormat(status)">
  10. Loading...
  11. </a>
  12. <span class="px-1 text-lighter">
  13. ·
  14. </span>
  15. <a class="font-weight-bold text-lighter"
  16. :href="statusUrl(status)">
  17. {{shortTimestamp(status.created_at)}}
  18. </a>
  19. <span class="text-right" style="flex-grow:1;">
  20. <button class="btn btn-link text-dark py-0" type="button" @click="ctxMenu()">
  21. <span class="fas fa-ellipsis-v text-lighter"></span>
  22. <span class="sr-only">Post Menu</span>
  23. </button>
  24. </span>
  25. </div>
  26. <div class="pl-2">
  27. <details v-if="status.sensitive">
  28. <summary class="mb-2 font-weight-bold text-muted">Content Warning</summary>
  29. <p v-html="status.content" class="pt-2 text-break" style="font-size: 17px;"></p>
  30. </details>
  31. <p v-else v-html="status.content" class="pt-2 text-break" style="font-size: 17px;"></p>
  32. <p class="mb-0">
  33. <i class="fa-heart fa-lg cursor-pointer mr-3"
  34. :class="{ 'far text-muted': !status.favourited, 'fas text-danger': status.favourited }"
  35. @click="likeStatus(status, $event);">
  36. </i>
  37. <i class="far fa-comment cursor-pointer text-muted fa-lg mr-3"
  38. @click="commentFocus(status, $event)">
  39. </i>
  40. </p>
  41. </div>
  42. </div>
  43. </div>
  44. </div>
  45. </div>
  46. <div v-else class="card rounded-0 border-top-0 status-card card-md-rounded-0 shadow-none border">
  47. <div v-if="status" class="card-header d-inline-flex align-items-center bg-white">
  48. <div>
  49. <img class="rounded-circle box-shadow" :src="status.account.avatar" width="32px" height="32px" onerror="this.onerror=null;this.src='/storage/avatars/default.png?v=2'" alt="avatar">
  50. </div>
  51. <div class="pl-2">
  52. <a class="username font-weight-bold text-dark text-decoration-none text-break" v-bind:href="profileUrl(status)" v-html="statusCardUsernameFormat(status)">
  53. Loading...
  54. </a>
  55. <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;">
  56. <i class="fas fa-certificate text-danger fa-stack-1x"></i>
  57. <i class="fas fa-crown text-white fa-sm fa-stack-1x" style="font-size:7px;"></i>
  58. </span>
  59. <div class="d-flex align-items-center">
  60. <a v-if="status.place" class="small text-decoration-none text-muted" :href="'/discover/places/'+status.place.id+'/'+status.place.slug" title="Location" data-toggle="tooltip"><i class="fas fa-map-marked-alt"></i> {{status.place.name}}, {{status.place.country}}</a>
  61. </div>
  62. </div>
  63. <div class="text-right" style="flex-grow:1;">
  64. <button class="btn btn-link text-dark py-0" type="button" @click="ctxMenu()">
  65. <span class="fas fa-ellipsis-h text-lighter"></span>
  66. <span class="sr-only">Post Menu</span>
  67. </button>
  68. </div>
  69. </div>
  70. <div class="postPresenterContainer" style="background: #000;">
  71. <div v-if="status.pf_type === 'photo'" class="w-100">
  72. <photo-presenter :status="status" v-on:lightbox="lightbox" v-on:togglecw="status.sensitive = false"></photo-presenter>
  73. </div>
  74. <div v-else-if="status.pf_type === 'video'" class="w-100">
  75. <video-presenter :status="status" v-on:togglecw="status.sensitive = false"></video-presenter>
  76. </div>
  77. <div v-else-if="status.pf_type === 'photo:album'" class="w-100">
  78. <photo-album-presenter :status="status" v-on:lightbox="lightbox" v-on:togglecw="status.sensitive = false"></photo-album-presenter>
  79. </div>
  80. <div v-else-if="status.pf_type === 'video:album'" class="w-100">
  81. <video-album-presenter :status="status" v-on:togglecw="status.sensitive = false"></video-album-presenter>
  82. </div>
  83. <div v-else-if="status.pf_type === 'photo:video:album'" class="w-100">
  84. <mixed-album-presenter :status="status" v-on:lightbox="lightbox" v-on:togglecw="status.sensitive = false"></mixed-album-presenter>
  85. </div>
  86. <div v-else class="w-100">
  87. <p class="text-center p-0 font-weight-bold text-white">Error: Problem rendering preview.</p>
  88. </div>
  89. </div>
  90. <div v-if="config.features.label.covid.enabled && status.label && status.label.covid == true" class="card-body border-top border-bottom py-2 cursor-pointer pr-2" @click="labelRedirect()">
  91. <p class="font-weight-bold d-flex justify-content-between align-items-center mb-0">
  92. <span>
  93. <i class="fas fa-info-circle mr-2"></i>
  94. For information about COVID-19, {{config.features.label.covid.org}}
  95. </span>
  96. <span>
  97. <i class="fas fa-chevron-right text-lighter"></i>
  98. </span>
  99. </p>
  100. </div>
  101. <div class="card-body">
  102. <div v-if="reactionBar" class="reactions my-1 pb-2">
  103. <h3 v-if="status.favourited" class="fas fa-heart text-danger pr-3 m-0 cursor-pointer" title="Like" v-on:click="likeStatus(status, $event);"></h3>
  104. <h3 v-else class="far fa-heart pr-3 m-0 like-btn text-dark cursor-pointer" title="Like" v-on:click="likeStatus(status, $event);"></h3>
  105. <h3 v-if="!status.comments_disabled" class="far fa-comment text-dark pr-3 m-0 cursor-pointer" title="Comment" v-on:click="commentFocus(status, $event)"></h3>
  106. <span v-if="status.taggedPeople.length" class="float-right">
  107. <span class="font-weight-light small" style="color:#718096">
  108. <i class="far fa-user" data-toggle="tooltip" title="Tagged People"></i>
  109. <span v-for="(tag, index) in status.taggedPeople" class="mr-n2">
  110. <a :href="'/'+tag.username">
  111. <img :src="tag.avatar" width="20px" height="20px" class="border rounded-circle" data-toggle="tooltip" :title="'@'+tag.username" alt="Avatar">
  112. </a>
  113. </span>
  114. </span>
  115. </span>
  116. </div>
  117. <div v-if="status.liked_by.username && status.liked_by.username !== profile.username" class="likes mb-1">
  118. <span class="like-count">Liked by
  119. <a class="font-weight-bold text-dark" :href="status.liked_by.url">{{status.liked_by.username}}</a>
  120. <span v-if="status.liked_by.others == true">
  121. and <span class="font-weight-bold" v-if="status.liked_by.total_count_pretty">{{status.liked_by.total_count_pretty}}</span> <span class="font-weight-bold">others</span>
  122. </span>
  123. </span>
  124. </div>
  125. <div v-if="status.pf_type != 'text'" class="caption">
  126. <p v-if="!status.sensitive" class="mb-2 read-more" style="overflow: hidden;">
  127. <span class="username font-weight-bold">
  128. <bdi><a class="text-dark" :href="profileUrl(status)">{{status.account.username}}</a></bdi>
  129. </span>
  130. <span class="status-content" v-html="status.content"></span>
  131. </p>
  132. </div>
  133. <div class="timestamp mt-2">
  134. <p class="small mb-0">
  135. <a :href="statusUrl(status)" class="text-muted text-uppercase">
  136. <timeago :datetime="status.created_at" :auto-update="60" :converter-options="{includeSeconds:true}" :title="timestampFormat(status.created_at)" v-b-tooltip.hover.bottom></timeago>
  137. </a>
  138. <span v-if="recommended">
  139. <span class="px-1">&middot;</span>
  140. <span class="text-muted">Based on popular and trending content</span>
  141. </span>
  142. </p>
  143. </div>
  144. </div>
  145. </div>
  146. <context-menu
  147. ref="contextMenu"
  148. :status="status"
  149. :profile="profile"
  150. v-on:status-delete="statusDeleted"
  151. />
  152. </div>
  153. </template>
  154. <script type="text/javascript">
  155. import ContextMenu from './ContextMenu.vue';
  156. export default {
  157. props: {
  158. status: {
  159. type: Object
  160. },
  161. recommended: {
  162. type: Boolean,
  163. default: false
  164. },
  165. reactionBar: {
  166. type: Boolean,
  167. default: true
  168. }
  169. },
  170. components: {
  171. "context-menu": ContextMenu
  172. },
  173. data() {
  174. return {
  175. config: window.App.config,
  176. profile: {},
  177. loading: true,
  178. replies: [],
  179. replyId: null,
  180. lightboxMedia: false,
  181. showSuggestions: true,
  182. showReadMore: true,
  183. replyStatus: {},
  184. replyText: '',
  185. replyNsfw: false,
  186. emoji: window.App.util.emoji,
  187. }
  188. },
  189. mounted() {
  190. this.profile = window._sharedData.curUser;
  191. },
  192. methods: {
  193. formatCount(count) {
  194. return App.util.format.count(count);
  195. },
  196. statusUrl(status) {
  197. if(status.local == true) {
  198. return status.url;
  199. }
  200. return '/i/web/post/_/' + status.account.id + '/' + status.id;
  201. },
  202. profileUrl(status) {
  203. if(status.local == true) {
  204. return status.account.url;
  205. }
  206. return '/i/web/profile/_/' + status.account.id;
  207. },
  208. timestampFormat(timestamp) {
  209. let ts = new Date(timestamp);
  210. return ts.toDateString() + ' ' + ts.toLocaleTimeString();
  211. },
  212. shortTimestamp(ts) {
  213. return window.App.util.format.timeAgo(ts);
  214. },
  215. statusCardUsernameFormat(status) {
  216. if(status.account.local == true) {
  217. return status.account.username;
  218. }
  219. let fmt = window.App.config.username.remote.format;
  220. let txt = window.App.config.username.remote.custom;
  221. let usr = status.account.username;
  222. let dom = document.createElement('a');
  223. dom.href = status.account.url;
  224. dom = dom.hostname;
  225. switch(fmt) {
  226. case '@':
  227. return usr + '<span class="text-lighter font-weight-bold">@' + dom + '</span>';
  228. break;
  229. case 'from':
  230. return usr + '<span class="text-lighter font-weight-bold"> <span class="font-weight-normal">from</span> ' + dom + '</span>';
  231. break;
  232. case 'custom':
  233. return usr + '<span class="text-lighter font-weight-bold"> ' + txt + ' ' + dom + '</span>';
  234. break;
  235. default:
  236. return usr + '<span class="text-lighter font-weight-bold">@' + dom + '</span>';
  237. break;
  238. }
  239. },
  240. lightbox(status) {
  241. window.location.href = status.media_attachments[0].url;
  242. },
  243. labelRedirect(type) {
  244. let url = '/i/redirect?url=' + encodeURI(this.config.features.label.covid.url);
  245. window.location.href = url;
  246. },
  247. likeStatus(status, event) {
  248. if($('body').hasClass('loggedIn') == false) {
  249. return;
  250. }
  251. let count = status.favourites_count;
  252. status.favourited = !status.favourited;
  253. axios.post('/i/like', {
  254. item: status.id
  255. }).then(res => {
  256. status.favourites_count = res.data.count;
  257. }).catch(err => {
  258. status.favourited = !status.favourited;
  259. status.favourites_count = count;
  260. swal('Error', 'Something went wrong, please try again later.', 'error');
  261. });
  262. window.navigator.vibrate(200);
  263. if(status.favourited) {
  264. setTimeout(function() {
  265. event.target.classList.add('animate__animated', 'animate__bounce');
  266. },100);
  267. }
  268. },
  269. commentFocus(status, $event) {
  270. this.$emit('comment-focus', status);
  271. },
  272. commentSubmit(status, $event) {
  273. this.replySending = true;
  274. let id = status.id;
  275. let comment = this.replyText;
  276. let limit = this.config.uploader.max_caption_length;
  277. if(comment.length > limit) {
  278. this.replySending = false;
  279. swal('Comment Too Long', 'Please make sure your comment is '+limit+' characters or less.', 'error');
  280. return;
  281. }
  282. axios.post('/i/comment', {
  283. item: id,
  284. comment: comment,
  285. sensitive: this.replyNsfw
  286. }).then(res => {
  287. this.replyText = '';
  288. this.replies.push(res.data.entity);
  289. this.$refs.replyModal.hide();
  290. });
  291. this.replySending = false;
  292. },
  293. owner(status) {
  294. return this.profile.id === status.account.id;
  295. },
  296. admin() {
  297. return this.profile.is_admin == true;
  298. },
  299. ownerOrAdmin(status) {
  300. return this.owner(status) || this.admin();
  301. },
  302. ctxMenu() {
  303. this.$refs.contextMenu.open();
  304. },
  305. timeAgo(ts) {
  306. return App.util.format.timeAgo(ts);
  307. },
  308. statusDeleted(status) {
  309. this.$emit('status-delete', status);
  310. }
  311. }
  312. }
  313. </script>