updateConvo convenience method

This commit is contained in:
Samuel Newman
2026-04-24 10:49:13 +03:00
parent a20c576df9
commit ee88dbcad2
+20 -20
View File
@@ -538,6 +538,14 @@ export class Convo {
this.convo = parseConvoView(convo, this.senderUserDid) ?? this.convo this.convo = parseConvoView(convo, this.senderUserDid) ?? this.convo
} }
private updateConvo(convo: Partial<ChatBskyConvoDefs.ConvoView>) {
if (this.convo) {
this.convo =
parseConvoView({...this.convo.view, ...convo}, this.senderUserDid) ??
this.convo
}
}
/** /**
* Initialises the convo with placeholder data, if provided. We still refetch it before rendering the convo, * Initialises the convo with placeholder data, if provided. We still refetch it before rendering the convo,
* but this allows us to render the convo header immediately. * but this allows us to render the convo header immediately.
@@ -944,8 +952,7 @@ export class Convo {
message, message,
}) })
if (this.convo?.view.status === 'request') { if (this.convo?.view.status === 'request') {
this.setConvo({ this.updateConvo({
...this.convo.view,
status: 'accepted', status: 'accepted',
}) })
} }
@@ -957,22 +964,18 @@ export class Convo {
} }
markConvoAccepted() { markConvoAccepted() {
if (this.convo) { this.updateConvo({
this.setConvo({
...this.convo.view,
status: 'accepted', status: 'accepted',
}) })
}
this.commit() this.commit()
} }
updateMuted(muted: boolean) { updateMuted(muted: boolean) {
if (this.convo) { this.updateConvo({
this.setConvo({
...this.convo.view,
muted, muted,
}) })
}
this.commit() this.commit()
} }
@@ -981,8 +984,7 @@ export class Convo {
throw new Error('updateGroupName can only be called on group convo') throw new Error('updateGroupName can only be called on group convo')
} }
this.setConvo({ this.updateConvo({
...this.convo.view,
kind: { kind: {
...this.convo.details, ...this.convo.details,
name, name,
@@ -996,12 +998,11 @@ export class Convo {
if (this.convo?.kind !== 'group') { if (this.convo?.kind !== 'group') {
throw new Error('updateGroupMembers can only be called on group convo') throw new Error('updateGroupMembers can only be called on group convo')
} }
if (this.convo) {
this.setConvo({ this.updateConvo({
...this.convo.view,
members, members,
}) })
}
this.commit() this.commit()
} }
@@ -1009,15 +1010,14 @@ export class Convo {
if (this.convo?.kind !== 'group') { if (this.convo?.kind !== 'group') {
throw new Error('updateJoinLink can only be called on group convo') throw new Error('updateJoinLink can only be called on group convo')
} }
if (this.convo) {
this.setConvo({ this.updateConvo({
...this.convo.view,
kind: { kind: {
...this.convo.details, ...this.convo.details,
joinLink, joinLink,
}, },
}) })
}
this.commit() this.commit()
} }