@@ -65,11 +65,53 @@ func updatePost(w http.ResponseWriter, r *http.Request) {
6565 return
6666 }
6767
68- json .NewEncoder (w ).Encode (updatedPost )
68+ // attempt to enrich response with thread and actor (speaker/company)
69+ var threadID * primitive.ObjectID
70+ var speakerID * primitive.ObjectID
71+ var companyID * primitive.ObjectID
72+
73+ if thread , terr := mongodb .Threads .FindByPost (updatedPost .ID ); terr == nil && thread != nil {
74+ threadID = & thread .ID
75+
76+ // try to find owning speaker/company for this thread
77+ if sp , _ := mongodb .Speakers .FindThread (thread .ID ); sp != nil {
78+ sid := sp .ID
79+ speakerID = & sid
80+ }
81+ if co , _ := mongodb .Companies .FindThread (thread .ID ); co != nil && speakerID == nil {
82+ cid := co .ID
83+ companyID = & cid
84+ }
85+ }
86+
87+ // build response payload keeping backward compatibility intent minimal
88+ resp := map [string ]interface {}{
89+ "post" : updatedPost ,
90+ }
91+ if threadID != nil {
92+ resp ["thread" ] = threadID .Hex ()
93+ }
94+ if speakerID != nil {
95+ resp ["speaker" ] = speakerID .Hex ()
96+ }
97+ if companyID != nil {
98+ resp ["company" ] = companyID .Hex ()
99+ }
100+
101+ json .NewEncoder (w ).Encode (resp )
102+
103+ // notify with enriched context so notifications have thread/actor
104+ notif := mongodb.CreateNotificationData {
105+ Kind : models .NotificationKindUpdated ,
106+ Post : & updatedPost .ID ,
107+ Thread : threadID ,
108+ }
109+ if speakerID != nil {
110+ notif .Speaker = speakerID
111+ }
112+ if companyID != nil {
113+ notif .Company = companyID
114+ }
69115
70- // notify
71- mongodb .Notifications .Notify (credentials .ID , mongodb.CreateNotificationData {
72- Kind : models .NotificationKindUpdated ,
73- Post : & updatedPost .ID ,
74- })
116+ mongodb .Notifications .Notify (credentials .ID , notif )
75117}
0 commit comments