1
1
import { AppWebsocket , CellId } from '@holochain/client'
2
2
import { WeServices } from '@lightningrodlabs/we-applet'
3
- import { ObjectFlags } from 'typescript'
4
- import { PROFILES_ZOME_NAME } from '../holochainConfig'
5
3
import { Profile , WhoAmIOutput } from '../types'
6
4
import { AgentPubKeyB64 , UpdateInput } from '../types/shared'
7
- import callZome from './callZome'
8
5
import { WireRecord } from './hdkCrud'
6
+ import { get } from 'svelte/store'
9
7
10
- const ZOME_FN_NAMES = {
11
- CREATE_WHOAMI : 'create_whoami' ,
12
- CREATE_IMPORTED_PROFILE : 'create_imported_profile' ,
13
- UPDATE_WHOAMI : 'update_whoami' ,
14
- WHOAMI : 'whoami' ,
15
- FETCH_AGENTS : 'fetch_agents' ,
16
- FETCH_AGENT_ADDRESS : 'fetch_agent_address' ,
17
- }
18
8
function weToAcornProfile ( weProfile : WeProfile ) : Profile {
19
9
let acornProfile : Profile
20
10
Object . keys ( weProfile . fields ) . forEach ( ( key ) => {
@@ -40,8 +30,7 @@ function acornToWeProfile(acornProfile: Profile, nickname: string): WeProfile {
40
30
return weProfile
41
31
}
42
32
async function getMyNickname ( weServices : WeServices ) : Promise < string > {
43
- let myWeProfile : WeProfile
44
- ( await weServices . profilesStore . fetchMyProfile ( ) ) . subscribe ( ( profile ) => { myWeProfile = profile } )
33
+ let myWeProfile = get ( await weServices . profilesStore . fetchMyProfile ( ) ) ;
45
34
return myWeProfile . nickname
46
35
}
47
36
export interface WeProfile {
@@ -84,8 +73,7 @@ const WeProfilesApi = (appWebsocket: AppWebsocket, weServices: WeServices) => {
84
73
}
85
74
} ,
86
75
whoami : async ( cellId : CellId ) : Promise < WhoAmIOutput > => {
87
- let myWeProfile
88
- ( await weServices . profilesStore . fetchMyProfile ( ) ) . subscribe ( ( profile ) => { myWeProfile = profile } )
76
+ let myWeProfile = get ( await weServices . profilesStore . fetchMyProfile ( ) ) ;
89
77
return {
90
78
actionHash : null ,
91
79
entryHash : null ,
@@ -95,22 +83,12 @@ const WeProfilesApi = (appWebsocket: AppWebsocket, weServices: WeServices) => {
95
83
}
96
84
} ,
97
85
fetchAgents : async ( cellId : CellId ) : Promise < Array < Profile > > => {
98
- return callZome (
99
- appWebsocket ,
100
- cellId ,
101
- PROFILES_ZOME_NAME ,
102
- ZOME_FN_NAMES . FETCH_AGENTS ,
103
- null
104
- )
86
+ let profiles : Array < Profile > = get ( await weServices . profilesStore . fetchAllProfiles ( ) ) . values ( ) . map ( ( weProfile ) => weToAcornProfile ( weProfile ) ) ;
87
+ return profiles
105
88
} ,
106
89
fetchAgentAddress : async ( cellId : CellId ) : Promise < AgentPubKeyB64 > => {
107
- return callZome (
108
- appWebsocket ,
109
- cellId ,
110
- PROFILES_ZOME_NAME ,
111
- ZOME_FN_NAMES . FETCH_AGENT_ADDRESS ,
112
- null
113
- )
90
+ // is this an alright way to convert the byte array to string?
91
+ return new TextDecoder ( ) . decode ( weServices . profilesStore . myAgentPubKey )
114
92
} ,
115
93
}
116
94
}
0 commit comments