Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(friends): move friend method from hounddog into getters #3246

Merged
merged 5 commits into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions components/views/chat/chatbar/Chatbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {
import { Config } from '~/config'
import { UploadDropItemType } from '~/types/files/file'
import { Group } from '~/types/messaging'
import { RootState } from '~/types/store/store'
import { ConversationParticipant } from '~/store/conversation/types'

export default Vue.extend({
components: {
Expand All @@ -41,8 +43,16 @@ export default Vue.extend({
},
computed: {
...mapGetters('chat', ['getFiles']),
...mapState(['ui', 'friends', 'webrtc', 'chat', 'textile', 'conversation']),
activeFriend() {
...mapGetters('friends', ['getActiveFriend']),
...mapState({
ui: (state) => (state as RootState).ui,
friends: (state) => (state as RootState).friends,
webrtc: (state) => (state as RootState).webrtc,
chat: (state) => (state as RootState).chat,
textile: (state) => (state as RootState).textile,
conversation: (state) => (state as RootState).conversation,
}),
activeFriend(): ConversationParticipant {
return this.conversation?.participants?.[0]
},
/**
Expand Down Expand Up @@ -128,7 +138,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', ['findFriendByKey']),
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.findFriendByKey(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', ['findFriendByKey']),
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.findFriendByKey(this.reply.from)

if (friend?.profilePicture) {
return `${this.$Config.textile.browser}/ipfs/${friend?.profilePicture}`
Expand Down
5 changes: 1 addition & 4 deletions components/views/files/upload/Upload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<script lang="ts">
import { FilePlusIcon, PlusIcon } from 'satellite-lucide-icons'
import Vue, { PropType } from 'vue'
import { mapState } from 'vuex'
import { mapState, mapGetters } from 'vuex'
josephmcg marked this conversation as resolved.
Show resolved Hide resolved
import { Config } from '~/config'
import { PropCommonEnum } from '~/libraries/Enums/enums'
import { isHeic } from '~/utilities/FileType'
Expand Down Expand Up @@ -42,9 +42,6 @@ export default Vue.extend({
...mapState({
consentScan: (state) => (state as RootState).settings.consentScan,
}),
activeFriend(): Friend | undefined {
return this.$Hounddog.getActiveFriend(this.$store.state.friends)
},
},
methods: {
/**
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
4 changes: 0 additions & 4 deletions plugins/local/classLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { RootStore } from '~/types/store/store'
import TextileManager from '~/libraries/Textile/TextileManager'
import { TextileFileSystem } from '~/libraries/Files/TextileFileSystem'
// Utils
import Hounddog from '~/utilities/Hounddog'
import BucketManager from '~/libraries/Textile/BucketManager'
import Logger from '~/utilities/Logger'

Expand All @@ -27,7 +26,6 @@ declare module 'vue/types/vue' {
$typedStore: RootStore
$TextileManager: TextileManager
$BucketManager: BucketManager
$Hounddog: Hounddog
$Logger: Logger
$FileSystem: TextileFileSystem
}
Expand All @@ -43,7 +41,6 @@ declare module '@nuxt/types' {
$typedStore: RootStore
$TextileManager: TextileManager
$BucketManager: BucketManager
$Hounddog: Hounddog
$Logger: Logger
$FileSystem: TextileFileSystem
}
Expand All @@ -55,7 +52,6 @@ Vue.prototype.$Crypto = new Crypto()
Vue.prototype.$Security = new Security()
Vue.prototype.$TextileManager = new TextileManager()
Vue.prototype.$Config = Config
Vue.prototype.$Hounddog = new Hounddog(Vue.prototype.$store)
Vue.prototype.$Logger = new Logger(Vue.prototype.$Config.debug)
Vue.prototype.$FileSystem = new TextileFileSystem()

Expand Down
121 changes: 1 addition & 120 deletions store/friends/actions.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import Vue from 'vue'
import { AccountsError } from '../accounts/types'
import { AccountsError, RegistrationStatus } from '../accounts/types'
import * as module from './actions'
import { db } from '~/libraries/SatelliteDB/SatelliteDB'
import SolanaManager from '~/libraries/Solana/SolanaManager/SolanaManager'
import * as Hounddog from '~/utilities/Hounddog'
import { RegistrationStatus } from '~/store/accounts/types'
import { DataStateType } from '~/store/dataState/types'
import FriendsProgram from '~/libraries/Solana/FriendsProgram/FriendsProgram'

Expand All @@ -17,127 +15,10 @@ const mockFPLogger = {

FriendsProgram.mockImplementation(() => mockFPLogger)

const HounddogDefault = Hounddog.default
Vue.prototype.$Hounddog = new HounddogDefault({
accounts: {
storePin: true,
loading: true,
locked: true,
pin: '',
pinHash: '',
active: '',
gasPrice: '',
phrase: '',
error: '',
encryptedPhrase: '',
registered: true,
details: {
name: '',
address: '',
status: '',
state: 'idle',
unreadCount: 123,
profilePicture: '',
badge: 'community',
userAccount: '',
mailboxId: '',
textilePubkey: '',
},
registrationStatus: RegistrationStatus.IN_PROGRESS,
lastVisited: '',
},
dataState: {
files: DataStateType.Empty,
friends: DataStateType.Loading,
search: DataStateType.Ready,
},
friends: {
incomingRequests: [
{
requestId: '',
account: {
accountId: '',
from: '',
status: 123,
fromMailboxId: '',
toMailboxId: '',
to: '',
},
pending: true,
from: '',
userInfo: {
name: '',
servers: {},
status: '',
photoHash: '',
},
},
],
outgoingRequests: [
{
to: '',
requestId: '',
account: {
accountId: '',
from: '',
status: 123,
fromMailboxId: '',
toMailboxId: '',
to: '',
},
pending: true,
},
],
all: [
{
publicKey: 'NoWiFi4you',
typingState: 'NOT_TYPING',
item: {},
pending: true,
activeChat: true,
encryptedTextilePubkey: '',
name: 'Taurus Nix',
address: '0xdf9eb223bafbe5c5271415c75aecd68c21fe3d7f',
account: {
accountId: 'Checking Account',
from: '.',
status: 429,
fromMailboxId: '12345',
toMailboxId: 'v4.0.0-rc.4',
to: './path/to/file',
},
textilePubkey: 'https://accounts.google.com/o/oauth2/revoke?token=%s',
status: '',
state: 'idle',
unreadCount: 123,
profilePicture: '',
badge: 'community',
userAccount: '',
mailboxId: '',
},
],
},
textile: {
initialized: true,
conversations: {},
conversationLoading: true,
messageLoading: true,
uploadProgress: {
abc: {
progress: 42,
finished: false,
name: 'file.pdf',
},
},
},
})
Vue.prototype.$SolanaManager = new SolanaManager()

describe('default functions', () => {
test('module.default.initialize', async () => {
const HounddogConstructor = Vue.prototype.$Hounddog

HounddogConstructor.friendExists = jest.fn().mockReturnValueOnce(true)
const mockData = [
{
key: '1',
Expand Down
Loading