StatusCard.vue 13 KB

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