add support for storing and using lastMessageSeen Time from ui and using to calculate unread counts
continuous-integration/drone/pr Build is passing
Details
continuous-integration/drone/pr Build is passing
Details
This commit is contained in:
parent
1acae32030
commit
cd48642411
|
@ -8,6 +8,7 @@ const Picture = "picture"
|
|||
const DefaultProfilePicture = "defaultPicture"
|
||||
const ShowBlocked = "show-blocked"
|
||||
const Archived = "archived"
|
||||
const LastSeenTime = "lastMessageSeenTime"
|
||||
|
||||
const ProfileTypeV1DefaultPassword = "v1-defaultPassword"
|
||||
const ProfileTypeV1Password = "v1-userPassword"
|
||||
|
|
|
@ -31,3 +31,5 @@ const (
|
|||
// ConversationNotificationPolicyNever enum for conversation indicating to opt in to never do notifications
|
||||
ConversationNotificationPolicyNever = "ConversationNotificationPolicy.Never"
|
||||
)
|
||||
|
||||
const DartIso8601 = "2006-01-02T15:04:05.999Z"
|
||||
|
|
|
@ -201,6 +201,28 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string {
|
|||
isArchived = event.False
|
||||
}
|
||||
|
||||
unread := 0
|
||||
lastSeenTimeStr, set := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants2.LastSeenTime)
|
||||
if set {
|
||||
lastSeenTime, err := time.Parse(constants2.DartIso8601, lastSeenTimeStr)
|
||||
if err == nil {
|
||||
// get last 100 messages and count how many are after the lastSeenTime (100 cus hte ui just shows 99+ after)
|
||||
messages, err := profile.GetMostRecentMessages(conversationInfo.ID, 0, 0, 100)
|
||||
if err == nil {
|
||||
for _, message := range messages {
|
||||
msgTime, err := time.Parse(time.RFC3339Nano, message.Attr[constants.AttrSentTimestamp])
|
||||
if err == nil {
|
||||
if msgTime.UTC().After(lastSeenTime.UTC()) {
|
||||
unread++
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
groupServer, _ := conversationInfo.GetAttribute(attr.LocalScope, attr.LegacyGroupZone, constants.GroupServer)
|
||||
|
||||
stateHandle := conversationInfo.Handle
|
||||
|
@ -241,7 +263,7 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string {
|
|||
Blocked: blocked,
|
||||
SaveHistory: saveHistory,
|
||||
Messages: count,
|
||||
Unread: 0,
|
||||
Unread: unread,
|
||||
LastMessage: strconv.Itoa(getLastMessageTime(lastMessage)),
|
||||
IsGroup: conversationInfo.IsGroup(),
|
||||
GroupServer: groupServer,
|
||||
|
|
Reference in New Issue