forked from cwtch.im/libcwtch-go
rejig notification policies around mute, opt in, default always and conversations around default, never, optin
This commit is contained in:
parent
ce09ccdd6a
commit
758af8dcaf
|
@ -18,11 +18,8 @@ const PeerOnline = "peer-online"
|
||||||
// Description is used on server contacts,
|
// Description is used on server contacts,
|
||||||
const Description = "description"
|
const Description = "description"
|
||||||
|
|
||||||
// NotificationOptIn is the attribute label for conversations. When App NotificationPolicy is OptIn a true value here opts in
|
// ConversationNotificationPolicy is the attribute label for conversations. When App NotificationPolicy is OptIn a true value here opts in
|
||||||
const NotificationOptIn = "notification-opt-in"
|
const ConversationNotificationPolicy = "notification-policy"
|
||||||
|
|
||||||
// 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"
|
const StateProfilePane = "state-profile-pane"
|
||||||
const StateSelectedConversation = "state-selected-conversation"
|
const StateSelectedConversation = "state-selected-conversation"
|
||||||
|
|
|
@ -22,3 +22,12 @@ const (
|
||||||
// NotificationConversation enum for message["notification"] that means emit a notification event with Conversation handle included
|
// NotificationConversation enum for message["notification"] that means emit a notification event with Conversation handle included
|
||||||
NotificationConversation = NotificationType("ContactInfo")
|
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"
|
||||||
|
)
|
||||||
|
|
|
@ -16,6 +16,5 @@ type Contact struct {
|
||||||
GroupServer string `json:"groupServer"`
|
GroupServer string `json:"groupServer"`
|
||||||
IsArchived bool `json:"isArchived"`
|
IsArchived bool `json:"isArchived"`
|
||||||
Identifier int `json:"identifier"`
|
Identifier int `json:"identifier"`
|
||||||
NotificationOptIn bool `json:"notificationOptIn""`
|
NotificationPolicy string `json:"notificationPolicy""`
|
||||||
NotificationOptOut bool `json:"notificationOptOut""`
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -220,13 +220,9 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string {
|
||||||
|
|
||||||
lastMessage, _ := profile.GetMostRecentMessages(conversationInfo.ID, 0, 0, 1)
|
lastMessage, _ := profile.GetMostRecentMessages(conversationInfo.ID, 0, 0, 1)
|
||||||
|
|
||||||
notificationOptIn := false
|
notificationPolicy := constants2.ConversationNotificationPolicyDefault
|
||||||
if notificationOptInAttr, exists := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants2.NotificationOptIn); exists {
|
if notificationPolicyAttr, exists := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants2.ConversationNotificationPolicy); exists {
|
||||||
notificationOptIn = notificationOptInAttr == "true"
|
notificationPolicy = notificationPolicyAttr
|
||||||
}
|
|
||||||
notificationOptOut := false
|
|
||||||
if notificationOptOutAttr, exists := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants2.NotificationOptOut); exists {
|
|
||||||
notificationOptOut = notificationOptOutAttr == "true"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
contacts = append(contacts, Contact{
|
contacts = append(contacts, Contact{
|
||||||
|
@ -245,8 +241,7 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string {
|
||||||
IsGroup: conversationInfo.IsGroup(),
|
IsGroup: conversationInfo.IsGroup(),
|
||||||
GroupServer: groupServer,
|
GroupServer: groupServer,
|
||||||
IsArchived: isArchived == event.True,
|
IsArchived: isArchived == event.True,
|
||||||
NotificationOptIn: notificationOptIn,
|
NotificationPolicy: notificationPolicy,
|
||||||
NotificationOptOut: notificationOptOut,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,30 +8,44 @@ import (
|
||||||
|
|
||||||
func determineNotification(ci *model.Conversation) constants.NotificationType {
|
func determineNotification(ci *model.Conversation) constants.NotificationType {
|
||||||
settings := ReadGlobalSettings()
|
settings := ReadGlobalSettings()
|
||||||
|
|
||||||
switch settings.NotificationPolicy {
|
switch settings.NotificationPolicy {
|
||||||
case NotificationPolicyNone:
|
case NotificationPolicyMute:
|
||||||
return constants.NotificationNone
|
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:
|
case NotificationPolicyOptIn:
|
||||||
if ci != nil {
|
if ci != nil {
|
||||||
if optIn, exists := ci.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.NotificationOptIn); exists && optIn == "true" {
|
if policy, exists := ci.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.ConversationNotificationPolicy); exists {
|
||||||
if settings.NotificationContent == "NotificationContent.ContactInfo" {
|
switch policy {
|
||||||
return constants.NotificationConversation
|
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
|
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
|
return constants.NotificationNone
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func notificationContentToNotificationType(notificationContent string) constants.NotificationType {
|
||||||
|
if notificationContent == "NotificationContent.ContactInfo" {
|
||||||
|
return constants.NotificationConversation
|
||||||
|
}
|
||||||
|
return constants.NotificationEvent
|
||||||
|
}
|
||||||
|
|
|
@ -29,9 +29,9 @@ const saltFile = "SALT"
|
||||||
type NotificationPolicy string
|
type NotificationPolicy string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
NotificationPolicyNone = NotificationPolicy("NotificationPolicy.None")
|
NotificationPolicyMute = NotificationPolicy("NotificationPolicy.Mute")
|
||||||
NotificationPolicyOptOut = NotificationPolicy("NotificationPolicy.OptOut")
|
NotificationPolicyOptIn = NotificationPolicy("NotificationPolicy.OptIn")
|
||||||
NotificationPolicyOptIn = NotificationPolicy("NotificationPolicy.OptIn")
|
NotificationPolicyDefaultAll = NotificationPolicy("NotificationPolicy.DefaultAll")
|
||||||
)
|
)
|
||||||
|
|
||||||
type GlobalSettings struct {
|
type GlobalSettings struct {
|
||||||
|
|
Loading…
Reference in New Issue