52 lines
1.8 KiB
Go
52 lines
1.8 KiB
Go
|
package utils
|
||
|
|
||
|
import (
|
||
|
"cwtch.im/cwtch/app"
|
||
|
"cwtch.im/cwtch/model"
|
||
|
"cwtch.im/cwtch/model/attr"
|
||
|
"git.openprivacy.ca/cwtch.im/libcwtch-go/constants"
|
||
|
)
|
||
|
|
||
|
func determineNotification(ci *model.Conversation, settings app.GlobalSettings) constants.NotificationType {
|
||
|
switch settings.NotificationPolicy {
|
||
|
case app.NotificationPolicyMute:
|
||
|
return constants.NotificationNone
|
||
|
case app.NotificationPolicyOptIn:
|
||
|
if ci != nil {
|
||
|
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.NotificationNone
|
||
|
case app.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
|
||
|
}
|