2022-02-05 00:17:39 +00:00
|
|
|
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 {
|
2022-02-08 02:12:57 +00:00
|
|
|
case NotificationPolicyMute:
|
2022-02-05 00:17:39 +00:00
|
|
|
return constants.NotificationNone
|
2022-02-08 02:12:57 +00:00
|
|
|
case NotificationPolicyOptIn:
|
2022-02-05 00:17:39 +00:00
|
|
|
if ci != nil {
|
2022-02-08 02:12:57 +00:00
|
|
|
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)
|
|
|
|
}
|
2022-02-05 00:17:39 +00:00
|
|
|
}
|
|
|
|
}
|
2022-02-08 02:12:57 +00:00
|
|
|
return constants.NotificationNone
|
|
|
|
case NotificationPolicyDefaultAll:
|
2022-02-05 00:17:39 +00:00
|
|
|
if ci != nil {
|
2022-02-08 02:12:57 +00:00
|
|
|
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)
|
2022-02-05 00:17:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-02-08 02:12:57 +00:00
|
|
|
return notificationContentToNotificationType(settings.NotificationContent)
|
2022-02-05 00:17:39 +00:00
|
|
|
}
|
|
|
|
return constants.NotificationNone
|
|
|
|
}
|
2022-02-08 02:12:57 +00:00
|
|
|
|
|
|
|
func notificationContentToNotificationType(notificationContent string) constants.NotificationType {
|
|
|
|
if notificationContent == "NotificationContent.ContactInfo" {
|
|
|
|
return constants.NotificationConversation
|
|
|
|
}
|
|
|
|
return constants.NotificationEvent
|
|
|
|
}
|