From ee88dbcad20116d2a63e345d1a74aa8dd663a5e5 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Fri, 24 Apr 2026 10:49:13 +0300 Subject: [PATCH] updateConvo convenience method --- src/state/messages/convo/agent.ts | 62 +++++++++++++++---------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/src/state/messages/convo/agent.ts b/src/state/messages/convo/agent.ts index 7167f4858f..31b079bfb7 100644 --- a/src/state/messages/convo/agent.ts +++ b/src/state/messages/convo/agent.ts @@ -538,6 +538,14 @@ export class Convo { this.convo = parseConvoView(convo, this.senderUserDid) ?? this.convo } + private updateConvo(convo: Partial) { + 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, * but this allows us to render the convo header immediately. @@ -944,8 +952,7 @@ export class Convo { message, }) if (this.convo?.view.status === 'request') { - this.setConvo({ - ...this.convo.view, + this.updateConvo({ status: 'accepted', }) } @@ -957,22 +964,18 @@ export class Convo { } markConvoAccepted() { - if (this.convo) { - this.setConvo({ - ...this.convo.view, - status: 'accepted', - }) - } + this.updateConvo({ + status: 'accepted', + }) + this.commit() } updateMuted(muted: boolean) { - if (this.convo) { - this.setConvo({ - ...this.convo.view, - muted, - }) - } + this.updateConvo({ + muted, + }) + this.commit() } @@ -981,8 +984,7 @@ export class Convo { throw new Error('updateGroupName can only be called on group convo') } - this.setConvo({ - ...this.convo.view, + this.updateConvo({ kind: { ...this.convo.details, name, @@ -996,12 +998,11 @@ export class Convo { if (this.convo?.kind !== 'group') { throw new Error('updateGroupMembers can only be called on group convo') } - if (this.convo) { - this.setConvo({ - ...this.convo.view, - members, - }) - } + + this.updateConvo({ + members, + }) + this.commit() } @@ -1009,15 +1010,14 @@ export class Convo { if (this.convo?.kind !== 'group') { throw new Error('updateJoinLink can only be called on group convo') } - if (this.convo) { - this.setConvo({ - ...this.convo.view, - kind: { - ...this.convo.details, - joinLink, - }, - }) - } + + this.updateConvo({ + kind: { + ...this.convo.details, + joinLink, + }, + }) + this.commit() }