rejig notification policies around mute, opt in, default always and conversations around default, never, optin

This commit is contained in:
Dan Ballard 2022-02-07 21:12:57 -05:00
parent ce09ccdd6a
commit 758af8dcaf
6 changed files with 49 additions and 35 deletions

View File

@ -18,11 +18,8 @@ const PeerOnline = "peer-online"
// Description is used on server contacts,
const Description = "description"
// NotificationOptIn is the attribute label for conversations. When App NotificationPolicy is OptIn a true value here opts in
const NotificationOptIn = "notification-opt-in"
// NotificationOptOut is the attribute label for conversations. When App NotificationPolicy is OptOut a true value here opts out
const NotificationOptOut = "notification-opt-out"
// ConversationNotificationPolicy is the attribute label for conversations. When App NotificationPolicy is OptIn a true value here opts in
const ConversationNotificationPolicy = "notification-policy"
const StateProfilePane = "state-profile-pane"
const StateSelectedConversation = "state-selected-conversation"

View File

@ -22,3 +22,12 @@ const (
// NotificationConversation enum for message["notification"] that means emit a notification event with Conversation handle included
NotificationConversation = NotificationType("ContactInfo")
)
const (
// ConversationNotificationPolicyDefault enum for conversations indicating to use global notification policy
ConversationNotificationPolicyDefault = "ConversationNotificationPolicy.Default"
// ConversationNotificationPolicyOptIn enum for conversation indicating to opt in to nofitications when allowed
ConversationNotificationPolicyOptIn = "ConversationNotificationPolicy.OptIn"
// ConversationNotificationPolicyNever enum for conversation indicating to opt in to never do notifications
ConversationNotificationPolicyNever = "ConversationNotificationPolicy.Never"
)

View File

@ -16,6 +16,5 @@ type Contact struct {
GroupServer string `json:"groupServer"`
IsArchived bool `json:"isArchived"`
Identifier int `json:"identifier"`
NotificationOptIn bool `json:"notificationOptIn""`
NotificationOptOut bool `json:"notificationOptOut""`
NotificationPolicy string `json:"notificationPolicy""`
}

View File

@ -220,13 +220,9 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string {
lastMessage, _ := profile.GetMostRecentMessages(conversationInfo.ID, 0, 0, 1)
notificationOptIn := false
if notificationOptInAttr, exists := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants2.NotificationOptIn); exists {
notificationOptIn = notificationOptInAttr == "true"
}
notificationOptOut := false
if notificationOptOutAttr, exists := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants2.NotificationOptOut); exists {
notificationOptOut = notificationOptOutAttr == "true"
notificationPolicy := constants2.ConversationNotificationPolicyDefault
if notificationPolicyAttr, exists := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants2.ConversationNotificationPolicy); exists {
notificationPolicy = notificationPolicyAttr
}
contacts = append(contacts, Contact{
@ -245,8 +241,7 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string {
IsGroup: conversationInfo.IsGroup(),
GroupServer: groupServer,
IsArchived: isArchived == event.True,
NotificationOptIn: notificationOptIn,
NotificationOptOut: notificationOptOut,
NotificationPolicy: notificationPolicy,
})
}
}

View File

@ -8,30 +8,44 @@ import (
func determineNotification(ci *model.Conversation) constants.NotificationType {
settings := ReadGlobalSettings()
switch settings.NotificationPolicy {
case NotificationPolicyNone:
case NotificationPolicyMute:
return constants.NotificationNone
case NotificationPolicyOptOut:
if ci != nil {
if optOut, exists := ci.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.NotificationOptOut); exists && optOut == "true" {
return constants.NotificationNone
}
}
if settings.NotificationContent == "NotificationContent.ContactInfo" {
return constants.NotificationConversation
}
return constants.NotificationEvent
case NotificationPolicyOptIn:
if ci != nil {
if optIn, exists := ci.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.NotificationOptIn); exists && optIn == "true" {
if settings.NotificationContent == "NotificationContent.ContactInfo" {
return constants.NotificationConversation
if policy, exists := ci.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.ConversationNotificationPolicy); exists {
switch policy {
case constants.ConversationNotificationPolicyDefault:
return constants.NotificationNone
case constants.ConversationNotificationPolicyNever:
return constants.NotificationNone
case constants.ConversationNotificationPolicyOptIn:
return notificationContentToNotificationType(settings.NotificationContent)
}
return constants.NotificationEvent
}
}
return constants.NotificationNone
case NotificationPolicyDefaultAll:
if ci != nil {
if policy, exists := ci.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.ConversationNotificationPolicy); exists {
switch policy {
case constants.ConversationNotificationPolicyNever:
return constants.NotificationNone
case constants.ConversationNotificationPolicyDefault:
fallthrough
case constants.ConversationNotificationPolicyOptIn:
return notificationContentToNotificationType(settings.NotificationContent)
}
}
}
return notificationContentToNotificationType(settings.NotificationContent)
}
return constants.NotificationNone
}
func notificationContentToNotificationType(notificationContent string) constants.NotificationType {
if notificationContent == "NotificationContent.ContactInfo" {
return constants.NotificationConversation
}
return constants.NotificationEvent
}

View File

@ -29,9 +29,9 @@ const saltFile = "SALT"
type NotificationPolicy string
const (
NotificationPolicyNone = NotificationPolicy("NotificationPolicy.None")
NotificationPolicyOptOut = NotificationPolicy("NotificationPolicy.OptOut")
NotificationPolicyOptIn = NotificationPolicy("NotificationPolicy.OptIn")
NotificationPolicyMute = NotificationPolicy("NotificationPolicy.Mute")
NotificationPolicyOptIn = NotificationPolicy("NotificationPolicy.OptIn")
NotificationPolicyDefaultAll = NotificationPolicy("NotificationPolicy.DefaultAll")
)
type GlobalSettings struct {