mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-04-28 14:29:19 +08:00
Merge branch 'pre-release-v3.8.4' into cherry-pick-964ee7a
This commit is contained in:
+3
-1
@@ -27,6 +27,7 @@ import (
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/apistruct"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/authverify"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/webhook"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/rpcli"
|
||||
"github.com/openimsdk/protocol/constant"
|
||||
"github.com/openimsdk/protocol/msg"
|
||||
@@ -210,6 +211,8 @@ func (m *MessageApi) getSendMsgReq(c *gin.Context, req apistruct.SendMsg) (sendM
|
||||
data = apistruct.AtElem{}
|
||||
case constant.Custom:
|
||||
data = apistruct.CustomElem{}
|
||||
case constant.MarkdownText:
|
||||
data = apistruct.MarkdownTextElem{}
|
||||
case constant.OANotification:
|
||||
data = apistruct.OANotificationElem{}
|
||||
req.SessionType = constant.NotificationChatType
|
||||
@@ -521,7 +524,6 @@ func (m *MessageApi) SendSimpleMessage(c *gin.Context) {
|
||||
apiresp.GinError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
m.ginRespSendMsg(c, sendReq, respPb)
|
||||
}
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ func (m *msgServer) webhookAfterSendSingleMsg(ctx context.Context, after *config
|
||||
CommonCallbackReq: toCommonCallback(ctx, msg, cbapi.CallbackAfterSendSingleMsgCommand),
|
||||
RecvID: msg.MsgData.RecvID,
|
||||
}
|
||||
m.webhookClient.AsyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, &cbapi.CallbackAfterSendSingleMsgResp{}, after)
|
||||
m.webhookClient.AsyncPostWithQuery(ctx, cbReq.GetCallbackCommand(), cbReq, &cbapi.CallbackAfterSendSingleMsgResp{}, after, buildKeyMsgDataQuery(msg.MsgData))
|
||||
}
|
||||
|
||||
func (m *msgServer) webhookBeforeSendGroupMsg(ctx context.Context, before *config.BeforeConfig, msg *pbchat.SendMsgReq) error {
|
||||
@@ -134,7 +134,8 @@ func (m *msgServer) webhookAfterSendGroupMsg(ctx context.Context, after *config.
|
||||
CommonCallbackReq: toCommonCallback(ctx, msg, cbapi.CallbackAfterSendGroupMsgCommand),
|
||||
GroupID: msg.MsgData.GroupID,
|
||||
}
|
||||
m.webhookClient.AsyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, &cbapi.CallbackAfterSendGroupMsgResp{}, after)
|
||||
|
||||
m.webhookClient.AsyncPostWithQuery(ctx, cbReq.GetCallbackCommand(), cbReq, &cbapi.CallbackAfterSendGroupMsgResp{}, after, buildKeyMsgDataQuery(msg.MsgData))
|
||||
}
|
||||
|
||||
func (m *msgServer) webhookBeforeMsgModify(ctx context.Context, before *config.BeforeConfig, msg *pbchat.SendMsgReq, beforeMsgData **sdkws.MsgData) error {
|
||||
@@ -203,3 +204,15 @@ func (m *msgServer) webhookAfterRevokeMsg(ctx context.Context, after *config.Aft
|
||||
}
|
||||
m.webhookClient.AsyncPost(ctx, callbackReq.GetCallbackCommand(), callbackReq, &cbapi.CallbackAfterRevokeMsgResp{}, after)
|
||||
}
|
||||
|
||||
func buildKeyMsgDataQuery(msg *sdkws.MsgData) map[string]string {
|
||||
keyMsgData := apistruct.KeyMsgData{
|
||||
SendID: msg.SendID,
|
||||
RecvID: msg.RecvID,
|
||||
GroupID: msg.GroupID,
|
||||
}
|
||||
|
||||
return map[string]string{
|
||||
webhook.Key: base64.StdEncoding.EncodeToString(stringutil.StructToJsonBytes(keyMsgData)),
|
||||
}
|
||||
}
|
||||
|
||||
+36
-12
@@ -1,11 +1,13 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||
pbchat "github.com/openimsdk/protocol/msg"
|
||||
"github.com/openimsdk/tools/utils/datautil"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||
"github.com/openimsdk/protocol/constant"
|
||||
pbchat "github.com/openimsdk/protocol/msg"
|
||||
"github.com/openimsdk/tools/utils/datautil"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -13,28 +15,50 @@ const (
|
||||
)
|
||||
|
||||
func filterAfterMsg(msg *pbchat.SendMsgReq, after *config.AfterConfig) bool {
|
||||
return filterMsg(msg, after.AttentionIds, after.AllowedTypes, after.DeniedTypes)
|
||||
return filterMsg(msg, after.AttentionIds, after.DeniedTypes)
|
||||
}
|
||||
|
||||
func filterBeforeMsg(msg *pbchat.SendMsgReq, before *config.BeforeConfig) bool {
|
||||
return filterMsg(msg, nil, before.AllowedTypes, before.DeniedTypes)
|
||||
return filterMsg(msg, nil, before.DeniedTypes)
|
||||
}
|
||||
|
||||
func filterMsg(msg *pbchat.SendMsgReq, attentionIds, allowedTypes, deniedTypes []string) bool {
|
||||
func filterMsg(msg *pbchat.SendMsgReq, attentionIds []string, deniedTypes []int32) bool {
|
||||
// According to the attentionIds configuration, only some users are sent
|
||||
if len(attentionIds) != 0 && !datautil.Contains([]string{msg.MsgData.SendID, msg.MsgData.RecvID}, attentionIds...) {
|
||||
if len(attentionIds) != 0 && !datautil.Contain(msg.MsgData.RecvID, attentionIds...) {
|
||||
return false
|
||||
}
|
||||
if len(allowedTypes) != 0 && !isInInterval(msg.MsgData.ContentType, allowedTypes) {
|
||||
|
||||
if defaultDeniedTypes(msg.MsgData.ContentType) {
|
||||
return false
|
||||
}
|
||||
if len(deniedTypes) != 0 && isInInterval(msg.MsgData.ContentType, deniedTypes) {
|
||||
|
||||
if len(deniedTypes) != 0 && datautil.Contain(msg.MsgData.ContentType, deniedTypes...) {
|
||||
return false
|
||||
}
|
||||
//if len(allowedTypes) != 0 && !isInInterval(msg.MsgData.ContentType, allowedTypes) {
|
||||
// return false
|
||||
//}
|
||||
//if len(deniedTypes) != 0 && isInInterval(msg.MsgData.ContentType, deniedTypes) {
|
||||
// return false
|
||||
//}
|
||||
return true
|
||||
}
|
||||
|
||||
func isInInterval(contentType int32, interval []string) bool {
|
||||
func defaultDeniedTypes(contentType int32) bool {
|
||||
if contentType >= constant.NotificationBegin && contentType <= constant.NotificationEnd {
|
||||
return true
|
||||
}
|
||||
if contentType == constant.Typing {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// isInInterval if data is in interval
|
||||
// Supports two formats: a single type or a range. The range is defined by the lower and upper bounds connected with a hyphen ("-")
|
||||
// e.g. [1, 100, 200-500, 600-700] means that only data within the range
|
||||
// {1, 100} ∪ [200, 500] ∪ [600, 700] will return true.
|
||||
func isInInterval(data int32, interval []string) bool {
|
||||
for _, v := range interval {
|
||||
if strings.Contains(v, separator) {
|
||||
// is interval
|
||||
@@ -50,7 +74,7 @@ func isInInterval(contentType int32, interval []string) bool {
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if datautil.BetweenEq(int(contentType), bottom, top) {
|
||||
if datautil.BetweenEq(int(data), bottom, top) {
|
||||
return true
|
||||
}
|
||||
} else {
|
||||
@@ -58,7 +82,7 @@ func isInInterval(contentType int32, interval []string) bool {
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if int(contentType) == iv {
|
||||
if int(data) == iv {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
+15
-24
@@ -16,13 +16,15 @@ package msg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/authverify"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/servererrs"
|
||||
"github.com/openimsdk/tools/utils/datautil"
|
||||
"github.com/openimsdk/tools/utils/encrypt"
|
||||
"github.com/openimsdk/tools/utils/timeutil"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/openimsdk/protocol/constant"
|
||||
"github.com/openimsdk/protocol/msg"
|
||||
@@ -62,6 +64,13 @@ func (m *msgServer) messageVerification(ctx context.Context, data *msg.SendMsgRe
|
||||
if err := m.webhookBeforeSendSingleMsg(ctx, &m.config.WebhooksConfig.BeforeSendSingleMsg, data); err != nil {
|
||||
return err
|
||||
}
|
||||
u, err := m.UserLocalCache.GetUserInfo(ctx, data.MsgData.SendID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if authverify.CheckSystemAccount(ctx, u.AppMangerLevel) {
|
||||
return nil
|
||||
}
|
||||
black, err := m.FriendLocalCache.IsBlack(ctx, data.MsgData.SendID, data.MsgData.RecvID)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -137,27 +146,9 @@ func (m *msgServer) encapsulateMsgData(msg *sdkws.MsgData) {
|
||||
msg.SendTime = timeutil.GetCurrentTimestampByMill()
|
||||
}
|
||||
switch msg.ContentType {
|
||||
case constant.Text:
|
||||
fallthrough
|
||||
case constant.Picture:
|
||||
fallthrough
|
||||
case constant.Voice:
|
||||
fallthrough
|
||||
case constant.Video:
|
||||
fallthrough
|
||||
case constant.File:
|
||||
fallthrough
|
||||
case constant.AtText:
|
||||
fallthrough
|
||||
case constant.Merger:
|
||||
fallthrough
|
||||
case constant.Card:
|
||||
fallthrough
|
||||
case constant.Location:
|
||||
fallthrough
|
||||
case constant.Custom:
|
||||
fallthrough
|
||||
case constant.Quote:
|
||||
case constant.Text, constant.Picture, constant.Voice, constant.Video,
|
||||
constant.File, constant.AtText, constant.Merger, constant.Card,
|
||||
constant.Location, constant.Custom, constant.Quote, constant.AdvancedText, constant.MarkdownText:
|
||||
case constant.Revoke:
|
||||
datautil.SetSwitchFromOptions(msg.Options, constant.IsUnreadCount, false)
|
||||
datautil.SetSwitchFromOptions(msg.Options, constant.IsOfflinePush, false)
|
||||
|
||||
@@ -566,7 +566,7 @@ func (s *userServer) SearchNotificationAccount(ctx context.Context, req *pbuser.
|
||||
}
|
||||
|
||||
// Convert users to response format
|
||||
resp := s.userModelToResp(users, req.Pagination)
|
||||
resp := s.userModelToResp(users, req.Pagination, req.AppManagerLevel)
|
||||
if resp.Total != 0 {
|
||||
return resp, nil
|
||||
}
|
||||
@@ -576,17 +576,24 @@ func (s *userServer) SearchNotificationAccount(ctx context.Context, req *pbuser.
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp = s.userModelToResp(users, req.Pagination)
|
||||
resp = s.userModelToResp(users, req.Pagination, req.AppManagerLevel)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// If no keyword, find users with notification settings
|
||||
users, err = s.db.FindNotification(ctx, constant.AppNotificationAdmin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if req.AppManagerLevel != nil {
|
||||
users, err = s.db.FindNotification(ctx, int64(*req.AppManagerLevel))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
users, err = s.db.FindSystemAccount(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
resp := s.userModelToResp(users, req.Pagination)
|
||||
resp := s.userModelToResp(users, req.Pagination, req.AppManagerLevel)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -625,11 +632,16 @@ func (s *userServer) genUserID() string {
|
||||
return string(data)
|
||||
}
|
||||
|
||||
func (s *userServer) userModelToResp(users []*tablerelation.User, pagination pagination.Pagination) *pbuser.SearchNotificationAccountResp {
|
||||
func (s *userServer) userModelToResp(users []*tablerelation.User, pagination pagination.Pagination, appManagerLevel *int32) *pbuser.SearchNotificationAccountResp {
|
||||
accounts := make([]*pbuser.NotificationAccountInfo, 0)
|
||||
var total int64
|
||||
for _, v := range users {
|
||||
if v.AppMangerLevel >= constant.AppNotificationAdmin && !datautil.Contain(v.UserID, s.config.Share.IMAdminUserID...) {
|
||||
if appManagerLevel != nil {
|
||||
if v.AppMangerLevel != *appManagerLevel {
|
||||
continue
|
||||
}
|
||||
}
|
||||
temp := &pbuser.NotificationAccountInfo{
|
||||
UserID: v.UserID,
|
||||
FaceURL: v.FaceURL,
|
||||
|
||||
Reference in New Issue
Block a user