support multiple community description callbacks (#280)
This commit is contained in:
parent
944170247e
commit
aebf9da6c1
|
@ -27,7 +27,7 @@ export class Community {
|
||||||
public description!: CommunityDescription
|
public description!: CommunityDescription
|
||||||
public chats: Map<string, Chat>
|
public chats: Map<string, Chat>
|
||||||
#members: Map<string, Member>
|
#members: Map<string, Member>
|
||||||
public callback: ((description: CommunityDescription) => void) | undefined
|
#descriptionCallbacks: Set<(description: CommunityDescription) => void>
|
||||||
|
|
||||||
constructor(client: Client, publicKey: string) {
|
constructor(client: Client, publicKey: string) {
|
||||||
this.client = client
|
this.client = client
|
||||||
|
@ -37,6 +37,7 @@ export class Community {
|
||||||
|
|
||||||
this.chats = new Map()
|
this.chats = new Map()
|
||||||
this.#members = new Map()
|
this.#members = new Map()
|
||||||
|
this.#descriptionCallbacks = new Set()
|
||||||
}
|
}
|
||||||
|
|
||||||
public async start() {
|
public async start() {
|
||||||
|
@ -220,7 +221,9 @@ export class Community {
|
||||||
this.description = description
|
this.description = description
|
||||||
|
|
||||||
// callback
|
// callback
|
||||||
this.callback?.(this.description)
|
this.#descriptionCallbacks.forEach(callback =>
|
||||||
|
callback({ ...this.description })
|
||||||
|
)
|
||||||
|
|
||||||
// Chats
|
// Chats
|
||||||
// handle
|
// handle
|
||||||
|
@ -231,10 +234,10 @@ export class Community {
|
||||||
}
|
}
|
||||||
|
|
||||||
public onChange = (callback: (description: CommunityDescription) => void) => {
|
public onChange = (callback: (description: CommunityDescription) => void) => {
|
||||||
this.callback = callback
|
this.#descriptionCallbacks.add(callback)
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
this.callback = undefined
|
this.#descriptionCallbacks.delete(callback)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue