Skip to content

Commit 625a08d

Browse files
committed
feat(conversation): add support for nested websocket property updates and broadcast changes for all contact and custom attributes
1 parent bf1510b commit 625a08d

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

cmd/conversation.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,8 @@ func handleUpdateContactCustomAttributes(r *fastglue.Request) error {
546546
if err := app.user.UpdateCustomAttributes(conversation.ContactID, attributes); err != nil {
547547
return sendErrorEnvelope(r, err)
548548
}
549+
// Broadcast update.
550+
app.conversation.BroadcastConversationUpdate(conversation.UUID, "contact.custom_attributes", attributes)
549551
return r.SendEnvelope(true)
550552
}
551553

frontend/src/stores/conversation.js

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -611,15 +611,34 @@ export const useConversationStore = defineStore('conversation', () => {
611611
}
612612
}
613613

614+
/**
615+
* Update a conversation property, supports nested paths via dot notation
616+
* @param {Object} update - { uuid, prop, value }
617+
*/
614618
function updateConversationProp (update) {
615-
// Update the current conversation if it matches the UUID.
616-
if (conversation.data?.uuid === update.uuid) {
617-
conversation.data[update.prop] = update.value
619+
const updateNested = (obj, prop, value) => {
620+
if (!prop.includes('.')) {
621+
obj[prop] = value
622+
return
623+
}
624+
625+
const keys = prop.split('.')
626+
const lastKey = keys.pop()
627+
const target = keys.reduce((o, key) => o[key] = o[key] || {}, obj)
628+
target[lastKey] = value
618629
}
619-
// Update the conversation in the list if it exists.
620-
const existingConversation = conversations?.data?.find(c => c.uuid === update.uuid)
630+
631+
const { uuid, prop, value } = update
632+
633+
// Conversation is currently open? Update it.
634+
if (conversation.data?.uuid === uuid) {
635+
updateNested(conversation.data, prop, value)
636+
}
637+
638+
// Update conversation if it exists in the list.
639+
const existingConversation = conversations?.data?.find(c => c.uuid === uuid)
621640
if (existingConversation) {
622-
existingConversation[update.prop] = update.value
641+
updateNested(existingConversation, prop, value)
623642
}
624643
}
625644

internal/conversation/conversation.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,8 @@ func (c *Manager) UpdateConversationCustomAttributes(uuid string, customAttribut
924924
c.lo.Error("error updating conversation custom attributes", "error", err)
925925
return envelope.NewError(envelope.GeneralError, c.i18n.Ts("globals.messages.errorUpdating", "name", "{globals.terms.conversation}"), nil)
926926
}
927+
// Broadcast the custom attributes update.
928+
c.BroadcastConversationUpdate(uuid, "custom_attributes", customAttributes)
927929
return nil
928930
}
929931

0 commit comments

Comments
 (0)