@@ -170,54 +170,63 @@ func (s *MessageService) FetchMessages(ctx context.Context, req *models.FetchMes
170170 if evt .Type != event .EventMessage {
171171 continue
172172 }
173- msg := convertEvent (evt )
173+ // return models.Message{
174+ // ID: string(evt.ID),
175+ // SendingDate: sendingDate,
176+ // Sender: string(evt.Sender),
177+ // Recipient: string(evt.RoomID),
178+ // Text: body,
179+ // ContentType: contentType,
180+ // StreamID: string(evt.RoomID),
181+ // }
182+
183+ // Debug entire raw event JSON for troubleshooting
184+ if b , err := evt .MarshalJSON (); err != nil {
185+ logger .Debug ().Str ("event" , string (b )).Msg ("processing event" )
186+ }
187+ body := ""
188+ if b , ok := evt .Content .Raw ["body" ].(string ); ok {
189+ body = b
190+ }
191+
192+ sms := models.SMS {
193+ SMSID : string (evt .ID ),
194+ // SendingDate: msg.SendingDate,
195+ SMSText : body ,
196+ ContentType : "text/plain" ,
197+ // StreamID: msg.StreamID,
198+ }
174199
175200 // Determine if I sent the message
176- senderMatrixID := msg .Sender
201+ senderMatrixID := string ( evt .Sender )
177202 isSent := isSentBy (senderMatrixID , string (userID ))
178203
179204 // Remap sender to identifier (e.g. "202" or "91201")
180- msg .Sender = string (s .resolveMatrixUser (senderMatrixID ))
205+ sms .Sender = string (s .resolveMatrixUser (senderMatrixID ))
181206
182207 // Determine Recipient
183208 if isSent {
184209 // I sent it. Recipient is the other person in the room.
185210 other := s .resolveRoomIDToOtherIdentifier (ctx , evt .RoomID , string (userID ))
186211 if other != "" {
187- msg .Recipient = other
212+ sms .Recipient = other
188213 }
189- // If other not found, msg.Recipient remains RoomID (default from convertEvent)
214+ sent = append (sent , sms )
215+
190216 } else {
191217 // I received it. Recipient is me.
192- msg .Recipient = callerIdentifier
193- }
218+ sms .Recipient = callerIdentifier
219+ received = append ( received , sms )
194220
195- // Convert internal Message to SMS
196- sms := models.SMS {
197- SMSID : msg .ID ,
198- SendingDate : msg .SendingDate ,
199- SMSText : msg .Text ,
200- ContentType : msg .ContentType ,
201- StreamID : msg .StreamID ,
202221 }
203-
204222 // Debug each processed message
205223 logger .Debug ().
206- Str ("event_id" , msg .ID ).
207- Str ("room_id" , msg .StreamID ).
208- Str ("sender" , msg .Sender ).
209- Str ("recipient" , msg .Recipient ).
224+ Str ("sender" , sms .Sender ).
225+ //Str("recipient", msg.Recipient).
210226 Bool ("is_sent" , isSent ).
211227 Interface ("sms" , sms ).
212228 Msg ("processed message from sync" )
213229
214- if isSent {
215- sms .Recipient = msg .Recipient
216- sent = append (sent , sms )
217- } else {
218- sms .Sender = msg .Sender
219- received = append (received , sms )
220- }
221230 }
222231 }
223232
@@ -498,28 +507,6 @@ func isSentBy(sender, username string) bool {
498507 return strings .EqualFold (normalizeMatrixID (sender ), normalizeMatrixID (username ))
499508}
500509
501- func convertEvent (evt * event.Event ) models.Message {
502- body := ""
503- if b , ok := evt .Content .Raw ["body" ].(string ); ok {
504- body = b
505- }
506- contentType := "text/plain"
507- if mt , ok := evt .Content .Raw ["msgtype" ].(string ); ok {
508- contentType = mt
509- }
510-
511- sendingDate := time .UnixMilli (evt .Timestamp ).UTC ().Format (time .RFC3339 )
512- return models.Message {
513- ID : string (evt .ID ),
514- SendingDate : sendingDate ,
515- Sender : string (evt .Sender ),
516- Recipient : string (evt .RoomID ),
517- Text : body ,
518- ContentType : contentType ,
519- StreamID : string (evt .RoomID ),
520- }
521- }
522-
523510func mapAuthErr (err error ) error {
524511 if errors .Is (err , ErrAuthentication ) {
525512 return err
0 commit comments