Merge pull request #3372 from withchao/pre-release-v3.8.4
feat: add rpc interface permission checkpull/3378/head
commit
2ec3708a27
@ -0,0 +1,117 @@
|
||||
package conversation
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/callbackstruct"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||
dbModel "github.com/openimsdk/open-im-server/v3/pkg/common/storage/model"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/webhook"
|
||||
"github.com/openimsdk/tools/utils/datautil"
|
||||
)
|
||||
|
||||
func (c *conversationServer) webhookBeforeCreateSingleChatConversations(ctx context.Context, before *config.BeforeConfig, req *dbModel.Conversation) error {
|
||||
return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
|
||||
cbReq := &callbackstruct.CallbackBeforeCreateSingleChatConversationsReq{
|
||||
CallbackCommand: callbackstruct.CallbackBeforeCreateSingleChatConversationsCommand,
|
||||
OwnerUserID: req.OwnerUserID,
|
||||
ConversationID: req.ConversationID,
|
||||
ConversationType: req.ConversationType,
|
||||
UserID: req.UserID,
|
||||
RecvMsgOpt: req.RecvMsgOpt,
|
||||
IsPinned: req.IsPinned,
|
||||
IsPrivateChat: req.IsPrivateChat,
|
||||
BurnDuration: req.BurnDuration,
|
||||
GroupAtType: req.GroupAtType,
|
||||
AttachedInfo: req.AttachedInfo,
|
||||
Ex: req.Ex,
|
||||
}
|
||||
|
||||
resp := &callbackstruct.CallbackBeforeCreateSingleChatConversationsResp{}
|
||||
|
||||
if err := c.webhookClient.SyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, resp, before); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
datautil.NotNilReplace(&req.RecvMsgOpt, resp.RecvMsgOpt)
|
||||
datautil.NotNilReplace(&req.IsPinned, resp.IsPinned)
|
||||
datautil.NotNilReplace(&req.IsPrivateChat, resp.IsPrivateChat)
|
||||
datautil.NotNilReplace(&req.BurnDuration, resp.BurnDuration)
|
||||
datautil.NotNilReplace(&req.GroupAtType, resp.GroupAtType)
|
||||
datautil.NotNilReplace(&req.AttachedInfo, resp.AttachedInfo)
|
||||
datautil.NotNilReplace(&req.Ex, resp.Ex)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func (c *conversationServer) webhookAfterCreateSingleChatConversations(ctx context.Context, after *config.AfterConfig, req *dbModel.Conversation) error {
|
||||
cbReq := &callbackstruct.CallbackAfterCreateSingleChatConversationsReq{
|
||||
CallbackCommand: callbackstruct.CallbackAfterCreateSingleChatConversationsCommand,
|
||||
OwnerUserID: req.OwnerUserID,
|
||||
ConversationID: req.ConversationID,
|
||||
ConversationType: req.ConversationType,
|
||||
UserID: req.UserID,
|
||||
RecvMsgOpt: req.RecvMsgOpt,
|
||||
IsPinned: req.IsPinned,
|
||||
IsPrivateChat: req.IsPrivateChat,
|
||||
BurnDuration: req.BurnDuration,
|
||||
GroupAtType: req.GroupAtType,
|
||||
AttachedInfo: req.AttachedInfo,
|
||||
Ex: req.Ex,
|
||||
}
|
||||
|
||||
c.webhookClient.AsyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, &callbackstruct.CallbackAfterCreateSingleChatConversationsResp{}, after)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *conversationServer) webhookBeforeCreateGroupChatConversations(ctx context.Context, before *config.BeforeConfig, req *dbModel.Conversation) error {
|
||||
return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
|
||||
cbReq := &callbackstruct.CallbackBeforeCreateGroupChatConversationsReq{
|
||||
CallbackCommand: callbackstruct.CallbackBeforeCreateGroupChatConversationsCommand,
|
||||
ConversationID: req.ConversationID,
|
||||
ConversationType: req.ConversationType,
|
||||
GroupID: req.GroupID,
|
||||
RecvMsgOpt: req.RecvMsgOpt,
|
||||
IsPinned: req.IsPinned,
|
||||
IsPrivateChat: req.IsPrivateChat,
|
||||
BurnDuration: req.BurnDuration,
|
||||
GroupAtType: req.GroupAtType,
|
||||
AttachedInfo: req.AttachedInfo,
|
||||
Ex: req.Ex,
|
||||
}
|
||||
|
||||
resp := &callbackstruct.CallbackBeforeCreateGroupChatConversationsResp{}
|
||||
|
||||
if err := c.webhookClient.SyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, resp, before); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
datautil.NotNilReplace(&req.RecvMsgOpt, resp.RecvMsgOpt)
|
||||
datautil.NotNilReplace(&req.IsPinned, resp.IsPinned)
|
||||
datautil.NotNilReplace(&req.IsPrivateChat, resp.IsPrivateChat)
|
||||
datautil.NotNilReplace(&req.BurnDuration, resp.BurnDuration)
|
||||
datautil.NotNilReplace(&req.GroupAtType, resp.GroupAtType)
|
||||
datautil.NotNilReplace(&req.AttachedInfo, resp.AttachedInfo)
|
||||
datautil.NotNilReplace(&req.Ex, resp.Ex)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func (c *conversationServer) webhookAfterCreateGroupChatConversations(ctx context.Context, after *config.AfterConfig, req *dbModel.Conversation) error {
|
||||
cbReq := &callbackstruct.CallbackAfterCreateGroupChatConversationsReq{
|
||||
CallbackCommand: callbackstruct.CallbackAfterCreateGroupChatConversationsCommand,
|
||||
ConversationID: req.ConversationID,
|
||||
ConversationType: req.ConversationType,
|
||||
GroupID: req.GroupID,
|
||||
RecvMsgOpt: req.RecvMsgOpt,
|
||||
IsPinned: req.IsPinned,
|
||||
IsPrivateChat: req.IsPrivateChat,
|
||||
BurnDuration: req.BurnDuration,
|
||||
GroupAtType: req.GroupAtType,
|
||||
AttachedInfo: req.AttachedInfo,
|
||||
Ex: req.Ex,
|
||||
}
|
||||
|
||||
c.webhookClient.AsyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, &callbackstruct.CallbackAfterCreateGroupChatConversationsResp{}, after)
|
||||
return nil
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
package conversation
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
dbModel "github.com/openimsdk/open-im-server/v3/pkg/common/storage/model"
|
||||
"github.com/openimsdk/protocol/conversation"
|
||||
)
|
||||
|
||||
func UpdateConversationsMap(ctx context.Context, req *conversation.SetConversationsReq) (m map[string]any, conversation dbModel.Conversation, err error) {
|
||||
m = make(map[string]any)
|
||||
|
||||
conversation.ConversationID = req.Conversation.ConversationID
|
||||
conversation.ConversationType = req.Conversation.ConversationType
|
||||
conversation.UserID = req.Conversation.UserID
|
||||
conversation.GroupID = req.Conversation.GroupID
|
||||
|
||||
if req.Conversation.RecvMsgOpt != nil {
|
||||
conversation.RecvMsgOpt = req.Conversation.RecvMsgOpt.Value
|
||||
m["recv_msg_opt"] = req.Conversation.RecvMsgOpt.Value
|
||||
}
|
||||
|
||||
if req.Conversation.AttachedInfo != nil {
|
||||
conversation.AttachedInfo = req.Conversation.AttachedInfo.Value
|
||||
m["attached_info"] = req.Conversation.AttachedInfo.Value
|
||||
}
|
||||
|
||||
if req.Conversation.Ex != nil {
|
||||
conversation.Ex = req.Conversation.Ex.Value
|
||||
m["ex"] = req.Conversation.Ex.Value
|
||||
}
|
||||
if req.Conversation.IsPinned != nil {
|
||||
conversation.IsPinned = req.Conversation.IsPinned.Value
|
||||
m["is_pinned"] = req.Conversation.IsPinned.Value
|
||||
}
|
||||
if req.Conversation.GroupAtType != nil {
|
||||
conversation.GroupAtType = req.Conversation.GroupAtType.Value
|
||||
m["group_at_type"] = req.Conversation.GroupAtType.Value
|
||||
}
|
||||
if req.Conversation.MsgDestructTime != nil {
|
||||
conversation.MsgDestructTime = req.Conversation.MsgDestructTime.Value
|
||||
m["msg_destruct_time"] = req.Conversation.MsgDestructTime.Value
|
||||
}
|
||||
if req.Conversation.IsMsgDestruct != nil {
|
||||
conversation.IsMsgDestruct = req.Conversation.IsMsgDestruct.Value
|
||||
m["is_msg_destruct"] = req.Conversation.IsMsgDestruct.Value
|
||||
}
|
||||
if req.Conversation.BurnDuration != nil {
|
||||
conversation.BurnDuration = req.Conversation.BurnDuration.Value
|
||||
m["burn_duration"] = req.Conversation.BurnDuration.Value
|
||||
}
|
||||
|
||||
return m, conversation, nil
|
||||
}
|
||||
|
||||
func UserUpdateCheckMap(ctx context.Context, userID string, req *conversation.ConversationReq, conversation *dbModel.Conversation) (unequal bool) {
|
||||
unequal = false
|
||||
|
||||
if req.RecvMsgOpt != nil && conversation.RecvMsgOpt != req.RecvMsgOpt.Value {
|
||||
unequal = true
|
||||
}
|
||||
if req.AttachedInfo != nil && conversation.AttachedInfo != req.AttachedInfo.Value {
|
||||
unequal = true
|
||||
}
|
||||
if req.Ex != nil && conversation.Ex != req.Ex.Value {
|
||||
unequal = true
|
||||
}
|
||||
if req.IsPinned != nil && conversation.IsPinned != req.IsPinned.Value {
|
||||
unequal = true
|
||||
}
|
||||
if req.GroupAtType != nil && conversation.GroupAtType != req.GroupAtType.Value {
|
||||
unequal = true
|
||||
}
|
||||
if req.MsgDestructTime != nil && conversation.MsgDestructTime != req.MsgDestructTime.Value {
|
||||
unequal = true
|
||||
}
|
||||
if req.IsMsgDestruct != nil && conversation.IsMsgDestruct != req.IsMsgDestruct.Value {
|
||||
unequal = true
|
||||
}
|
||||
if req.BurnDuration != nil && conversation.BurnDuration != req.BurnDuration.Value {
|
||||
unequal = true
|
||||
}
|
||||
|
||||
return unequal
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
package callbackstruct
|
||||
|
||||
type CallbackBeforeCreateSingleChatConversationsReq struct {
|
||||
CallbackCommand `json:"callbackCommand"`
|
||||
OwnerUserID string `json:"owner_user_id"`
|
||||
ConversationID string `json:"conversation_id"`
|
||||
ConversationType int32 `json:"conversation_type"`
|
||||
UserID string `json:"user_id"`
|
||||
RecvMsgOpt int32 `json:"recv_msg_opt"`
|
||||
IsPinned bool `json:"is_pinned"`
|
||||
IsPrivateChat bool `json:"is_private_chat"`
|
||||
BurnDuration int32 `json:"burn_duration"`
|
||||
GroupAtType int32 `json:"group_at_type"`
|
||||
AttachedInfo string `json:"attached_info"`
|
||||
Ex string `json:"ex"`
|
||||
}
|
||||
|
||||
type CallbackBeforeCreateSingleChatConversationsResp struct {
|
||||
CommonCallbackResp
|
||||
RecvMsgOpt *int32 `json:"recv_msg_opt"`
|
||||
IsPinned *bool `json:"is_pinned"`
|
||||
IsPrivateChat *bool `json:"is_private_chat"`
|
||||
BurnDuration *int32 `json:"burn_duration"`
|
||||
GroupAtType *int32 `json:"group_at_type"`
|
||||
AttachedInfo *string `json:"attached_info"`
|
||||
Ex *string `json:"ex"`
|
||||
}
|
||||
|
||||
type CallbackAfterCreateSingleChatConversationsReq struct {
|
||||
CallbackCommand `json:"callbackCommand"`
|
||||
OwnerUserID string `json:"owner_user_id"`
|
||||
ConversationID string `json:"conversation_id"`
|
||||
ConversationType int32 `json:"conversation_type"`
|
||||
UserID string `json:"user_id"`
|
||||
RecvMsgOpt int32 `json:"recv_msg_opt"`
|
||||
IsPinned bool `json:"is_pinned"`
|
||||
IsPrivateChat bool `json:"is_private_chat"`
|
||||
BurnDuration int32 `json:"burn_duration"`
|
||||
GroupAtType int32 `json:"group_at_type"`
|
||||
AttachedInfo string `json:"attached_info"`
|
||||
Ex string `json:"ex"`
|
||||
}
|
||||
|
||||
type CallbackAfterCreateSingleChatConversationsResp struct {
|
||||
CommonCallbackResp
|
||||
}
|
||||
|
||||
type CallbackBeforeCreateGroupChatConversationsReq struct {
|
||||
CallbackCommand `json:"callbackCommand"`
|
||||
OwnerUserID string `json:"owner_user_id"`
|
||||
ConversationID string `json:"conversation_id"`
|
||||
ConversationType int32 `json:"conversation_type"`
|
||||
GroupID string `json:"group_id"`
|
||||
RecvMsgOpt int32 `json:"recv_msg_opt"`
|
||||
IsPinned bool `json:"is_pinned"`
|
||||
IsPrivateChat bool `json:"is_private_chat"`
|
||||
BurnDuration int32 `json:"burn_duration"`
|
||||
GroupAtType int32 `json:"group_at_type"`
|
||||
AttachedInfo string `json:"attached_info"`
|
||||
Ex string `json:"ex"`
|
||||
}
|
||||
|
||||
type CallbackBeforeCreateGroupChatConversationsResp struct {
|
||||
CommonCallbackResp
|
||||
RecvMsgOpt *int32 `json:"recv_msg_opt"`
|
||||
IsPinned *bool `json:"is_pinned"`
|
||||
IsPrivateChat *bool `json:"is_private_chat"`
|
||||
BurnDuration *int32 `json:"burn_duration"`
|
||||
GroupAtType *int32 `json:"group_at_type"`
|
||||
AttachedInfo *string `json:"attached_info"`
|
||||
Ex *string `json:"ex"`
|
||||
}
|
||||
|
||||
type CallbackAfterCreateGroupChatConversationsReq struct {
|
||||
CallbackCommand `json:"callbackCommand"`
|
||||
OwnerUserID string `json:"owner_user_id"`
|
||||
ConversationID string `json:"conversation_id"`
|
||||
ConversationType int32 `json:"conversation_type"`
|
||||
GroupID string `json:"group_id"`
|
||||
RecvMsgOpt int32 `json:"recv_msg_opt"`
|
||||
IsPinned bool `json:"is_pinned"`
|
||||
IsPrivateChat bool `json:"is_private_chat"`
|
||||
BurnDuration int32 `json:"burn_duration"`
|
||||
GroupAtType int32 `json:"group_at_type"`
|
||||
AttachedInfo string `json:"attached_info"`
|
||||
Ex string `json:"ex"`
|
||||
}
|
||||
|
||||
type CallbackAfterCreateGroupChatConversationsResp struct {
|
||||
CommonCallbackResp
|
||||
}
|
Loading…
Reference in new issue