@@ -125,35 +125,21 @@ func (s *MessageService) SendMessage(ctx context.Context, req *models.SendMessag
125125func (s * MessageService ) FetchMessages (ctx context.Context , req * models.FetchMessagesRequest ) (* models.FetchMessagesResponse , error ) {
126126 logger .Debug ().Interface ("request" , req ).Msg ("fetch messages request received" )
127127
128- // The user to impersonate is taken from the 'Username' field.
128+ // The username sent by the app is always an extension number like 91201
129129 userID := s .resolveMatrixUser (strings .TrimSpace (req .Username ))
130130 if userID == "" {
131131 logger .Warn ().Msg ("fetch messages: empty user ID" )
132132 return nil , ErrAuthentication
133133 }
134134
135- since := req .LastID
136- filterAfterEventID := ""
135+ logger .Debug ().Str ("user_id" , string (userID )).Msg ("syncing messages from matrix" )
137136
138- // Acrobits might send a Matrix Event ID (starts with $) as last_id.
139- // Matrix Sync requires a stream token (usually starts with s).
140- // If we get an Event ID, we must perform an initial sync (empty since)
141- // and let the Matrix client filter the results to return only messages after that event.
142- if strings .HasPrefix (since , "$" ) {
143- logger .Debug ().Str ("last_id" , since ).Msg ("received event ID as last_id, performing initial sync with event filtering" )
144- filterAfterEventID = since
145- since = ""
146- }
147-
148- logger .Debug ().Str ("user_id" , string (userID )).Str ("since" , since ).Msg ("syncing messages from matrix" )
149-
150- resp , err := s .matrixClient .Sync (ctx , userID , since , filterAfterEventID )
137+ resp , err := s .matrixClient .Sync (ctx , userID )
151138 if err != nil {
152139 // If the token is invalid (e.g. expired or from a different session), retry with a full sync.
153140 if strings .Contains (err .Error (), "Invalid stream token" ) || strings .Contains (err .Error (), "M_UNKNOWN" ) {
154141 logger .Warn ().Err (err ).Msg ("invalid stream token, retrying with full sync" )
155- since = ""
156- resp , err = s .matrixClient .Sync (ctx , userID , since , filterAfterEventID )
142+ resp , err = s .matrixClient .Sync (ctx , userID )
157143 }
158144 }
159145 if err != nil {
@@ -163,7 +149,7 @@ func (s *MessageService) FetchMessages(ctx context.Context, req *models.FetchMes
163149
164150 received , sent := make ([]models.SMS , 0 , 8 ), make ([]models.SMS , 0 , 8 )
165151
166- // Resolve the caller's identifier (e.g. "91201")
152+ // Resolve the caller's identifier (e.g. "91201" -> "201" )
167153 callerIdentifier := s .resolveMatrixIDToIdentifier (string (userID ))
168154
169155 for _ , room := range resp .Rooms .Join {
@@ -295,7 +281,9 @@ func (s *MessageService) resolveMatrixIDToIdentifier(matrixID string) string {
295281
296282 // No mapping found, return the original Matrix ID
297283 return matrixID
298- } // resolveRoomIDToOtherIdentifier finds the identifier of the "other" participant in a room.
284+ }
285+
286+ // resolveRoomIDToOtherIdentifier finds the identifier of the "other" participant in a room.
299287func (s * MessageService ) resolveRoomIDToOtherIdentifier (ctx context.Context , roomID id.RoomID , myMatrixID string ) string {
300288 aliases := s .matrixClient .GetRoomAliases (ctx , roomID )
301289 my := strings .TrimSpace (myMatrixID )
0 commit comments