mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-01 03:03:10 -06:00
Merge branch 'main' into implement-push-notifications
This commit is contained in:
commit
4d71df84ff
|
|
@ -87,6 +87,12 @@ func (d *mockDeviceListUpdaterDatabase) MarkDeviceListStale(ctx context.Context,
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *mockDeviceListUpdaterDatabase) isStale(userID string) bool {
|
||||||
|
d.mu.Lock()
|
||||||
|
defer d.mu.Unlock()
|
||||||
|
return d.staleUsers[userID]
|
||||||
|
}
|
||||||
|
|
||||||
// StoreRemoteDeviceKeys persists the given keys. Keys with the same user ID and device ID will be replaced. An empty KeyJSON removes the key
|
// StoreRemoteDeviceKeys persists the given keys. Keys with the same user ID and device ID will be replaced. An empty KeyJSON removes the key
|
||||||
// for this (user, device). Does not modify the stream ID for keys.
|
// for this (user, device). Does not modify the stream ID for keys.
|
||||||
func (d *mockDeviceListUpdaterDatabase) StoreRemoteDeviceKeys(ctx context.Context, keys []api.DeviceMessage, clear []string) error {
|
func (d *mockDeviceListUpdaterDatabase) StoreRemoteDeviceKeys(ctx context.Context, keys []api.DeviceMessage, clear []string) error {
|
||||||
|
|
@ -169,7 +175,7 @@ func TestUpdateHavePrevID(t *testing.T) {
|
||||||
if !reflect.DeepEqual(db.storedKeys, []api.DeviceMessage{want}) {
|
if !reflect.DeepEqual(db.storedKeys, []api.DeviceMessage{want}) {
|
||||||
t.Errorf("DB didn't store correct event, got %v want %v", db.storedKeys, want)
|
t.Errorf("DB didn't store correct event, got %v want %v", db.storedKeys, want)
|
||||||
}
|
}
|
||||||
if db.staleUsers[event.UserID] {
|
if db.isStale(event.UserID) {
|
||||||
t.Errorf("%s incorrectly marked as stale", event.UserID)
|
t.Errorf("%s incorrectly marked as stale", event.UserID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -243,7 +249,7 @@ func TestUpdateNoPrevID(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
// Now we should have a fresh list and the keys and emitted something
|
// Now we should have a fresh list and the keys and emitted something
|
||||||
if db.staleUsers[event.UserID] {
|
if db.isStale(event.UserID) {
|
||||||
t.Errorf("%s still marked as stale", event.UserID)
|
t.Errorf("%s still marked as stale", event.UserID)
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(producer.events, []api.DeviceMessage{want}) {
|
if !reflect.DeepEqual(producer.events, []api.DeviceMessage{want}) {
|
||||||
|
|
@ -259,6 +265,7 @@ func TestUpdateNoPrevID(t *testing.T) {
|
||||||
// Test that if we make N calls to ManualUpdate for the same user, we only do it once, assuming the
|
// Test that if we make N calls to ManualUpdate for the same user, we only do it once, assuming the
|
||||||
// update is still ongoing.
|
// update is still ongoing.
|
||||||
func TestDebounce(t *testing.T) {
|
func TestDebounce(t *testing.T) {
|
||||||
|
t.Skipf("panic on closed channel on GHA")
|
||||||
db := &mockDeviceListUpdaterDatabase{
|
db := &mockDeviceListUpdaterDatabase{
|
||||||
staleUsers: make(map[string]bool),
|
staleUsers: make(map[string]bool),
|
||||||
prevIDsExist: func(string, []int) bool {
|
prevIDsExist: func(string, []int) bool {
|
||||||
|
|
@ -304,7 +311,7 @@ func TestDebounce(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// user should be marked as stale
|
// user should be marked as stale
|
||||||
if !db.staleUsers[userID] {
|
if !db.isStale(userID) {
|
||||||
t.Errorf("user %s not marked as stale", userID)
|
t.Errorf("user %s not marked as stale", userID)
|
||||||
}
|
}
|
||||||
// now send the response over federation
|
// now send the response over federation
|
||||||
|
|
@ -330,7 +337,7 @@ func TestDebounce(t *testing.T) {
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
// user is no longer stale now
|
// user is no longer stale now
|
||||||
if db.staleUsers[userID] {
|
if db.isStale(userID) {
|
||||||
t.Errorf("user %s is marked as stale", userID)
|
t.Errorf("user %s is marked as stale", userID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,8 +53,7 @@ func Setup(
|
||||||
) {
|
) {
|
||||||
rateLimits := httputil.NewRateLimits(rateLimit)
|
rateLimits := httputil.NewRateLimits(rateLimit)
|
||||||
|
|
||||||
r0mux := publicAPIMux.PathPrefix("/r0").Subrouter()
|
v3mux := publicAPIMux.PathPrefix("/{apiversion:(?:r0|v1|v3)}/").Subrouter()
|
||||||
v1mux := publicAPIMux.PathPrefix("/v1").Subrouter()
|
|
||||||
|
|
||||||
activeThumbnailGeneration := &types.ActiveThumbnailGeneration{
|
activeThumbnailGeneration := &types.ActiveThumbnailGeneration{
|
||||||
PathToResult: map[string]*types.ThumbnailGenerationResult{},
|
PathToResult: map[string]*types.ThumbnailGenerationResult{},
|
||||||
|
|
@ -80,21 +79,18 @@ func Setup(
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
r0mux.Handle("/upload", uploadHandler).Methods(http.MethodPost, http.MethodOptions)
|
v3mux.Handle("/upload", uploadHandler).Methods(http.MethodPost, http.MethodOptions)
|
||||||
r0mux.Handle("/config", configHandler).Methods(http.MethodGet, http.MethodOptions)
|
v3mux.Handle("/config", configHandler).Methods(http.MethodGet, http.MethodOptions)
|
||||||
v1mux.Handle("/upload", uploadHandler).Methods(http.MethodPost, http.MethodOptions)
|
|
||||||
|
|
||||||
activeRemoteRequests := &types.ActiveRemoteRequests{
|
activeRemoteRequests := &types.ActiveRemoteRequests{
|
||||||
MXCToResult: map[string]*types.RemoteRequestResult{},
|
MXCToResult: map[string]*types.RemoteRequestResult{},
|
||||||
}
|
}
|
||||||
|
|
||||||
downloadHandler := makeDownloadAPI("download", cfg, rateLimits, db, client, activeRemoteRequests, activeThumbnailGeneration)
|
downloadHandler := makeDownloadAPI("download", cfg, rateLimits, db, client, activeRemoteRequests, activeThumbnailGeneration)
|
||||||
r0mux.Handle("/download/{serverName}/{mediaId}", downloadHandler).Methods(http.MethodGet, http.MethodOptions)
|
v3mux.Handle("/download/{serverName}/{mediaId}", downloadHandler).Methods(http.MethodGet, http.MethodOptions)
|
||||||
r0mux.Handle("/download/{serverName}/{mediaId}/{downloadName}", downloadHandler).Methods(http.MethodGet, http.MethodOptions)
|
v3mux.Handle("/download/{serverName}/{mediaId}/{downloadName}", downloadHandler).Methods(http.MethodGet, http.MethodOptions)
|
||||||
v1mux.Handle("/download/{serverName}/{mediaId}", downloadHandler).Methods(http.MethodGet, http.MethodOptions) // TODO: remove when synapse is fixed
|
|
||||||
v1mux.Handle("/download/{serverName}/{mediaId}/{downloadName}", downloadHandler).Methods(http.MethodGet, http.MethodOptions) // TODO: remove when synapse is fixed
|
|
||||||
|
|
||||||
r0mux.Handle("/thumbnail/{serverName}/{mediaId}",
|
v3mux.Handle("/thumbnail/{serverName}/{mediaId}",
|
||||||
makeDownloadAPI("thumbnail", cfg, rateLimits, db, client, activeRemoteRequests, activeThumbnailGeneration),
|
makeDownloadAPI("thumbnail", cfg, rateLimits, db, client, activeRemoteRequests, activeThumbnailGeneration),
|
||||||
).Methods(http.MethodGet, http.MethodOptions)
|
).Methods(http.MethodGet, http.MethodOptions)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue