StatusCard.vue 15 KB

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