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

feat(iridium): connect to users manager #4353

Merged
merged 9 commits into from
Aug 19, 2022
13 changes: 6 additions & 7 deletions components/interactables/UserPicker/UserPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@ export default Vue.extend({
data: () => ({
selected: [] as Friend[],
filter: '',
friendsList: iridium.friends.state.details,
friendDids: iridium.friends.state.friends,
}),
computed: {
friends() {
if (!this.exclude.length) {
return Object.values(this.friendsList)
}
return Object.values(this.friendsList).filter(
(friend) => !this.exclude.includes(friend.did),
)
return Object.values(this.friendDids)
.filter((did) => !this.exclude.includes(did))
.map((did) => {
return iridium.users.getUser(did)
})
},
filteredFriends(): Friend[] {
if (!this.filter) {
Expand Down
23 changes: 17 additions & 6 deletions components/views/friends/requests/Requests.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ import Vue from 'vue'
import iridium from '~/libraries/Iridium/IridiumManager'
import type { FriendRequest } from '~/libraries/Iridium/friends/types'

function notNull<TValue>(value: TValue | null): value is TValue {
return value !== null
}

export default Vue.extend({
name: 'FriendRequests',
data() {
Expand All @@ -66,15 +70,22 @@ export default Vue.extend({
}
},
computed: {
requests(): FriendRequest[] {
return Object.values(this.friends.requests)
.map((request) => {
const user = iridium.users.getUser(request.user.did)
if (!user) {
return null
}
return { ...request, user }
})
.filter(notNull)
},
incomingRequests(): FriendRequest[] {
return Object.values(this.friends.requests).filter(
(r: FriendRequest) => r.incoming && r.status !== 'accepted',
)
return this.requests.filter((r) => r.incoming && r.status !== 'accepted')
},
outgoingRequests(): FriendRequest[] {
return Object.values(this.friends.requests).filter(
(r: FriendRequest) => !r.incoming && r.status === 'pending',
)
return this.requests.filter((r) => !r.incoming && r.status === 'pending')
},
},
})
Expand Down
7 changes: 2 additions & 5 deletions components/views/friends/search/Search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,13 @@ export default Vue.extend({
this.error = this.$t('friends.self_add') as string
return
}
await iridium.users.searchPeer(friendId)
const hasFriend = iridium.friends.isFriend(friendId)
if (hasFriend) {
this.error = this.$t('friends.already_friend') as string
}

this.user = {
did: friendId,
name: friendId,
status: 'offline',
}
this.user = iridium.users.getUser(friendId)
this.searching = false
},
onFriendRequestSent() {
Expand Down
2 changes: 1 addition & 1 deletion components/views/media/incomingCall/IncomingCall.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default Vue.extend({
if (this.isGroup) {
return
}
return iridium.friends.getFriend(this.incomingCall.did)
return iridium.users.getUser(this.incomingCall.did)
},
callerAvatar(): string {
if (!this.caller) {
Expand Down
4 changes: 2 additions & 2 deletions components/views/navigation/mobile/toolbar/Toolbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default Vue.extend({
},
data() {
return {
friends: iridium.friends.state.details,
users: iridium.users.state,
groups: iridium.groups.state,
isGroupInviteVisible: false,
webrtc: iridium.webRTC.state,
Expand Down Expand Up @@ -65,7 +65,7 @@ export default Vue.extend({
if (!friendDid) {
return
}
return this.friends[friendDid]
return this.users[friendDid]
},
groupMembers(): GroupMemberDetails[] {
const members = (this.details as Group).members ?? []
Expand Down
11 changes: 5 additions & 6 deletions components/views/navigation/sidebar/list/item/Item.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,21 @@
@click="openConversation"
data-cy="sidebar-user"
>
<template v-if="details">
<UiUserState v-if="conversation.type === 'direct'" :user="details" />
<UiGroupIcon v-else :group="details" />
<template>
<UiUserState v-if="conversation.type === 'direct'" :user="user" />
<UiGroupIcon v-else :participants="participants" />
</template>
<div class="user-info">
<TypographyText
v-if="details"
class="ellipsis"
color="light"
font="heading"
weight="bold"
data-cy="sidebar-user-name"
>
{{ details.name }}
{{ conversation.name }}
</TypographyText>
<TypographyText v-if="details" size="sm" data-cy="sidebar-user-name">
<TypographyText size="sm" data-cy="sidebar-user-name">
<div
v-html="wrapEmoji(markdownToHtml(lastMessageDisplay))"
class="ellipsis"
Expand Down
21 changes: 8 additions & 13 deletions components/views/navigation/sidebar/list/item/Item.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ export default Vue.extend({
accounts: (state) => (state as RootState).accounts,
}),
...mapGetters('settings', ['getTimestamp', 'getDate']),
user(): User | null {
return iridium.users.getUser(this.conversation.participants[0])
},
participants(): (User | null)[] {
return this.conversation.participants.map((did) => {
return iridium.users.getUser(did)
})
},
contextMenuValues(): ContextMenuItem[] {
return this.conversation.type === 'direct'
? [
Expand Down Expand Up @@ -96,19 +104,6 @@ export default Vue.extend({
// }
},

details(): User | Group | undefined {
if (this.conversation.type === 'direct') {
const friendDid = this.conversation.participants.find(
(f) => f !== iridium.connector?.id,
)
if (!friendDid) {
return
}
return this.friends[friendDid]
}
return this.groups[this.conversation.id]
},

isSelected(): boolean {
return this.conversation.id === this.$route.params.id
},
Expand Down
10 changes: 5 additions & 5 deletions components/views/navigation/sidebar/live/Live.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default Vue.extend({
data() {
return {
webrtc: iridium.webRTC,
friends: iridium.friends.state.details,
users: iridium.users.state,
groups: iridium.groups.state,
}
},
Expand All @@ -32,7 +32,7 @@ export default Vue.extend({
return false // TODO : Fix later
},
selUserName(): string {
const sUser = Object.values(this.friends).find(
const sUser = Object.values(this.users).find(
(friend) => friend.did === this.webrtc.state.activeCall?.did,
)
return sUser?.name ?? ''
Expand Down Expand Up @@ -62,7 +62,7 @@ export default Vue.extend({
if (!participant) {
return
}
return Object.values(this.friends).find((f) => f.did === participant)
return Object.values(this.users).find((f) => f.did === participant)
},
groupMembers(): GroupMemberDetails[] {
const members = (this.details as Group).members ?? []
Expand All @@ -71,13 +71,13 @@ export default Vue.extend({
enableRTC(): boolean {
if (this.isGroup) {
const memberIds = this.groupMembers.map((m) => m.id)
return Object.values(this.friends).some(
return Object.values(this.users).some(
(friend: Friend) =>
memberIds.includes(friend.did) && friend.status === 'online',
)
}
// Check current recipient is on the user's friends list
const friend = Object.values(this.friends).find(
const friend = Object.values(this.users).find(
(f) => f.did === (this.details as User)?.did,
)
return friend?.status === 'online'
Expand Down
8 changes: 4 additions & 4 deletions components/views/navigation/toolbar/Toolbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default Vue.extend({
searchRecommend,
showAlerts: false,
searchQuery: '' as string,
friends: iridium.friends.state.details,
users: iridium.users.state,
groups: iridium.groups.state,
isGroupInviteVisible: false,
webrtc: iridium.webRTC.state,
Expand Down Expand Up @@ -89,7 +89,7 @@ export default Vue.extend({
if (!friendDid) {
return
}
return this.friends[friendDid]
return this.users[friendDid]
},
groupMembers(): GroupMemberDetails[] {
const members = (this.details as Group).members ?? []
Expand All @@ -108,13 +108,13 @@ export default Vue.extend({
// todo- hook up to usermanager
if (this.isGroup) {
const memberIds = this.groupMembers.map((m) => m.id)
return Object.values(this.friends).some(
return Object.values(this.users).some(
(friend: Friend) =>
memberIds.includes(friend.did) && friend.status === 'online',
)
}
// Check current recipient is on the user's friends list
const friend = Object.values(this.friends).find(
const friend = Object.values(this.users).find(
(f) => f.did === (this.details as User)?.did,
)
return friend?.status === 'online'
Expand Down
26 changes: 25 additions & 1 deletion libraries/Iridium/IridiumManager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Emitter, createIridiumIPFS } from '@satellite-im/iridium'
import type { IridiumIPFS } from '@satellite-im/iridium'
import UsersManager from './users/UsersManager'
import { Account } from '~/libraries/BlockchainClient/interfaces'
import IdentityManager from '~/libraries/Iridium/IdentityManager'
import GroupManager from '~/libraries/Iridium/groups/GroupManager'
Expand All @@ -24,6 +25,7 @@ export class IridiumManager extends Emitter {
notifications: NotificationManager
webRTC: WebRTCManager
settings: SettingsManager
users: UsersManager

constructor() {
super()
Expand All @@ -35,6 +37,7 @@ export class IridiumManager extends Emitter {
this.webRTC = new WebRTCManager(this)
this.settings = new SettingsManager(this)
this.notifications = new NotificationManager(this)
this.users = new UsersManager(this)
}

/**
Expand Down Expand Up @@ -77,7 +80,7 @@ export class IridiumManager extends Emitter {
logger.log('iridium/manager', 'creating new root document', doc)
doc = {
id: this.connector.id,
profile: { name: 'guest' },
profile: {},
groups: {},
friends: {},
conversations: {},
Expand Down Expand Up @@ -108,11 +111,32 @@ export class IridiumManager extends Emitter {
await this.settings.init()
logger.log('iridium/manager', 'notification settings')
await this.notifications.init()
logger.log('iridium/manager', 'initializing users')
await this.users.init()
logger.log('iridium/manager', 'ready')

await this.sendSyncInit()

this.ready = true
}

async sendSyncInit() {
const connector = this.connector
const profile = this.profile.state
if (!connector?.p2p.primaryNodeID || !profile) {
return
}

const payload = {
type: 'sync/init',
at: Date.now(),
name: profile.name,
avatar: profile.photoHash,
}
await connector.p2p.send(connector.p2p.primaryNodeID, payload)
}
}

const instance = new IridiumManager()
window.i = instance
export default instance
2 changes: 1 addition & 1 deletion libraries/Iridium/chat/ChatManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export default class ChatManager extends Emitter<ConversationMessage> {
`/conversations/${conversationId}/message/${message.id}`,
message,
)
const friendName = this.iridium.friends.getFriend(message?.from)
const friendName = this.iridium.users.getUser(message?.from)
const buildNotification: Partial<Notification> = {
fromName: friendName?.name,
at: Date.now(),
Expand Down
Loading