Message.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <template>
  2. <div class="dm-chat-message chat-msg">
  3. <div
  4. class="media d-inline-flex mb-0"
  5. :class="{ isAuthor: convo.isAuthor }"
  6. >
  7. <img v-if="!convo.isAuthor && !hideAvatars" class="mr-3 shadow msg-avatar" :src="thread.avatar" alt="avatar" width="50" onerror="this.onerror=null;this.src='/storage/avatars/default.jpg';">
  8. <div class="media-body">
  9. <p v-if="convo.type == 'photo'" class="pill-to p-0 shadow">
  10. <img
  11. :src="convo.media"
  12. class="media-embed"
  13. style="cursor: pointer;"
  14. onerror="this.onerror=null;this.src='/storage/no-preview.png';"
  15. @click.prevent="expandMedia">
  16. </p>
  17. <div v-else-if="convo.type == 'link'" class="d-inline-flex mb-0 cursor-pointer">
  18. <div class="card shadow border" style="width:240px;border-radius: 18px;">
  19. <div class="card-body p-0" :title="convo.text">
  20. <div class="media align-items-center">
  21. <div v-if="convo.meta.local" class="bg-primary mr-3 p-3" style="border-radius: 18px;">
  22. <i class="fas fa-link text-white fa-2x"></i>
  23. </div>
  24. <div v-else class="bg-light mr-3 p-3" style="border-radius: 18px;">
  25. <i class="fas fa-link text-lighter fa-2x"></i>
  26. </div>
  27. <div class="media-body text-muted small text-truncate pr-2 font-weight-bold">
  28. {{convo.meta.local ? convo.text.substr(8) : convo.meta.domain}}
  29. </div>
  30. </div>
  31. </div>
  32. </div>
  33. </div>
  34. <p v-else-if="convo.type == 'video'" class="pill-to p-0 shadow mb-0" style="line-height: 0;">
  35. <video :src="convo.media" class="media-embed" style="border-radius:20px;" controls>
  36. </video>
  37. <!-- <span class="d-block bg-primary d-flex align-items-center justify-content-center" style="width:200px;height: 110px;border-radius: 20px;">
  38. <div class="text-center">
  39. <p class="mb-1">
  40. <i class="fas fa-play fa-2x text-white"></i>
  41. </p>
  42. <p class="mb-0 small font-weight-bold text-white">
  43. Play
  44. </p>
  45. </div>
  46. </span> -->
  47. </p>
  48. <p v-else-if="convo.type == 'emoji'" class="p-0 emoji-msg">
  49. {{convo.text}}
  50. </p>
  51. <p v-else-if="convo.type == 'story:react'" class="pill-to p-0 shadow" style="width: 140px;margin-bottom: 10px;position:relative;">
  52. <img :src="convo.meta.story_media_url" width="140" style="border-radius:20px;" onerror="this.onerror=null;this.src='/storage/no-preview.png';">
  53. <span class="badge badge-light rounded-pill border" style="font-size: 20px;position: absolute;bottom:-10px;left:-10px;">
  54. {{convo.meta.reaction}}
  55. </span>
  56. </p>
  57. <span v-else-if="convo.type == 'story:comment'" class="p-0" style="display: flex;justify-content: flex-start;margin-bottom: 10px;position:relative;">
  58. <span class="">
  59. <img class="d-block pill-to p-0 mr-0 pr-0 mb-n1" :src="convo.meta.story_media_url" width="140" style="border-radius:20px;" onerror="this.onerror=null;this.src='/storage/no-preview.png';">
  60. <span class="pill-to shadow text-break" style="width:fit-content;">{{convo.meta.caption}}</span>
  61. </span>
  62. </span>
  63. <p v-else :class="[largerText ? 'pill-to shadow larger-text text-break':'pill-to shadow text-break']">
  64. {{convo.text}}
  65. </p>
  66. <p v-if="convo.type == 'story:react'" class="small text-muted mb-0 ml-0">
  67. <span class="font-weight-bold">{{ convo.meta.story_actor_username }}</span> reacted your story
  68. </p>
  69. <p v-if="convo.type == 'story:comment'" class="small text-muted mb-0 ml-0">
  70. <span class="font-weight-bold">{{ convo.meta.story_actor_username }}</span> replied to your story
  71. </p>
  72. <p
  73. class="msg-timestamp small text-muted font-weight-bold d-flex align-items-center justify-content-start"
  74. data-timestamp="timestamp">
  75. <span
  76. v-if="convo.hidden"
  77. class="small pr-2"
  78. title="Filtered Message"
  79. data-toggle="tooltip"
  80. data-placement="bottom">
  81. <i class="fas fa-lock"></i>
  82. </span>
  83. <span v-if="!hideTimestamps">
  84. {{convo.timeAgo}}
  85. </span>
  86. <button
  87. v-if="convo.isAuthor"
  88. class="btn btn-link btn-sm text-lighter pl-2 font-weight-bold"
  89. @click="confirmDelete">
  90. <i class="far fa-trash-alt"></i>
  91. </button>
  92. </p>
  93. </div>
  94. <img v-if="convo.isAuthor && !hideAvatars" class="ml-3 shadow msg-avatar" :src="profile.avatar" alt="avatar" width="50" onerror="this.onerror=null;this.src='/storage/avatars/default.jpg';">
  95. </div>
  96. </div>
  97. </template>
  98. <script type="text/javascript">
  99. import BigPicture from 'bigpicture';
  100. export default {
  101. props: {
  102. thread: {
  103. type: Object
  104. },
  105. convo: {
  106. type: Object
  107. },
  108. hideAvatars: {
  109. type: Boolean,
  110. default: false
  111. },
  112. hideTimestamps: {
  113. type: Boolean,
  114. default: false
  115. },
  116. largerText: {
  117. type: Boolean,
  118. default: false
  119. }
  120. },
  121. data() {
  122. return {
  123. profile: window._sharedData.user
  124. }
  125. },
  126. methods: {
  127. truncate(t) {
  128. return _.truncate(t);
  129. },
  130. viewOriginal() {
  131. let url = this.ctxContext.media;
  132. window.location.href = url;
  133. return;
  134. },
  135. isEmoji(text) {
  136. const onlyEmojis = text.replace(new RegExp('[\u0000-\u1eeff]', 'g'), '')
  137. const visibleChars = text.replace(new RegExp('[\n\r\s]+|( )+', 'g'), '')
  138. return onlyEmojis.length === visibleChars.length
  139. },
  140. copyText() {
  141. window.App.util.clipboard(this.ctxContext.text);
  142. this.closeCtxMenu();
  143. return;
  144. },
  145. clickLink() {
  146. let url = this.ctxContext.text;
  147. if(this.ctxContext.meta.local != true) {
  148. url = '/i/redirect?url=' + encodeURI(this.ctxContext.text);
  149. }
  150. window.location.href = url;
  151. },
  152. formatCount(val) {
  153. return window.App.util.format.count(val);
  154. },
  155. confirmDelete() {
  156. this.$emit('confirm-delete');
  157. },
  158. expandMedia(e) {
  159. BigPicture({
  160. el: e.target
  161. })
  162. }
  163. }
  164. }
  165. </script>
  166. <style lang="scss" scoped>
  167. .chat-msg {
  168. padding-top: 0;
  169. padding-bottom: 0;
  170. }
  171. .reply-btn {
  172. position: absolute;
  173. bottom: 54px;
  174. right: 20px;
  175. width: 90px;
  176. text-align: center;
  177. border-radius: 0 3px 3px 0;
  178. }
  179. .media-body .bg-primary {
  180. background: linear-gradient(135deg, #2EA2F4 0%, #0B93F6 100%) !important;
  181. }
  182. .pill-to {
  183. background: var(--bg-light);
  184. font-weight: 500;
  185. border-radius: 20px !important;
  186. padding-left: 1rem;
  187. padding-right: 1rem;
  188. padding-top: 0.5rem;
  189. padding-bottom: 0.5rem;
  190. margin-right: 3rem;
  191. margin-bottom: 0.25rem;
  192. }
  193. .pill-from {
  194. color: white !important;
  195. text-align: right !important;
  196. background: linear-gradient(135deg, #2EA2F4 0%, #0B93F6 100%) !important;
  197. font-weight: 500;
  198. border-radius: 20px !important;
  199. padding-left: 1rem;
  200. padding-right: 1rem;
  201. padding-top: 0.5rem;
  202. padding-bottom: 0.5rem;
  203. margin-left: 3rem;
  204. margin-bottom: 0.25rem;
  205. }
  206. .chat-smsg:hover {
  207. background: var(--light-hover-bg);
  208. }
  209. .no-focus {
  210. border: none !important;
  211. }
  212. .no-focus:focus {
  213. outline: none !important;
  214. outline-width: 0 !important;
  215. box-shadow: none;
  216. -moz-box-shadow: none;
  217. -webkit-box-shadow: none;
  218. }
  219. .emoji-msg {
  220. font-size: 4rem !important;
  221. line-height: 30px !important;
  222. margin-top: 10px !important;
  223. }
  224. .larger-text {
  225. font-size: 22px;
  226. }
  227. .dm-chat-message {
  228. .isAuthor {
  229. float: right;
  230. margin-right: 0.5rem !important;
  231. .pill-to {
  232. color: white !important;
  233. text-align: right !important;
  234. background: linear-gradient(135deg, #2EA2F4 0%, #0B93F6 100%) !important;
  235. font-weight: 500;
  236. border-radius: 20px !important;
  237. padding-left: 1rem;
  238. padding-right: 1rem;
  239. padding-top: 0.5rem;
  240. padding-bottom: 0.5rem;
  241. margin-left: 3rem;
  242. margin-right: 0;
  243. margin-bottom: 0.25rem;
  244. }
  245. .msg-timestamp {
  246. display: block !important;
  247. text-align: right;
  248. margin-bottom: 0;
  249. }
  250. }
  251. .msg-avatar {
  252. width: 50px;
  253. height: 50px;
  254. border-radius: 14px;
  255. }
  256. .media-embed {
  257. width: 140px;
  258. border-radius: 20px;
  259. @media (min-width: 450px) {
  260. width: 200px;
  261. }
  262. }
  263. }
  264. </style>