Fix fetching more than one chunk of initial history
This commit is contained in:
parent
37fd5dba2c
commit
1285aa4327
1 changed files with 6 additions and 4 deletions
10
portal.go
10
portal.go
|
@ -28,6 +28,7 @@ import (
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"mime"
|
"mime"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
@ -172,6 +173,7 @@ func (portal *Portal) handleMessageLoop() {
|
||||||
|
|
||||||
func (portal *Portal) handleMessage(msg PortalMessage) {
|
func (portal *Portal) handleMessage(msg PortalMessage) {
|
||||||
if len(portal.MXID) == 0 {
|
if len(portal.MXID) == 0 {
|
||||||
|
portal.log.Warnln("handleMessage called even though portal.MXID is empty")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
switch data := msg.data.(type) {
|
switch data := msg.data.(type) {
|
||||||
|
@ -189,6 +191,8 @@ func (portal *Portal) handleMessage(msg PortalMessage) {
|
||||||
portal.HandleMessageRevoke(msg.source, data)
|
portal.HandleMessageRevoke(msg.source, data)
|
||||||
case FakeMessage:
|
case FakeMessage:
|
||||||
portal.HandleFakeMessage(msg.source, data)
|
portal.HandleFakeMessage(msg.source, data)
|
||||||
|
default:
|
||||||
|
portal.log.Warnln("Unknown message type:", reflect.TypeOf(msg.data))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -626,14 +630,12 @@ func (portal *Portal) FillInitialHistory(user *User) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
chunk, ok := resp.Content.([]interface{})
|
chunk, ok := resp.Content.([]interface{})
|
||||||
if !ok {
|
if !ok || len(chunk) == 0 {
|
||||||
return fmt.Errorf("history response not a list")
|
|
||||||
} else if len(chunk) == 0 {
|
|
||||||
portal.log.Infoln("Chunk empty, starting handling of loaded messages")
|
portal.log.Infoln("Chunk empty, starting handling of loaded messages")
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
messages = append(messages, chunk...)
|
messages = append(chunk, messages...)
|
||||||
|
|
||||||
portal.log.Debugfln("Fetched chunk and received %d messages", len(chunk))
|
portal.log.Debugfln("Fetched chunk and received %d messages", len(chunk))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue