Merge pull request 'for getConnectionsSortedByLastSeen, ignore accepted on servers' (#480) from serverAccept into master
continuous-integration/drone/push Build is pending Details

Reviewed-on: #480
Reviewed-by: Sarah Jamie Lewis <sarah@openprivacy.ca>
This commit is contained in:
Sarah Jamie Lewis 2022-12-06 05:28:31 +00:00
commit 7de9c21f7b
2 changed files with 19 additions and 9 deletions

View File

@ -203,7 +203,7 @@ func (cr *contactRetry) run() {
case event.QueueJoinServer: case event.QueueJoinServer:
fallthrough fallthrough
case event.QueuePeerRequest: case event.QueuePeerRequest:
lastSeen, err := time.Parse(e.Data[event.LastSeen], time.RFC3339Nano) lastSeen, err := time.Parse(time.RFC3339Nano, e.Data[event.LastSeen])
if err != nil { if err != nil {
lastSeen = event.CwtchEpoch lastSeen = event.CwtchEpoch
} }

View File

@ -1030,24 +1030,35 @@ type LastSeenConversation struct {
} }
func (cp *cwtchPeer) GetConversationLastSeenTime(conversationId int) time.Time { func (cp *cwtchPeer) GetConversationLastSeenTime(conversationId int) time.Time {
lastTime := event.CwtchEpoch
timestamp, err := cp.GetConversationAttribute(conversationId, attr.LocalScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants.AttrLastConnectionTime))) timestamp, err := cp.GetConversationAttribute(conversationId, attr.LocalScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants.AttrLastConnectionTime)))
if err == nil { if err == nil {
if time, err := time.Parse(time.RFC3339Nano, timestamp); err == nil { if time, err := time.Parse(time.RFC3339Nano, timestamp); err == nil {
return time lastTime = time
} }
} }
// for peers
lastMessage, _ := cp.GetMostRecentMessages(conversationId, 0, 0, 1) lastMessage, _ := cp.GetMostRecentMessages(conversationId, 0, 0, 1)
if len(lastMessage) != 0 { if len(lastMessage) != 0 {
time, err := time.Parse(time.RFC3339Nano, lastMessage[0].Attr[constants.AttrSentTimestamp]) lastMsgTime, err := time.Parse(time.RFC3339Nano, lastMessage[0].Attr[constants.AttrSentTimestamp])
if err == nil { if err == nil {
return time if lastMsgTime.After(lastTime) {
lastTime = lastMsgTime
}
} }
} }
// Cwtch launch date // for servers
return event.CwtchEpoch recentTimeStr, err := cp.GetConversationAttribute(conversationId, attr.LocalScope.ConstructScopedZonedPath(attr.LegacyGroupZone.ConstructZonedPath(constants.SyncMostRecentMessageTime)))
if err == nil {
if recentTime, err := time.Parse(time.RFC3339Nano, recentTimeStr); err == nil && recentTime.After(lastTime) {
lastTime = recentTime
}
}
return lastTime
} }
func (cp *cwtchPeer) getConnectionsSortedByLastSeen(doPeers, doServers bool) []*LastSeenConversation { func (cp *cwtchPeer) getConnectionsSortedByLastSeen(doPeers, doServers bool) []*LastSeenConversation {
@ -1055,17 +1066,16 @@ func (cp *cwtchPeer) getConnectionsSortedByLastSeen(doPeers, doServers bool) []*
byRecent := []*LastSeenConversation{} byRecent := []*LastSeenConversation{}
for _, conversation := range conversations { for _, conversation := range conversations {
if conversation.Accepted && !conversation.IsGroup() { if !conversation.IsGroup() {
if conversation.IsServer() { if conversation.IsServer() {
if !doServers { if !doServers {
continue continue
} }
} else { } else {
if !doPeers { if !doPeers || !conversation.Accepted {
continue continue
} }
} }
byRecent = append(byRecent, &LastSeenConversation{conversation, cp.GetConversationLastSeenTime(conversation.ID)}) byRecent = append(byRecent, &LastSeenConversation{conversation, cp.GetConversationLastSeenTime(conversation.ID)})
} }
} }