StatusCard.vue 13 KB

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