Fix sync position with partial info used as complete one in syncserver and notifier

Signed-off-by: Alex Chen <minecnly@gmail.com>
This commit is contained in:
Cnly 2019-06-26 22:56:58 +08:00
parent 55219aa746
commit 2a9dab21f8
3 changed files with 16 additions and 2 deletions

View file

@ -331,7 +331,8 @@ func (d *SyncServerDatasource) IncrementalSync(
fromPos, toPos types.SyncPosition,
numRecentEventsPerRoom int,
) (*types.Response, error) {
res := types.NewResponse(toPos)
nextBatchPos := fromPos.WithUpdates(toPos)
res := types.NewResponse(nextBatchPos)
var joinedRoomIDs []string
var err error

View file

@ -66,7 +66,7 @@ func (n *Notifier) OnNewEvent(ev *gomatrixserverlib.Event, roomID string, userID
// This needs to be done PRIOR to waking up users as they will read this value.
n.streamLock.Lock()
defer n.streamLock.Unlock()
n.currPos = pos
n.currPos = n.currPos.WithUpdates(pos)
n.removeEmptyUserStreams()

View file

@ -41,6 +41,19 @@ func (sp SyncPosition) IsAfter(other SyncPosition) bool {
sp.TypingPosition > other.TypingPosition
}
// WithUpdates returns a copy of sp with updates represented by other applied.
// If a fieldn is not 0 in other, it is considered an update.
func (sp SyncPosition) WithUpdates(other SyncPosition) SyncPosition {
ret := sp
if other.PDUPosition != 0 {
ret.PDUPosition = other.PDUPosition
}
if other.TypingPosition != 0 {
ret.TypingPosition = other.TypingPosition
}
return ret
}
// PrevEventRef represents a reference to a previous event in a state event upgrade
type PrevEventRef struct {
PrevContent json.RawMessage `json:"prev_content"`