More considered server side sync capability

This commit is contained in:
Sarah Jamie Lewis 2020-07-22 12:35:49 -07:00
parent f74e8647ef
commit 7c73df1f06
1 changed files with 9 additions and 1 deletions

View File

@ -39,7 +39,6 @@ func (ta *TokenboardServer) Init(connection tapir.Connection) {
ta.AuthApp.Init(connection)
if connection.HasCapability(applications.AuthCapability) {
ta.connection = connection
ta.connection.SetCapability(groups.CwtchServerSyncedCapability)
go ta.Listen()
} else {
connection.Close()
@ -85,6 +84,15 @@ func (ta *TokenboardServer) Listen() {
data, _ = json.Marshal(message)
ta.connection.Send(data)
}
newMessages := ta.LegacyMessageStore.FetchMessages()
// Set sync and then send any new messages that might have happened while we were syncing
ta.connection.SetCapability(groups.CwtchServerSyncedCapability)
if len(newMessages) > len(messages) {
for _, message := range newMessages[len(messages):] {
data, _ = json.Marshal(groups.Message{MessageType: groups.NewMessageMessage, NewMessage: &groups.NewMessage{EGM: *message}})
ta.connection.Send(data)
}
}
} else {
log.Debugf("Server Closing Connection Because of Malformed ReplayRequestMessage Packet")
ta.connection.Close()