瀏覽代碼

Fix fetching more than one chunk of initial history

Tulir Asokan 6 年之前
父節點
當前提交
1285aa4327
共有 1 個文件被更改,包括 6 次插入4 次删除
  1. 6 4
      portal.go

+ 6 - 4
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 {
-			return fmt.Errorf("history response not a list")
-		} else if len(chunk) == 0 {
+		if !ok || 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))