Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

ChatView.vue 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <template lang="pug">
  2. main.view--chat
  3. header.mb6(v-if='profile && grouping')
  4. h3 chatting with:
  5. p {{ target.profile_id }} | {{ grouping.profile.user_name }} | {{ grouping.profile.user_email }}
  6. h3 logged in as:
  7. p {{ profile.id }} | {{ profile._profile.user_name }} | {{ profile._profile.user_email }}
  8. //- p subscriptions: {{ profile.chatter.subscriptions }}
  9. hr
  10. .w-flex.column(v-if='!grouping._loading')
  11. .w-flex.row
  12. button(@click='reveal(7)') reveal my name
  13. button(@click='reveal(8)') reveal my email
  14. // TODO: Remove later, only for testing
  15. button(@click='checkData()') check data
  16. // TODO: Refactor, what if two people have the same name, etc.?
  17. // NOTE: see notes in services/grouping.service.js and
  18. // services/notification.service.js
  19. p you revealed:
  20. span(v-if="grouping.revealed[profile.id.value]")
  21. ul(v-for="reveal in grouping.revealed[profile.id.value]")
  22. li {{ reveal.description }}: {{ profile._profile[reveal.description] }}
  23. p they revealed:
  24. // BUG: persists, but doesn't display upon reveal
  25. span(v-if="grouping.revealed[target.profile_id]")
  26. ul(v-for="reveal in grouping.revealed[target.profile_id]")
  27. li {{ reveal.description }}: {{ target[reveal.description] }}
  28. // BUG: reveals immediately, but does not persist
  29. ul(v-for="revealed in grouping.revealedFromNotification")
  30. li(v-if="revealed[revealed.tag_description] !== profile._profile[revealed.tag_description]") {{ revealed.tag_description }}: {{ revealed[revealed.tag_description] }}
  31. article
  32. template(v-if='isLoading')
  33. w-spinner(bounce)
  34. template(v-if='!isLoading && target')
  35. ul#messages.w-flex.column
  36. template(v-for='chatmessage in messages')
  37. li(
  38. :class='[{ me: chatmessage.publisher == profile.id.value }, chatmessage.publisher]'
  39. v-if='chatmessage.message && chatmessage.message.description'
  40. )
  41. ChatBubble(
  42. :message='chatmessage.message.description'
  43. :publisher-id='chatmessage.publisher'
  44. :time='chatmessage.timetoken'
  45. )
  46. template(v-else-if='!isLoading && !target')
  47. p No match found between profile {{ $route.params.pid }} and {{ profile.id }}...
  48. footer.w-flex.row
  49. w-input(@keyup.enter='sendMessage' outline v-model='toSend')
  50. w-button(@click='sendMessage')
  51. w-icon.icon-paper-plane
  52. MainNav
  53. </template>
  54. <script lang="js">
  55. import ChatBubble from '../components/ChatBubble.vue'
  56. import { currentProfile } from '../services'
  57. import { mixins } from '../utils'
  58. export default {
  59. name: 'ProfileView',
  60. components: { ChatBubble },
  61. mixins: [mixins.profileMixin],
  62. data: () => ({
  63. target: null,
  64. toSend: '',
  65. messages: [],
  66. grouping: {},
  67. them: {},
  68. }),
  69. // TODO: Make sure grouping.profile.profile_id actually exists
  70. computed: {
  71. theyRevealed() {
  72. return this.them
  73. },
  74. },
  75. watch: {
  76. async profile() {
  77. this.loadTargetProfile()
  78. currentProfile._loading.value = true
  79. this.messages = await currentProfile.chatter.getHistory(this.grouping.grouping_name)
  80. currentProfile.chatter.setOnMessage(this._onMessage)
  81. currentProfile._loading.value = false
  82. },
  83. },
  84. async created() {
  85. this.loadTargetProfile()
  86. currentProfile._loading.value = true
  87. this.grouping = this.getGrouping()
  88. this.them = this.grouping.profile
  89. this.messages = await currentProfile.chatter.getHistory(this.grouping.grouping_name)
  90. console.log('this.messages :>> ', this.messages)
  91. currentProfile.chatter.setOnMessage(this._onMessage)
  92. currentProfile._loading.value = false
  93. },
  94. methods: {
  95. async reveal(tagId) {
  96. const grouping = this.getGrouping()
  97. await grouping.reveal(currentProfile.id.value, tagId)
  98. },
  99. // TODO: remove, only for testing reveal()
  100. async checkData() {
  101. console.log('currentProfile :=>', currentProfile)
  102. },
  103. /**
  104. * Pubnub message callback fires when message event
  105. * is detected. We define is HERE because we need the
  106. * component state and `this` context
  107. */
  108. _onMessage(e) {
  109. if (!e.message) return
  110. this.messages.push(e)
  111. },
  112. // TODO: test this
  113. getGrouping() {
  114. if (this.$route.params.pid === currentProfile.profile_id) {
  115. console.warn('WARNING :=> You cannot chat with yourself!!!')
  116. }
  117. return currentProfile.groupings.find(
  118. g => g.profile.profile_id == this.$route.params.pid,
  119. )
  120. },
  121. sendMessage() {
  122. const grouping = this.getGrouping()
  123. currentProfile.chatter.publish(grouping.grouping_name, this.toSend)
  124. this.toSend = ''
  125. },
  126. // TODO: test this
  127. loadTargetProfile() {
  128. try {
  129. const grouping = this.getGrouping()
  130. if (!grouping) {
  131. throw `no match found for ${currentProfile.id.value}`
  132. }
  133. this.target = grouping.profile
  134. } catch (err) {
  135. console.error(err)
  136. }
  137. },
  138. },
  139. }
  140. </script>
  141. <style lang="sass">
  142. main.view--chat
  143. article ul
  144. list-style: none
  145. > li
  146. font-family: sans-serif
  147. background-color: powderblue
  148. margin: 0 0.5em 1em 2em
  149. &.me
  150. margin: 0 2em 1em 0.5em
  151. background-color: lightgreen
  152. p:first-of-type
  153. font-size: 10px
  154. </style>