Skip to content

Commit

Permalink
SDK - rename user metadata helpers to member metadata (#821)
Browse files Browse the repository at this point in the history
We have user streams, and these are not that. I want to rename the
UserDeviceKeyPayload to something more generic. UserMetadataPayload
seemed like the obvious choice, but the namespace was taken by helpers
for the member payload.

This should be renamed either way, member metadata is more correct here.
  • Loading branch information
texuf authored Aug 20, 2024
1 parent 800aec5 commit 6d02e8d
Show file tree
Hide file tree
Showing 15 changed files with 77 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { StreamStateEvents } from './streamEvents'
import { bin_toString, dlog } from '@river-build/dlog'
import { userIdFromAddress } from './id'

export class userMetadata_Nft {
export class MemberMetadata_Nft {
log = dlog('csb:streams:Nft')
readonly streamId: string
readonly userIdToEventId = new Map<string, string>()
Expand Down
8 changes: 5 additions & 3 deletions packages/sdk/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ export class Client
check(isDefined(this.cryptoBackend))
const stream = this.stream(streamId)
check(isDefined(stream), 'stream not found')
stream.view.getUserMetadata().usernames.setLocalUsername(this.userId, username)
stream.view.getMemberMetadata().usernames.setLocalUsername(this.userId, username)
const encryptedData = await this.cryptoBackend.encryptGroupEvent(streamId, username)
encryptedData.checksum = usernameChecksum(username, streamId)
try {
Expand All @@ -941,7 +941,7 @@ export class Client
},
)
} catch (err) {
stream.view.getUserMetadata().usernames.resetLocalUsername(this.userId)
stream.view.getMemberMetadata().usernames.resetLocalUsername(this.userId)
throw err
}
}
Expand Down Expand Up @@ -1004,7 +1004,9 @@ export class Client
isUsernameAvailable(streamId: string, username: string): boolean {
const stream = this.streams.get(streamId)
check(isDefined(stream), 'stream not found')
return stream.view.getUserMetadata().usernames.cleartextUsernameAvailable(username) ?? false
return (
stream.view.getMemberMetadata().usernames.cleartextUsernameAvailable(username) ?? false
)
}

