@@ -3,6 +3,7 @@ package connectors
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ "slices"
6
7
"sync"
7
8
"time"
8
9
@@ -114,7 +115,7 @@ func (m *Matrix) cancelActiveJobForRoom(roomID string) {
114
115
func (m * Matrix ) handleRoomMessage (a * agent.Agent , evt * event.Event ) {
115
116
if m .roomID != evt .RoomID .String () && m .roomMode { // If we have a roomID and it's not the same as the event room
116
117
// Skip messages from other rooms
117
- xlog .Info ("Skipping reply to room" , evt .RoomID , m .roomID )
118
+ xlog .Info ("Skipping reply to room" , "event room" , evt .RoomID , "config room" , m .roomID )
118
119
return
119
120
}
120
121
@@ -126,16 +127,11 @@ func (m *Matrix) handleRoomMessage(a *agent.Agent, evt *event.Event) {
126
127
// Skip if message does not mention the bot
127
128
mentioned := false
128
129
if evt .Content .AsMessage ().Mentions != nil {
129
- for _ , mention := range evt .Content .AsMessage ().Mentions .UserIDs {
130
- if mention == m .client .UserID {
131
- mentioned = true
132
- break
133
- }
134
- }
130
+ mentioned = slices .Contains (evt .Content .AsMessage ().Mentions .UserIDs , m .client .UserID )
135
131
}
136
132
137
133
if ! mentioned && ! m .roomMode {
138
- xlog .Info ("Skipping reply because it does not mention the bot" , evt . RoomID , m . roomID )
134
+ xlog .Info ("Skipping reply because it does not mention the bot" , "mentions" , evt . Content . AsMessage (). Mentions . UserIDs )
139
135
return
140
136
}
141
137
@@ -181,7 +177,7 @@ func (m *Matrix) handleRoomMessage(a *agent.Agent, evt *event.Event) {
181
177
job .Cancel ()
182
178
for i , j := range m .activeJobs [evt .RoomID .String ()] {
183
179
if j .UUID == job .UUID {
184
- m .activeJobs [evt .RoomID .String ()] = append (m .activeJobs [evt .RoomID .String ()][: i ], m . activeJobs [ evt . RoomID . String ()][ i + 1 :] ... )
180
+ m .activeJobs [evt .RoomID .String ()] = slices . Delete (m .activeJobs [evt .RoomID .String ()], i , i + 1 )
185
181
break
186
182
}
187
183
}
@@ -252,21 +248,21 @@ func (m *Matrix) Start(a *agent.Agent) {
252
248
// Start syncing
253
249
go func () {
254
250
for {
255
- err := client .SyncWithContext (a .Context ())
256
-
257
- xlog .Info ("Syncing" )
258
- if err != nil {
259
- xlog .Error (fmt .Sprintf ("Error syncing: %v" , err ))
260
- time .Sleep (5 * time .Second )
251
+ select {
252
+ case <- a .Context ().Done ():
253
+ xlog .Info ("Context cancelled, stopping sync loop" )
254
+ return
255
+ default :
256
+ err := client .SyncWithContext (a .Context ())
257
+
258
+ xlog .Info ("Syncing" )
259
+ if err != nil {
260
+ xlog .Error (fmt .Sprintf ("Error syncing: %v" , err ))
261
+ time .Sleep (5 * time .Second )
262
+ }
261
263
}
262
264
}
263
265
}()
264
-
265
- // Handle shutdown
266
- go func () {
267
- <- a .Context ().Done ()
268
- client .StopSync ()
269
- }()
270
266
}
271
267
272
268
// MatrixConfigMeta returns the metadata for Matrix connector configuration fields
0 commit comments