add support for storing and using lastMessageSeen Time from ui and using to calculate unread counts #80
|
@ -8,6 +8,7 @@ const Picture = "picture"
|
||||||
const DefaultProfilePicture = "defaultPicture"
|
const DefaultProfilePicture = "defaultPicture"
|
||||||
const ShowBlocked = "show-blocked"
|
const ShowBlocked = "show-blocked"
|
||||||
const Archived = "archived"
|
const Archived = "archived"
|
||||||
|
const LastSeenTime = "lastMessageSeenTime"
|
||||||
|
|
||||||
const ProfileTypeV1DefaultPassword = "v1-defaultPassword"
|
const ProfileTypeV1DefaultPassword = "v1-defaultPassword"
|
||||||
const ProfileTypeV1Password = "v1-userPassword"
|
const ProfileTypeV1Password = "v1-userPassword"
|
||||||
|
|
|
@ -31,3 +31,5 @@ const (
|
||||||
// ConversationNotificationPolicyNever enum for conversation indicating to opt in to never do notifications
|
// ConversationNotificationPolicyNever enum for conversation indicating to opt in to never do notifications
|
||||||
ConversationNotificationPolicyNever = "ConversationNotificationPolicy.Never"
|
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
|
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)
|
groupServer, _ := conversationInfo.GetAttribute(attr.LocalScope, attr.LegacyGroupZone, constants.GroupServer)
|
||||||
|
|
||||||
stateHandle := conversationInfo.Handle
|
stateHandle := conversationInfo.Handle
|
||||||
|
@ -241,7 +263,7 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string {
|
||||||
Blocked: blocked,
|
Blocked: blocked,
|
||||||
SaveHistory: saveHistory,
|
SaveHistory: saveHistory,
|
||||||
Messages: count,
|
Messages: count,
|
||||||
Unread: 0,
|
Unread: unread,
|
||||||
LastMessage: strconv.Itoa(getLastMessageTime(lastMessage)),
|
LastMessage: strconv.Itoa(getLastMessageTime(lastMessage)),
|
||||||
IsGroup: conversationInfo.IsGroup(),
|
IsGroup: conversationInfo.IsGroup(),
|
||||||
GroupServer: groupServer,
|
GroupServer: groupServer,
|
||||||
|
|
Reference in New Issue
replace with time.RFC3339 (which is the same as ISO8601)
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