adding support for settings for notification policy and content, per convo opt in/outs, and attaching relevant info to messages
continuous-integration/drone/pr Build is passing
Details
continuous-integration/drone/pr Build is passing
Details
This commit is contained in:
parent
d77d7bbc52
commit
643496abbf
|
@ -17,6 +17,9 @@ const PeerOnline = "peer-online"
|
||||||
// Description is used on server contacts,
|
// Description is used on server contacts,
|
||||||
const Description = "description"
|
const Description = "description"
|
||||||
|
|
||||||
|
const NotificationOptIn = "notification-opt-in"
|
||||||
|
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"
|
||||||
const StateSelectedProfileTime = "state-selected-profile-time"
|
const StateSelectedProfileTime = "state-selected-profile-time"
|
||||||
|
|
|
@ -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 is an event response for event.Status signifying a call failed in error, ideally accompanied by a event.Error
|
||||||
StatusError = "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"
|
||||||
|
)
|
||||||
|
|
|
@ -1,18 +1,19 @@
|
||||||
package utils
|
package utils
|
||||||
|
|
||||||
type Contact struct {
|
type Contact struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Onion string `json:"onion"`
|
Onion string `json:"onion"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
Picture string `json:"picture"`
|
Picture string `json:"picture"`
|
||||||
Accepted bool `json:"accepted"`
|
Accepted bool `json:"accepted"`
|
||||||
Blocked bool `json:"blocked"`
|
Blocked bool `json:"blocked"`
|
||||||
SaveHistory string `json:"saveConversationHistory"`
|
SaveHistory string `json:"saveConversationHistory"`
|
||||||
Messages int `json:"numMessages"`
|
Messages int `json:"numMessages"`
|
||||||
Unread int `json:"numUnread"`
|
Unread int `json:"numUnread"`
|
||||||
LastMessage string `json:"lastMsgTime"`
|
LastMessage string `json:"lastMsgTime"`
|
||||||
IsGroup bool `json:"isGroup"`
|
IsGroup bool `json:"isGroup"`
|
||||||
GroupServer string `json:"groupServer"`
|
GroupServer string `json:"groupServer"`
|
||||||
IsArchived bool `json:"isArchived"`
|
IsArchived bool `json:"isArchived"`
|
||||||
Identifier int `json:"identifier"`
|
Identifier int `json:"identifier"`
|
||||||
|
Options map[string]string `json:"options"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -204,6 +204,14 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string {
|
||||||
|
|
||||||
lastMessage, _ := profile.GetMostRecentMessages(conversationInfo.ID, 0, 0, 1)
|
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{
|
contacts = append(contacts, Contact{
|
||||||
Name: name,
|
Name: name,
|
||||||
Identifier: conversationInfo.ID,
|
Identifier: conversationInfo.ID,
|
||||||
|
@ -219,6 +227,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,
|
||||||
|
Options: options,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -276,6 +285,8 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
|
||||||
if ci.Accepted {
|
if ci.Accepted {
|
||||||
handleImagePreviews(profile, &ev.Event, ci.ID, ci.ID)
|
handleImagePreviews(profile, &ev.Event, ci.ID, ci.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ev.Event.Data["notification"] = determineNotification(ci)
|
||||||
case event.NewMessageFromGroup:
|
case event.NewMessageFromGroup:
|
||||||
// only needs contact nickname and picture, for displaying on popup notifications
|
// only needs contact nickname and picture, for displaying on popup notifications
|
||||||
ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"])
|
ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"])
|
||||||
|
@ -296,6 +307,7 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
|
||||||
if ci != nil && ci.Accepted {
|
if ci != nil && ci.Accepted {
|
||||||
handleImagePreviews(profile, &ev.Event, conversationID, ci.ID)
|
handleImagePreviews(profile, &ev.Event, conversationID, ci.ID)
|
||||||
}
|
}
|
||||||
|
ev.Event.Data["notification"] = determineNotification(ci)
|
||||||
case event.PeerAcknowledgement:
|
case event.PeerAcknowledgement:
|
||||||
ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"])
|
ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"])
|
||||||
if ci != nil && err == nil {
|
if ci != nil && err == nil {
|
||||||
|
|
|
@ -34,6 +34,8 @@ type GlobalSettings struct {
|
||||||
ExperimentsEnabled bool
|
ExperimentsEnabled bool
|
||||||
Experiments map[string]bool
|
Experiments map[string]bool
|
||||||
BlockUnknownConnections bool
|
BlockUnknownConnections bool
|
||||||
|
NotificationPolicy string
|
||||||
|
NotificationContent string
|
||||||
StreamerMode bool
|
StreamerMode bool
|
||||||
StateRootPane int
|
StateRootPane int
|
||||||
FirstTime bool
|
FirstTime bool
|
||||||
|
@ -62,6 +64,8 @@ var DefaultGlobalSettings = GlobalSettings{
|
||||||
StreamerMode: false,
|
StreamerMode: false,
|
||||||
UIColumnModePortrait: "DualpaneMode.Single",
|
UIColumnModePortrait: "DualpaneMode.Single",
|
||||||
UIColumnModeLandscape: "DualpaneMode.CopyPortrait",
|
UIColumnModeLandscape: "DualpaneMode.CopyPortrait",
|
||||||
|
NotificationPolicy: "NotificationPolicy.OptOut",
|
||||||
|
NotificationContent: "NotificationContent.SimpleEvent",
|
||||||
DownloadPath: "",
|
DownloadPath: "",
|
||||||
AllowAdvancedTorConfig: false,
|
AllowAdvancedTorConfig: false,
|
||||||
CustomTorrc: "",
|
CustomTorrc: "",
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"cwtch.im/cwtch/model"
|
||||||
|
"cwtch.im/cwtch/model/attr"
|
||||||
"encoding/base32"
|
"encoding/base32"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"git.openprivacy.ca/cwtch.im/libcwtch-go/constants"
|
||||||
"git.openprivacy.ca/openprivacy/log"
|
"git.openprivacy.ca/openprivacy/log"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
@ -27,3 +30,29 @@ func RandomGroupImage(handle string) string {
|
||||||
}
|
}
|
||||||
return "servers/" + choices[int(barr[0])%len(choices)] + ".png"
|
return "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