async waitForStream(
Expand Down
10 changes: 5 additions & 5 deletions packages/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export * from './streamStateView_UnknownContent'
export * from './streamStateView_User'
export * from './streamStateView_UserDeviceKey'
export * from './streamStateView_UserInbox'
export * from './streamStateView_UserMetadata'
export * from './streamStateView_MemberMetadata'
export * from './streamStateView_UserSettings'
export * from './streamUtils'
export * from './sync-agent/db'
Expand Down Expand Up @@ -71,8 +71,8 @@ export * from './syncedStreams'
export * from './syncedStreamsExtension'
export * from './types'
export * from './unauthenticatedClient'
export * from './userMetadata_DisplayNames'
export * from './userMetadata_EnsAddresses'
export * from './userMetadata_Nft'
export * from './userMetadata_Usernames'
export * from './memberMetadata_DisplayNames'
export * from './memberMetadata_EnsAddresses'
export * from './MemberMetadata_Nft'
export * from './memberMetadata_Usernames'
export * from './utils'
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { make_MemberPayload_Nft } from './types'
import { bin_fromString, bin_toString } from '@river-build/dlog'

describe('userMetadataTests', () => {
describe('memberMetadataTests', () => {
let bobsClient: Client
let alicesClient: Client
let evesClient: Client
Expand Down Expand Up @@ -68,7 +68,7 @@ describe('userMetadataTests', () => {
const expected = new Map<string, string>([[bobsClient.userId, 'bob']])
for (const client of [bobsClient, alicesClient]) {
const streamView = client.streams.get(streamId)!.view
expect(streamView.getUserMetadata().displayNames.plaintextDisplayNames).toEqual(
expect(streamView.getMemberMetadata().displayNames.plaintextDisplayNames).toEqual(
expected,
)
}
Expand Down Expand Up @@ -116,7 +116,7 @@ describe('userMetadataTests', () => {
const streamView = client.streams.get(streamId)?.view
expect(streamView).toBeDefined()
const clientDisplayNames =
streamView!.getUserMetadata().displayNames.plaintextDisplayNames
streamView!.getMemberMetadata().displayNames.plaintextDisplayNames
expect(clientDisplayNames).toEqual(expected)
}
})
Expand Down Expand Up @@ -176,7 +176,7 @@ describe('userMetadataTests', () => {
const streamView = client.streams.get(streamId)?.view
expect(streamView).toBeDefined()
const clientDisplayNames =
streamView!.getUserMetadata().displayNames.plaintextDisplayNames
streamView!.getMemberMetadata().displayNames.plaintextDisplayNames
expect(clientDisplayNames).toEqual(expected)
}
})
Expand Down Expand Up @@ -204,7 +204,7 @@ describe('userMetadataTests', () => {

const expected = new Map<string, string>([[bobsClient.userId, 'bob']])
const alicesClientDisplayNames =
alicesClient.streams.get(streamId)?.view.membershipContent.userMetadata.displayNames
alicesClient.streams.get(streamId)?.view.membershipContent.memberMetadata.displayNames
.plaintextDisplayNames
expect(alicesClientDisplayNames).toEqual(expected)
})
Expand Down Expand Up @@ -239,13 +239,13 @@ describe('userMetadataTests', () => {
const expected = new Map<string, string>([[bobsClient.userId, 'bob-username']])
// expect username to get updated immediately
expect(
bobsClient.streams.get(streamId)!.view.getUserMetadata().usernames.plaintextUsernames,
bobsClient.streams.get(streamId)!.view.getMemberMetadata().usernames.plaintextUsernames,
).toEqual(expected)

expect(
bobsClient.streams
.get(streamId)!
.view.getUserMetadata()
.view.getMemberMetadata()
.usernames.info(bobsClient.userId).username,
).toEqual('bob-username')

Expand All @@ -257,10 +257,10 @@ describe('userMetadataTests', () => {

for (const client of [bobsClient, alicesClient]) {
const streamView = client.streams.get(streamId)!.view
expect(streamView.getUserMetadata().usernames.plaintextUsernames).toEqual(expected)
expect(streamView.getUserMetadata().usernames.info(bobsClient.userId).username).toEqual(
'bob-username',
)
expect(streamView.getMemberMetadata().usernames.plaintextUsernames).toEqual(expected)
expect(
streamView.getMemberMetadata().usernames.info(bobsClient.userId).username,
).toEqual('bob-username')
}
})

Expand Down Expand Up @@ -304,7 +304,7 @@ describe('userMetadataTests', () => {

for (const client of [bobsClient, alicesClient]) {
const streamView = client.streams.get(streamId)!.view
expect(streamView.getUserMetadata()?.usernames.plaintextUsernames).toEqual(expected)
expect(streamView.getMemberMetadata()?.usernames.plaintextUsernames).toEqual(expected)
}
})

Expand Down Expand Up @@ -365,7 +365,7 @@ describe('userMetadataTests', () => {

for (const client of [bobsClient, alicesClient, evesClient]) {
const streamView = client.streams.get(streamId)!.view
expect(streamView.getUserMetadata().usernames.plaintextUsernames).toEqual(expected)
expect(streamView.getMemberMetadata().usernames.plaintextUsernames).toEqual(expected)
}
})

Expand Down Expand Up @@ -407,7 +407,7 @@ describe('userMetadataTests', () => {
])
for (const client of [bobsClient, alicesClient]) {
const streamView = client.streams.get(streamId)!.view
expect(streamView.getUserMetadata().ensAddresses.confirmedEnsAddresses).toEqual(
expect(streamView.getMemberMetadata().ensAddresses.confirmedEnsAddresses).toEqual(
expected,
)
}
Expand Down Expand Up @@ -455,7 +455,7 @@ describe('userMetadataTests', () => {
for (const client of [bobsClient, alicesClient]) {
const streamView = client.streams.get(streamId)?.view
expect(streamView).toBeDefined()
const ensAddresses = streamView!.getUserMetadata().ensAddresses.confirmedEnsAddresses
const ensAddresses = streamView!.getMemberMetadata().ensAddresses.confirmedEnsAddresses
expect(ensAddresses).toEqual(expected)
}
})
Expand Down Expand Up @@ -515,7 +515,7 @@ describe('userMetadataTests', () => {
for (const client of [bobsClient, alicesClient, evesClient]) {
const streamView = client.streams.get(streamId)?.view
expect(streamView).toBeDefined()
const ensAddresses = streamView!.getUserMetadata().ensAddresses.confirmedEnsAddresses
const ensAddresses = streamView!.getMemberMetadata().ensAddresses.confirmedEnsAddresses
expect(ensAddresses).toEqual(expected)
}
})
Expand Down Expand Up @@ -591,9 +591,9 @@ describe('userMetadataTests', () => {
const expected = new Map<string, MemberPayload_Nft>([[bobsClient.userId, nft]])
for (const client of [bobsClient, alicesClient]) {
const streamView = client.streams.get(streamId)!.view
expect(streamView.getUserMetadata().nfts.confirmedNfts).toEqual(expected)
const bobInfo = streamView.getUserMetadata().nfts.info(bobsClient.userId)
expect(bobInfo!.tokenId).toEqual('11111111112222222233333333')
expect(streamView.getMemberMetadata().nfts.confirmedNfts).toEqual(expected)
const bobInfo = streamView.getMemberMetadata().nfts.info(bobsClient.userId)
expect(bobInfo?.tokenId).toEqual('11111111112222222233333333')
}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
*/

import { EncryptedData } from '@river-build/proto'
import { UserMetadata_DisplayNames } from './userMetadata_DisplayNames'
import { MemberMetadata_DisplayNames } from './memberMetadata_DisplayNames'

describe('userMetadata_DisplayNamesTests', () => {
describe('memberMetadata_DisplayNamesTests', () => {
const streamId = 'streamid1'
let displayNames: UserMetadata_DisplayNames
let displayNames: MemberMetadata_DisplayNames
beforeEach(() => {
displayNames = new UserMetadata_DisplayNames(streamId)
displayNames = new MemberMetadata_DisplayNames(streamId)
})

test('clientCanSetDisplayName', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import TypedEmitter from 'typed-emitter'
import { dlog } from '@river-build/dlog'
import { StreamEncryptionEvents, StreamStateEvents } from './streamEvents'

export class UserMetadata_DisplayNames {
export class MemberMetadata_DisplayNames {
log = dlog('csb:streams:displaynames')
readonly streamId: string
readonly userIdToEventId = new Map<string, string>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
*/

import { userIdFromAddress } from './id'
import { userMetadata_EnsAddresses } from './userMetadata_EnsAddresses'
import { MemberMetadata_EnsAddresses } from './memberMetadata_EnsAddresses'
import { makeRandomUserAddress } from './util.test'

describe('userMetadata_EnsAddressesTests', () => {
describe('memberMetadata_EnsAddressesTests', () => {
const streamId = 'streamid1'
let ensAddresses: userMetadata_EnsAddresses
let ensAddresses: MemberMetadata_EnsAddresses
beforeEach(() => {
ensAddresses = new userMetadata_EnsAddresses(streamId)
ensAddresses = new MemberMetadata_EnsAddresses(streamId)
})

test('clientCanSetEnsAddress', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { dlog } from '@river-build/dlog'
import { StreamStateEvents } from './streamEvents'
import { userIdFromAddress } from './id'

export class userMetadata_EnsAddresses {
export class MemberMetadata_EnsAddresses {
log = dlog('csb:streams:ensAddresses')
readonly streamId: string
readonly userIdToEventId = new Map<string, string>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
*/

import { MemberPayload_Nft } from '@river-build/proto'
import { userMetadata_Nft } from './userMetadata_Nft'
import { MemberMetadata_Nft } from './MemberMetadata_Nft'
import { makeRandomUserAddress } from './util.test'
import { bin_fromString } from '@river-build/dlog'

describe('userMetadata_NftTests', () => {
describe('memberMetadata_NftTests', () => {
const streamId = 'streamid1'
let nfts: userMetadata_Nft
let nfts: MemberMetadata_Nft
beforeEach(() => {
nfts = new userMetadata_Nft(streamId)
nfts = new MemberMetadata_Nft(streamId)
})

test('clientCanSetNft', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
*/

import { EncryptedData } from '@river-build/proto'
import { UserMetadata_Usernames } from './userMetadata_Usernames'
import { MemberMetadata_Usernames } from './memberMetadata_Usernames'
import { usernameChecksum } from './utils'

describe('userMetadata_UsernamesTests', () => {
describe('memberMetadata_UsernamesTests', () => {
const streamId = 'streamid1'
let usernames: UserMetadata_Usernames
let usernames: MemberMetadata_Usernames
beforeEach(() => {
usernames = new UserMetadata_Usernames(streamId)
usernames = new MemberMetadata_Usernames(streamId)
})

test('clientCanSetUsername', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { usernameChecksum } from './utils'
import { dlog } from '@river-build/dlog'
import { StreamEncryptionEvents, StreamStateEvents } from './streamEvents'

export class UserMetadata_Usernames {
export class MemberMetadata_Usernames {
log = dlog('csb:streams:usernames')
readonly streamId: string
readonly plaintextUsernames = new Map<string, string>()
Expand Down
8 changes: 4 additions & 4 deletions packages/sdk/src/streamStateView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import {
import { StreamStateView_UserInbox } from './streamStateView_UserInbox'
import { DecryptedContent } from './encryptedContentTypes'
import { StreamStateView_UnknownContent } from './streamStateView_UnknownContent'
import { StreamStateView_UserMetadata } from './streamStateView_UserMetadata'
import { StreamStateView_MemberMetadata } from './streamStateView_MemberMetadata'
import { StreamStateView_ChannelMetadata } from './streamStateView_ChannelMetadata'
import { StreamEvents, StreamEncryptionEvents, StreamStateEvents } from './streamEvents'
import isEqual from 'lodash/isEqual'
Expand Down Expand Up @@ -83,7 +83,7 @@ export interface IStreamStateView {
get userInboxContent(): StreamStateView_UserInbox
get mediaContent(): StreamStateView_Media
getMembers(): StreamStateView_Members
getUserMetadata(): StreamStateView_UserMetadata
getMemberMetadata(): StreamStateView_MemberMetadata
getChannelMetadata(): StreamStateView_ChannelMetadata | undefined
getContent(): StreamStateView_AbstractContent
userIsEntitledToKeyExchange(userId: string): boolean
Expand Down Expand Up @@ -746,8 +746,8 @@ export class StreamStateView implements IStreamStateView {
return this.membershipContent
}

getUserMetadata(): StreamStateView_UserMetadata {
return this.membershipContent.userMetadata
getMemberMetadata(): StreamStateView_MemberMetadata {
return this.membershipContent.memberMetadata
}

getChannelMetadata(): StreamStateView_ChannelMetadata | undefined {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import {
import TypedEmitter from 'typed-emitter'
import { ConfirmedTimelineEvent, RemoteTimelineEvent } from './types'
import { StreamEncryptionEvents, StreamStateEvents } from './streamEvents'
import { UserMetadata_Usernames } from './userMetadata_Usernames'
import { UserMetadata_DisplayNames } from './userMetadata_DisplayNames'
import { MemberMetadata_Usernames } from './memberMetadata_Usernames'
import { MemberMetadata_DisplayNames } from './memberMetadata_DisplayNames'
import { bin_toHexString } from '@river-build/dlog'
import { userMetadata_EnsAddresses } from './userMetadata_EnsAddresses'
import { userMetadata_Nft } from './userMetadata_Nft'
import { MemberMetadata_EnsAddresses } from './memberMetadata_EnsAddresses'
import { MemberMetadata_Nft } from './MemberMetadata_Nft'

export type UserInfo = {
username: string
Expand All @@ -26,17 +26,17 @@ export type UserInfo = {
}
}

export class StreamStateView_UserMetadata {
readonly usernames: UserMetadata_Usernames
readonly displayNames: UserMetadata_DisplayNames
readonly ensAddresses: userMetadata_EnsAddresses
readonly nfts: userMetadata_Nft
export class StreamStateView_MemberMetadata {
readonly usernames: MemberMetadata_Usernames
readonly displayNames: MemberMetadata_DisplayNames
readonly ensAddresses: MemberMetadata_EnsAddresses
readonly nfts: MemberMetadata_Nft

constructor(streamId: string) {
this.usernames = new UserMetadata_Usernames(streamId)
this.displayNames = new UserMetadata_DisplayNames(streamId)
this.ensAddresses = new userMetadata_EnsAddresses(streamId)
this.nfts = new userMetadata_Nft(streamId)
this.usernames = new MemberMetadata_Usernames(streamId)
this.displayNames = new MemberMetadata_DisplayNames(streamId)
this.ensAddresses = new MemberMetadata_EnsAddresses(streamId)
this.nfts = new MemberMetadata_Nft(streamId)
}

applySnapshot(
Expand Down
Loading

0 comments on commit 6d02e8d

Please sign in to comment.