mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-08-01 05:42:46 +00:00
Make syncapi use userapi (#1136)
* Make syncapi use userapi * Unbreak things * Fix tests * Lint
This commit is contained in:
parent
1942928ee5
commit
83391da0e0
9 changed files with 106 additions and 28 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue