Browse Source

add support for storing and using lastMessageSeen Time from ui and using to calculate unread counts

unreadSync
Dan Ballard 5 months ago
parent
commit
cd48642411
  1. 1
      constants/attributes.go
  2. 2
      constants/globals.go
  3. 24
      utils/eventHandler.go

1
constants/attributes.go

@ -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"

2
constants/globals.go

@ -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"

24
utils/eventHandler.go

@ -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,

Loading…
Cancel
Save