aboutsummaryrefslogtreecommitdiff
path: root/syncapi/sync
diff options
context:
space:
mode:
authorKegsay <kegan@matrix.org>2020-06-16 17:05:38 +0100
committerGitHub <noreply@github.com>2020-06-16 17:05:38 +0100
commit83391da0e04dda7a52589ee7ec6df2b615571894 (patch)
tree0a0ffcc5b7209600eaf042ee317a0681e0bd7f59 /syncapi/sync
parent1942928ee5e0398beed45c8b1c63d7b13e89b646 (diff)
Make syncapi use userapi (#1136)
* Make syncapi use userapi * Unbreak things * Fix tests * Lint
Diffstat (limited to 'syncapi/sync')
-rw-r--r--syncapi/sync/requestpool.go45
1 files changed, 24 insertions, 21 deletions
diff --git a/syncapi/sync/requestpool.go b/syncapi/sync/requestpool.go
index ec22a05f..26b925ea 100644
--- a/syncapi/sync/requestpool.go
+++ b/syncapi/sync/requestpool.go
@@ -21,7 +21,6 @@ import (
"net/http"
"time"
- "github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
"github.com/matrix-org/dendrite/clientapi/jsonerror"
"github.com/matrix-org/dendrite/syncapi/storage"
"github.com/matrix-org/dendrite/syncapi/types"
@@ -33,14 +32,14 @@ import (
// RequestPool manages HTTP long-poll connections for /sync
type RequestPool struct {
- db storage.Database
- accountDB accounts.Database
- notifier *Notifier
+ db storage.Database
+ userAPI userapi.UserInternalAPI
+ notifier *Notifier
}
// NewRequestPool makes a new RequestPool
-func NewRequestPool(db storage.Database, n *Notifier, adb accounts.Database) *RequestPool {
- return &RequestPool{db, adb, n}
+func NewRequestPool(db storage.Database, n *Notifier, userAPI userapi.UserInternalAPI) *RequestPool {
+ return &RequestPool{db, userAPI, n}
}
// OnIncomingSyncRequest is called when a client makes a /sync request. This function MUST be
@@ -193,6 +192,7 @@ func (rp *RequestPool) currentSyncForUser(req syncRequest, latestPos types.Strea
return
}
+// nolint:gocyclo
func (rp *RequestPool) appendAccountData(
data *types.Response, userID string, req syncRequest, currentPos types.StreamPosition,
accountDataFilter *gomatrixserverlib.EventFilter,
@@ -202,25 +202,21 @@ func (rp *RequestPool) appendAccountData(
// data keys were set between two message. This isn't a huge issue since the
// duplicate data doesn't represent a huge quantity of data, but an optimisation
// here would be making sure each data is sent only once to the client.
- localpart, _, err := gomatrixserverlib.SplitID('@', userID)
- if err != nil {
- return nil, err
- }
-
if req.since == nil {
// If this is the initial sync, we don't need to check if a data has
// already been sent. Instead, we send the whole batch.
- var global []gomatrixserverlib.ClientEvent
- var rooms map[string][]gomatrixserverlib.ClientEvent
- global, rooms, err = rp.accountDB.GetAccountData(req.ctx, localpart)
+ var res userapi.QueryAccountDataResponse
+ err := rp.userAPI.QueryAccountData(req.ctx, &userapi.QueryAccountDataRequest{
+ UserID: userID,
+ }, &res)
if err != nil {
return nil, err
}
- data.AccountData.Events = global
+ data.AccountData.Events = res.GlobalAccountData
for r, j := range data.Rooms.Join {
- if len(rooms[r]) > 0 {
- j.AccountData.Events = rooms[r]
+ if len(res.RoomAccountData[r]) > 0 {
+ j.AccountData.Events = res.RoomAccountData[r]
data.Rooms.Join[r] = j
}
}
@@ -256,13 +252,20 @@ func (rp *RequestPool) appendAccountData(
events := []gomatrixserverlib.ClientEvent{}
// Request the missing data from the database
for _, dataType := range dataTypes {
- event, err := rp.accountDB.GetAccountDataByType(
- req.ctx, localpart, roomID, dataType,
- )
+ var res userapi.QueryAccountDataResponse
+ err = rp.userAPI.QueryAccountData(req.ctx, &userapi.QueryAccountDataRequest{
+ UserID: userID,
+ RoomID: roomID,
+ DataType: dataType,
+ }, &res)
if err != nil {
return nil, err
}
- events = append(events, *event)
+ if len(res.RoomAccountData[roomID]) > 0 {
+ events = append(events, res.RoomAccountData[roomID]...)
+ } else if len(res.GlobalAccountData) > 0 {
+ events = append(events, res.GlobalAccountData...)
+ }
}
// Append the data to the response