Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ChatView.vue 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template lang="pug">
  2. main.view--chat
  3. header(v-if='profile')
  4. p {{ profile.chatter }}
  5. hr
  6. p messages: {{ messages }}
  7. hr
  8. p subscriptions: {{ profile.chatter.subscriptions }}
  9. article(v-if='profile.isLoggedIn && target')
  10. h3 {{ profile.id }}&nbsp;
  11. span chatting with: {{ target.profile_id }}
  12. ul#messages.w-flex.column
  13. //- li.pa1(v-for='(message, i in messages)')
  14. //- w-card.w-flex.row
  15. //- article
  16. //- p {{ message.message }}
  17. //- footer
  18. //- p {{ message.publisher }} | {{ message.timetoken }}
  19. //- w-button.my12(@click='openDrawer = i' text) setting
  20. //- w-drawer(absolute v-model='openDrawer' width='160px')
  21. //- p some settings things
  22. input(@keyup.enter='sendMessage' v-model='toSend')
  23. button(@click='sendMessage') send
  24. p(v-else-if='profile.isLoggedIn && !target') No match found between profile {{ $route.params.pid }} and {{ profile.id }}...
  25. w-spinner(bounce v-else)
  26. MainNav
  27. </template>
  28. <script>
  29. import { currentProfile } from '../services'
  30. export default {
  31. name: 'ProfileView',
  32. data: () => ({
  33. target: null,
  34. toSend: '',
  35. messages: [],
  36. openDrawer: null,
  37. }),
  38. computed: {
  39. profile: () => currentProfile,
  40. },
  41. watch: {
  42. profile() {
  43. this.loadTargetProfile()
  44. currentProfile.chatter.setOnMessage(this._onMessage)
  45. },
  46. },
  47. created() {
  48. this.loadTargetProfile()
  49. currentProfile.chatter.setOnMessage(this._onMessage)
  50. },
  51. methods: {
  52. /**
  53. * Pubnub message callback fires when message event
  54. * is detected. We define is HERE because we need the
  55. * component state and `this` context
  56. */
  57. _onMessage(e) {
  58. if (!e.message) return
  59. this.messages.push(e)
  60. },
  61. // TODO: test this
  62. getGrouping() {
  63. return currentProfile.groupings.find(
  64. g => g.profile.profile_id == this.$route.params.pid,
  65. )
  66. },
  67. sendMessage() {
  68. const grouping = this.getGrouping()
  69. currentProfile.chatter.publish(grouping.grouping_name, this.toSend)
  70. this.toSend = ''
  71. },
  72. // TODO: test this
  73. loadTargetProfile() {
  74. try {
  75. const grouping = this.getGrouping()
  76. if (!grouping) {
  77. throw `no match found for ${currentProfile.id.value}`
  78. }
  79. console.log('grouping :', grouping)
  80. this.target = grouping.profile
  81. } catch (err) {
  82. console.error(err)
  83. }
  84. },
  85. },
  86. }
  87. </script>