PR comments: enumerification
This commit is contained in:
parent
e5e4d21fa0
commit
ce09ccdd6a
|
@ -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"
|
||||
|
|
|
@ -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")
|
||||
)
|
||||
|
|
|
@ -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""`
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Reference in New Issue