[WIP] fix: Add check to empty since token (/sync)

This commit is contained in:
ChronosX88 2019-08-18 14:57:13 +04:00
parent b911c7e351
commit 53372cc1c1
Signed by: ChronosXYZ
GPG Key ID: 085A69A82C8C511A

View File

@ -355,14 +355,20 @@ func (user *User) GetFilterByID(filterID string) *common.Filter {
func (user *User) Sync(token string, request mSync.SyncRequest) (response *mSync.SyncReply, err models.ApiError) { func (user *User) Sync(token string, request mSync.SyncRequest) (response *mSync.SyncReply, err models.ApiError) {
response = mSync.BuildEmptySyncReply() response = mSync.BuildEmptySyncReply()
emptyEventList := true
emptySinceToken := true
var eventsList []events.Event
if request.Since != "" {
emptySinceToken = false
eventsList := user.backend.GetEventsSince(user, request.Since, 0) // TODO filtering eventsList := user.backend.GetEventsSince(user, request.Since, 0) // TODO filtering
var eventListEmpty bool
if len(eventsList) != 0 { if len(eventsList) != 0 {
eventListEmpty = false emptyEventList = false
}
} }
if !eventListEmpty { if !emptyEventList {
for _, room := range user.JoinedRooms() { for _, room := range user.JoinedRooms() {
filteredEventList := filterEventsByRoom(room.ID(), eventsList) filteredEventList := filterEventsByRoom(room.ID(), eventsList)
var prevBatch string var prevBatch string
@ -386,6 +392,8 @@ func (user *User) Sync(token string, request mSync.SyncRequest) (response *mSync
} }
} }
response.NextBatch = eventsList[len(eventsList)-1].ID() response.NextBatch = eventsList[len(eventsList)-1].ID()
} else if emptySinceToken {
// TODO
} else { } else {
// TODO wait for new events or just return empty response when timeout is reached // TODO wait for new events or just return empty response when timeout is reached
} }