StatusCard.vue 10 KB

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