Changeset 0.28.3 (#187)
This commit is contained in:
@@ -338,18 +338,36 @@ func (h *WorkflowInstanceHandler) readWorkflowState(ctx context.Context, channel
|
||||
return
|
||||
}
|
||||
|
||||
// emitWorkflowEvent pushes a workflow event to all connected clients in the channel's room.
|
||||
// emitWorkflowEvent pushes a workflow event to all user participants in the channel.
|
||||
// Uses SendToUser (not room-scoped Bus.Publish) because room subscriptions are
|
||||
// not yet wired on the client side. See websocket.md § Room Model.
|
||||
func (h *WorkflowInstanceHandler) emitWorkflowEvent(label, channelID string, data map[string]any) {
|
||||
if h.hub == nil {
|
||||
return
|
||||
}
|
||||
payload, _ := json.Marshal(data)
|
||||
h.hub.GetBus().Publish(events.Event{
|
||||
evt := events.Event{
|
||||
Label: label,
|
||||
Room: channelID,
|
||||
Payload: payload,
|
||||
Ts: time.Now().UnixMilli(),
|
||||
})
|
||||
}
|
||||
|
||||
// Send to all user participants in the channel
|
||||
rows, err := database.DB.Query(database.Q(`
|
||||
SELECT participant_id FROM channel_participants
|
||||
WHERE channel_id = $1 AND participant_type = 'user'
|
||||
`), channelID)
|
||||
if err != nil {
|
||||
log.Printf("[ws] %s: failed to query participants for channel %s: %v", label, channelID[:min(8, len(channelID))], err)
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var uid string
|
||||
if rows.Scan(&uid) == nil {
|
||||
h.hub.SendToUser(uid, evt)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// triggerOnComplete checks if the workflow has an on_complete chain config
|
||||
|
||||
Reference in New Issue
Block a user