|
|
|
@ -51,6 +51,12 @@ var DefaultEventsToHandle = []event.Type{
|
|
|
|
|
event.NewGetValMessageFromPeer,
|
|
|
|
|
event.ProtocolEngineStopped,
|
|
|
|
|
event.RetryServerRequest,
|
|
|
|
|
event.PeerStateChange,
|
|
|
|
|
event.ServerStateChange,
|
|
|
|
|
event.SendMessageToPeerError,
|
|
|
|
|
event.NewRetValMessageFromPeer,
|
|
|
|
|
event.ManifestReceived,
|
|
|
|
|
event.FileDownloaded,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// cwtchPeer manages incoming and outgoing connections and all processing for a Cwtch cwtchPeer
|
|
|
|
@ -1051,6 +1057,10 @@ func (cp *cwtchPeer) eventHandler() {
|
|
|
|
|
// Time to either acknowledge the message or insert a new message
|
|
|
|
|
// Re-encode signature to base64
|
|
|
|
|
cp.attemptInsertOrAcknowledgeLegacyGroupConversation(conversationInfo.ID, base64.StdEncoding.EncodeToString(signature), dgm)
|
|
|
|
|
if serverState, exists := cp.state[ev.Data[event.GroupServer]]; exists && serverState == connections.AUTHENTICATED {
|
|
|
|
|
// server is syncing, update it's most recent sync message time
|
|
|
|
|
cp.SetConversationAttribute(ci.ID, attr.LocalScope.ConstructScopedZonedPath(attr.LegacyGroupZone.ConstructZonedPath(constants.SyncMostRecentMessageTime)), time.Unix(int64(dgm.Timestamp), 0).Format(time.RFC3339Nano))
|
|
|
|
|
}
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -1127,8 +1137,6 @@ func (cp *cwtchPeer) eventHandler() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***** Non default but requestable handleable events *****/
|
|
|
|
|
|
|
|
|
|
case event.ManifestReceived:
|
|
|
|
|
log.Debugf("Manifest Received Event!: %v", ev)
|
|
|
|
|
handle := ev.Data[event.Handle]
|
|
|
|
@ -1238,8 +1246,37 @@ func (cp *cwtchPeer) eventHandler() {
|
|
|
|
|
cp.mutex.Unlock()
|
|
|
|
|
case event.ServerStateChange:
|
|
|
|
|
cp.mutex.Lock()
|
|
|
|
|
cp.state[ev.Data[event.GroupServer]] = connections.ConnectionStateToType()[ev.Data[event.ConnectionState]]
|
|
|
|
|
state := connections.ConnectionStateToType()[ev.Data[event.ConnectionState]]
|
|
|
|
|
cp.state[ev.Data[event.GroupServer]] = state
|
|
|
|
|
cp.mutex.Unlock()
|
|
|
|
|
|
|
|
|
|
// If starting to sync, determine last message from known groups on server so we can calculate sync progress
|
|
|
|
|
if state == connections.AUTHENTICATED {
|
|
|
|
|
conversations, err := cp.FetchConversations()
|
|
|
|
|
mostRecentTime := time.Date(2020, 6, 1, 0, 0, 0, 0, time.UTC)
|
|
|
|
|
if err == nil {
|
|
|
|
|
for _, conversationInfo := range conversations {
|
|
|
|
|
if server, exists := conversationInfo.GetAttribute(attr.LocalScope, attr.LegacyGroupZone, constants.GroupServer); exists && server == ev.Data[event.GroupServer] {
|
|
|
|
|
lastMessage, _ := cp.GetMostRecentMessages(conversationInfo.ID, 0, 0, 1)
|
|
|
|
|
if len(lastMessage) == 0 {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
lastGroupMsgTime, err := time.Parse(time.RFC3339Nano, lastMessage[0].Attr[constants.AttrSentTimestamp])
|
|
|
|
|
if err != nil {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
if lastGroupMsgTime.After(mostRecentTime) {
|
|
|
|
|
mostRecentTime = lastGroupMsgTime
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
serverInfo, err := cp.FetchConversationInfo(ev.Data[event.GroupServer])
|
|
|
|
|
if err == nil {
|
|
|
|
|
cp.SetConversationAttribute(serverInfo.ID, attr.LocalScope.ConstructScopedZonedPath(attr.LegacyGroupZone.ConstructZonedPath(constants.SyncPreLastMessageTime)), mostRecentTime.Format(time.RFC3339Nano))
|
|
|
|
|
cp.SetConversationAttribute(serverInfo.ID, attr.LocalScope.ConstructScopedZonedPath(attr.LegacyGroupZone.ConstructZonedPath(constants.SyncMostRecentMessageTime)), mostRecentTime.Format(time.RFC3339Nano))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
if ev.EventType != "" {
|
|
|
|
|
log.Errorf("peer event handler received an event it was not subscribed for: %v", ev.EventType)
|
|
|
|
|