1
0

StatusCard.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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="status.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. }
  217. },
  218. mounted() {
  219. this.profile = window._sharedData.curUser;
  220. },
  221. methods: {
  222. formatCount(count) {
  223. return App.util.format.count(count);
  224. },
  225. statusUrl(status) {
  226. if(status.local == true) {
  227. return status.url;
  228. }
  229. return '/i/web/post/_/' + status.account.id + '/' + status.id;
  230. },
  231. profileUrl(status) {
  232. if(status.local == true) {
  233. return status.account.url;
  234. }
  235. return '/i/web/profile/_/' + status.account.id;
  236. },
  237. timestampFormat(timestamp) {
  238. let ts = new Date(timestamp);
  239. return ts.toDateString() + ' ' + ts.toLocaleTimeString();
  240. },
  241. shortTimestamp(ts) {
  242. return window.App.util.format.timeAgo(ts);
  243. },
  244. statusCardUsernameFormat(status) {
  245. if(status.account.local == true) {
  246. return status.account.username;
  247. }
  248. let fmt = window.App.config.username.remote.format;
  249. let txt = window.App.config.username.remote.custom;
  250. let usr = status.account.username;
  251. let dom = document.createElement('a');
  252. dom.href = status.account.url;
  253. dom = dom.hostname;
  254. switch(fmt) {
  255. case '@':
  256. return usr + '<span class="text-lighter font-weight-bold">@' + dom + '</span>';
  257. break;
  258. case 'from':
  259. return usr + '<span class="text-lighter font-weight-bold"> <span class="font-weight-normal">from</span> ' + dom + '</span>';
  260. break;
  261. case 'custom':
  262. return usr + '<span class="text-lighter font-weight-bold"> ' + txt + ' ' + dom + '</span>';
  263. break;
  264. default:
  265. return usr + '<span class="text-lighter font-weight-bold">@' + dom + '</span>';
  266. break;
  267. }
  268. },
  269. lightbox(status) {
  270. window.location.href = status.media_attachments[0].url;
  271. },
  272. labelRedirect(type) {
  273. let url = '/i/redirect?url=' + encodeURI(this.config.features.label.covid.url);
  274. window.location.href = url;
  275. },
  276. likeStatus(status, event) {
  277. if($('body').hasClass('loggedIn') == false) {
  278. return;
  279. }
  280. let count = status.favourites_count;
  281. status.favourited = !status.favourited;
  282. axios.post('/i/like', {
  283. item: status.id
  284. }).then(res => {
  285. status.favourites_count = res.data.count;
  286. status.favourited = !!status.favourited;
  287. }).catch(err => {
  288. status.favourited = !!status.favourited;
  289. status.favourites_count = count;
  290. swal('Error', 'Something went wrong, please try again later.', 'error');
  291. });
  292. window.navigator.vibrate(200);
  293. if(status.favourited) {
  294. setTimeout(function() {
  295. event.target.classList.add('animate__animated', 'animate__bounce');
  296. },100);
  297. }
  298. },
  299. commentFocus(status, $event) {
  300. this.$emit('comment-focus', status);
  301. },
  302. commentSubmit(status, $event) {
  303. this.replySending = true;
  304. let id = status.id;
  305. let comment = this.replyText;
  306. let limit = this.config.uploader.max_caption_length;
  307. if(comment.length > limit) {
  308. this.replySending = false;
  309. swal('Comment Too Long', 'Please make sure your comment is '+limit+' characters or less.', 'error');
  310. return;
  311. }
  312. axios.post('/i/comment', {
  313. item: id,
  314. comment: comment,
  315. sensitive: this.replyNsfw
  316. }).then(res => {
  317. this.replyText = '';
  318. this.replies.push(res.data.entity);
  319. this.$refs.replyModal.hide();
  320. });
  321. this.replySending = false;
  322. },
  323. owner(status) {
  324. return this.profile.id === status.account.id;
  325. },
  326. admin() {
  327. return this.profile.is_admin == true;
  328. },
  329. ownerOrAdmin(status) {
  330. return this.owner(status) || this.admin();
  331. },
  332. ctxMenu() {
  333. this.$refs.contextMenu.open();
  334. },
  335. timeAgo(ts) {
  336. return App.util.format.timeAgo(ts);
  337. },
  338. statusDeleted(status) {
  339. this.$emit('status-delete', status);
  340. },
  341. canFollow(status) {
  342. if(!status.hasOwnProperty('relationship')) {
  343. return false;
  344. }
  345. if(!status.hasOwnProperty('account') || !status.account.hasOwnProperty('id')) {
  346. return false;
  347. }
  348. if(status.account.id === this.profile.id) {
  349. return false;
  350. }
  351. return !status.relationship.following;
  352. },
  353. follow(id) {
  354. event.currentTarget.blur();
  355. axios.post('/i/follow', {
  356. item: id
  357. }).then(res => {
  358. this.status.relationship.following = true;
  359. this.$emit('followed', id);
  360. }).catch(err => {
  361. if(err.response.data.message) {
  362. swal('Error', err.response.data.message, 'error');
  363. }
  364. });
  365. },
  366. unfollow(id) {
  367. event.currentTarget.blur();
  368. axios.post('/i/follow', {
  369. item: id
  370. }).then(res => {
  371. this.status.relationship.following = false;
  372. this.$emit('unfollowed', id);
  373. }).catch(err => {
  374. if(err.response.data.message) {
  375. swal('Error', err.response.data.message, 'error');
  376. }
  377. });
  378. }
  379. }
  380. }
  381. </script>
  382. <style lang="scss">
  383. .status-card-component {
  384. .status-content {
  385. font-size: 17px;
  386. }
  387. &.status-card-sm {
  388. .status-content {
  389. font-size: 14px;
  390. }
  391. .fa-lg {
  392. font-size: unset;
  393. line-height: unset;
  394. vertical-align: unset;
  395. }
  396. }
  397. }
  398. </style>