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

Merged
dan merged 1 commits from unreadSync into trunk 2022-04-04 21:45:15 +00:00
3 changed files with 26 additions and 1 deletions

View File

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

View File

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

replace with time.RFC3339 (which is the same as ISO8601)

replace with time.RFC3339 (which is the same as ISO8601)
Review

sadly they are slightly incompatible

go is
RFC3339 = "2006-01-02T15:04:05Z07:00" 
which is slightly incompatible with
DartIso8601 = "2006-01-02T15:04:05.999Z"

i tried and they werent compatible

sadly they are slightly incompatible go is RFC3339 = "2006-01-02T15:04:05Z07:00"  which is slightly incompatible with DartIso8601 = "2006-01-02T15:04:05.999Z" i tried and they werent compatible

View File

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