@@ -156,98 +156,21 @@ func (ec *EventCoordinator) EmitItemUpdatedWithContext(original, updated *models
156156func (ec * EventCoordinator ) emitItemUpdatedInternal (original , updated * models.Item , statusChanged , assigneeChanged bool , actorUserID int , fieldChanges []HistoryEntry , actionContext * ActionContext , actorUsername ... string ) {
157157 actorName := resolveActorName (actorUserID , actorUsername )
158158
159- // Construct the item key (e.g., "TST-1")
160- itemKey := fmt .Sprintf ("%s-%d" , updated .WorkspaceKey , updated .WorkspaceItemNumber )
161-
162- // Emit notification events
163159 if ec .notificationService != nil {
164- // Get status name if status changed
165160 var statusName string
166- if statusChanged && updated .StatusID != nil {
167- _ = ec .db .QueryRow ("SELECT name FROM statuses WHERE id = ?" , * updated .StatusID ).Scan (& statusName )
168- }
169-
170- // Emit status changed notification
171161 if statusChanged {
172- ec .notificationService .EmitEvent (& NotificationEvent {
173- EventType : models .EventStatusChanged ,
174- WorkspaceID : updated .WorkspaceID ,
175- ActorUserID : actorUserID ,
176- ItemID : updated .ID ,
177- AssigneeID : updated .AssigneeID ,
178- CreatorID : original .CreatorID ,
179- Title : "Status Changed" ,
180- TemplateData : map [string ]any {
181- "item.title" : updated .Title ,
182- "item.key" : itemKey ,
183- "item.id" : updated .ID ,
184- "status.name" : statusName ,
185- "user.name" : actorName ,
186- },
187- })
188- }
189-
190- // Emit assignee changed notification
191- if assigneeChanged {
192- ec .notificationService .EmitEvent (& NotificationEvent {
193- EventType : models .EventItemAssigned ,
194- WorkspaceID : updated .WorkspaceID ,
195- ActorUserID : actorUserID ,
196- ItemID : updated .ID ,
197- AssigneeID : updated .AssigneeID ,
198- CreatorID : original .CreatorID ,
199- Title : "Item Assigned" ,
200- TemplateData : map [string ]any {
201- "item.title" : updated .Title ,
202- "item.key" : itemKey ,
203- "item.id" : updated .ID ,
204- "user.name" : actorName ,
205- },
206- })
207- }
208-
209- // Emit item updated notification (when not status or assignee change)
210- if ! statusChanged && ! assigneeChanged {
211- ec .notificationService .EmitEvent (& NotificationEvent {
212- EventType : models .EventItemUpdated ,
213- WorkspaceID : updated .WorkspaceID ,
214- ActorUserID : actorUserID ,
215- ItemID : updated .ID ,
216- AssigneeID : updated .AssigneeID ,
217- CreatorID : original .CreatorID ,
218- Title : "Item Updated" ,
219- TemplateData : map [string ]any {
220- "item.title" : updated .Title ,
221- "item.key" : itemKey ,
222- "item.id" : updated .ID ,
223- "user.name" : actorName ,
224- },
225- })
162+ statusName , _ = itemUpdateStatusName (ec .db , updated .StatusID )
226163 }
164+ emitItemUpdateNotifications (ec .notificationService .EmitEvent , original , updated ,
165+ statusChanged , assigneeChanged , actorUserID , actorName , statusName )
227166 }
228167
229- // Emit action events for automation
230168 if ec .actionService != nil {
231169 if statusChanged {
232- event := & models.ActionEvent {
233- EventType : models .ActionTriggerStatusTransition ,
234- WorkspaceID : updated .WorkspaceID ,
235- ItemID : updated .ID ,
236- ActorUserID : actorUserID ,
237- OldValues : map [string ]any {
238- "status_id" : original .StatusID ,
239- },
240- NewValues : map [string ]any {
241- "status_id" : updated .StatusID ,
242- "title" : updated .Title ,
243- "assignee_id" : updated .AssigneeID ,
244- "creator_id" : updated .CreatorID ,
245- },
246- }
170+ event := newStatusTransitionActionEvent (original , updated , actorUserID )
247171 applyActionContext (event , actionContext )
248172 ec .actionService .EmitActionEvent (event )
249173 } else {
250- // Build OldValues/NewValues dynamically from field changes
251174 oldVals := make (map [string ]any )
252175 newVals := make (map [string ]any )
253176 for _ , fc := range fieldChanges {
@@ -268,17 +191,7 @@ func (ec *EventCoordinator) emitItemUpdatedInternal(original, updated *models.It
268191 }
269192 }
270193
271- // Dispatch webhook events
272- if ec .webhookDispatcher != nil {
273- if statusChanged {
274- ec .webhookDispatcher .DispatchEvent ("status.changed" , updated )
275- }
276- if assigneeChanged {
277- ec .webhookDispatcher .DispatchEvent ("item.assigned" , updated )
278- }
279- // Always dispatch item.updated for any update
280- ec .webhookDispatcher .DispatchEvent ("item.updated" , updated )
281- }
194+ dispatchItemUpdateWebhooks (ec .webhookDispatcher , updated , statusChanged , assigneeChanged )
282195}
283196
284197func actionEventFieldName (historyFieldName string ) string {
0 commit comments