You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Open-IM-Server/pkg/utils/options.go

168 lines
3.6 KiB

2 years ago
package utils
2 years ago
import "github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
type Options map[string]bool
type OptionsOpt func(Options)
func NewOptions(opts ...OptionsOpt) Options {
options := make(map[string]bool, 11)
2 years ago
options[constant.IsNotNotification] = false
options[constant.IsSendMsg] = false
2 years ago
options[constant.IsHistory] = false
options[constant.IsPersistent] = false
options[constant.IsOfflinePush] = false
options[constant.IsUnreadCount] = false
options[constant.IsConversationUpdate] = false
options[constant.IsSenderSync] = false
options[constant.IsNotPrivate] = false
options[constant.IsSenderConversationUpdate] = false
options[constant.IsSenderNotificationPush] = false
options[constant.IsReactionFromCache] = false
for _, opt := range opts {
opt(options)
}
return options
}
2 years ago
func NewMsgOptions() Options {
options := make(map[string]bool, 11)
options[constant.IsOfflinePush] = false
return make(map[string]bool)
}
2 years ago
func WithOptions(options Options, opts ...OptionsOpt) Options {
for _, opt := range opts {
opt(options)
}
return options
}
2 years ago
func WithNotNotification(b bool) OptionsOpt {
2 years ago
return func(options Options) {
2 years ago
options[constant.IsNotNotification] = b
2 years ago
}
}
func WithSendMsg(b bool) OptionsOpt {
2 years ago
return func(options Options) {
options[constant.IsSendMsg] = b
}
}
func WithHistory(b bool) OptionsOpt {
return func(options Options) {
options[constant.IsHistory] = b
2 years ago
}
}
func WithPersistent() OptionsOpt {
return func(options Options) {
options[constant.IsPersistent] = true
}
}
2 years ago
func WithOfflinePush(b bool) OptionsOpt {
2 years ago
return func(options Options) {
2 years ago
options[constant.IsOfflinePush] = b
2 years ago
}
}
2 years ago
func WithUnreadCount(b bool) OptionsOpt {
2 years ago
return func(options Options) {
2 years ago
options[constant.IsUnreadCount] = b
2 years ago
}
}
func WithConversationUpdate() OptionsOpt {
return func(options Options) {
options[constant.IsConversationUpdate] = true
}
}
func WithSenderSync() OptionsOpt {
return func(options Options) {
options[constant.IsSenderSync] = true
}
}
func WithNotPrivate() OptionsOpt {
return func(options Options) {
options[constant.IsNotPrivate] = true
}
}
func WithSenderConversationUpdate() OptionsOpt {
return func(options Options) {
options[constant.IsSenderConversationUpdate] = true
}
}
func WithSenderNotificationPush() OptionsOpt {
return func(options Options) {
options[constant.IsSenderNotificationPush] = true
}
}
func WithReactionFromCache() OptionsOpt {
return func(options Options) {
options[constant.IsReactionFromCache] = true
}
}
func (o Options) Is(notification string) bool {
v, ok := o[notification]
if !ok || v {
return true
}
return false
}
2 years ago
func (o Options) IsNotNotification() bool {
2 years ago
return o.Is(constant.IsNotNotification)
2 years ago
}
func (o Options) IsSendMsg() bool {
return o.Is(constant.IsSendMsg)
}
func (o Options) IsHistory() bool {
2 years ago
return o.Is(constant.IsHistory)
}
func (o Options) IsPersistent() bool {
2 years ago
return o.Is(constant.IsPersistent)
}
func (o Options) IsOfflinePush() bool {
2 years ago
return o.Is(constant.IsOfflinePush)
}
func (o Options) IsUnreadCount() bool {
2 years ago
return o.Is(constant.IsUnreadCount)
}
func (o Options) IsConversationUpdate() bool {
2 years ago
return o.Is(constant.IsConversationUpdate)
}
func (o Options) IsSenderSync() bool {
2 years ago
return o.Is(constant.IsSenderSync)
}
func (o Options) IsNotPrivate() bool {
2 years ago
return o.Is(constant.IsNotPrivate)
}
func (o Options) IsSenderConversationUpdate() bool {
2 years ago
return o.Is(constant.IsSenderConversationUpdate)
}
func (o Options) IsSenderNotificationPush() bool {
2 years ago
return o.Is(constant.IsSenderNotificationPush)
}
func (o Options) IsReactionFromCache() bool {
2 years ago
return o.Is(constant.IsReactionFromCache)
}