mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-09 03:25:59 +08:00
feat: merge v3dev into main
This commit is contained in:
@@ -60,7 +60,7 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e
|
||||
func (s *authServer) UserToken(ctx context.Context, req *pbAuth.UserTokenReq) (*pbAuth.UserTokenResp, error) {
|
||||
resp := pbAuth.UserTokenResp{}
|
||||
if req.Secret != config.Config.Secret {
|
||||
return nil, errs.ErrIdentity.Wrap("secret invalid")
|
||||
return nil, errs.ErrNoPermission.Wrap("secret invalid")
|
||||
}
|
||||
if _, err := s.userRpcClient.GetUserInfo(ctx, req.UserID); err != nil {
|
||||
return nil, err
|
||||
@@ -115,14 +115,13 @@ func (s *authServer) ParseToken(
|
||||
}
|
||||
|
||||
func (s *authServer) ForceLogout(ctx context.Context, req *pbAuth.ForceLogoutReq) (*pbAuth.ForceLogoutResp, error) {
|
||||
resp := pbAuth.ForceLogoutResp{}
|
||||
if err := tokenverify.CheckAdmin(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := s.forceKickOff(ctx, req.UserID, req.PlatformID, mcontext.GetOperationID(ctx)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
return &pbAuth.ForceLogoutResp{}, nil
|
||||
}
|
||||
|
||||
func (s *authServer) forceKickOff(ctx context.Context, userID string, platformID int32, operationID string) error {
|
||||
@@ -134,8 +133,7 @@ func (s *authServer) forceKickOff(ctx context.Context, userID string, platformID
|
||||
client := msggateway.NewMsgGatewayClient(v)
|
||||
kickReq := &msggateway.KickUserOfflineReq{KickUserIDList: []string{userID}, PlatformID: platformID}
|
||||
_, err := client.KickUserOffline(ctx, kickReq)
|
||||
s.RegisterCenter.CloseConn(v)
|
||||
return utils.Wrap(err, "")
|
||||
}
|
||||
return errs.ErrInternalServer.Wrap()
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,24 +1,8 @@
|
||||
// Copyright © 2023 OpenIM. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package conversation
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/convert"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache"
|
||||
@@ -33,6 +17,7 @@ import (
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient/notification"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type conversationServer struct {
|
||||
@@ -59,19 +44,12 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e
|
||||
pbConversation.RegisterConversationServer(server, &conversationServer{
|
||||
conversationNotificationSender: notification.NewConversationNotificationSender(&msgRpcClient),
|
||||
groupRpcClient: &groupRpcClient,
|
||||
conversationDatabase: controller.NewConversationDatabase(
|
||||
conversationDB,
|
||||
cache.NewConversationRedis(rdb, cache.GetDefaultOpt(), conversationDB),
|
||||
tx.NewGorm(db),
|
||||
),
|
||||
conversationDatabase: controller.NewConversationDatabase(conversationDB, cache.NewConversationRedis(rdb, cache.GetDefaultOpt(), conversationDB), tx.NewGorm(db)),
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *conversationServer) GetConversation(
|
||||
ctx context.Context,
|
||||
req *pbConversation.GetConversationReq,
|
||||
) (*pbConversation.GetConversationResp, error) {
|
||||
func (c *conversationServer) GetConversation(ctx context.Context, req *pbConversation.GetConversationReq) (*pbConversation.GetConversationResp, error) {
|
||||
conversations, err := c.conversationDatabase.FindConversations(ctx, req.OwnerUserID, []string{req.ConversationID})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -84,10 +62,7 @@ func (c *conversationServer) GetConversation(
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (c *conversationServer) GetAllConversations(
|
||||
ctx context.Context,
|
||||
req *pbConversation.GetAllConversationsReq,
|
||||
) (*pbConversation.GetAllConversationsResp, error) {
|
||||
func (c *conversationServer) GetAllConversations(ctx context.Context, req *pbConversation.GetAllConversationsReq) (*pbConversation.GetAllConversationsResp, error) {
|
||||
conversations, err := c.conversationDatabase.GetUserAllConversation(ctx, req.OwnerUserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -97,10 +72,7 @@ func (c *conversationServer) GetAllConversations(
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (c *conversationServer) GetConversations(
|
||||
ctx context.Context,
|
||||
req *pbConversation.GetConversationsReq,
|
||||
) (*pbConversation.GetConversationsResp, error) {
|
||||
func (c *conversationServer) GetConversations(ctx context.Context, req *pbConversation.GetConversationsReq) (*pbConversation.GetConversationsResp, error) {
|
||||
conversations, err := c.conversationDatabase.FindConversations(ctx, req.OwnerUserID, req.ConversationIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -110,32 +82,12 @@ func (c *conversationServer) GetConversations(
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (c *conversationServer) BatchSetConversations(
|
||||
ctx context.Context,
|
||||
req *pbConversation.BatchSetConversationsReq,
|
||||
) (*pbConversation.BatchSetConversationsResp, error) {
|
||||
conversations := convert.ConversationsPb2DB(req.Conversations)
|
||||
err := c.conversationDatabase.SetUserConversations(ctx, req.OwnerUserID, conversations)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_ = c.conversationNotificationSender.ConversationChangeNotification(ctx, req.OwnerUserID)
|
||||
return &pbConversation.BatchSetConversationsResp{}, nil
|
||||
}
|
||||
|
||||
func (c *conversationServer) SetConversation(
|
||||
ctx context.Context,
|
||||
req *pbConversation.SetConversationReq,
|
||||
) (*pbConversation.SetConversationResp, error) {
|
||||
func (c *conversationServer) SetConversation(ctx context.Context, req *pbConversation.SetConversationReq) (*pbConversation.SetConversationResp, error) {
|
||||
var conversation tableRelation.ConversationModel
|
||||
if err := utils.CopyStructFields(&conversation, req.Conversation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err := c.conversationDatabase.SetUserConversations(
|
||||
ctx,
|
||||
req.Conversation.OwnerUserID,
|
||||
[]*tableRelation.ConversationModel{&conversation},
|
||||
)
|
||||
err := c.conversationDatabase.SetUserConversations(ctx, req.Conversation.OwnerUserID, []*tableRelation.ConversationModel{&conversation})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -144,79 +96,7 @@ func (c *conversationServer) SetConversation(
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (c *conversationServer) SetRecvMsgOpt(
|
||||
ctx context.Context,
|
||||
req *pbConversation.SetRecvMsgOptReq,
|
||||
) (*pbConversation.SetRecvMsgOptResp, error) {
|
||||
if err := c.conversationDatabase.SetUsersConversationFiledTx(ctx, []string{req.OwnerUserID}, &tableRelation.ConversationModel{OwnerUserID: req.OwnerUserID, ConversationID: req.ConversationID, RecvMsgOpt: req.RecvMsgOpt}, map[string]interface{}{"recv_msg_opt": req.RecvMsgOpt}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_ = c.conversationNotificationSender.ConversationChangeNotification(ctx, req.OwnerUserID)
|
||||
return &pbConversation.SetRecvMsgOptResp{}, nil
|
||||
}
|
||||
|
||||
// deprecated
|
||||
func (c *conversationServer) ModifyConversationField(
|
||||
ctx context.Context,
|
||||
req *pbConversation.ModifyConversationFieldReq,
|
||||
) (*pbConversation.ModifyConversationFieldResp, error) {
|
||||
resp := &pbConversation.ModifyConversationFieldResp{}
|
||||
var err error
|
||||
if req.Conversation.ConversationType == constant.GroupChatType {
|
||||
groupInfo, err := c.groupRpcClient.GetGroupInfo(ctx, req.Conversation.GroupID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if groupInfo.Status == constant.GroupStatusDismissed && req.FieldType != constant.FieldUnread {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
conversation := convert.ConversationPb2DB(req.Conversation)
|
||||
if req.FieldType == constant.FieldIsPrivateChat {
|
||||
err := c.conversationDatabase.SyncPeerUserPrivateConversationTx(
|
||||
ctx,
|
||||
[]*tableRelation.ConversationModel{conversation},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c.conversationNotificationSender.ConversationSetPrivateNotification(
|
||||
ctx,
|
||||
req.Conversation.OwnerUserID,
|
||||
req.Conversation.UserID,
|
||||
req.Conversation.IsPrivateChat,
|
||||
)
|
||||
return resp, nil
|
||||
}
|
||||
filedMap := make(map[string]interface{})
|
||||
switch req.FieldType {
|
||||
case constant.FieldRecvMsgOpt:
|
||||
filedMap["recv_msg_opt"] = req.Conversation.RecvMsgOpt
|
||||
case constant.FieldGroupAtType:
|
||||
filedMap["group_at_type"] = req.Conversation.GroupAtType
|
||||
case constant.FieldIsPinned:
|
||||
filedMap["is_pinned"] = req.Conversation.IsPinned
|
||||
case constant.FieldEx:
|
||||
filedMap["ex"] = req.Conversation.Ex
|
||||
case constant.FieldAttachedInfo:
|
||||
filedMap["attached_info"] = req.Conversation.AttachedInfo
|
||||
case constant.FieldBurnDuration:
|
||||
filedMap["burn_duration"] = req.Conversation.BurnDuration
|
||||
}
|
||||
err = c.conversationDatabase.SetUsersConversationFiledTx(ctx, req.UserIDList, conversation, filedMap)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range req.UserIDList {
|
||||
c.conversationNotificationSender.ConversationChangeNotification(ctx, v)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (c *conversationServer) SetConversations(
|
||||
ctx context.Context,
|
||||
req *pbConversation.SetConversationsReq,
|
||||
) (*pbConversation.SetConversationsResp, error) {
|
||||
func (c *conversationServer) SetConversations(ctx context.Context, req *pbConversation.SetConversationsReq) (*pbConversation.SetConversationsResp, error) {
|
||||
if req.Conversation == nil {
|
||||
return nil, errs.ErrArgs.Wrap("conversation must not be nil")
|
||||
}
|
||||
@@ -228,6 +108,12 @@ func (c *conversationServer) SetConversations(
|
||||
if groupInfo.Status == constant.GroupStatusDismissed {
|
||||
return nil, err
|
||||
}
|
||||
// for _, userID := range req.UserIDs {
|
||||
// if _, err := c.groupRpcClient.GetGroupMemberCache(ctx, req.Conversation.GroupID, userID); err != nil {
|
||||
// log.ZError(ctx, "user not in group", err, "userID", userID, "groupID", req.Conversation.GroupID)
|
||||
// return nil, err
|
||||
// }
|
||||
// }
|
||||
}
|
||||
var conversation tableRelation.ConversationModel
|
||||
conversation.ConversationID = req.Conversation.ConversationID
|
||||
@@ -250,24 +136,25 @@ func (c *conversationServer) SetConversations(
|
||||
if req.Conversation.GroupAtType != nil {
|
||||
m["group_at_type"] = req.Conversation.GroupAtType.Value
|
||||
}
|
||||
if req.Conversation.IsPrivateChat != nil {
|
||||
if req.Conversation.MsgDestructTime != nil {
|
||||
m["msg_destruct_time"] = req.Conversation.MsgDestructTime.Value
|
||||
}
|
||||
if req.Conversation.IsMsgDestruct != nil {
|
||||
m["is_msg_destruct"] = req.Conversation.IsMsgDestruct.Value
|
||||
}
|
||||
if req.Conversation.IsPrivateChat != nil && req.Conversation.ConversationType != constant.SuperGroupChatType {
|
||||
var conversations []*tableRelation.ConversationModel
|
||||
for _, ownerUserID := range req.UserIDs {
|
||||
conversation2 := conversation
|
||||
conversation.OwnerUserID = ownerUserID
|
||||
conversation.IsPrivateChat = req.Conversation.IsPrivateChat.Value
|
||||
conversation2.OwnerUserID = ownerUserID
|
||||
conversation2.IsPrivateChat = req.Conversation.IsPrivateChat.Value
|
||||
conversations = append(conversations, &conversation2)
|
||||
}
|
||||
if err := c.conversationDatabase.SyncPeerUserPrivateConversationTx(ctx, conversations); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, ownerUserID := range req.UserIDs {
|
||||
c.conversationNotificationSender.ConversationSetPrivateNotification(
|
||||
ctx,
|
||||
ownerUserID,
|
||||
req.Conversation.UserID,
|
||||
req.Conversation.IsPrivateChat.Value,
|
||||
)
|
||||
for _, userID := range req.UserIDs {
|
||||
c.conversationNotificationSender.ConversationSetPrivateNotification(ctx, userID, req.Conversation.UserID, req.Conversation.IsPrivateChat.Value)
|
||||
}
|
||||
}
|
||||
if req.Conversation.BurnDuration != nil {
|
||||
@@ -284,10 +171,7 @@ func (c *conversationServer) SetConversations(
|
||||
}
|
||||
|
||||
// 获取超级大群开启免打扰的用户ID
|
||||
func (c *conversationServer) GetRecvMsgNotNotifyUserIDs(
|
||||
ctx context.Context,
|
||||
req *pbConversation.GetRecvMsgNotNotifyUserIDsReq,
|
||||
) (*pbConversation.GetRecvMsgNotNotifyUserIDsResp, error) {
|
||||
func (c *conversationServer) GetRecvMsgNotNotifyUserIDs(ctx context.Context, req *pbConversation.GetRecvMsgNotNotifyUserIDsReq) (*pbConversation.GetRecvMsgNotNotifyUserIDsResp, error) {
|
||||
userIDs, err := c.conversationDatabase.FindRecvMsgNotNotifyUserIDs(ctx, req.GroupID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -296,10 +180,7 @@ func (c *conversationServer) GetRecvMsgNotNotifyUserIDs(
|
||||
}
|
||||
|
||||
// create conversation without notification for msg redis transfer
|
||||
func (c *conversationServer) CreateSingleChatConversations(
|
||||
ctx context.Context,
|
||||
req *pbConversation.CreateSingleChatConversationsReq,
|
||||
) (*pbConversation.CreateSingleChatConversationsResp, error) {
|
||||
func (c *conversationServer) CreateSingleChatConversations(ctx context.Context, req *pbConversation.CreateSingleChatConversationsReq) (*pbConversation.CreateSingleChatConversationsResp, error) {
|
||||
var conversation tableRelation.ConversationModel
|
||||
conversation.ConversationID = utils.GetConversationIDBySessionType(constant.SingleChatType, req.RecvID, req.SendID)
|
||||
conversation.ConversationType = constant.SingleChatType
|
||||
@@ -320,10 +201,7 @@ func (c *conversationServer) CreateSingleChatConversations(
|
||||
return &pbConversation.CreateSingleChatConversationsResp{}, nil
|
||||
}
|
||||
|
||||
func (c *conversationServer) CreateGroupChatConversations(
|
||||
ctx context.Context,
|
||||
req *pbConversation.CreateGroupChatConversationsReq,
|
||||
) (*pbConversation.CreateGroupChatConversationsResp, error) {
|
||||
func (c *conversationServer) CreateGroupChatConversations(ctx context.Context, req *pbConversation.CreateGroupChatConversationsReq) (*pbConversation.CreateGroupChatConversationsResp, error) {
|
||||
err := c.conversationDatabase.CreateGroupChatConversation(ctx, req.GroupID, req.UserIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -331,10 +209,7 @@ func (c *conversationServer) CreateGroupChatConversations(
|
||||
return &pbConversation.CreateGroupChatConversationsResp{}, nil
|
||||
}
|
||||
|
||||
func (c *conversationServer) SetConversationMaxSeq(
|
||||
ctx context.Context,
|
||||
req *pbConversation.SetConversationMaxSeqReq,
|
||||
) (*pbConversation.SetConversationMaxSeqResp, error) {
|
||||
func (c *conversationServer) SetConversationMaxSeq(ctx context.Context, req *pbConversation.SetConversationMaxSeqReq) (*pbConversation.SetConversationMaxSeqResp, error) {
|
||||
if err := c.conversationDatabase.UpdateUsersConversationFiled(ctx, req.OwnerUserID, req.ConversationID,
|
||||
map[string]interface{}{"max_seq": req.MaxSeq}); err != nil {
|
||||
return nil, err
|
||||
@@ -342,10 +217,7 @@ func (c *conversationServer) SetConversationMaxSeq(
|
||||
return &pbConversation.SetConversationMaxSeqResp{}, nil
|
||||
}
|
||||
|
||||
func (c *conversationServer) GetConversationIDs(
|
||||
ctx context.Context,
|
||||
req *pbConversation.GetConversationIDsReq,
|
||||
) (*pbConversation.GetConversationIDsResp, error) {
|
||||
func (c *conversationServer) GetConversationIDs(ctx context.Context, req *pbConversation.GetConversationIDsReq) (*pbConversation.GetConversationIDsResp, error) {
|
||||
conversationIDs, err := c.conversationDatabase.GetConversationIDs(ctx, req.UserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -353,10 +225,7 @@ func (c *conversationServer) GetConversationIDs(
|
||||
return &pbConversation.GetConversationIDsResp{ConversationIDs: conversationIDs}, nil
|
||||
}
|
||||
|
||||
func (c *conversationServer) GetUserConversationIDsHash(
|
||||
ctx context.Context,
|
||||
req *pbConversation.GetUserConversationIDsHashReq,
|
||||
) (*pbConversation.GetUserConversationIDsHashResp, error) {
|
||||
func (c *conversationServer) GetUserConversationIDsHash(ctx context.Context, req *pbConversation.GetUserConversationIDsHashReq) (*pbConversation.GetUserConversationIDsHashResp, error) {
|
||||
hash, err := c.conversationDatabase.GetUserConversationIDsHash(ctx, req.OwnerUserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -364,15 +233,10 @@ func (c *conversationServer) GetUserConversationIDsHash(
|
||||
return &pbConversation.GetUserConversationIDsHashResp{Hash: hash}, nil
|
||||
}
|
||||
|
||||
func (c *conversationServer) GetConversationsByConversationID(
|
||||
ctx context.Context,
|
||||
req *pbConversation.GetConversationsByConversationIDReq,
|
||||
) (*pbConversation.GetConversationsByConversationIDResp, error) {
|
||||
func (c *conversationServer) GetConversationsByConversationID(ctx context.Context, req *pbConversation.GetConversationsByConversationIDReq) (*pbConversation.GetConversationsByConversationIDResp, error) {
|
||||
conversations, err := c.conversationDatabase.GetConversationsByConversationID(ctx, req.ConversationIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pbConversation.GetConversationsByConversationIDResp{
|
||||
Conversations: convert.ConversationsDB2Pb(conversations),
|
||||
}, nil
|
||||
return &pbConversation.GetConversationsByConversationIDResp{Conversations: convert.ConversationsDB2Pb(conversations)}, nil
|
||||
}
|
||||
|
||||
@@ -15,19 +15,23 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/mcontext"
|
||||
"time"
|
||||
|
||||
pbGroup "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/group"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
|
||||
)
|
||||
|
||||
func UpdateGroupInfoMap(group *sdkws.GroupInfoForSet) map[string]any {
|
||||
func UpdateGroupInfoMap(ctx context.Context, group *sdkws.GroupInfoForSet) map[string]any {
|
||||
m := make(map[string]any)
|
||||
if group.GroupName != "" {
|
||||
m["name"] = group.GroupName
|
||||
}
|
||||
if group.Notification != "" {
|
||||
m["Notification"] = group.Notification
|
||||
m["notification"] = group.Notification
|
||||
m["notification_update_time"] = time.Now()
|
||||
m["notification_user_id"] = mcontext.GetOpUserID(ctx)
|
||||
}
|
||||
if group.Introduction != "" {
|
||||
m["introduction"] = group.Introduction
|
||||
|
||||
+63
-174
@@ -1,22 +1,10 @@
|
||||
// Copyright © 2023 OpenIM. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package group
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
pbConversation "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/conversation"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/wrapperspb"
|
||||
"math/big"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
@@ -29,8 +17,6 @@ import (
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/mw/specialerror"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller"
|
||||
@@ -45,6 +31,7 @@ import (
|
||||
pbGroup "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/group"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error {
|
||||
@@ -70,17 +57,13 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e
|
||||
pbGroup.RegisterGroupServer(server, &groupServer{
|
||||
GroupDatabase: database,
|
||||
User: userRpcClient,
|
||||
Notification: notification.NewGroupNotificationSender(
|
||||
database,
|
||||
&msgRpcClient,
|
||||
func(ctx context.Context, userIDs []string) ([]notification.CommonUser, error) {
|
||||
users, err := userRpcClient.GetUsersInfo(ctx, userIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return utils.Slice(users, func(e *sdkws.UserInfo) notification.CommonUser { return e }), nil
|
||||
},
|
||||
),
|
||||
Notification: notification.NewGroupNotificationSender(database, &msgRpcClient, &userRpcClient, func(ctx context.Context, userIDs []string) ([]notification.CommonUser, error) {
|
||||
users, err := userRpcClient.GetUsersInfo(ctx, userIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return utils.Slice(users, func(e *sdkws.UserInfo) notification.CommonUser { return e }), nil
|
||||
}),
|
||||
conversationRpcClient: conversationRpcClient,
|
||||
msgRpcClient: msgRpcClient,
|
||||
})
|
||||
@@ -137,16 +120,7 @@ func (s *groupServer) GenGroupID(ctx context.Context, groupID *string) error {
|
||||
}
|
||||
}
|
||||
for i := 0; i < 10; i++ {
|
||||
id := utils.Md5(
|
||||
strings.Join(
|
||||
[]string{
|
||||
mcontext.GetOperationID(ctx),
|
||||
strconv.FormatInt(time.Now().UnixNano(), 10),
|
||||
strconv.Itoa(rand.Int()),
|
||||
},
|
||||
",;,",
|
||||
),
|
||||
)
|
||||
id := utils.Md5(strings.Join([]string{mcontext.GetOperationID(ctx), strconv.FormatInt(time.Now().UnixNano(), 10), strconv.Itoa(rand.Int())}, ",;,"))
|
||||
bi := big.NewInt(0)
|
||||
bi.SetString(id[0:8], 16)
|
||||
id = bi.String()
|
||||
@@ -260,10 +234,7 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) GetJoinedGroupList(
|
||||
ctx context.Context,
|
||||
req *pbGroup.GetJoinedGroupListReq,
|
||||
) (*pbGroup.GetJoinedGroupListResp, error) {
|
||||
func (s *groupServer) GetJoinedGroupList(ctx context.Context, req *pbGroup.GetJoinedGroupListReq) (*pbGroup.GetJoinedGroupListResp, error) {
|
||||
resp := &pbGroup.GetJoinedGroupListResp{}
|
||||
if err := tokenverify.CheckAccessV3(ctx, req.FromUserID); err != nil {
|
||||
return nil, err
|
||||
@@ -273,8 +244,7 @@ func (s *groupServer) GetJoinedGroupList(
|
||||
pageNumber = req.Pagination.PageNumber
|
||||
showNumber = req.Pagination.ShowNumber
|
||||
}
|
||||
// total, members, err := s.GroupDatabase.PageGroupMember(ctx, nil, []string{req.FromUserID}, nil, pageNumber,
|
||||
// showNumber)
|
||||
//total, members, err := s.GroupDatabase.PageGroupMember(ctx, nil, []string{req.FromUserID}, nil, pageNumber, showNumber)
|
||||
total, members, err := s.GroupDatabase.PageGetJoinGroup(ctx, req.FromUserID, pageNumber, showNumber)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -313,10 +283,7 @@ func (s *groupServer) GetJoinedGroupList(
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) InviteUserToGroup(
|
||||
ctx context.Context,
|
||||
req *pbGroup.InviteUserToGroupReq,
|
||||
) (*pbGroup.InviteUserToGroupResp, error) {
|
||||
func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.InviteUserToGroupReq) (*pbGroup.InviteUserToGroupResp, error) {
|
||||
resp := &pbGroup.InviteUserToGroupResp{}
|
||||
if len(req.InvitedUserIDs) == 0 {
|
||||
return nil, errs.ErrArgs.Wrap("user empty")
|
||||
@@ -417,10 +384,7 @@ func (s *groupServer) InviteUserToGroup(
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) GetGroupAllMember(
|
||||
ctx context.Context,
|
||||
req *pbGroup.GetGroupAllMemberReq,
|
||||
) (*pbGroup.GetGroupAllMemberResp, error) {
|
||||
func (s *groupServer) GetGroupAllMember(ctx context.Context, req *pbGroup.GetGroupAllMemberReq) (*pbGroup.GetGroupAllMemberResp, error) {
|
||||
resp := &pbGroup.GetGroupAllMemberResp{}
|
||||
group, err := s.GroupDatabase.TakeGroup(ctx, req.GroupID)
|
||||
if err != nil {
|
||||
@@ -448,10 +412,7 @@ func (s *groupServer) GetGroupAllMember(
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) GetGroupMemberList(
|
||||
ctx context.Context,
|
||||
req *pbGroup.GetGroupMemberListReq,
|
||||
) (*pbGroup.GetGroupMemberListResp, error) {
|
||||
func (s *groupServer) GetGroupMemberList(ctx context.Context, req *pbGroup.GetGroupMemberListReq) (*pbGroup.GetGroupMemberListResp, error) {
|
||||
resp := &pbGroup.GetGroupMemberListResp{}
|
||||
total, members, err := s.PageGetGroupMember(ctx, req.GroupID, req.Pagination.PageNumber, req.Pagination.ShowNumber)
|
||||
log.ZDebug(ctx, "GetGroupMemberList", "total", total, "members", members, "length", len(members))
|
||||
@@ -464,10 +425,7 @@ func (s *groupServer) GetGroupMemberList(
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) KickGroupMember(
|
||||
ctx context.Context,
|
||||
req *pbGroup.KickGroupMemberReq,
|
||||
) (*pbGroup.KickGroupMemberResp, error) {
|
||||
func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGroupMemberReq) (*pbGroup.KickGroupMemberResp, error) {
|
||||
resp := &pbGroup.KickGroupMemberResp{}
|
||||
group, err := s.GroupDatabase.TakeGroup(ctx, req.GroupID)
|
||||
if err != nil {
|
||||
@@ -575,10 +533,7 @@ func (s *groupServer) KickGroupMember(
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) GetGroupMembersInfo(
|
||||
ctx context.Context,
|
||||
req *pbGroup.GetGroupMembersInfoReq,
|
||||
) (*pbGroup.GetGroupMembersInfoResp, error) {
|
||||
func (s *groupServer) GetGroupMembersInfo(ctx context.Context, req *pbGroup.GetGroupMembersInfoReq) (*pbGroup.GetGroupMembersInfoResp, error) {
|
||||
resp := &pbGroup.GetGroupMembersInfoResp{}
|
||||
if len(req.UserIDs) == 0 {
|
||||
return nil, errs.ErrArgs.Wrap("userIDs empty")
|
||||
@@ -605,10 +560,7 @@ func (s *groupServer) GetGroupMembersInfo(
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) GetGroupApplicationList(
|
||||
ctx context.Context,
|
||||
req *pbGroup.GetGroupApplicationListReq,
|
||||
) (*pbGroup.GetGroupApplicationListResp, error) {
|
||||
func (s *groupServer) GetGroupApplicationList(ctx context.Context, req *pbGroup.GetGroupApplicationListReq) (*pbGroup.GetGroupApplicationListResp, error) {
|
||||
pageNumber, showNumber := utils.GetPage(req.Pagination)
|
||||
|
||||
groupIDs, err := s.GroupDatabase.FindUserManagedGroupID(ctx, req.FromUserID)
|
||||
@@ -659,19 +611,12 @@ func (s *groupServer) GetGroupApplicationList(
|
||||
return e.GroupID
|
||||
})
|
||||
resp.GroupRequests = utils.Slice(groupRequests, func(e *relationTb.GroupRequestModel) *sdkws.GroupRequest {
|
||||
return convert.Db2PbGroupRequest(
|
||||
e,
|
||||
userMap[e.UserID],
|
||||
convert.Db2PbGroupInfo(groupMap[e.GroupID], ownerMap[e.GroupID].UserID, groupMemberNumMap[e.GroupID]),
|
||||
)
|
||||
return convert.Db2PbGroupRequest(e, userMap[e.UserID], convert.Db2PbGroupInfo(groupMap[e.GroupID], ownerMap[e.GroupID].UserID, groupMemberNumMap[e.GroupID]))
|
||||
})
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) GetGroupsInfo(
|
||||
ctx context.Context,
|
||||
req *pbGroup.GetGroupsInfoReq,
|
||||
) (*pbGroup.GetGroupsInfoResp, error) {
|
||||
func (s *groupServer) GetGroupsInfo(ctx context.Context, req *pbGroup.GetGroupsInfoReq) (*pbGroup.GetGroupsInfoResp, error) {
|
||||
resp := &pbGroup.GetGroupsInfoResp{}
|
||||
if len(req.GroupIDs) == 0 {
|
||||
return nil, errs.ErrArgs.Wrap("groupID is empty")
|
||||
@@ -701,10 +646,7 @@ func (s *groupServer) GetGroupsInfo(
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) GroupApplicationResponse(
|
||||
ctx context.Context,
|
||||
req *pbGroup.GroupApplicationResponseReq,
|
||||
) (*pbGroup.GroupApplicationResponseResp, error) {
|
||||
func (s *groupServer) GroupApplicationResponse(ctx context.Context, req *pbGroup.GroupApplicationResponseReq) (*pbGroup.GroupApplicationResponseResp, error) {
|
||||
defer log.ZInfo(ctx, utils.GetFuncName()+" Return")
|
||||
if !utils.Contain(req.HandleResult, constant.GroupResponseAgree, constant.GroupResponseRefuse) {
|
||||
return nil, errs.ErrArgs.Wrap("HandleResult unknown")
|
||||
@@ -776,10 +718,7 @@ func (s *groupServer) GroupApplicationResponse(
|
||||
return &pbGroup.GroupApplicationResponseResp{}, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) JoinGroup(
|
||||
ctx context.Context,
|
||||
req *pbGroup.JoinGroupReq,
|
||||
) (resp *pbGroup.JoinGroupResp, err error) {
|
||||
func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq) (resp *pbGroup.JoinGroupResp, err error) {
|
||||
defer log.ZInfo(ctx, "JoinGroup.Return")
|
||||
user, err := s.User.GetUserInfo(ctx, req.InviterUserID)
|
||||
if err != nil {
|
||||
@@ -879,10 +818,7 @@ func (s *groupServer) deleteMemberAndSetConversationSeq(ctx context.Context, gro
|
||||
return s.conversationRpcClient.SetConversationMaxSeq(ctx, userIDs, conevrsationID, maxSeq)
|
||||
}
|
||||
|
||||
func (s *groupServer) SetGroupInfo(
|
||||
ctx context.Context,
|
||||
req *pbGroup.SetGroupInfoReq,
|
||||
) (*pbGroup.SetGroupInfoResp, error) {
|
||||
func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInfoReq) (*pbGroup.SetGroupInfoResp, error) {
|
||||
var opMember *relationTb.GroupMemberModel
|
||||
if !tokenverify.IsAppManagerUid(ctx) {
|
||||
var err error
|
||||
@@ -910,7 +846,7 @@ func (s *groupServer) SetGroupInfo(
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
data := UpdateGroupInfoMap(req.GroupInfoForSet)
|
||||
data := UpdateGroupInfoMap(ctx, req.GroupInfoForSet)
|
||||
if len(data) == 0 {
|
||||
return resp, nil
|
||||
}
|
||||
@@ -931,11 +867,25 @@ func (s *groupServer) SetGroupInfo(
|
||||
}
|
||||
var num int
|
||||
if req.GroupInfoForSet.Notification != "" {
|
||||
go func() {
|
||||
nctx := mcontext.NewCtx("@@@" + mcontext.GetOperationID(ctx))
|
||||
conversation := &pbConversation.ConversationReq{
|
||||
ConversationID: utils.GetConversationIDBySessionType(constant.SuperGroupChatType, req.GroupInfoForSet.GroupID),
|
||||
ConversationType: constant.SuperGroupChatType,
|
||||
GroupID: req.GroupInfoForSet.GroupID,
|
||||
}
|
||||
resp, err := s.GetGroupMemberUserIDs(nctx, &pbGroup.GetGroupMemberUserIDsReq{GroupID: req.GroupInfoForSet.GroupID})
|
||||
if err != nil {
|
||||
log.ZWarn(ctx, "GetGroupMemberIDs", err)
|
||||
return
|
||||
}
|
||||
conversation.GroupAtType = &wrapperspb.Int32Value{Value: constant.GroupNotification}
|
||||
if err := s.conversationRpcClient.SetConversations(nctx, resp.UserIDs, conversation); err != nil {
|
||||
log.ZWarn(ctx, "SetConversations", err, resp.UserIDs, conversation)
|
||||
}
|
||||
}()
|
||||
num++
|
||||
s.Notification.GroupInfoSetAnnouncementNotification(
|
||||
ctx,
|
||||
&sdkws.GroupInfoSetAnnouncementTips{Group: tips.Group, OpUser: tips.OpUser},
|
||||
)
|
||||
s.Notification.GroupInfoSetAnnouncementNotification(ctx, &sdkws.GroupInfoSetAnnouncementTips{Group: tips.Group, OpUser: tips.OpUser})
|
||||
|
||||
}
|
||||
switch len(data) - num {
|
||||
@@ -952,10 +902,7 @@ func (s *groupServer) SetGroupInfo(
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) TransferGroupOwner(
|
||||
ctx context.Context,
|
||||
req *pbGroup.TransferGroupOwnerReq,
|
||||
) (*pbGroup.TransferGroupOwnerResp, error) {
|
||||
func (s *groupServer) TransferGroupOwner(ctx context.Context, req *pbGroup.TransferGroupOwnerReq) (*pbGroup.TransferGroupOwnerResp, error) {
|
||||
resp := &pbGroup.TransferGroupOwnerResp{}
|
||||
group, err := s.GroupDatabase.TakeGroup(ctx, req.GroupID)
|
||||
if err != nil {
|
||||
@@ -1034,20 +981,9 @@ func (s *groupServer) GetGroups(ctx context.Context, req *pbGroup.GetGroupsReq)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) GetGroupMembersCMS(
|
||||
ctx context.Context,
|
||||
req *pbGroup.GetGroupMembersCMSReq,
|
||||
) (*pbGroup.GetGroupMembersCMSResp, error) {
|
||||
func (s *groupServer) GetGroupMembersCMS(ctx context.Context, req *pbGroup.GetGroupMembersCMSReq) (*pbGroup.GetGroupMembersCMSResp, error) {
|
||||
resp := &pbGroup.GetGroupMembersCMSResp{}
|
||||
total, members, err := s.GroupDatabase.SearchGroupMember(
|
||||
ctx,
|
||||
req.UserName,
|
||||
[]string{req.GroupID},
|
||||
nil,
|
||||
nil,
|
||||
req.Pagination.PageNumber,
|
||||
req.Pagination.ShowNumber,
|
||||
)
|
||||
total, members, err := s.GroupDatabase.SearchGroupMember(ctx, req.UserName, []string{req.GroupID}, nil, nil, req.Pagination.PageNumber, req.Pagination.ShowNumber)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1067,10 +1003,7 @@ func (s *groupServer) GetGroupMembersCMS(
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) GetUserReqApplicationList(
|
||||
ctx context.Context,
|
||||
req *pbGroup.GetUserReqApplicationListReq,
|
||||
) (*pbGroup.GetUserReqApplicationListResp, error) {
|
||||
func (s *groupServer) GetUserReqApplicationList(ctx context.Context, req *pbGroup.GetUserReqApplicationListReq) (*pbGroup.GetUserReqApplicationListResp, error) {
|
||||
resp := &pbGroup.GetUserReqApplicationListResp{}
|
||||
user, err := s.User.GetPublicUserInfo(ctx, req.UserID)
|
||||
if err != nil {
|
||||
@@ -1117,19 +1050,12 @@ func (s *groupServer) GetUserReqApplicationList(
|
||||
return nil, err
|
||||
}
|
||||
resp.GroupRequests = utils.Slice(requests, func(e *relationTb.GroupRequestModel) *sdkws.GroupRequest {
|
||||
return convert.Db2PbGroupRequest(
|
||||
e,
|
||||
user,
|
||||
convert.Db2PbGroupInfo(groupMap[e.GroupID], ownerMap[e.GroupID].UserID, uint32(groupMemberNum[e.GroupID])),
|
||||
)
|
||||
return convert.Db2PbGroupRequest(e, user, convert.Db2PbGroupInfo(groupMap[e.GroupID], ownerMap[e.GroupID].UserID, uint32(groupMemberNum[e.GroupID])))
|
||||
})
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) DismissGroup(
|
||||
ctx context.Context,
|
||||
req *pbGroup.DismissGroupReq,
|
||||
) (*pbGroup.DismissGroupResp, error) {
|
||||
func (s *groupServer) DismissGroup(ctx context.Context, req *pbGroup.DismissGroupReq) (*pbGroup.DismissGroupResp, error) {
|
||||
defer log.ZInfo(ctx, "DismissGroup.return")
|
||||
resp := &pbGroup.DismissGroupResp{}
|
||||
owner, err := s.TakeGroupOwner(ctx, req.GroupID)
|
||||
@@ -1178,10 +1104,7 @@ func (s *groupServer) DismissGroup(
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) MuteGroupMember(
|
||||
ctx context.Context,
|
||||
req *pbGroup.MuteGroupMemberReq,
|
||||
) (*pbGroup.MuteGroupMemberResp, error) {
|
||||
func (s *groupServer) MuteGroupMember(ctx context.Context, req *pbGroup.MuteGroupMemberReq) (*pbGroup.MuteGroupMemberResp, error) {
|
||||
resp := &pbGroup.MuteGroupMemberResp{}
|
||||
//if err := tokenverify.CheckAccessV3(ctx, req.UserID); err != nil {
|
||||
// return nil, err
|
||||
@@ -1216,10 +1139,7 @@ func (s *groupServer) MuteGroupMember(
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) CancelMuteGroupMember(
|
||||
ctx context.Context,
|
||||
req *pbGroup.CancelMuteGroupMemberReq,
|
||||
) (*pbGroup.CancelMuteGroupMemberResp, error) {
|
||||
func (s *groupServer) CancelMuteGroupMember(ctx context.Context, req *pbGroup.CancelMuteGroupMemberReq) (*pbGroup.CancelMuteGroupMemberResp, error) {
|
||||
resp := &pbGroup.CancelMuteGroupMemberResp{}
|
||||
//member, err := s.GroupDatabase.TakeGroupMember(ctx, req.GroupID, req.UserID)
|
||||
//if err != nil {
|
||||
@@ -1231,8 +1151,7 @@ func (s *groupServer) CancelMuteGroupMember(
|
||||
// return nil, err
|
||||
// }
|
||||
// if opMember.RoleLevel <= member.RoleLevel {
|
||||
// return nil, errs.ErrNoPermission.Wrap(fmt.Sprintf("self RoleLevel %d target %d", opMember.RoleLevel,
|
||||
// member.RoleLevel))
|
||||
// return nil, errs.ErrNoPermission.Wrap(fmt.Sprintf("self RoleLevel %d target %d", opMember.RoleLevel, member.RoleLevel))
|
||||
// }
|
||||
//}
|
||||
//if err := tokenverify.CheckAccessV3(ctx, req.UserID); err != nil {
|
||||
@@ -1280,10 +1199,7 @@ func (s *groupServer) MuteGroup(ctx context.Context, req *pbGroup.MuteGroupReq)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) CancelMuteGroup(
|
||||
ctx context.Context,
|
||||
req *pbGroup.CancelMuteGroupReq,
|
||||
) (*pbGroup.CancelMuteGroupResp, error) {
|
||||
func (s *groupServer) CancelMuteGroup(ctx context.Context, req *pbGroup.CancelMuteGroupReq) (*pbGroup.CancelMuteGroupResp, error) {
|
||||
resp := &pbGroup.CancelMuteGroupResp{}
|
||||
if err := s.CheckGroupAdmin(ctx, req.GroupID); err != nil {
|
||||
return nil, err
|
||||
@@ -1295,10 +1211,7 @@ func (s *groupServer) CancelMuteGroup(
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) SetGroupMemberInfo(
|
||||
ctx context.Context,
|
||||
req *pbGroup.SetGroupMemberInfoReq,
|
||||
) (*pbGroup.SetGroupMemberInfoResp, error) {
|
||||
func (s *groupServer) SetGroupMemberInfo(ctx context.Context, req *pbGroup.SetGroupMemberInfoReq) (*pbGroup.SetGroupMemberInfoResp, error) {
|
||||
resp := &pbGroup.SetGroupMemberInfoResp{}
|
||||
if len(req.Members) == 0 {
|
||||
return nil, errs.ErrArgs.Wrap("members empty")
|
||||
@@ -1325,11 +1238,9 @@ func (s *groupServer) SetGroupMemberInfo(
|
||||
delete(duplicateMap, [...]string{member.GroupID, member.UserID})
|
||||
}
|
||||
if len(duplicateMap) > 0 {
|
||||
return nil, errs.ErrArgs.Wrap(
|
||||
"user not found" + strings.Join(utils.Slice(utils.Keys(duplicateMap), func(e [2]string) string {
|
||||
return fmt.Sprintf("[group: %s user: %s]", e[0], e[1])
|
||||
}), ","),
|
||||
)
|
||||
return nil, errs.ErrArgs.Wrap("user not found" + strings.Join(utils.Slice(utils.Keys(duplicateMap), func(e [2]string) string {
|
||||
return fmt.Sprintf("[group: %s user: %s]", e[0], e[1])
|
||||
}), ","))
|
||||
}
|
||||
memberMap := utils.SliceToMap(members, func(e *relationTb.GroupMemberModel) [2]string {
|
||||
return [...]string{e.GroupID, e.UserID}
|
||||
@@ -1359,9 +1270,7 @@ func (s *groupServer) SetGroupMemberInfo(
|
||||
}
|
||||
dbMember, ok := memberMap[[...]string{member.GroupID, member.UserID}]
|
||||
if !ok {
|
||||
return nil, errs.ErrRecordNotFound.Wrap(
|
||||
fmt.Sprintf("user %s not in group %s", member.UserID, member.GroupID),
|
||||
)
|
||||
return nil, errs.ErrRecordNotFound.Wrap(fmt.Sprintf("user %s not in group %s", member.UserID, member.GroupID))
|
||||
}
|
||||
//if opMember.RoleLevel == constant.GroupOwner {
|
||||
// continue
|
||||
@@ -1423,25 +1332,14 @@ func (s *groupServer) SetGroupMemberInfo(
|
||||
if member.Nickname != nil || member.FaceURL != nil || member.Ex != nil {
|
||||
log.ZDebug(ctx, "setGroupMemberInfo notification", "member", member.UserID)
|
||||
if err := s.Notification.GroupMemberInfoSetNotification(ctx, member.GroupID, member.UserID); err != nil {
|
||||
log.ZError(
|
||||
ctx,
|
||||
"setGroupMemberInfo notification failed",
|
||||
err,
|
||||
"member",
|
||||
member.UserID,
|
||||
"groupID",
|
||||
member.GroupID,
|
||||
)
|
||||
log.ZError(ctx, "setGroupMemberInfo notification failed", err, "member", member.UserID, "groupID", member.GroupID)
|
||||
}
|
||||
}
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) GetGroupAbstractInfo(
|
||||
ctx context.Context,
|
||||
req *pbGroup.GetGroupAbstractInfoReq,
|
||||
) (*pbGroup.GetGroupAbstractInfoResp, error) {
|
||||
func (s *groupServer) GetGroupAbstractInfo(ctx context.Context, req *pbGroup.GetGroupAbstractInfoReq) (*pbGroup.GetGroupAbstractInfoResp, error) {
|
||||
resp := &pbGroup.GetGroupAbstractInfoResp{}
|
||||
if len(req.GroupIDs) == 0 {
|
||||
return nil, errs.ErrArgs.Wrap("groupIDs empty")
|
||||
@@ -1472,10 +1370,7 @@ func (s *groupServer) GetGroupAbstractInfo(
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) GetUserInGroupMembers(
|
||||
ctx context.Context,
|
||||
req *pbGroup.GetUserInGroupMembersReq,
|
||||
) (*pbGroup.GetUserInGroupMembersResp, error) {
|
||||
func (s *groupServer) GetUserInGroupMembers(ctx context.Context, req *pbGroup.GetUserInGroupMembersReq) (*pbGroup.GetUserInGroupMembersResp, error) {
|
||||
resp := &pbGroup.GetUserInGroupMembersResp{}
|
||||
if len(req.GroupIDs) == 0 {
|
||||
return nil, errs.ErrArgs.Wrap("groupIDs empty")
|
||||
@@ -1499,10 +1394,7 @@ func (s *groupServer) GetUserInGroupMembers(
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) GetGroupMemberUserIDs(
|
||||
ctx context.Context,
|
||||
req *pbGroup.GetGroupMemberUserIDsReq,
|
||||
) (resp *pbGroup.GetGroupMemberUserIDsResp, err error) {
|
||||
func (s *groupServer) GetGroupMemberUserIDs(ctx context.Context, req *pbGroup.GetGroupMemberUserIDsReq) (resp *pbGroup.GetGroupMemberUserIDsResp, err error) {
|
||||
resp = &pbGroup.GetGroupMemberUserIDsResp{}
|
||||
resp.UserIDs, err = s.GroupDatabase.FindGroupMemberUserID(ctx, req.GroupID)
|
||||
if err != nil {
|
||||
@@ -1511,10 +1403,7 @@ func (s *groupServer) GetGroupMemberUserIDs(
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) GetGroupMemberRoleLevel(
|
||||
ctx context.Context,
|
||||
req *pbGroup.GetGroupMemberRoleLevelReq,
|
||||
) (*pbGroup.GetGroupMemberRoleLevelResp, error) {
|
||||
func (s *groupServer) GetGroupMemberRoleLevel(ctx context.Context, req *pbGroup.GetGroupMemberRoleLevelReq) (*pbGroup.GetGroupMemberRoleLevelResp, error) {
|
||||
resp := &pbGroup.GetGroupMemberRoleLevelResp{}
|
||||
if len(req.RoleLevels) == 0 {
|
||||
return nil, errs.ErrArgs.Wrap("RoleLevels empty")
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/group"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (s *groupServer) GroupCreateCount(ctx context.Context, req *group.GroupCreateCountReq) (*group.GroupCreateCountResp, error) {
|
||||
if req.Start > req.End {
|
||||
return nil, errs.ErrArgs.Wrap("start > end")
|
||||
}
|
||||
total, err := s.GroupDatabase.CountTotal(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
start := time.UnixMilli(req.Start)
|
||||
before, err := s.GroupDatabase.CountTotal(ctx, &start)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
count, err := s.GroupDatabase.CountRangeEverydayTotal(ctx, start, time.UnixMilli(req.End))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &group.GroupCreateCountResp{Total: total, Before: before, Count: count}, nil
|
||||
}
|
||||
@@ -1,414 +0,0 @@
|
||||
// Copyright © 2023 OpenIM. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package msg
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msg"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
|
||||
)
|
||||
|
||||
func (m *msgServer) SetMessageReactionExtensions(
|
||||
ctx context.Context,
|
||||
req *msg.SetMessageReactionExtensionsReq,
|
||||
) (resp *msg.SetMessageReactionExtensionsResp, err error) {
|
||||
//resp = &msg.SetMessageReactionExtensionsResp{}
|
||||
////resp.ClientMsgID = req.ClientMsgID
|
||||
////resp.MsgFirstModifyTime = req.MsgFirstModifyTime
|
||||
//
|
||||
//if err := CallbackSetMessageReactionExtensions(ctx, req); err != nil {
|
||||
// return nil, err
|
||||
//}
|
||||
////if ExternalExtension
|
||||
//if req.IsExternalExtensions {
|
||||
// resp.MsgFirstModifyTime = req.MsgFirstModifyTime
|
||||
// notification.ExtendMessageUpdatedNotification(req.OperationID, req.OpUserID, req.conversationID,
|
||||
// req.SessionType, req, &resp, !req.IsReact, false)
|
||||
// return resp, nil
|
||||
//}
|
||||
//isExists, err := m.MsgDatabase.JudgeMessageReactionExist(ctx, req.ClientMsgID, req.SessionType)
|
||||
//if err != nil {
|
||||
// return nil, err
|
||||
//}
|
||||
//
|
||||
//if !isExists {
|
||||
// if !req.IsReact {
|
||||
// resp.MsgFirstModifyTime = utils.GetCurrentTimestampByMill()
|
||||
// for k, v := range req.ReactionExtensions {
|
||||
// err := m.MessageLocker.LockMessageTypeKey(ctx, req.ClientMsgID, k)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// v.LatestUpdateTime = utils.GetCurrentTimestampByMill()
|
||||
// if err := m.MsgDatabase.SetMessageTypeKeyValue(ctx, req.ClientMsgID, req.SessionType, k,
|
||||
// utils.StructToJsonString(v)); err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// }
|
||||
// resp.IsReact = true
|
||||
// _, err := m.MsgDatabase.SetMessageReactionExpire(ctx, req.ClientMsgID, req.SessionType,
|
||||
// time.Duration(24*3)*time.Hour)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// } else {
|
||||
// err := m.MessageLocker.LockGlobalMessage(ctx, req.ClientMsgID)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// mongoValue, err := m.MsgDatabase.GetExtendMsg(ctx, req.conversationID, req.SessionType, req.ClientMsgID,
|
||||
// req.MsgFirstModifyTime)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// setValue := make(map[string]*sdkws.KeyValue)
|
||||
// for k, v := range req.ReactionExtensions {
|
||||
//
|
||||
// temp := new(sdkws.KeyValue)
|
||||
// if vv, ok := mongoValue.ReactionExtensions[k]; ok {
|
||||
// utils.CopyStructFields(temp, &vv)
|
||||
// if v.LatestUpdateTime != vv.LatestUpdateTime {
|
||||
// setKeyResultInfo(&resp, 300, "message have update", req.ClientMsgID, k, temp)
|
||||
// continue
|
||||
// }
|
||||
// }
|
||||
// temp.TypeKey = k
|
||||
// temp.Value = v.Value
|
||||
// temp.LatestUpdateTime = utils.GetCurrentTimestampByMill()
|
||||
// setValue[k] = temp
|
||||
// }
|
||||
// err = db.DB.InsertOrUpdateReactionExtendMsgSet(req.conversationID, req.SessionType, req.ClientMsgID,
|
||||
// req.MsgFirstModifyTime, setValue)
|
||||
// if err != nil {
|
||||
// for _, value := range setValue {
|
||||
// temp := new(msg.KeyValueResp)
|
||||
// temp.KeyValue = value
|
||||
// temp.ErrMsg = err.Error()
|
||||
// temp.ErrCode = 100
|
||||
// resp.Result = append(resp.Result, temp)
|
||||
// }
|
||||
// } else {
|
||||
// for _, value := range setValue {
|
||||
// temp := new(msg.KeyValueResp)
|
||||
// temp.KeyValue = value
|
||||
// resp.Result = append(resp.Result, temp)
|
||||
// }
|
||||
// }
|
||||
// lockErr := m.dMessageLocker.UnLockGlobalMessage(req.ClientMsgID)
|
||||
// if lockErr != nil {
|
||||
// log.Error(req.OperationID, "UnLockGlobalMessage err:", lockErr.Error())
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//} else {
|
||||
// log.Debug(req.OperationID, "redis handle secondly", req.String())
|
||||
//
|
||||
// for k, v := range req.Pb2Model {
|
||||
// err := m.dMessageLocker.LockMessageTypeKey(req.ClientMsgID, k)
|
||||
// if err != nil {
|
||||
// setKeyResultInfo(&resp, 100, err.Error(), req.ClientMsgID, k, v)
|
||||
// continue
|
||||
// }
|
||||
// redisValue, err := db.DB.GetMessageTypeKeyValue(req.ClientMsgID, req.SessionType, k)
|
||||
// if err != nil && err != go_redis.Nil {
|
||||
// setKeyResultInfo(&resp, 200, err.Error(), req.ClientMsgID, k, v)
|
||||
// continue
|
||||
// }
|
||||
// temp := new(sdkws.KeyValue)
|
||||
// utils.JsonStringToStruct(redisValue, temp)
|
||||
// if v.LatestUpdateTime != temp.LatestUpdateTime {
|
||||
// setKeyResultInfo(&resp, 300, "message have update", req.ClientMsgID, k, temp)
|
||||
// continue
|
||||
// } else {
|
||||
// v.LatestUpdateTime = utils.GetCurrentTimestampByMill()
|
||||
// newerr := db.DB.SetMessageTypeKeyValue(req.ClientMsgID, req.SessionType, k, utils.StructToJsonString(v))
|
||||
// if newerr != nil {
|
||||
// setKeyResultInfo(&resp, 201, newerr.Error(), req.ClientMsgID, k, temp)
|
||||
// continue
|
||||
// }
|
||||
// setKeyResultInfo(&resp, 0, "", req.ClientMsgID, k, v)
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//}
|
||||
//if !isExists {
|
||||
// if !req.IsReact {
|
||||
// notification.ExtendMessageUpdatedNotification(req.OperationID, req.OpUserID, req.conversationID,
|
||||
// req.SessionType, req, &resp, true, true)
|
||||
// } else {
|
||||
// notification.ExtendMessageUpdatedNotification(req.OperationID, req.OpUserID, req.conversationID,
|
||||
// req.SessionType, req, &resp, false, false)
|
||||
// }
|
||||
//} else {
|
||||
// notification.ExtendMessageUpdatedNotification(req.OperationID, req.OpUserID, req.conversationID,
|
||||
// req.SessionType, req, &resp, false, true)
|
||||
//}
|
||||
//log.Debug(req.OperationID, utils.GetSelfFuncName(), "m return is:", resp.String())
|
||||
return resp, nil
|
||||
|
||||
}
|
||||
|
||||
func (m *msgServer) setKeyResultInfo(
|
||||
ctx context.Context,
|
||||
r *msg.SetMessageReactionExtensionsResp,
|
||||
errCode int32,
|
||||
errMsg, clientMsgID, typeKey string,
|
||||
keyValue *sdkws.KeyValue,
|
||||
) {
|
||||
temp := new(msg.KeyValueResp)
|
||||
temp.KeyValue = keyValue
|
||||
temp.ErrCode = errCode
|
||||
temp.ErrMsg = errMsg
|
||||
r.Result = append(r.Result, temp)
|
||||
_ = m.MessageLocker.UnLockMessageTypeKey(ctx, clientMsgID, typeKey)
|
||||
}
|
||||
|
||||
func (m *msgServer) setDeleteKeyResultInfo(
|
||||
ctx context.Context,
|
||||
r *msg.DeleteMessagesReactionExtensionsResp,
|
||||
errCode int32,
|
||||
errMsg, clientMsgID, typeKey string,
|
||||
keyValue *sdkws.KeyValue,
|
||||
) {
|
||||
temp := new(msg.KeyValueResp)
|
||||
temp.KeyValue = keyValue
|
||||
temp.ErrCode = errCode
|
||||
temp.ErrMsg = errMsg
|
||||
r.Result = append(r.Result, temp)
|
||||
_ = m.MessageLocker.UnLockMessageTypeKey(ctx, clientMsgID, typeKey)
|
||||
}
|
||||
|
||||
func (m *msgServer) GetMessagesReactionExtensions(
|
||||
ctx context.Context,
|
||||
req *msg.GetMessagesReactionExtensionsReq,
|
||||
) (resp *msg.GetMessagesReactionExtensionsResp, err error) {
|
||||
//log.Debug(req.OperationID, utils.GetSelfFuncName(), "m args is:", req.String())
|
||||
//var rResp msg.GetMessageListReactionExtensionsResp
|
||||
//for _, messageValue := range req.MessageReactionKeyList {
|
||||
// var oneMessage msg.SingleMessageExtensionResult
|
||||
// oneMessage.ClientMsgID = messageValue.ClientMsgID
|
||||
//
|
||||
// isExists, err := db.DB.JudgeMessageReactionExist(messageValue.ClientMsgID, req.SessionType)
|
||||
// if err != nil {
|
||||
// rResp.ErrCode = 100
|
||||
// rResp.ErrMsg = err.Error()
|
||||
// return &rResp, nil
|
||||
// }
|
||||
// if isExists {
|
||||
// redisValue, err := db.DB.GetOneMessageAllReactionList(messageValue.ClientMsgID, req.SessionType)
|
||||
// if err != nil {
|
||||
// oneMessage.ErrCode = 100
|
||||
// oneMessage.ErrMsg = err.Error()
|
||||
// rResp.SingleMessageResult = append(rResp.SingleMessageResult, &oneMessage)
|
||||
// continue
|
||||
// }
|
||||
// keyMap := make(map[string]*sdkws.KeyValue)
|
||||
//
|
||||
// for k, v := range redisValue {
|
||||
// temp := new(sdkws.KeyValue)
|
||||
// utils.JsonStringToStruct(v, temp)
|
||||
// keyMap[k] = temp
|
||||
// }
|
||||
// oneMessage.Pb2Model = keyMap
|
||||
//
|
||||
// } else {
|
||||
// mongoValue, err := db.DB.GetExtendMsg(req.conversationID, req.SessionType, messageValue.ClientMsgID,
|
||||
// messageValue.MsgFirstModifyTime)
|
||||
// if err != nil {
|
||||
// oneMessage.ErrCode = 100
|
||||
// oneMessage.ErrMsg = err.Error()
|
||||
// rResp.SingleMessageResult = append(rResp.SingleMessageResult, &oneMessage)
|
||||
// continue
|
||||
// }
|
||||
// keyMap := make(map[string]*sdkws.KeyValue)
|
||||
//
|
||||
// for k, v := range mongoValue.Pb2Model {
|
||||
// temp := new(sdkws.KeyValue)
|
||||
// temp.TypeKey = v.TypeKey
|
||||
// temp.Value = v.Value
|
||||
// temp.LatestUpdateTime = v.LatestUpdateTime
|
||||
// keyMap[k] = temp
|
||||
// }
|
||||
// oneMessage.Pb2Model = keyMap
|
||||
// }
|
||||
// rResp.SingleMessageResult = append(rResp.SingleMessageResult, &oneMessage)
|
||||
//}
|
||||
//log.Debug(req.OperationID, utils.GetSelfFuncName(), "m return is:", rResp.String())
|
||||
return resp, nil
|
||||
|
||||
}
|
||||
|
||||
func (m *msgServer) AddMessageReactionExtensions(
|
||||
ctx context.Context,
|
||||
req *msg.ModifyMessageReactionExtensionsReq,
|
||||
) (resp *msg.ModifyMessageReactionExtensionsResp, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (m *msgServer) DeleteMessageReactionExtensions(
|
||||
ctx context.Context,
|
||||
req *msg.DeleteMessagesReactionExtensionsReq,
|
||||
) (resp *msg.DeleteMessagesReactionExtensionsResp, err error) {
|
||||
//log.Debug(req.OperationID, utils.GetSelfFuncName(), "m args is:", req.String())
|
||||
//var rResp msg.DeleteMessagesReactionExtensionsResp
|
||||
//callbackResp := notification.callbackDeleteMessageReactionExtensions(req)
|
||||
//if callbackResp.ActionCode != constant.ActionAllow || callbackResp.ErrCode != 0 {
|
||||
// rResp.ErrCode = int32(callbackResp.ErrCode)
|
||||
// rResp.ErrMsg = callbackResp.ErrMsg
|
||||
// for _, value := range req.Pb2Model {
|
||||
// temp := new(msg.KeyValueResp)
|
||||
// temp.KeyValue = value
|
||||
// temp.ErrMsg = callbackResp.ErrMsg
|
||||
// temp.ErrCode = 100
|
||||
// rResp.Result = append(rResp.Result, temp)
|
||||
// }
|
||||
// return &rResp, nil
|
||||
//}
|
||||
////if ExternalExtension
|
||||
//if req.IsExternalExtensions {
|
||||
// rResp.Result = callbackResp.ResultReactionExtensionList
|
||||
// notification.ExtendMessageDeleteNotification(req.OperationID, req.OpUserID, req.conversationID, req.SessionType,
|
||||
// req, &rResp, false, false)
|
||||
// return &rResp, nil
|
||||
//
|
||||
//}
|
||||
//for _, v := range callbackResp.ResultReactionExtensions {
|
||||
// if v.ErrCode != 0 {
|
||||
// func(req *[]*sdkws.KeyValue, typeKey string) {
|
||||
// for i := 0; i < len(*req); i++ {
|
||||
// if (*req)[i].TypeKey == typeKey {
|
||||
// *req = append((*req)[:i], (*req)[i+1:]...)
|
||||
// }
|
||||
// }
|
||||
// }(&req.Pb2Model, v.KeyValue.TypeKey)
|
||||
// rResp.Result = append(rResp.Result, v)
|
||||
// }
|
||||
//}
|
||||
//isExists, err := db.DB.JudgeMessageReactionExist(req.ClientMsgID, req.SessionType)
|
||||
//if err != nil {
|
||||
// rResp.ErrCode = 100
|
||||
// rResp.ErrMsg = err.Error()
|
||||
// for _, value := range req.Pb2Model {
|
||||
// temp := new(msg.KeyValueResp)
|
||||
// temp.KeyValue = value
|
||||
// temp.ErrMsg = err.Error()
|
||||
// temp.ErrCode = 100
|
||||
// rResp.Result = append(rResp.Result, temp)
|
||||
// }
|
||||
// return &rResp, nil
|
||||
//}
|
||||
//
|
||||
//if isExists {
|
||||
// log.Debug(req.OperationID, "redis handle this delete", req.String())
|
||||
// for _, v := range req.Pb2Model {
|
||||
// err := m.dMessageLocker.LockMessageTypeKey(req.ClientMsgID, v.TypeKey)
|
||||
// if err != nil {
|
||||
// setDeleteKeyResultInfo(&rResp, 100, err.Error(), req.ClientMsgID, v.TypeKey, v)
|
||||
// continue
|
||||
// }
|
||||
//
|
||||
// redisValue, err := db.DB.GetMessageTypeKeyValue(req.ClientMsgID, req.SessionType, v.TypeKey)
|
||||
// if err != nil && err != go_redis.Nil {
|
||||
// setDeleteKeyResultInfo(&rResp, 200, err.Error(), req.ClientMsgID, v.TypeKey, v)
|
||||
// continue
|
||||
// }
|
||||
// temp := new(sdkws.KeyValue)
|
||||
// utils.JsonStringToStruct(redisValue, temp)
|
||||
// if v.LatestUpdateTime != temp.LatestUpdateTime {
|
||||
// setDeleteKeyResultInfo(&rResp, 300, "message have update", req.ClientMsgID, v.TypeKey, temp)
|
||||
// continue
|
||||
// } else {
|
||||
// newErr := db.DB.DeleteOneMessageKey(req.ClientMsgID, req.SessionType, v.TypeKey)
|
||||
// if newErr != nil {
|
||||
// setDeleteKeyResultInfo(&rResp, 201, newErr.Error(), req.ClientMsgID, v.TypeKey, temp)
|
||||
// continue
|
||||
// }
|
||||
// setDeleteKeyResultInfo(&rResp, 0, "", req.ClientMsgID, v.TypeKey, v)
|
||||
// }
|
||||
// }
|
||||
//} else {
|
||||
// err := m.dMessageLocker.LockGlobalMessage(req.ClientMsgID)
|
||||
// if err != nil {
|
||||
// rResp.ErrCode = 100
|
||||
// rResp.ErrMsg = err.Error()
|
||||
// for _, value := range req.Pb2Model {
|
||||
// temp := new(msg.KeyValueResp)
|
||||
// temp.KeyValue = value
|
||||
// temp.ErrMsg = err.Error()
|
||||
// temp.ErrCode = 100
|
||||
// rResp.Result = append(rResp.Result, temp)
|
||||
// }
|
||||
// return &rResp, nil
|
||||
// }
|
||||
// mongoValue, err := db.DB.GetExtendMsg(req.conversationID, req.SessionType, req.ClientMsgID,
|
||||
// req.MsgFirstModifyTime)
|
||||
// if err != nil {
|
||||
// rResp.ErrCode = 200
|
||||
// rResp.ErrMsg = err.Error()
|
||||
// for _, value := range req.Pb2Model {
|
||||
// temp := new(msg.KeyValueResp)
|
||||
// temp.KeyValue = value
|
||||
// temp.ErrMsg = err.Error()
|
||||
// temp.ErrCode = 100
|
||||
// rResp.Result = append(rResp.Result, temp)
|
||||
// }
|
||||
// return &rResp, nil
|
||||
// }
|
||||
// setValue := make(map[string]*sdkws.KeyValue)
|
||||
// for _, v := range req.Pb2Model {
|
||||
//
|
||||
// temp := new(sdkws.KeyValue)
|
||||
// if vv, ok := mongoValue.Pb2Model[v.TypeKey]; ok {
|
||||
// utils.CopyStructFields(temp, &vv)
|
||||
// if v.LatestUpdateTime != vv.LatestUpdateTime {
|
||||
// setDeleteKeyResultInfo(&rResp, 300, "message have update", req.ClientMsgID, v.TypeKey, temp)
|
||||
// continue
|
||||
// }
|
||||
// } else {
|
||||
// setDeleteKeyResultInfo(&rResp, 400, "key not in", req.ClientMsgID, v.TypeKey, v)
|
||||
// continue
|
||||
// }
|
||||
// temp.TypeKey = v.TypeKey
|
||||
// setValue[v.TypeKey] = temp
|
||||
// }
|
||||
// err = db.DB.DeleteReactionExtendMsgSet(req.conversationID, req.SessionType, req.ClientMsgID,
|
||||
// req.MsgFirstModifyTime, setValue)
|
||||
// if err != nil {
|
||||
// for _, value := range setValue {
|
||||
// temp := new(msg.KeyValueResp)
|
||||
// temp.KeyValue = value
|
||||
// temp.ErrMsg = err.Error()
|
||||
// temp.ErrCode = 100
|
||||
// rResp.Result = append(rResp.Result, temp)
|
||||
// }
|
||||
// } else {
|
||||
// for _, value := range setValue {
|
||||
// temp := new(msg.KeyValueResp)
|
||||
// temp.KeyValue = value
|
||||
// rResp.Result = append(rResp.Result, temp)
|
||||
// }
|
||||
// }
|
||||
// lockErr := m.dMessageLocker.UnLockGlobalMessage(req.ClientMsgID)
|
||||
// if lockErr != nil {
|
||||
// log.Error(req.OperationID, "UnLockGlobalMessage err:", lockErr.Error())
|
||||
// }
|
||||
//
|
||||
//}
|
||||
// notification.ExtendMessageDeleteNotification(req.OperationID, req.OpUserID, req.conversationID, req.SessionType,
|
||||
// req, &rResp, false, isExists)
|
||||
//log.Debug(req.OperationID, utils.GetSelfFuncName(), "m return is:", rResp.String())
|
||||
return resp, nil
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
// Copyright © 2023 OpenIM. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package msg
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
cbapi "github.com/OpenIMSDK/Open-IM-Server/pkg/callbackstruct"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/http"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/mcontext"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msg"
|
||||
)
|
||||
|
||||
func callbackSetMessageReactionExtensions(ctx context.Context, setReq *msg.SetMessageReactionExtensionsReq) error {
|
||||
if !config.Config.Callback.CallbackAfterSendGroupMsg.Enable {
|
||||
return nil
|
||||
}
|
||||
req := &cbapi.CallbackBeforeSetMessageReactionExtReq{
|
||||
OperationID: mcontext.GetOperationID(ctx),
|
||||
CallbackCommand: constant.CallbackBeforeSetMessageReactionExtensionCommand,
|
||||
ConversationID: setReq.ConversationID,
|
||||
OpUserID: mcontext.GetOpUserID(ctx),
|
||||
SessionType: setReq.SessionType,
|
||||
ReactionExtensionList: setReq.ReactionExtensions,
|
||||
ClientMsgID: setReq.ClientMsgID,
|
||||
IsReact: setReq.IsReact,
|
||||
IsExternalExtensions: setReq.IsExternalExtensions,
|
||||
MsgFirstModifyTime: setReq.MsgFirstModifyTime,
|
||||
}
|
||||
resp := &cbapi.CallbackBeforeSetMessageReactionExtResp{}
|
||||
if err := http.CallBackPostReturn(ctx, cbURL(), req, resp, config.Config.Callback.CallbackAfterSendGroupMsg); err != nil {
|
||||
return err
|
||||
}
|
||||
setReq.MsgFirstModifyTime = resp.MsgFirstModifyTime
|
||||
return nil
|
||||
}
|
||||
|
||||
func callbackDeleteMessageReactionExtensions(
|
||||
ctx context.Context,
|
||||
setReq *msg.DeleteMessagesReactionExtensionsReq,
|
||||
) error {
|
||||
if !config.Config.Callback.CallbackAfterSendGroupMsg.Enable {
|
||||
return nil
|
||||
}
|
||||
req := &cbapi.CallbackDeleteMessageReactionExtReq{
|
||||
OperationID: setReq.OperationID,
|
||||
CallbackCommand: constant.CallbackBeforeDeleteMessageReactionExtensionsCommand,
|
||||
ConversationID: setReq.ConversationID,
|
||||
OpUserID: setReq.OpUserID,
|
||||
SessionType: setReq.SessionType,
|
||||
ReactionExtensionList: setReq.ReactionExtensions,
|
||||
ClientMsgID: setReq.ClientMsgID,
|
||||
IsExternalExtensions: setReq.IsExternalExtensions,
|
||||
MsgFirstModifyTime: setReq.MsgFirstModifyTime,
|
||||
}
|
||||
resp := &cbapi.CallbackDeleteMessageReactionExtResp{}
|
||||
return http.CallBackPostReturn(ctx, cbURL(), req, resp, config.Config.Callback.CallbackAfterSendGroupMsg)
|
||||
}
|
||||
|
||||
func callbackGetMessageListReactionExtensions(ctx context.Context, getReq *msg.GetMessagesReactionExtensionsReq) error {
|
||||
if !config.Config.Callback.CallbackAfterSendGroupMsg.Enable {
|
||||
return nil
|
||||
}
|
||||
req := &cbapi.CallbackGetMessageListReactionExtReq{
|
||||
OperationID: mcontext.GetOperationID(ctx),
|
||||
CallbackCommand: constant.CallbackGetMessageListReactionExtensionsCommand,
|
||||
ConversationID: getReq.ConversationID,
|
||||
OpUserID: mcontext.GetOperationID(ctx),
|
||||
SessionType: getReq.SessionType,
|
||||
TypeKeyList: getReq.TypeKeys,
|
||||
}
|
||||
resp := &cbapi.CallbackGetMessageListReactionExtResp{}
|
||||
return http.CallBackPostReturn(ctx, cbURL(), req, resp, config.Config.Callback.CallbackAfterSendGroupMsg)
|
||||
}
|
||||
|
||||
func callbackAddMessageReactionExtensions(ctx context.Context, setReq *msg.ModifyMessageReactionExtensionsReq) error {
|
||||
req := &cbapi.CallbackAddMessageReactionExtReq{
|
||||
OperationID: mcontext.GetOperationID(ctx),
|
||||
CallbackCommand: constant.CallbackAddMessageListReactionExtensionsCommand,
|
||||
ConversationID: setReq.ConversationID,
|
||||
OpUserID: mcontext.GetOperationID(ctx),
|
||||
SessionType: setReq.SessionType,
|
||||
ReactionExtensionList: setReq.ReactionExtensions,
|
||||
ClientMsgID: setReq.ClientMsgID,
|
||||
IsReact: setReq.IsReact,
|
||||
IsExternalExtensions: setReq.IsExternalExtensions,
|
||||
MsgFirstModifyTime: setReq.MsgFirstModifyTime,
|
||||
}
|
||||
resp := &cbapi.CallbackAddMessageReactionExtResp{}
|
||||
return http.CallBackPostReturn(ctx, cbURL(), req, resp, config.Config.Callback.CallbackAfterSendGroupMsg)
|
||||
}
|
||||
@@ -99,7 +99,6 @@ func (m *msgServer) RevokeMsg(ctx context.Context, req *msg.RevokeMsgReq) (*msg.
|
||||
}
|
||||
now := time.Now().UnixMilli()
|
||||
err = m.MsgDatabase.RevokeMsg(ctx, req.ConversationID, req.Seq, &unRelationTb.RevokeModel{
|
||||
ID: uuid.New().String(),
|
||||
Role: role,
|
||||
UserID: req.UserID,
|
||||
Nickname: user.Nickname,
|
||||
|
||||
+19
-15
@@ -31,20 +31,24 @@ import (
|
||||
|
||||
func (m *msgServer) SendMsg(ctx context.Context, req *pbMsg.SendMsgReq) (resp *pbMsg.SendMsgResp, error error) {
|
||||
resp = &pbMsg.SendMsgResp{}
|
||||
flag := isMessageHasReadEnabled(req.MsgData)
|
||||
if !flag {
|
||||
return nil, errs.ErrMessageHasReadDisable.Wrap()
|
||||
}
|
||||
m.encapsulateMsgData(req.MsgData)
|
||||
switch req.MsgData.SessionType {
|
||||
case constant.SingleChatType:
|
||||
return m.sendMsgSingleChat(ctx, req)
|
||||
case constant.NotificationChatType:
|
||||
return m.sendMsgNotification(ctx, req)
|
||||
case constant.SuperGroupChatType:
|
||||
return m.sendMsgSuperGroupChat(ctx, req)
|
||||
default:
|
||||
return nil, errs.ErrArgs.Wrap("unknown sessionType")
|
||||
if req.MsgData != nil {
|
||||
flag := isMessageHasReadEnabled(req.MsgData)
|
||||
if !flag {
|
||||
return nil, errs.ErrMessageHasReadDisable.Wrap()
|
||||
}
|
||||
m.encapsulateMsgData(req.MsgData)
|
||||
switch req.MsgData.SessionType {
|
||||
case constant.SingleChatType:
|
||||
return m.sendMsgSingleChat(ctx, req)
|
||||
case constant.NotificationChatType:
|
||||
return m.sendMsgNotification(ctx, req)
|
||||
case constant.SuperGroupChatType:
|
||||
return m.sendMsgSuperGroupChat(ctx, req)
|
||||
default:
|
||||
return nil, errs.ErrArgs.Wrap("unknown sessionType")
|
||||
}
|
||||
} else {
|
||||
return nil, errs.ErrArgs.Wrap("msgData is nil")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,7 +164,7 @@ func (m *msgServer) sendMsgSingleChat(ctx context.Context, req *pbMsg.SendMsgReq
|
||||
}
|
||||
if !isSend {
|
||||
promePkg.Inc(promePkg.SingleChatMsgProcessFailedCounter)
|
||||
return nil, errs.ErrUserNotRecvMsg
|
||||
return nil, nil
|
||||
} else {
|
||||
if err = callbackBeforeSendSingleMsg(ctx, req); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -1,42 +1,25 @@
|
||||
// Copyright © 2023 OpenIM. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package msg
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/localcache"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/tx"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/unrelation"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/prome"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/conversation"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msg"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type MessageInterceptorChain []MessageInterceptorFunc
|
||||
type msgServer struct {
|
||||
RegisterCenter discoveryregistry.SvcDiscoveryRegistry
|
||||
MsgDatabase controller.CommonMsgDatabase
|
||||
ExtendMsgDatabase controller.ExtendMsgDatabase
|
||||
Group *rpcclient.GroupRpcClient
|
||||
User *rpcclient.UserRpcClient
|
||||
Conversation *rpcclient.ConversationRpcClient
|
||||
@@ -77,13 +60,6 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e
|
||||
}
|
||||
cacheModel := cache.NewMsgCacheModel(rdb)
|
||||
msgDocModel := unrelation.NewMsgMongoDriver(mongo.GetDatabase())
|
||||
extendMsgModel := unrelation.NewExtendMsgSetMongoDriver(mongo.GetDatabase())
|
||||
extendMsgCacheModel := cache.NewExtendMsgSetCacheRedis(rdb, extendMsgModel, cache.GetDefaultOpt())
|
||||
extendMsgDatabase := controller.NewExtendMsgDatabase(
|
||||
extendMsgModel,
|
||||
extendMsgCacheModel,
|
||||
tx.NewMongo(mongo.GetClient()),
|
||||
)
|
||||
msgDatabase := controller.NewCommonMsgDatabase(msgDocModel, cacheModel)
|
||||
conversationClient := rpcclient.NewConversationRpcClient(client)
|
||||
userRpcClient := rpcclient.NewUserRpcClient(client)
|
||||
@@ -94,7 +70,6 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e
|
||||
User: &userRpcClient,
|
||||
Group: &groupRpcClient,
|
||||
MsgDatabase: msgDatabase,
|
||||
ExtendMsgDatabase: extendMsgDatabase,
|
||||
RegisterCenter: client,
|
||||
GroupLocalCache: localcache.NewGroupLocalCache(&groupRpcClient),
|
||||
ConversationLocalCache: localcache.NewConversationLocalCache(&conversationClient),
|
||||
@@ -125,8 +100,7 @@ func (m *msgServer) initPrometheus() {
|
||||
}
|
||||
|
||||
func (m *msgServer) conversationAndGetRecvID(conversation *conversation.Conversation, userID string) (recvID string) {
|
||||
if conversation.ConversationType == constant.SingleChatType ||
|
||||
conversation.ConversationType == constant.NotificationChatType {
|
||||
if conversation.ConversationType == constant.SingleChatType || conversation.ConversationType == constant.NotificationChatType {
|
||||
if userID == conversation.OwnerUserID {
|
||||
recvID = conversation.UserID
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msg"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (m *msgServer) GetActiveUser(ctx context.Context, req *msg.GetActiveUserReq) (*msg.GetActiveUserResp, error) {
|
||||
msgCount, userCount, users, dateCount, err := m.MsgDatabase.RangeUserSendCount(ctx, time.UnixMilli(req.Start), time.UnixMilli(req.End), req.Group, req.Ase, req.Pagination.PageNumber, req.Pagination.ShowNumber)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var pbUsers []*msg.ActiveUser
|
||||
if len(users) > 0 {
|
||||
userIDs := utils.Slice(users, func(e *unrelation.UserCount) string { return e.UserID })
|
||||
userMap, err := m.User.GetUsersInfoMap(ctx, userIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pbUsers = make([]*msg.ActiveUser, 0, len(users))
|
||||
for _, user := range users {
|
||||
pbUser := userMap[user.UserID]
|
||||
if pbUser == nil {
|
||||
pbUser = &sdkws.UserInfo{
|
||||
UserID: user.UserID,
|
||||
Nickname: user.UserID,
|
||||
}
|
||||
}
|
||||
pbUsers = append(pbUsers, &msg.ActiveUser{
|
||||
User: pbUser,
|
||||
Count: user.Count,
|
||||
})
|
||||
}
|
||||
}
|
||||
return &msg.GetActiveUserResp{
|
||||
MsgCount: msgCount,
|
||||
UserCount: userCount,
|
||||
DateCount: dateCount,
|
||||
Users: pbUsers,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m *msgServer) GetActiveGroup(ctx context.Context, req *msg.GetActiveGroupReq) (*msg.GetActiveGroupResp, error) {
|
||||
msgCount, groupCount, groups, dateCount, err := m.MsgDatabase.RangeGroupSendCount(ctx, time.UnixMilli(req.Start), time.UnixMilli(req.End), req.Ase, req.Pagination.PageNumber, req.Pagination.ShowNumber)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var pbGroups []*msg.ActiveGroup
|
||||
if len(groups) > 0 {
|
||||
groupIDs := utils.Slice(groups, func(e *unrelation.GroupCount) string { return e.GroupID })
|
||||
resp, err := m.Group.GetGroupInfos(ctx, groupIDs, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
groupMap := make(map[string]*sdkws.GroupInfo, len(groups))
|
||||
for i, group := range groups {
|
||||
groupMap[group.GroupID] = resp[i]
|
||||
}
|
||||
pbGroups = make([]*msg.ActiveGroup, 0, len(groups))
|
||||
for _, group := range groups {
|
||||
pbGroup := groupMap[group.GroupID]
|
||||
if pbGroup == nil {
|
||||
pbGroup = &sdkws.GroupInfo{
|
||||
GroupID: group.GroupID,
|
||||
GroupName: group.GroupID,
|
||||
}
|
||||
}
|
||||
pbGroups = append(pbGroups, &msg.ActiveGroup{
|
||||
Group: pbGroup,
|
||||
Count: group.Count,
|
||||
})
|
||||
}
|
||||
}
|
||||
return &msg.GetActiveGroupResp{
|
||||
MsgCount: msgCount,
|
||||
GroupCount: groupCount,
|
||||
DateCount: dateCount,
|
||||
Groups: pbGroups,
|
||||
}, nil
|
||||
}
|
||||
+133
-34
@@ -1,52 +1,151 @@
|
||||
// Copyright © 2023 OpenIM. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package third
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/tokenverify"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/s3/cont"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/mcontext"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/third"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (t *thirdServer) ApplyPut(ctx context.Context, req *third.ApplyPutReq) (*third.ApplyPutResp, error) {
|
||||
return t.s3dataBase.ApplyPut(ctx, req)
|
||||
func (t *thirdServer) PartLimit(ctx context.Context, req *third.PartLimitReq) (*third.PartLimitResp, error) {
|
||||
limit := t.s3dataBase.PartLimit()
|
||||
return &third.PartLimitResp{
|
||||
MinPartSize: limit.MinPartSize,
|
||||
MaxPartSize: limit.MaxPartSize,
|
||||
MaxNumSize: int32(limit.MaxNumSize),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (t *thirdServer) GetPut(ctx context.Context, req *third.GetPutReq) (*third.GetPutResp, error) {
|
||||
return t.s3dataBase.GetPut(ctx, req)
|
||||
func (t *thirdServer) PartSize(ctx context.Context, req *third.PartSizeReq) (*third.PartSizeResp, error) {
|
||||
size, err := t.s3dataBase.PartSize(ctx, req.Size)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &third.PartSizeResp{Size: size}, nil
|
||||
}
|
||||
|
||||
func (t *thirdServer) ConfirmPut(ctx context.Context, req *third.ConfirmPutReq) (*third.ConfirmPutResp, error) {
|
||||
return t.s3dataBase.ConfirmPut(ctx, req)
|
||||
}
|
||||
|
||||
func (t *thirdServer) GetUrl(ctx context.Context, req *third.GetUrlReq) (*third.GetUrlResp, error) {
|
||||
if req.Expires <= 0 {
|
||||
if err := tokenverify.CheckAdmin(ctx); err != nil {
|
||||
return nil, err
|
||||
func (t *thirdServer) InitiateMultipartUpload(ctx context.Context, req *third.InitiateMultipartUploadReq) (*third.InitiateMultipartUploadResp, error) {
|
||||
defer log.ZDebug(ctx, "return")
|
||||
if err := checkUploadName(ctx, req.Name); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
expireTime := time.Now().Add(t.defaultExpire)
|
||||
result, err := t.s3dataBase.InitiateMultipartUpload(ctx, req.Hash, req.Size, t.defaultExpire, int(req.MaxParts))
|
||||
if err != nil {
|
||||
if haErr, ok := errs.Unwrap(err).(*cont.HashAlreadyExistsError); ok {
|
||||
obj := &relation.ObjectModel{
|
||||
Name: req.Name,
|
||||
UserID: mcontext.GetOpUserID(ctx),
|
||||
Hash: req.Hash,
|
||||
Key: haErr.Object.Key,
|
||||
Size: haErr.Object.Size,
|
||||
ContentType: req.ContentType,
|
||||
Cause: req.Cause,
|
||||
CreateTime: time.Now(),
|
||||
}
|
||||
if err := t.s3dataBase.SetObject(ctx, obj); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &third.InitiateMultipartUploadResp{
|
||||
Url: t.apiAddress(obj.Name),
|
||||
}, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
var sign *third.AuthSignParts
|
||||
if result.Sign != nil && len(result.Sign.Parts) > 0 {
|
||||
sign = &third.AuthSignParts{
|
||||
Url: result.Sign.URL,
|
||||
Query: toPbMapArray(result.Sign.Query),
|
||||
Header: toPbMapArray(result.Sign.Header),
|
||||
Parts: make([]*third.SignPart, len(result.Sign.Parts)),
|
||||
}
|
||||
for i, part := range result.Sign.Parts {
|
||||
sign.Parts[i] = &third.SignPart{
|
||||
PartNumber: int32(part.PartNumber),
|
||||
Url: part.URL,
|
||||
Query: toPbMapArray(part.Query),
|
||||
Header: toPbMapArray(part.Header),
|
||||
}
|
||||
}
|
||||
}
|
||||
return t.s3dataBase.GetUrl(ctx, req)
|
||||
return &third.InitiateMultipartUploadResp{
|
||||
Upload: &third.UploadInfo{
|
||||
UploadID: result.UploadID,
|
||||
PartSize: result.PartSize,
|
||||
Sign: sign,
|
||||
ExpireTime: expireTime.UnixMilli(),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (t *thirdServer) GetHashInfo(ctx context.Context, req *third.GetHashInfoReq) (*third.GetHashInfoResp, error) {
|
||||
return t.s3dataBase.GetHashInfo(ctx, req)
|
||||
func (t *thirdServer) AuthSign(ctx context.Context, req *third.AuthSignReq) (*third.AuthSignResp, error) {
|
||||
defer log.ZDebug(ctx, "return")
|
||||
partNumbers := utils.Slice(req.PartNumbers, func(partNumber int32) int { return int(partNumber) })
|
||||
result, err := t.s3dataBase.AuthSign(ctx, req.UploadID, partNumbers)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp := &third.AuthSignResp{
|
||||
Url: result.URL,
|
||||
Query: toPbMapArray(result.Query),
|
||||
Header: toPbMapArray(result.Header),
|
||||
Parts: make([]*third.SignPart, len(result.Parts)),
|
||||
}
|
||||
for i, part := range result.Parts {
|
||||
resp.Parts[i] = &third.SignPart{
|
||||
PartNumber: int32(part.PartNumber),
|
||||
Url: part.URL,
|
||||
Query: toPbMapArray(part.Query),
|
||||
Header: toPbMapArray(part.Header),
|
||||
}
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (t *thirdServer) CleanObject(ctx context.Context, now time.Time) {
|
||||
t.s3dataBase.CleanExpirationObject(ctx, now)
|
||||
func (t *thirdServer) CompleteMultipartUpload(ctx context.Context, req *third.CompleteMultipartUploadReq) (*third.CompleteMultipartUploadResp, error) {
|
||||
defer log.ZDebug(ctx, "return")
|
||||
if err := checkUploadName(ctx, req.Name); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result, err := t.s3dataBase.CompleteMultipartUpload(ctx, req.UploadID, req.Parts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
obj := &relation.ObjectModel{
|
||||
Name: req.Name,
|
||||
UserID: mcontext.GetOpUserID(ctx),
|
||||
Hash: result.Hash,
|
||||
Key: result.Key,
|
||||
Size: result.Size,
|
||||
ContentType: req.ContentType,
|
||||
Cause: req.Cause,
|
||||
CreateTime: time.Now(),
|
||||
}
|
||||
if err := t.s3dataBase.SetObject(ctx, obj); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &third.CompleteMultipartUploadResp{
|
||||
Url: t.apiAddress(obj.Name),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (t *thirdServer) AccessURL(ctx context.Context, req *third.AccessURLReq) (*third.AccessURLResp, error) {
|
||||
expireTime, rawURL, err := t.s3dataBase.AccessURL(ctx, req.Name, t.defaultExpire)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &third.AccessURLResp{
|
||||
Url: rawURL,
|
||||
ExpireTime: expireTime.UnixMilli(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (t *thirdServer) apiAddress(name string) string {
|
||||
return t.apiURL + name
|
||||
}
|
||||
|
||||
+39
-39
@@ -1,80 +1,83 @@
|
||||
// Copyright © 2023 OpenIM. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package third
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/s3"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/s3/cos"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/s3/minio"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/s3/oss"
|
||||
"net/url"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"time"
|
||||
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/obj"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/relation"
|
||||
relationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/third"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error {
|
||||
u, err := url.Parse(config.Config.Object.ApiURL)
|
||||
if err != nil {
|
||||
apiURL := config.Config.Object.ApiURL
|
||||
if apiURL == "" {
|
||||
return fmt.Errorf("api url is empty")
|
||||
}
|
||||
if _, err := url.Parse(config.Config.Object.ApiURL); err != nil {
|
||||
return err
|
||||
}
|
||||
if apiURL[len(apiURL)-1] != '/' {
|
||||
apiURL += "/"
|
||||
}
|
||||
rdb, err := cache.NewRedis()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
o, err := obj.NewMinioInterface()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
db, err := relation.NewGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := db.AutoMigrate(&relationTb.ObjectHashModel{}, &relationTb.ObjectInfoModel{}, &relationTb.ObjectPutModel{}); err != nil {
|
||||
if err := db.AutoMigrate(&relationTb.ObjectModel{}); err != nil {
|
||||
return err
|
||||
}
|
||||
// 根据配置文件策略选择 oss 方式
|
||||
enable := config.Config.Object.Enable
|
||||
var o s3.Interface
|
||||
switch config.Config.Object.Enable {
|
||||
case "minio":
|
||||
o, err = minio.NewMinio()
|
||||
case "cos":
|
||||
o, err = cos.NewCos()
|
||||
case "oss":
|
||||
o, err = oss.NewOSS()
|
||||
default:
|
||||
err = fmt.Errorf("invalid object enable: %s", enable)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
third.RegisterThirdServer(server, &thirdServer{
|
||||
apiURL: apiURL,
|
||||
thirdDatabase: controller.NewThirdDatabase(cache.NewMsgCacheModel(rdb)),
|
||||
userRpcClient: rpcclient.NewUserRpcClient(client),
|
||||
s3dataBase: controller.NewS3Database(
|
||||
o,
|
||||
relation.NewObjectHash(db),
|
||||
relation.NewObjectInfo(db),
|
||||
relation.NewObjectPut(db),
|
||||
u,
|
||||
),
|
||||
s3dataBase: controller.NewS3Database(o, relation.NewObjectInfo(db)),
|
||||
defaultExpire: time.Hour * 24 * 7,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
type thirdServer struct {
|
||||
apiURL string
|
||||
thirdDatabase controller.ThirdDatabase
|
||||
s3dataBase controller.S3Database
|
||||
userRpcClient rpcclient.UserRpcClient
|
||||
defaultExpire time.Duration
|
||||
}
|
||||
|
||||
func (t *thirdServer) FcmUpdateToken(
|
||||
ctx context.Context,
|
||||
req *third.FcmUpdateTokenReq,
|
||||
) (resp *third.FcmUpdateTokenResp, err error) {
|
||||
func (t *thirdServer) FcmUpdateToken(ctx context.Context, req *third.FcmUpdateTokenReq) (resp *third.FcmUpdateTokenResp, err error) {
|
||||
err = t.thirdDatabase.FcmUpdateToken(ctx, req.Account, int(req.PlatformID), req.FcmToken, req.ExpireTime)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -82,10 +85,7 @@ func (t *thirdServer) FcmUpdateToken(
|
||||
return &third.FcmUpdateTokenResp{}, nil
|
||||
}
|
||||
|
||||
func (t *thirdServer) SetAppBadge(
|
||||
ctx context.Context,
|
||||
req *third.SetAppBadgeReq,
|
||||
) (resp *third.SetAppBadgeResp, err error) {
|
||||
func (t *thirdServer) SetAppBadge(ctx context.Context, req *third.SetAppBadgeReq) (resp *third.SetAppBadgeResp, err error) {
|
||||
err = t.thirdDatabase.SetAppBadge(ctx, req.UserID, int(req.AppUnreadCount))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package third
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/mcontext"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/tokenverify"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/third"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
func toPbMapArray(m map[string][]string) []*third.KeyValues {
|
||||
res := make([]*third.KeyValues, 0, len(m))
|
||||
for key := range m {
|
||||
res = append(res, &third.KeyValues{
|
||||
Key: key,
|
||||
Values: m[key],
|
||||
})
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func checkUploadName(ctx context.Context, name string) error {
|
||||
if name == "" {
|
||||
return errs.ErrArgs.Wrap("name is empty")
|
||||
}
|
||||
if name[0] == '/' {
|
||||
return errs.ErrArgs.Wrap("name cannot start with `/`")
|
||||
}
|
||||
if err := checkValidObjectName(name); err != nil {
|
||||
return errs.ErrArgs.Wrap(err.Error())
|
||||
}
|
||||
opUserID := mcontext.GetOpUserID(ctx)
|
||||
if opUserID == "" {
|
||||
return errs.ErrNoPermission.Wrap("opUserID is empty")
|
||||
}
|
||||
if !tokenverify.IsManagerUserID(opUserID) {
|
||||
if !strings.HasPrefix(name, opUserID+"/") {
|
||||
return errs.ErrNoPermission.Wrap(fmt.Sprintf("name must start with `%s/`", opUserID))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkValidObjectNamePrefix(objectName string) error {
|
||||
if len(objectName) > 1024 {
|
||||
return errors.New("object name cannot be longer than 1024 characters")
|
||||
}
|
||||
if !utf8.ValidString(objectName) {
|
||||
return errors.New("object name with non UTF-8 strings are not supported")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkValidObjectName(objectName string) error {
|
||||
if strings.TrimSpace(objectName) == "" {
|
||||
return errors.New("object name cannot be empty")
|
||||
}
|
||||
return checkValidObjectNamePrefix(objectName)
|
||||
}
|
||||
@@ -29,13 +29,18 @@ func (s *userServer) UserRegisterCount(
|
||||
if req.Start > req.End {
|
||||
return nil, errs.ErrArgs.Wrap("start > end")
|
||||
}
|
||||
total, err := s.CountTotal(ctx)
|
||||
total, err := s.CountTotal(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
count, err := s.CountRangeEverydayTotal(ctx, time.UnixMilli(req.Start), time.UnixMilli(req.End))
|
||||
start := time.UnixMilli(req.Start)
|
||||
before, err := s.CountTotal(ctx, &start)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pbuser.UserRegisterCountResp{Total: total, Count: count}, nil
|
||||
count, err := s.CountRangeEverydayTotal(ctx, start, time.UnixMilli(req.End))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pbuser.UserRegisterCountResp{Total: total, Before: before, Count: count}, nil
|
||||
}
|
||||
|
||||
+17
-59
@@ -1,26 +1,12 @@
|
||||
// Copyright © 2023 OpenIM. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
|
||||
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/convert"
|
||||
@@ -37,9 +23,8 @@ import (
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient/notification"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type userServer struct {
|
||||
@@ -63,7 +48,7 @@ func Start(client registry.SvcDiscoveryRegistry, server *grpc.Server) error {
|
||||
}
|
||||
users := make([]*tablerelation.UserModel, 0)
|
||||
if len(config.Config.Manager.UserID) != len(config.Config.Manager.Nickname) {
|
||||
return errs.ErrConfig.Wrap("len(config.Config.Manager.AppManagerUid) != len(config.Config.Manager.Nickname)")
|
||||
return errors.New("len(config.Config.Manager.AppManagerUid) != len(config.Config.Manager.Nickname)")
|
||||
}
|
||||
for k, v := range config.Config.Manager.UserID {
|
||||
users = append(users, &tablerelation.UserModel{UserID: v, Nickname: config.Config.Manager.Nickname[k]})
|
||||
@@ -74,22 +59,16 @@ func Start(client registry.SvcDiscoveryRegistry, server *grpc.Server) error {
|
||||
friendRpcClient := rpcclient.NewFriendRpcClient(client)
|
||||
msgRpcClient := rpcclient.NewMessageRpcClient(client)
|
||||
u := &userServer{
|
||||
UserDatabase: database,
|
||||
RegisterCenter: client,
|
||||
friendRpcClient: &friendRpcClient,
|
||||
notificationSender: notification.NewFriendNotificationSender(
|
||||
&msgRpcClient,
|
||||
notification.WithDBFunc(database.FindWithError),
|
||||
),
|
||||
UserDatabase: database,
|
||||
RegisterCenter: client,
|
||||
friendRpcClient: &friendRpcClient,
|
||||
notificationSender: notification.NewFriendNotificationSender(&msgRpcClient, notification.WithDBFunc(database.FindWithError)),
|
||||
}
|
||||
pbuser.RegisterUserServer(server, u)
|
||||
return u.UserDatabase.InitOnce(context.Background(), users)
|
||||
}
|
||||
|
||||
func (s *userServer) GetDesignateUsers(
|
||||
ctx context.Context,
|
||||
req *pbuser.GetDesignateUsersReq,
|
||||
) (resp *pbuser.GetDesignateUsersResp, err error) {
|
||||
func (s *userServer) GetDesignateUsers(ctx context.Context, req *pbuser.GetDesignateUsersReq) (resp *pbuser.GetDesignateUsersResp, err error) {
|
||||
resp = &pbuser.GetDesignateUsersResp{}
|
||||
users, err := s.FindWithError(ctx, req.UserIDs)
|
||||
if err != nil {
|
||||
@@ -102,10 +81,7 @@ func (s *userServer) GetDesignateUsers(
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *userServer) UpdateUserInfo(
|
||||
ctx context.Context,
|
||||
req *pbuser.UpdateUserInfoReq,
|
||||
) (resp *pbuser.UpdateUserInfoResp, err error) {
|
||||
func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbuser.UpdateUserInfoReq) (resp *pbuser.UpdateUserInfoResp, err error) {
|
||||
resp = &pbuser.UpdateUserInfoResp{}
|
||||
err = tokenverify.CheckAccessV3(ctx, req.UserInfo.UserID)
|
||||
if err != nil {
|
||||
@@ -130,10 +106,7 @@ func (s *userServer) UpdateUserInfo(
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *userServer) SetGlobalRecvMessageOpt(
|
||||
ctx context.Context,
|
||||
req *pbuser.SetGlobalRecvMessageOptReq,
|
||||
) (resp *pbuser.SetGlobalRecvMessageOptResp, err error) {
|
||||
func (s *userServer) SetGlobalRecvMessageOpt(ctx context.Context, req *pbuser.SetGlobalRecvMessageOptReq) (resp *pbuser.SetGlobalRecvMessageOptResp, err error) {
|
||||
resp = &pbuser.SetGlobalRecvMessageOptResp{}
|
||||
if _, err := s.FindWithError(ctx, []string{req.UserID}); err != nil {
|
||||
return nil, err
|
||||
@@ -147,10 +120,7 @@ func (s *userServer) SetGlobalRecvMessageOpt(
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *userServer) AccountCheck(
|
||||
ctx context.Context,
|
||||
req *pbuser.AccountCheckReq,
|
||||
) (resp *pbuser.AccountCheckResp, err error) {
|
||||
func (s *userServer) AccountCheck(ctx context.Context, req *pbuser.AccountCheckReq) (resp *pbuser.AccountCheckResp, err error) {
|
||||
resp = &pbuser.AccountCheckResp{}
|
||||
if utils.Duplicate(req.CheckUserIDs) {
|
||||
return nil, errs.ErrArgs.Wrap("userID repeated")
|
||||
@@ -179,10 +149,7 @@ func (s *userServer) AccountCheck(
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *userServer) GetPaginationUsers(
|
||||
ctx context.Context,
|
||||
req *pbuser.GetPaginationUsersReq,
|
||||
) (resp *pbuser.GetPaginationUsersResp, err error) {
|
||||
func (s *userServer) GetPaginationUsers(ctx context.Context, req *pbuser.GetPaginationUsersReq) (resp *pbuser.GetPaginationUsersResp, err error) {
|
||||
var pageNumber, showNumber int32
|
||||
if req.Pagination != nil {
|
||||
pageNumber = req.Pagination.PageNumber
|
||||
@@ -195,17 +162,14 @@ func (s *userServer) GetPaginationUsers(
|
||||
return &pbuser.GetPaginationUsersResp{Total: int32(total), Users: convert.UsersDB2Pb(users)}, err
|
||||
}
|
||||
|
||||
func (s *userServer) UserRegister(
|
||||
ctx context.Context,
|
||||
req *pbuser.UserRegisterReq,
|
||||
) (resp *pbuser.UserRegisterResp, err error) {
|
||||
func (s *userServer) UserRegister(ctx context.Context, req *pbuser.UserRegisterReq) (resp *pbuser.UserRegisterResp, err error) {
|
||||
resp = &pbuser.UserRegisterResp{}
|
||||
if len(req.Users) == 0 {
|
||||
return nil, errs.ErrArgs.Wrap("users is empty")
|
||||
}
|
||||
if req.Secret != config.Config.Secret {
|
||||
log.ZDebug(ctx, "UserRegister", config.Config.Secret, req.Secret)
|
||||
return nil, errs.ErrIdentity.Wrap("secret invalid")
|
||||
return nil, errs.ErrNoPermission.Wrap("secret invalid")
|
||||
}
|
||||
if utils.DuplicateAny(req.Users, func(e *sdkws.UserInfo) string { return e.UserID }) {
|
||||
return nil, errs.ErrArgs.Wrap("userID repeated")
|
||||
@@ -246,10 +210,7 @@ func (s *userServer) UserRegister(
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *userServer) GetGlobalRecvMessageOpt(
|
||||
ctx context.Context,
|
||||
req *pbuser.GetGlobalRecvMessageOptReq,
|
||||
) (resp *pbuser.GetGlobalRecvMessageOptResp, err error) {
|
||||
func (s *userServer) GetGlobalRecvMessageOpt(ctx context.Context, req *pbuser.GetGlobalRecvMessageOptReq) (resp *pbuser.GetGlobalRecvMessageOptResp, err error) {
|
||||
user, err := s.FindWithError(ctx, []string{req.UserID})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -257,10 +218,7 @@ func (s *userServer) GetGlobalRecvMessageOpt(
|
||||
return &pbuser.GetGlobalRecvMessageOptResp{GlobalRecvMsgOpt: user[0].GlobalRecvMsgOpt}, nil
|
||||
}
|
||||
|
||||
func (s *userServer) GetAllUserID(
|
||||
ctx context.Context,
|
||||
req *pbuser.GetAllUserIDReq,
|
||||
) (resp *pbuser.GetAllUserIDResp, err error) {
|
||||
func (s *userServer) GetAllUserID(ctx context.Context, req *pbuser.GetAllUserIDReq) (resp *pbuser.GetAllUserIDResp, err error) {
|
||||
userIDs, err := s.UserDatabase.GetAllUserID(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user