From e5e4d21fa01be6d14e010e04786c2d7e6ab82d3b Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Fri, 4 Feb 2022 16:25:06 -0500 Subject: [PATCH 1/3] adding support for settings for notification policy and content, per convo opt in/outs, and attaching relevant info to messages --- constants/attributes.go | 3 +++ constants/globals.go | 9 +++++++++ go.sum | 1 - utils/contacts.go | 31 ++++++++++++++++--------------- utils/eventHandler.go | 12 ++++++++++++ utils/settings.go | 4 ++++ utils/utils.go | 29 +++++++++++++++++++++++++++++ 7 files changed, 73 insertions(+), 16 deletions(-) diff --git a/constants/attributes.go b/constants/attributes.go index 122f390..97e3d6c 100644 --- a/constants/attributes.go +++ b/constants/attributes.go @@ -18,6 +18,9 @@ const PeerOnline = "peer-online" // Description is used on server contacts, const Description = "description" +const NotificationOptIn = "notification-opt-in" +const NotificationOptOut = "notification-opt-out" + const StateProfilePane = "state-profile-pane" const StateSelectedConversation = "state-selected-conversation" const StateSelectedProfileTime = "state-selected-profile-time" diff --git a/constants/globals.go b/constants/globals.go index 8f9dd1a..ea51637 100644 --- a/constants/globals.go +++ b/constants/globals.go @@ -11,3 +11,12 @@ const ( // StatusError is an event response for event.Status signifying a call failed in error, ideally accompanied by a event.Error StatusError = "error" ) + +const ( + // NotificationNone enum for message["notification"] that means no notification + NotificationNone = "None" + // NotificationEvent enum for message["notification"] that means emit a notification that a message event happened only + NotificationEvent = "SimpleEvent" + // NotificationConversation enum for message["notification"] that means emit a notification event with Conversation handle included + NotificationConversation = "ContactInfo" +) diff --git a/go.sum b/go.sum index c732cdc..b5e60e3 100644 --- a/go.sum +++ b/go.sum @@ -274,7 +274,6 @@ golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHl golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= -golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028 h1:4+4C/Iv2U4fMZBiMCc98MG1In4gJY5YRhtpDNeDeHWs= golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= diff --git a/utils/contacts.go b/utils/contacts.go index 4d5ae57..3588935 100644 --- a/utils/contacts.go +++ b/utils/contacts.go @@ -1,19 +1,20 @@ package utils type Contact struct { - Name string `json:"name"` - Onion string `json:"onion"` - Status string `json:"status"` - Picture string `json:"picture"` - DefaultPicture string `json:"defaultPicture"` - Accepted bool `json:"accepted"` - Blocked bool `json:"blocked"` - SaveHistory string `json:"saveConversationHistory"` - Messages int `json:"numMessages"` - Unread int `json:"numUnread"` - LastMessage string `json:"lastMsgTime"` - IsGroup bool `json:"isGroup"` - GroupServer string `json:"groupServer"` - IsArchived bool `json:"isArchived"` - Identifier int `json:"identifier"` + Name string `json:"name"` + Onion string `json:"onion"` + Status string `json:"status"` + Picture string `json:"picture"` + DefaultPicture string `json:"defaultPicture"` + Accepted bool `json:"accepted"` + Blocked bool `json:"blocked"` + SaveHistory string `json:"saveConversationHistory"` + Messages int `json:"numMessages"` + Unread int `json:"numUnread"` + LastMessage string `json:"lastMsgTime"` + IsGroup bool `json:"isGroup"` + GroupServer string `json:"groupServer"` + IsArchived bool `json:"isArchived"` + Identifier int `json:"identifier"` + Options map[string]string `json:"options"` } diff --git a/utils/eventHandler.go b/utils/eventHandler.go index 32cf941..a1e9d80 100644 --- a/utils/eventHandler.go +++ b/utils/eventHandler.go @@ -220,6 +220,14 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string { lastMessage, _ := profile.GetMostRecentMessages(conversationInfo.ID, 0, 0, 1) + options := make(map[string]string) + if notificationOptIn, exists := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants2.NotificationOptIn); exists { + options[constants2.NotificationOptIn] = notificationOptIn + } + if notificationOptOut, exists := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants2.NotificationOptOut); exists { + options[constants2.NotificationOptOut] = notificationOptOut + } + contacts = append(contacts, Contact{ Name: name, Identifier: conversationInfo.ID, @@ -236,6 +244,7 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string { IsGroup: conversationInfo.IsGroup(), GroupServer: groupServer, IsArchived: isArchived == event.True, + Options: options, }) } } @@ -305,6 +314,8 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string { if ci.Accepted { handleImagePreviews(profile, &ev.Event, ci.ID, ci.ID) } + + ev.Event.Data["notification"] = determineNotification(ci) case event.NewMessageFromGroup: // only needs contact nickname and picture, for displaying on popup notifications ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"]) @@ -327,6 +338,7 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string { if ci != nil && ci.Accepted { handleImagePreviews(profile, &ev.Event, conversationID, ci.ID) } + ev.Event.Data["notification"] = determineNotification(ci) case event.PeerAcknowledgement: ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"]) if ci != nil && err == nil { diff --git a/utils/settings.go b/utils/settings.go index 5acfee1..4281a02 100644 --- a/utils/settings.go +++ b/utils/settings.go @@ -34,6 +34,8 @@ type GlobalSettings struct { ExperimentsEnabled bool Experiments map[string]bool BlockUnknownConnections bool + NotificationPolicy string + NotificationContent string StreamerMode bool StateRootPane int FirstTime bool @@ -62,6 +64,8 @@ var DefaultGlobalSettings = GlobalSettings{ StreamerMode: false, UIColumnModePortrait: "DualpaneMode.Single", UIColumnModeLandscape: "DualpaneMode.CopyPortrait", + NotificationPolicy: "NotificationPolicy.OptOut", + NotificationContent: "NotificationContent.SimpleEvent", DownloadPath: "", AllowAdvancedTorConfig: false, CustomTorrc: "", diff --git a/utils/utils.go b/utils/utils.go index 7c8a161..f67731c 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -1,8 +1,11 @@ package utils import ( + "cwtch.im/cwtch/model" + "cwtch.im/cwtch/model/attr" "encoding/base32" "encoding/hex" + "git.openprivacy.ca/cwtch.im/libcwtch-go/constants" "git.openprivacy.ca/openprivacy/log" "strings" ) @@ -27,3 +30,29 @@ func RandomGroupImage(handle string) string { } return "assets/servers/" + choices[int(barr[0])%len(choices)] + ".png" } + +func determineNotification(ci *model.Conversation) string { + settings := ReadGlobalSettings() + + switch settings.NotificationPolicy { + case "NotificationPolicy.None": + return constants.NotificationNone + case "NotificationPolicy.OptOut": + 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 "NotificationPolicy.OptIn": + if optIn, exists := ci.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.NotificationOptIn); exists && optIn == "true" { + if settings.NotificationContent == "NotificationContent.ContactInfo" { + return constants.NotificationConversation + } + return constants.NotificationEvent + } + return constants.NotificationNone + } + return constants.NotificationNone +} -- 2.25.1 From ce09ccdd6af1872dd49112c323e7d5d923b77978 Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Fri, 4 Feb 2022 19:17:39 -0500 Subject: [PATCH 2/3] PR comments: enumerification --- constants/attributes.go | 3 +++ constants/globals.go | 8 ++++--- utils/contacts.go | 33 ++++++++++++++-------------- utils/eventHandler.go | 48 +++++++++++++++++++++-------------------- utils/notifications.go | 37 +++++++++++++++++++++++++++++++ utils/settings.go | 10 ++++++++- utils/utils.go | 29 ------------------------- 7 files changed, 96 insertions(+), 72 deletions(-) create mode 100644 utils/notifications.go diff --git a/constants/attributes.go b/constants/attributes.go index 97e3d6c..32a5bfa 100644 --- a/constants/attributes.go +++ b/constants/attributes.go @@ -18,7 +18,10 @@ 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" const StateProfilePane = "state-profile-pane" diff --git a/constants/globals.go b/constants/globals.go index ea51637..aacfd0e 100644 --- a/constants/globals.go +++ b/constants/globals.go @@ -12,11 +12,13 @@ const ( StatusError = "error" ) +type NotificationType string + const ( // NotificationNone enum for message["notification"] that means no notification - NotificationNone = "None" + NotificationNone = NotificationType("None") // NotificationEvent enum for message["notification"] that means emit a notification that a message event happened only - NotificationEvent = "SimpleEvent" + NotificationEvent = NotificationType("SimpleEvent") // NotificationConversation enum for message["notification"] that means emit a notification event with Conversation handle included - NotificationConversation = "ContactInfo" + NotificationConversation = NotificationType("ContactInfo") ) diff --git a/utils/contacts.go b/utils/contacts.go index 3588935..3961246 100644 --- a/utils/contacts.go +++ b/utils/contacts.go @@ -1,20 +1,21 @@ package utils type Contact struct { - Name string `json:"name"` - Onion string `json:"onion"` - Status string `json:"status"` - Picture string `json:"picture"` - DefaultPicture string `json:"defaultPicture"` - Accepted bool `json:"accepted"` - Blocked bool `json:"blocked"` - SaveHistory string `json:"saveConversationHistory"` - Messages int `json:"numMessages"` - Unread int `json:"numUnread"` - LastMessage string `json:"lastMsgTime"` - IsGroup bool `json:"isGroup"` - GroupServer string `json:"groupServer"` - IsArchived bool `json:"isArchived"` - Identifier int `json:"identifier"` - Options map[string]string `json:"options"` + Name string `json:"name"` + Onion string `json:"onion"` + Status string `json:"status"` + Picture string `json:"picture"` + DefaultPicture string `json:"defaultPicture"` + Accepted bool `json:"accepted"` + Blocked bool `json:"blocked"` + SaveHistory string `json:"saveConversationHistory"` + Messages int `json:"numMessages"` + Unread int `json:"numUnread"` + LastMessage string `json:"lastMsgTime"` + IsGroup bool `json:"isGroup"` + GroupServer string `json:"groupServer"` + IsArchived bool `json:"isArchived"` + Identifier int `json:"identifier"` + NotificationOptIn bool `json:"notificationOptIn""` + NotificationOptOut bool `json:"notificationOptOut""` } diff --git a/utils/eventHandler.go b/utils/eventHandler.go index a1e9d80..5b6ff12 100644 --- a/utils/eventHandler.go +++ b/utils/eventHandler.go @@ -220,31 +220,33 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string { lastMessage, _ := profile.GetMostRecentMessages(conversationInfo.ID, 0, 0, 1) - options := make(map[string]string) - if notificationOptIn, exists := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants2.NotificationOptIn); exists { - options[constants2.NotificationOptIn] = notificationOptIn + notificationOptIn := false + if notificationOptInAttr, exists := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants2.NotificationOptIn); exists { + notificationOptIn = notificationOptInAttr == "true" } - if notificationOptOut, exists := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants2.NotificationOptOut); exists { - options[constants2.NotificationOptOut] = notificationOptOut + notificationOptOut := false + if notificationOptOutAttr, exists := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants2.NotificationOptOut); exists { + notificationOptOut = notificationOptOutAttr == "true" } contacts = append(contacts, Contact{ - Name: name, - Identifier: conversationInfo.ID, - Onion: conversationInfo.Handle, - Status: connections.ConnectionStateName[state], - Picture: cpicPath, - DefaultPicture: RandomProfileImage(conversationInfo.Handle), - Accepted: conversationInfo.Accepted, - Blocked: blocked, - SaveHistory: saveHistory, - Messages: count, - Unread: 0, - LastMessage: strconv.Itoa(getLastMessageTime(lastMessage)), - IsGroup: conversationInfo.IsGroup(), - GroupServer: groupServer, - IsArchived: isArchived == event.True, - Options: options, + Name: name, + Identifier: conversationInfo.ID, + Onion: conversationInfo.Handle, + Status: connections.ConnectionStateName[state], + Picture: cpicPath, + DefaultPicture: RandomProfileImage(conversationInfo.Handle), + Accepted: conversationInfo.Accepted, + Blocked: blocked, + SaveHistory: saveHistory, + Messages: count, + Unread: 0, + LastMessage: strconv.Itoa(getLastMessageTime(lastMessage)), + IsGroup: conversationInfo.IsGroup(), + GroupServer: groupServer, + IsArchived: isArchived == event.True, + NotificationOptIn: notificationOptIn, + NotificationOptOut: notificationOptOut, }) } } @@ -315,7 +317,7 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string { handleImagePreviews(profile, &ev.Event, ci.ID, ci.ID) } - ev.Event.Data["notification"] = determineNotification(ci) + ev.Event.Data["notification"] = string(determineNotification(ci)) case event.NewMessageFromGroup: // only needs contact nickname and picture, for displaying on popup notifications ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"]) @@ -338,7 +340,7 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string { if ci != nil && ci.Accepted { handleImagePreviews(profile, &ev.Event, conversationID, ci.ID) } - ev.Event.Data["notification"] = determineNotification(ci) + ev.Event.Data["notification"] = string(determineNotification(ci)) case event.PeerAcknowledgement: ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"]) if ci != nil && err == nil { diff --git a/utils/notifications.go b/utils/notifications.go new file mode 100644 index 0000000..5b5a50a --- /dev/null +++ b/utils/notifications.go @@ -0,0 +1,37 @@ +package utils + +import ( + "cwtch.im/cwtch/model" + "cwtch.im/cwtch/model/attr" + "git.openprivacy.ca/cwtch.im/libcwtch-go/constants" +) + +func determineNotification(ci *model.Conversation) constants.NotificationType { + settings := ReadGlobalSettings() + + switch settings.NotificationPolicy { + case NotificationPolicyNone: + 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 + } + return constants.NotificationEvent + } + } + return constants.NotificationNone + } + return constants.NotificationNone +} diff --git a/utils/settings.go b/utils/settings.go index 4281a02..5f6599e 100644 --- a/utils/settings.go +++ b/utils/settings.go @@ -26,6 +26,14 @@ var lock sync.Mutex const GlobalSettingsFilename = "ui.globals" const saltFile = "SALT" +type NotificationPolicy string + +const ( + NotificationPolicyNone = NotificationPolicy("NotificationPolicy.None") + NotificationPolicyOptOut = NotificationPolicy("NotificationPolicy.OptOut") + NotificationPolicyOptIn = NotificationPolicy("NotificationPolicy.OptIn") +) + type GlobalSettings struct { Locale string Theme string @@ -34,7 +42,7 @@ type GlobalSettings struct { ExperimentsEnabled bool Experiments map[string]bool BlockUnknownConnections bool - NotificationPolicy string + NotificationPolicy NotificationPolicy NotificationContent string StreamerMode bool StateRootPane int diff --git a/utils/utils.go b/utils/utils.go index f67731c..7c8a161 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -1,11 +1,8 @@ package utils import ( - "cwtch.im/cwtch/model" - "cwtch.im/cwtch/model/attr" "encoding/base32" "encoding/hex" - "git.openprivacy.ca/cwtch.im/libcwtch-go/constants" "git.openprivacy.ca/openprivacy/log" "strings" ) @@ -30,29 +27,3 @@ func RandomGroupImage(handle string) string { } return "assets/servers/" + choices[int(barr[0])%len(choices)] + ".png" } - -func determineNotification(ci *model.Conversation) string { - settings := ReadGlobalSettings() - - switch settings.NotificationPolicy { - case "NotificationPolicy.None": - return constants.NotificationNone - case "NotificationPolicy.OptOut": - 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 "NotificationPolicy.OptIn": - if optIn, exists := ci.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.NotificationOptIn); exists && optIn == "true" { - if settings.NotificationContent == "NotificationContent.ContactInfo" { - return constants.NotificationConversation - } - return constants.NotificationEvent - } - return constants.NotificationNone - } - return constants.NotificationNone -} -- 2.25.1 From 758af8dcaf2d3ba85e12ef2130ee686b350be806 Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Mon, 7 Feb 2022 21:12:57 -0500 Subject: [PATCH 3/3] rejig notification policies around mute, opt in, default always and conversations around default, never, optin --- constants/attributes.go | 7 ++----- constants/globals.go | 9 ++++++++ utils/contacts.go | 3 +-- utils/eventHandler.go | 13 ++++-------- utils/notifications.go | 46 +++++++++++++++++++++++++++-------------- utils/settings.go | 6 +++--- 6 files changed, 49 insertions(+), 35 deletions(-) diff --git a/constants/attributes.go b/constants/attributes.go index 32a5bfa..2fbe174 100644 --- a/constants/attributes.go +++ b/constants/attributes.go @@ -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" diff --git a/constants/globals.go b/constants/globals.go index aacfd0e..31cf2be 100644 --- a/constants/globals.go +++ b/constants/globals.go @@ -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" +) diff --git a/utils/contacts.go b/utils/contacts.go index 3961246..928bed3 100644 --- a/utils/contacts.go +++ b/utils/contacts.go @@ -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""` } diff --git a/utils/eventHandler.go b/utils/eventHandler.go index 5b6ff12..9437835 100644 --- a/utils/eventHandler.go +++ b/utils/eventHandler.go @@ -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, }) } } diff --git a/utils/notifications.go b/utils/notifications.go index 5b5a50a..8abb5d7 100644 --- a/utils/notifications.go +++ b/utils/notifications.go @@ -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 +} diff --git a/utils/settings.go b/utils/settings.go index 5f6599e..6b0b15e 100644 --- a/utils/settings.go +++ b/utils/settings.go @@ -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 { -- 2.25.1