Merge pull request 'for getConnectionsSortedByLastSeen, ignore accepted on servers' (#480) from serverAccept into master
continuous-integration/drone/push Build is pending
Details
continuous-integration/drone/push Build is pending
Details
Reviewed-on: #480 Reviewed-by: Sarah Jamie Lewis <sarah@openprivacy.ca>
This commit is contained in:
commit
7de9c21f7b
|
@ -203,7 +203,7 @@ func (cr *contactRetry) run() {
|
|||
case event.QueueJoinServer:
|
||||
fallthrough
|
||||
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 {
|
||||
lastSeen = event.CwtchEpoch
|
||||
}
|
||||
|
|
|
@ -1030,24 +1030,35 @@ type LastSeenConversation struct {
|
|||
}
|
||||
|
||||
func (cp *cwtchPeer) GetConversationLastSeenTime(conversationId int) time.Time {
|
||||
lastTime := event.CwtchEpoch
|
||||
|
||||
timestamp, err := cp.GetConversationAttribute(conversationId, attr.LocalScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants.AttrLastConnectionTime)))
|
||||
if 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)
|
||||
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 {
|
||||
return time
|
||||
if lastMsgTime.After(lastTime) {
|
||||
lastTime = lastMsgTime
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cwtch launch date
|
||||
return event.CwtchEpoch
|
||||
// for servers
|
||||
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 {
|
||||
|
@ -1055,17 +1066,16 @@ func (cp *cwtchPeer) getConnectionsSortedByLastSeen(doPeers, doServers bool) []*
|
|||
byRecent := []*LastSeenConversation{}
|
||||
|
||||
for _, conversation := range conversations {
|
||||
if conversation.Accepted && !conversation.IsGroup() {
|
||||
if !conversation.IsGroup() {
|
||||
if conversation.IsServer() {
|
||||
if !doServers {
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
if !doPeers {
|
||||
if !doPeers || !conversation.Accepted {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
byRecent = append(byRecent, &LastSeenConversation{conversation, cp.GetConversationLastSeenTime(conversation.ID)})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue