@@ -67,6 +67,8 @@ func (p *checklistPlugin) createItem(req *plugin.Request, res *plugin.Response)
6767 CreatedAt : now ,
6868 UpdatedAt : now ,
6969 }
70+ plugin .RecordActivity (taskID , projectID , req .Caller .UserID , "task.checklist_item.created" ,
71+ map [string ]any {"text" : b .Title , "_description" : "added checklist item: \" " + b .Title + "\" " })
7072 created (res , item )
7173}
7274
@@ -161,6 +163,26 @@ func (p *checklistPlugin) updateItem(req *plugin.Request, res *plugin.Response)
161163 CreatedAt : createdAt ,
162164 UpdatedAt : now ,
163165 }
166+ // Build change list for the activity record.
167+ changes := []map [string ]any {}
168+ oldTitle := sc .str ("title" )
169+ if b .Title != nil && * b .Title != oldTitle {
170+ changes = append (changes , map [string ]any {"field" : "title" , "old" : oldTitle , "new" : * b .Title })
171+ }
172+ oldChecked := sc .boolVal ("is_checked" )
173+ if b .IsChecked != nil && * b .IsChecked != oldChecked {
174+ changes = append (changes , map [string ]any {"field" : "is_checked" , "old" : oldChecked , "new" : * b .IsChecked })
175+ }
176+ oldAssignee := sc .strPtr ("assignee_id" )
177+ if b .AssigneeID != nil && (oldAssignee == nil || * oldAssignee != * b .AssigneeID ) {
178+ var oldAssigneeActivity any
179+ if oldAssignee != nil {
180+ oldAssigneeActivity = * oldAssignee
181+ }
182+ changes = append (changes , map [string ]any {"field" : "assignee_id" , "old" : oldAssigneeActivity , "new" : * b .AssigneeID })
183+ }
184+ plugin .RecordActivity (taskID , projectID , req .Caller .UserID , "task.checklist_item.updated" ,
185+ map [string ]any {"text" : updTitle , "changes" : changes , "_description" : "updated checklist item: \" " + updTitle + "\" " })
164186 ok (res , item )
165187}
166188
@@ -175,6 +197,23 @@ func (p *checklistPlugin) deleteItem(req *plugin.Request, res *plugin.Response)
175197 return
176198 }
177199
200+ // Fetch item title before deletion for activity record.
201+ titleResult , err := p .db .Query (
202+ `SELECT title FROM task_checklist_items WHERE id = $1 AND checklist_id = $2` ,
203+ itemID , checklistID ,
204+ )
205+ if err != nil {
206+ p .log .Error ("deleteItem title fetch: " + err .Error ())
207+ res .Error (500 , "failed to delete item" )
208+ return
209+ }
210+ if len (titleResult .Rows ) == 0 {
211+ res .Error (404 , "item not found" )
212+ return
213+ }
214+ itemTitleSC := newRowScanner (titleResult .Columns , titleResult .Rows [0 ])
215+ itemTitle := itemTitleSC .str ("title" )
216+
178217 affected , err := p .db .Exec (
179218 `DELETE FROM task_checklist_items WHERE id = $1 AND checklist_id = $2` ,
180219 itemID , checklistID ,
@@ -188,5 +227,7 @@ func (p *checklistPlugin) deleteItem(req *plugin.Request, res *plugin.Response)
188227 res .Error (404 , "item not found" )
189228 return
190229 }
230+ plugin .RecordActivity (taskID , projectID , req .Caller .UserID , "task.checklist_item.deleted" ,
231+ map [string ]any {"text" : itemTitle , "_description" : "removed checklist item: \" " + itemTitle + "\" " })
191232 res .NoContent ()
192233}
0 commit comments