Skip to content

Commit

Permalink
refactor(chat): replace hounddog calls with store getters
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonwoodland committed May 20, 2022
1 parent ba4027e commit b59f508
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 17 deletions.
3 changes: 2 additions & 1 deletion components/views/chat/chatbar/Chatbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default Vue.extend({
},
computed: {
...mapGetters('chat', ['getFiles']),
...mapGetters('friends', ['getActiveFriend']),
...mapState(['ui', 'friends', 'webrtc', 'chat', 'textile', 'conversation']),
activeFriend() {
return this.conversation?.participants?.[0]
Expand Down Expand Up @@ -128,7 +129,7 @@ export default Vue.extend({
watch: {
'friends.all': {
handler() {
const activeFriend = this.$Hounddog.getActiveFriend(this.friends)
const activeFriend = this.getActiveFriend()
if (activeFriend)
this.recipientTyping =
activeFriend.typingState === PropCommonEnum.TYPING
Expand Down
7 changes: 3 additions & 4 deletions components/views/chat/enhancers/glyphs/item/Item.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<template src="./Item.html"></template>
<script lang="ts">
import Vue, { PropType } from 'vue'
import { mapGetters } from 'vuex'
import { Glyph } from '~/types/ui/glyph'
import loadImg from '~/assets/img/glyphLoader.webp'
Expand Down Expand Up @@ -33,6 +34,7 @@ export default Vue.extend({
}
},
computed: {
...mapGetters('friends', ['findFriendByAddress']),
getSrc(): string {
return this.isLoaded ? this.src.replace('$1', 'small') : loadImg
},
Expand All @@ -54,10 +56,7 @@ export default Vue.extend({
},
sendGlyph() {
const { id, address } = this.$route.params
const activeFriend = this.$Hounddog.findFriendByAddress(
address,
this.$store.state.friends,
)
const activeFriend = this.findFriendByAddress(address)
if (!activeFriend && !id) {
return
Expand Down
5 changes: 3 additions & 2 deletions components/views/chat/group/Group.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template src="./Group.html"></template>
<script lang="ts">
import Vue, { PropType } from 'vue'
import { mapState } from 'vuex'
import { mapState, mapGetters } from 'vuex'
import { Config } from '~/config'
import { Group } from '~/types/messaging'
import {
Expand Down Expand Up @@ -38,6 +38,7 @@ export default Vue.extend({
},
computed: {
...mapState(['ui', 'friends', 'accounts', 'groups']),
...mapGetters('friends', ['findFriend']),
address() {
return (
this.groupMember?.name ||
Expand Down Expand Up @@ -71,7 +72,7 @@ export default Vue.extend({
}
// Try to find the friend you are talking to
const friend = this.$Hounddog.findFriend(this.group.from, this.friends)
const friend = this.findFriend(this.group.from)
if (friend?.profilePicture) {
return `${this.$Config.textile.browser}/ipfs/${friend?.profilePicture}`
Expand Down
9 changes: 4 additions & 5 deletions components/views/chat/message/Message.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template src="./Message.html"></template>
<script lang="ts">
import Vue, { PropType } from 'vue'
import { mapState } from 'vuex'
import { mapState, mapGetters } from 'vuex'
import { ArchiveIcon } from 'satellite-lucide-icons'
import ContextMenu from '~/components/mixins/UI/ContextMenu'
Expand Down Expand Up @@ -63,6 +63,7 @@ export default Vue.extend({
},
computed: {
...mapState(['ui', 'textile', 'accounts']),
...mapGetters('friends', ['findFriendByAddress']),
hasReactions(): boolean {
return (
this.$props.message.reactions && this.$props.message.reactions.length
Expand Down Expand Up @@ -305,10 +306,8 @@ export default Vue.extend({
if (message !== this.$props.message.payload) {
const { address } = this.$route.params
const recipient = this.$Hounddog.findFriendByAddress(
address,
this.$store.state.friends,
)
const recipient = this.findFriendByAddress(address)
if (!recipient) {
this.$store.dispatch('textile/editTextMessage', {
to: this.$store.state.friends.activeConversation.target
Expand Down
5 changes: 3 additions & 2 deletions components/views/chat/message/reply/Item/Item.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template src="./Item.html"></template>
<script lang="ts">
import Vue, { PropType } from 'vue'
import { mapState } from 'vuex'
import { mapState, mapGetters } from 'vuex'
import { UIMessage, Group } from '~/types/messaging'
import {
getUsernameFromState,
Expand Down Expand Up @@ -35,6 +35,7 @@ export default Vue.extend({
},
computed: {
...mapState(['ui', 'friends', 'accounts']),
...mapGetters('friends', ['findFriend']),
address() {
if (!this.reply.from) {
return ''
Expand Down Expand Up @@ -62,7 +63,7 @@ export default Vue.extend({
}
// Try to find the friend you are talking to
const friend = this.$Hounddog.findFriend(this.reply.from, this.friends)
const friend = this.findFriend(this.reply.from)
if (friend?.profilePicture) {
return `${this.$Config.textile.browser}/ipfs/${friend?.profilePicture}`
Expand Down
7 changes: 4 additions & 3 deletions pages/chat/direct/_address.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default Vue.extend({
friendsExist: (state) => (state as RootState).friends?.all?.length > 0,
}),
...mapGetters('textile', ['getInitialized']),
...mapGetters('friends', ['findFriendByAddress']),
groupedMessages() {
const { address } = this.$route.params
const conversation = this.$typedStore.state.textile.conversations[address]
Expand All @@ -34,7 +35,7 @@ export default Vue.extend({
const { address } = this.$route.params
const { friends } = this.$store.state
return this.$Hounddog?.findFriendByAddress(address, friends)
return this.findFriendByAddress(address)
},
},
watch: {
Expand All @@ -52,7 +53,7 @@ export default Vue.extend({
const { address } = this.$route.params
const { friends } = this.$store.state
const friend = this.$Hounddog?.findFriendByAddress(address, friends)
const friend = this.findFriendByAddress(address)
if (address && friend) {
this.$store.dispatch('textile/fetchMessages', {
Expand All @@ -71,7 +72,7 @@ export default Vue.extend({
const { address } = this.$route.params
const { friends } = this.$store.state
const friend = this.$Hounddog?.findFriendByAddress(address, friends)
const friend = this.findFriendByAddress(address)
if (address && friend) return
Expand Down

0 comments on commit b59f508

Please sign in to comment.