@@ -24,6 +24,7 @@ import (
24
24
"sync"
25
25
26
26
"github.com/matrix-org/gomatrixserverlib"
27
+ "github.com/matrix-org/gomatrixserverlib/fclient"
27
28
"github.com/matrix-org/util"
28
29
29
30
"github.com/matrix-org/dendrite/clientapi/api"
@@ -35,7 +36,7 @@ import (
35
36
36
37
var (
37
38
cacheMu sync.Mutex
38
- publicRoomsCache []gomatrixserverlib .PublicRoom
39
+ publicRoomsCache []fclient .PublicRoom
39
40
)
40
41
41
42
type PublicRoomReq struct {
@@ -56,7 +57,7 @@ type filter struct {
56
57
func GetPostPublicRooms (
57
58
req * http.Request , rsAPI roomserverAPI.ClientRoomserverAPI ,
58
59
extRoomsProvider api.ExtraPublicRoomsProvider ,
59
- federation * gomatrixserverlib .FederationClient ,
60
+ federation * fclient .FederationClient ,
60
61
cfg * config.ClientAPI ,
61
62
) util.JSONResponse {
62
63
var request PublicRoomReq
@@ -102,10 +103,10 @@ func GetPostPublicRooms(
102
103
103
104
func publicRooms (
104
105
ctx context.Context , request PublicRoomReq , rsAPI roomserverAPI.ClientRoomserverAPI , extRoomsProvider api.ExtraPublicRoomsProvider ,
105
- ) (* gomatrixserverlib .RespPublicRooms , error ) {
106
+ ) (* fclient .RespPublicRooms , error ) {
106
107
107
- response := gomatrixserverlib .RespPublicRooms {
108
- Chunk : []gomatrixserverlib .PublicRoom {},
108
+ response := fclient .RespPublicRooms {
109
+ Chunk : []fclient .PublicRoom {},
109
110
}
110
111
var limit int64
111
112
var offset int64
@@ -122,7 +123,7 @@ func publicRooms(
122
123
}
123
124
err = nil
124
125
125
- var rooms []gomatrixserverlib .PublicRoom
126
+ var rooms []fclient .PublicRoom
126
127
if request .Since == "" {
127
128
rooms = refreshPublicRoomCache (ctx , rsAPI , extRoomsProvider , request )
128
129
} else {
@@ -146,14 +147,14 @@ func publicRooms(
146
147
return & response , err
147
148
}
148
149
149
- func filterRooms (rooms []gomatrixserverlib .PublicRoom , searchTerm string ) []gomatrixserverlib .PublicRoom {
150
+ func filterRooms (rooms []fclient .PublicRoom , searchTerm string ) []fclient .PublicRoom {
150
151
if searchTerm == "" {
151
152
return rooms
152
153
}
153
154
154
155
normalizedTerm := strings .ToLower (searchTerm )
155
156
156
- result := make ([]gomatrixserverlib .PublicRoom , 0 )
157
+ result := make ([]fclient .PublicRoom , 0 )
157
158
for _ , room := range rooms {
158
159
if strings .Contains (strings .ToLower (room .Name ), normalizedTerm ) ||
159
160
strings .Contains (strings .ToLower (room .Topic ), normalizedTerm ) ||
@@ -214,7 +215,7 @@ func fillPublicRoomsReq(httpReq *http.Request, request *PublicRoomReq) *util.JSO
214
215
// limit=3&since=6 => G (prev='3', next='')
215
216
//
216
217
// A value of '-1' for prev/next indicates no position.
217
- func sliceInto (slice []gomatrixserverlib .PublicRoom , since int64 , limit int64 ) (subset []gomatrixserverlib .PublicRoom , prev , next int ) {
218
+ func sliceInto (slice []fclient .PublicRoom , since int64 , limit int64 ) (subset []fclient .PublicRoom , prev , next int ) {
218
219
prev = - 1
219
220
next = - 1
220
221
@@ -241,10 +242,10 @@ func sliceInto(slice []gomatrixserverlib.PublicRoom, since int64, limit int64) (
241
242
func refreshPublicRoomCache (
242
243
ctx context.Context , rsAPI roomserverAPI.ClientRoomserverAPI , extRoomsProvider api.ExtraPublicRoomsProvider ,
243
244
request PublicRoomReq ,
244
- ) []gomatrixserverlib .PublicRoom {
245
+ ) []fclient .PublicRoom {
245
246
cacheMu .Lock ()
246
247
defer cacheMu .Unlock ()
247
- var extraRooms []gomatrixserverlib .PublicRoom
248
+ var extraRooms []fclient .PublicRoom
248
249
if extRoomsProvider != nil {
249
250
extraRooms = extRoomsProvider .Rooms ()
250
251
}
@@ -269,7 +270,7 @@ func refreshPublicRoomCache(
269
270
util .GetLogger (ctx ).WithError (err ).Error ("PopulatePublicRooms failed" )
270
271
return publicRoomsCache
271
272
}
272
- publicRoomsCache = []gomatrixserverlib .PublicRoom {}
273
+ publicRoomsCache = []fclient .PublicRoom {}
273
274
publicRoomsCache = append (publicRoomsCache , pubRooms ... )
274
275
publicRoomsCache = append (publicRoomsCache , extraRooms ... )
275
276
publicRoomsCache = dedupeAndShuffle (publicRoomsCache )
@@ -281,16 +282,16 @@ func refreshPublicRoomCache(
281
282
return publicRoomsCache
282
283
}
283
284
284
- func getPublicRoomsFromCache () []gomatrixserverlib .PublicRoom {
285
+ func getPublicRoomsFromCache () []fclient .PublicRoom {
285
286
cacheMu .Lock ()
286
287
defer cacheMu .Unlock ()
287
288
return publicRoomsCache
288
289
}
289
290
290
- func dedupeAndShuffle (in []gomatrixserverlib .PublicRoom ) []gomatrixserverlib .PublicRoom {
291
+ func dedupeAndShuffle (in []fclient .PublicRoom ) []fclient .PublicRoom {
291
292
// de-duplicate rooms with the same room ID. We can join the room via any of these aliases as we know these servers
292
293
// are alive and well, so we arbitrarily pick one (purposefully shuffling them to spread the load a bit)
293
- var publicRooms []gomatrixserverlib .PublicRoom
294
+ var publicRooms []fclient .PublicRoom
294
295
haveRoomIDs := make (map [string ]bool )
295
296
rand .Shuffle (len (in ), func (i , j int ) {
296
297
in [i ], in [j ] = in [j ], in [i ]
0 commit comments