Merge pull request 'notificationPolicy' (#72) from notificationPolicy into trunk
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Reviewed-on: #72
This commit is contained in:
commit
d0d5300a95
|
@ -18,6 +18,9 @@ const PeerOnline = "peer-online"
|
||||||
// Description is used on server contacts,
|
// Description is used on server contacts,
|
||||||
const Description = "description"
|
const Description = "description"
|
||||||
|
|
||||||
|
// ConversationNotificationPolicy is the attribute label for conversations. When App NotificationPolicy is OptIn a true value here opts in
|
||||||
|
const ConversationNotificationPolicy = "notification-policy"
|
||||||
|
|
||||||
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,23 @@ 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"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type NotificationType string
|
||||||
|
|
||||||
|
const (
|
||||||
|
// NotificationNone enum for message["notification"] that means no notification
|
||||||
|
NotificationNone = NotificationType("None")
|
||||||
|
// NotificationEvent enum for message["notification"] that means emit a notification that a message event happened only
|
||||||
|
NotificationEvent = NotificationType("SimpleEvent")
|
||||||
|
// NotificationConversation enum for message["notification"] that means emit a notification event with Conversation handle included
|
||||||
|
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"
|
||||||
|
)
|
||||||
|
|
1
go.sum
1
go.sum
|
@ -274,7 +274,6 @@ golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHl
|
||||||
golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||||
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
|
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
|
||||||
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028 h1:4+4C/Iv2U4fMZBiMCc98MG1In4gJY5YRhtpDNeDeHWs=
|
|
||||||
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
|
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
|
||||||
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
|
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
|
||||||
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
|
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
|
||||||
|
|
|
@ -1,19 +1,20 @@
|
||||||
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"`
|
||||||
DefaultPicture string `json:"defaultPicture"`
|
DefaultPicture string `json:"defaultPicture"`
|
||||||
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"`
|
||||||
|
NotificationPolicy string `json:"notificationPolicy"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,22 +222,28 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string {
|
||||||
|
|
||||||
lastMessage, _ := profile.GetMostRecentMessages(conversationInfo.ID, 0, 0, 1)
|
lastMessage, _ := profile.GetMostRecentMessages(conversationInfo.ID, 0, 0, 1)
|
||||||
|
|
||||||
|
notificationPolicy := constants2.ConversationNotificationPolicyDefault
|
||||||
|
if notificationPolicyAttr, exists := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants2.ConversationNotificationPolicy); exists {
|
||||||
|
notificationPolicy = notificationPolicyAttr
|
||||||
|
}
|
||||||
|
|
||||||
contacts = append(contacts, Contact{
|
contacts = append(contacts, Contact{
|
||||||
Name: name,
|
Name: name,
|
||||||
Identifier: conversationInfo.ID,
|
Identifier: conversationInfo.ID,
|
||||||
Onion: conversationInfo.Handle,
|
Onion: conversationInfo.Handle,
|
||||||
Status: connections.ConnectionStateName[state],
|
Status: connections.ConnectionStateName[state],
|
||||||
Picture: cpicPath,
|
Picture: cpicPath,
|
||||||
DefaultPicture: RandomProfileImage(conversationInfo.Handle),
|
DefaultPicture: RandomProfileImage(conversationInfo.Handle),
|
||||||
Accepted: conversationInfo.Accepted,
|
Accepted: conversationInfo.Accepted,
|
||||||
Blocked: blocked,
|
Blocked: blocked,
|
||||||
SaveHistory: saveHistory,
|
SaveHistory: saveHistory,
|
||||||
Messages: count,
|
Messages: count,
|
||||||
Unread: 0,
|
Unread: 0,
|
||||||
LastMessage: strconv.Itoa(getLastMessageTime(lastMessage)),
|
LastMessage: strconv.Itoa(getLastMessageTime(lastMessage)),
|
||||||
IsGroup: conversationInfo.IsGroup(),
|
IsGroup: conversationInfo.IsGroup(),
|
||||||
GroupServer: groupServer,
|
GroupServer: groupServer,
|
||||||
IsArchived: isArchived == event.True,
|
IsArchived: isArchived == event.True,
|
||||||
|
NotificationPolicy: notificationPolicy,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -311,6 +317,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"] = string(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"])
|
||||||
|
@ -333,6 +341,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"] = string(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 {
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
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 NotificationPolicyMute:
|
||||||
|
return constants.NotificationNone
|
||||||
|
case 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 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
|
||||||
|
}
|
|
@ -26,6 +26,14 @@ var lock sync.Mutex
|
||||||
const GlobalSettingsFilename = "ui.globals"
|
const GlobalSettingsFilename = "ui.globals"
|
||||||
const saltFile = "SALT"
|
const saltFile = "SALT"
|
||||||
|
|
||||||
|
type NotificationPolicy string
|
||||||
|
|
||||||
|
const (
|
||||||
|
NotificationPolicyMute = NotificationPolicy("NotificationPolicy.Mute")
|
||||||
|
NotificationPolicyOptIn = NotificationPolicy("NotificationPolicy.OptIn")
|
||||||
|
NotificationPolicyDefaultAll = NotificationPolicy("NotificationPolicy.DefaultAll")
|
||||||
|
)
|
||||||
|
|
||||||
type GlobalSettings struct {
|
type GlobalSettings struct {
|
||||||
Locale string
|
Locale string
|
||||||
Theme string
|
Theme string
|
||||||
|
@ -34,6 +42,8 @@ type GlobalSettings struct {
|
||||||
ExperimentsEnabled bool
|
ExperimentsEnabled bool
|
||||||
Experiments map[string]bool
|
Experiments map[string]bool
|
||||||
BlockUnknownConnections bool
|
BlockUnknownConnections bool
|
||||||
|
NotificationPolicy NotificationPolicy
|
||||||
|
NotificationContent string
|
||||||
StreamerMode bool
|
StreamerMode bool
|
||||||
StateRootPane int
|
StateRootPane int
|
||||||
FirstTime bool
|
FirstTime bool
|
||||||
|
@ -62,6 +72,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: "",
|
||||||
|
|
Reference in New Issue