mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-12 21:16:00 +08:00
feat: ver3 branch
Signed-off-by: kubbot & kubecub <3293172751ysy@gmail.com>
This commit is contained in:
@@ -26,12 +26,6 @@ func (o *ConversationApi) GetConversations(c *gin.Context) {
|
||||
a2r.Call(conversation.ConversationClient.GetConversations, o.Client, c)
|
||||
}
|
||||
|
||||
// deprecated
|
||||
func (o *ConversationApi) SetConversation(c *gin.Context) {
|
||||
a2r.Call(conversation.ConversationClient.SetConversation, o.Client, c)
|
||||
}
|
||||
|
||||
// deprecated
|
||||
func (o *ConversationApi) BatchSetConversations(c *gin.Context) {
|
||||
a2r.Call(conversation.ConversationClient.BatchSetConversations, o.Client, c)
|
||||
}
|
||||
|
||||
+51
-76
@@ -19,15 +19,13 @@ import (
|
||||
func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.UniversalClient) *gin.Engine {
|
||||
discov.AddOption(mw.GrpcClient(), grpc.WithTransportCredentials(insecure.NewCredentials())) // 默认RPC中间件
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
//f, _ := os.Create("../logs/api.log")
|
||||
//gin.DefaultWriter = io.MultiWriter(f)
|
||||
//gin.SetMode(gin.DebugMode)
|
||||
r := gin.New()
|
||||
if v, ok := binding.Validator.Engine().(*validator.Validate); ok {
|
||||
_ = v.RegisterValidation("required_if", RequiredIf)
|
||||
}
|
||||
log.ZInfo(context.Background(), "load config", "config", config.Config)
|
||||
r.Use(gin.Recovery(), mw.CorsHandler(), mw.GinParseOperationID())
|
||||
u := NewUserApi(discov)
|
||||
if config.Config.Prometheus.Enable {
|
||||
prome.NewApiRequestCounter()
|
||||
prome.NewApiRequestFailedCounter()
|
||||
@@ -35,90 +33,77 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive
|
||||
r.Use(prome.PrometheusMiddleware)
|
||||
r.GET("/metrics", prome.PrometheusHandler())
|
||||
}
|
||||
userRouterGroup := r.Group("/user")
|
||||
ParseToken := mw.GinParseToken(rdb)
|
||||
userRouterGroup := r.Group("/user", ParseToken)
|
||||
{
|
||||
u := NewUserApi(discov)
|
||||
userRouterGroupChild := mw.NewRouterGroup(userRouterGroup, "")
|
||||
userRouterGroupChildToken := mw.NewRouterGroup(userRouterGroup, "", mw.WithGinParseToken(rdb))
|
||||
userRouterGroupChild.POST("/user_register", u.UserRegister)
|
||||
userRouterGroupChildToken.POST("/update_user_info", u.UpdateUserInfo) //1
|
||||
userRouterGroupChildToken.POST("/set_global_msg_recv_opt", u.SetGlobalRecvMessageOpt)
|
||||
userRouterGroupChildToken.POST("/get_users_info", u.GetUsersPublicInfo) //1
|
||||
userRouterGroupChildToken.POST("/get_all_users_uid", u.GetAllUsersID) // todo
|
||||
userRouterGroupChildToken.POST("/account_check", u.AccountCheck) // todo
|
||||
userRouterGroupChildToken.POST("/get_users", u.GetUsers)
|
||||
userRouterGroupChildToken.POST("/get_users_online_status", u.GetUsersOnlineStatus)
|
||||
userRouterGroup.POST("/update_user_info", u.UpdateUserInfo)
|
||||
userRouterGroup.POST("/set_global_msg_recv_opt", u.SetGlobalRecvMessageOpt)
|
||||
userRouterGroup.POST("/get_users_info", u.GetUsersPublicInfo)
|
||||
userRouterGroup.POST("/get_all_users_uid", u.GetAllUsersID)
|
||||
userRouterGroup.POST("/account_check", u.AccountCheck)
|
||||
userRouterGroup.POST("/get_users", u.GetUsers)
|
||||
userRouterGroup.POST("/get_users_online_status", u.GetUsersOnlineStatus)
|
||||
}
|
||||
//friend routing group
|
||||
friendRouterGroup := r.Group("/friend")
|
||||
friendRouterGroup := r.Group("/friend", ParseToken)
|
||||
{
|
||||
f := NewFriendApi(discov)
|
||||
friendRouterGroup.Use(mw.GinParseToken(rdb))
|
||||
friendRouterGroup.POST("/delete_friend", f.DeleteFriend) //1
|
||||
friendRouterGroup.POST("/get_friend_apply_list", f.GetFriendApplyList) //1
|
||||
friendRouterGroup.POST("/get_self_friend_apply_list", f.GetSelfApplyList) //1
|
||||
friendRouterGroup.POST("/get_friend_list", f.GetFriendList) //1
|
||||
friendRouterGroup.POST("/add_friend", f.ApplyToAddFriend) //1
|
||||
friendRouterGroup.POST("/add_friend_response", f.RespondFriendApply) //1
|
||||
friendRouterGroup.POST("/set_friend_remark", f.SetFriendRemark) //1
|
||||
friendRouterGroup.POST("/add_black", f.AddBlack) //1
|
||||
friendRouterGroup.POST("/get_black_list", f.GetPaginationBlacks) //1
|
||||
friendRouterGroup.POST("/remove_black", f.RemoveBlack) //1
|
||||
friendRouterGroup.POST("/import_friend", f.ImportFriends) //1
|
||||
friendRouterGroup.POST("/is_friend", f.IsFriend) //1
|
||||
friendRouterGroup.POST("/delete_friend", f.DeleteFriend)
|
||||
friendRouterGroup.POST("/get_friend_apply_list", f.GetFriendApplyList)
|
||||
friendRouterGroup.POST("/get_self_friend_apply_list", f.GetSelfApplyList)
|
||||
friendRouterGroup.POST("/get_friend_list", f.GetFriendList)
|
||||
friendRouterGroup.POST("/add_friend", f.ApplyToAddFriend)
|
||||
friendRouterGroup.POST("/add_friend_response", f.RespondFriendApply)
|
||||
friendRouterGroup.POST("/set_friend_remark", f.SetFriendRemark)
|
||||
friendRouterGroup.POST("/add_black", f.AddBlack)
|
||||
friendRouterGroup.POST("/get_black_list", f.GetPaginationBlacks)
|
||||
friendRouterGroup.POST("/remove_black", f.RemoveBlack)
|
||||
friendRouterGroup.POST("/import_friend", f.ImportFriends)
|
||||
friendRouterGroup.POST("/is_friend", f.IsFriend)
|
||||
}
|
||||
g := NewGroupApi(discov)
|
||||
groupRouterGroup := r.Group("/group")
|
||||
groupRouterGroup := r.Group("/group", ParseToken)
|
||||
{
|
||||
|
||||
groupRouterGroup.Use(mw.GinParseToken(rdb))
|
||||
groupRouterGroup.POST("/create_group", g.CreateGroup) //1
|
||||
groupRouterGroup.POST("/set_group_info", g.SetGroupInfo) //1
|
||||
groupRouterGroup.POST("/join_group", g.JoinGroup) //1
|
||||
groupRouterGroup.POST("/quit_group", g.QuitGroup) //1
|
||||
groupRouterGroup.POST("/group_application_response", g.ApplicationGroupResponse) //1
|
||||
groupRouterGroup.POST("/transfer_group", g.TransferGroupOwner) //1
|
||||
groupRouterGroup.POST("/get_recv_group_applicationList", g.GetRecvGroupApplicationList) //1
|
||||
groupRouterGroup.POST("/create_group", g.CreateGroup)
|
||||
groupRouterGroup.POST("/set_group_info", g.SetGroupInfo)
|
||||
groupRouterGroup.POST("/join_group", g.JoinGroup)
|
||||
groupRouterGroup.POST("/quit_group", g.QuitGroup)
|
||||
groupRouterGroup.POST("/group_application_response", g.ApplicationGroupResponse)
|
||||
groupRouterGroup.POST("/transfer_group", g.TransferGroupOwner)
|
||||
groupRouterGroup.POST("/get_recv_group_applicationList", g.GetRecvGroupApplicationList)
|
||||
groupRouterGroup.POST("/get_user_req_group_applicationList", g.GetUserReqGroupApplicationList)
|
||||
groupRouterGroup.POST("/get_groups_info", g.GetGroupsInfo) //1
|
||||
groupRouterGroup.POST("/kick_group", g.KickGroupMember) //1
|
||||
// groupRouterGroup.POST("/get_group_all_member_list", g.GetGroupAllMemberList) //1
|
||||
groupRouterGroup.POST("/get_group_members_info", g.GetGroupMembersInfo) //1
|
||||
groupRouterGroup.POST("/get_group_member_list", g.GetGroupMemberList) //1
|
||||
groupRouterGroup.POST("/invite_user_to_group", g.InviteUserToGroup) //1
|
||||
groupRouterGroup.POST("/get_groups_info", g.GetGroupsInfo)
|
||||
groupRouterGroup.POST("/kick_group", g.KickGroupMember)
|
||||
groupRouterGroup.POST("/get_group_members_info", g.GetGroupMembersInfo)
|
||||
groupRouterGroup.POST("/get_group_member_list", g.GetGroupMemberList)
|
||||
groupRouterGroup.POST("/invite_user_to_group", g.InviteUserToGroup)
|
||||
groupRouterGroup.POST("/get_joined_group_list", g.GetJoinedGroupList)
|
||||
groupRouterGroup.POST("/dismiss_group", g.DismissGroup) //
|
||||
groupRouterGroup.POST("/mute_group_member", g.MuteGroupMember)
|
||||
groupRouterGroup.POST("/cancel_mute_group_member", g.CancelMuteGroupMember) //MuteGroup
|
||||
groupRouterGroup.POST("/cancel_mute_group_member", g.CancelMuteGroupMember)
|
||||
groupRouterGroup.POST("/mute_group", g.MuteGroup)
|
||||
groupRouterGroup.POST("/cancel_mute_group", g.CancelMuteGroup)
|
||||
//groupRouterGroup.POST("/set_group_member_nickname", g.SetGroupMemberNickname)
|
||||
groupRouterGroup.POST("/set_group_member_info", g.SetGroupMemberInfo)
|
||||
groupRouterGroup.POST("/get_group_abstract_info", g.GetGroupAbstractInfo)
|
||||
}
|
||||
superGroupRouterGroup := r.Group("/super_group")
|
||||
superGroupRouterGroup := r.Group("/super_group", ParseToken)
|
||||
{
|
||||
superGroupRouterGroup.Use(mw.GinParseToken(rdb))
|
||||
superGroupRouterGroup.POST("/get_joined_group_list", g.GetJoinedSuperGroupList)
|
||||
superGroupRouterGroup.POST("/get_groups_info", g.GetSuperGroupsInfo)
|
||||
}
|
||||
////certificate
|
||||
//certificate
|
||||
authRouterGroup := r.Group("/auth")
|
||||
{
|
||||
a := NewAuthApi(discov)
|
||||
u := NewUserApi(discov)
|
||||
authRouterGroupChild := mw.NewRouterGroup(authRouterGroup, "")
|
||||
authRouterGroupChildToken := mw.NewRouterGroup(authRouterGroup, "", mw.WithGinParseToken(rdb))
|
||||
authRouterGroupChild.POST("/user_register", u.UserRegister) //1
|
||||
authRouterGroupChild.POST("/user_token", a.UserToken) //1
|
||||
authRouterGroupChildToken.POST("/parse_token", a.ParseToken) //1
|
||||
authRouterGroupChildToken.POST("/force_logout", a.ForceLogout) //1
|
||||
authRouterGroup.POST("/user_register", u.UserRegister)
|
||||
authRouterGroup.POST("/user_token", a.UserToken)
|
||||
authRouterGroup.POST("/parse_token", a.ParseToken)
|
||||
authRouterGroup.POST("/force_logout", ParseToken, a.ForceLogout)
|
||||
}
|
||||
////Third service
|
||||
thirdGroup := r.Group("/third")
|
||||
//Third service
|
||||
thirdGroup := r.Group("/third", ParseToken)
|
||||
{
|
||||
t := NewThirdApi(discov)
|
||||
thirdGroup.Use(mw.GinParseToken(rdb))
|
||||
thirdGroup.POST("/fcm_update_token", t.FcmUpdateToken)
|
||||
thirdGroup.POST("/set_app_badge", t.SetAppBadge)
|
||||
|
||||
@@ -129,11 +114,10 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive
|
||||
thirdGroup.POST("/object", t.GetURL)
|
||||
thirdGroup.GET("/object", t.GetURL)
|
||||
}
|
||||
////Message
|
||||
msgGroup := r.Group("/msg")
|
||||
//Message
|
||||
msgGroup := r.Group("/msg", ParseToken)
|
||||
{
|
||||
m := NewMessageApi(discov)
|
||||
msgGroup.Use(mw.GinParseToken(rdb))
|
||||
msgGroup.POST("/newest_seq", m.GetSeq)
|
||||
msgGroup.POST("/send_msg", m.SendMessage)
|
||||
msgGroup.POST("/pull_msg_by_seq", m.PullMsgBySeqs)
|
||||
@@ -151,32 +135,23 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive
|
||||
|
||||
msgGroup.POST("/batch_send_msg", m.ManagementBatchSendMsg)
|
||||
msgGroup.POST("/check_msg_is_send_success", m.CheckMsgIsSendSuccess)
|
||||
|
||||
//msgGroup.POST("/set_message_reaction_extensions", msg.SetMessageReactionExtensions)
|
||||
//msgGroup.POST("/get_message_list_reaction_extensions", msg.GetMessageListReactionExtensions)
|
||||
//msgGroup.POST("/add_message_reaction_extensions", msg.AddMessageReactionExtensions)
|
||||
//msgGroup.POST("/delete_message_reaction_extensions", msg.DeleteMessageReactionExtensions)
|
||||
}
|
||||
////Conversation
|
||||
conversationGroup := r.Group("/conversation")
|
||||
//Conversation
|
||||
conversationGroup := r.Group("/conversation", ParseToken)
|
||||
{
|
||||
c := NewConversationApi(discov)
|
||||
conversationGroup.Use(mw.GinParseToken(rdb))
|
||||
conversationGroup.POST("/get_all_conversations", c.GetAllConversations)
|
||||
conversationGroup.POST("/get_conversation", c.GetConversation)
|
||||
conversationGroup.POST("/get_conversations", c.GetConversations)
|
||||
conversationGroup.POST("/set_conversation", c.SetConversation)
|
||||
conversationGroup.POST("/batch_set_conversation", c.BatchSetConversations)
|
||||
conversationGroup.POST("/set_recv_msg_opt", c.SetRecvMsgOpt)
|
||||
conversationGroup.POST("/modify_conversation_field", c.ModifyConversationField)
|
||||
conversationGroup.POST("/set_conversations", c.SetConversations)
|
||||
}
|
||||
|
||||
statisticsGroup := r.Group("/statistics")
|
||||
statisticsGroup := r.Group("/statistics", ParseToken)
|
||||
{
|
||||
s := NewStatisticsApi(discov)
|
||||
conversationGroup.Use(mw.GinParseToken(rdb))
|
||||
statisticsGroup.POST("/user_register", s.UserRegister)
|
||||
statisticsGroup.POST("/user_register", u.UserRegisterCount)
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
@@ -57,3 +57,7 @@ func (u *UserApi) GetUsersOnlineStatus(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (u *UserApi) UserRegisterCount(c *gin.Context) {
|
||||
a2r.Call(user.UserClient.UserRegisterCount, u.Client, c)
|
||||
}
|
||||
|
||||
@@ -212,7 +212,7 @@ func (c *Client) PushMessage(ctx context.Context, msgData *sdkws.MsgData) error
|
||||
} else {
|
||||
msg.Msgs = m
|
||||
}
|
||||
log.ZDebug(ctx, "PushMessage", "msg", msg)
|
||||
log.ZDebug(ctx, "PushMessage", "msg", &msg)
|
||||
data, err := proto.Marshal(&msg)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -53,6 +53,9 @@ func StartTransfer(prometheusPort int) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if client.CreateRpcRootNodes(config.GetServiceNames()); err != nil {
|
||||
return err
|
||||
}
|
||||
client.AddOption(mw.GrpcClient(), grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
msgModel := cache.NewMsgCacheModel(rdb)
|
||||
msgDocModel := unrelation.NewMsgMongoDriver(mongo.GetDatabase())
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
|
||||
pbPush "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/push"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
@@ -26,7 +27,10 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e
|
||||
cacheModel := cache.NewMsgCacheModel(rdb)
|
||||
offlinePusher := NewOfflinePusher(cacheModel)
|
||||
database := controller.NewPushDatabase(cacheModel)
|
||||
pusher := NewPusher(client, offlinePusher, database, localcache.NewGroupLocalCache(client), localcache.NewConversationLocalCache(client))
|
||||
groupRpcClient := rpcclient.NewGroupRpcClient(client)
|
||||
conversationRpcClient := rpcclient.NewConversationRpcClient(client)
|
||||
msgRpcClient := rpcclient.NewMessageRpcClient(client)
|
||||
pusher := NewPusher(client, offlinePusher, database, localcache.NewGroupLocalCache(&groupRpcClient), localcache.NewConversationLocalCache(&conversationRpcClient), &conversationRpcClient, &groupRpcClient, &msgRpcClient)
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(2)
|
||||
go func() {
|
||||
|
||||
@@ -30,7 +30,7 @@ type Pusher struct {
|
||||
offlinePusher offlinepush.OfflinePusher
|
||||
groupLocalCache *localcache.GroupLocalCache
|
||||
conversationLocalCache *localcache.ConversationLocalCache
|
||||
msgClient *rpcclient.MessageRpcClient
|
||||
msgRpcClient *rpcclient.MessageRpcClient
|
||||
conversationRpcClient *rpcclient.ConversationRpcClient
|
||||
groupRpcClient *rpcclient.GroupRpcClient
|
||||
successCount int
|
||||
@@ -39,19 +39,17 @@ type Pusher struct {
|
||||
var errNoOfflinePusher = errors.New("no offlinePusher is configured")
|
||||
|
||||
func NewPusher(discov discoveryregistry.SvcDiscoveryRegistry, offlinePusher offlinepush.OfflinePusher, database controller.PushDatabase,
|
||||
groupLocalCache *localcache.GroupLocalCache, conversationLocalCache *localcache.ConversationLocalCache) *Pusher {
|
||||
msgClient := rpcclient.NewMessageRpcClient(discov)
|
||||
conversationRpcClient := rpcclient.NewConversationRpcClient(discov)
|
||||
groupRpcClient := rpcclient.NewGroupRpcClient(discov)
|
||||
groupLocalCache *localcache.GroupLocalCache, conversationLocalCache *localcache.ConversationLocalCache,
|
||||
conversationRpcClient *rpcclient.ConversationRpcClient, groupRpcClient *rpcclient.GroupRpcClient, msgRpcClient *rpcclient.MessageRpcClient) *Pusher {
|
||||
return &Pusher{
|
||||
discov: discov,
|
||||
database: database,
|
||||
offlinePusher: offlinePusher,
|
||||
groupLocalCache: groupLocalCache,
|
||||
conversationLocalCache: conversationLocalCache,
|
||||
msgClient: &msgClient,
|
||||
conversationRpcClient: &conversationRpcClient,
|
||||
groupRpcClient: &groupRpcClient,
|
||||
msgRpcClient: msgRpcClient,
|
||||
conversationRpcClient: conversationRpcClient,
|
||||
groupRpcClient: groupRpcClient,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +68,7 @@ func NewOfflinePusher(cache cache.MsgModel) offlinepush.OfflinePusher {
|
||||
|
||||
func (p *Pusher) DeleteMemberAndSetConversationSeq(ctx context.Context, groupID string, userIDs []string) error {
|
||||
conevrsationID := utils.GetConversationIDBySessionType(constant.SuperGroupChatType, groupID)
|
||||
maxSeq, err := p.msgClient.GetConversationMaxSeq(ctx, conevrsationID)
|
||||
maxSeq, err := p.msgRpcClient.GetConversationMaxSeq(ctx, conevrsationID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -33,13 +33,16 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e
|
||||
pbAuth.RegisterAuthServer(server, &authServer{
|
||||
userRpcClient: &userRpcClient,
|
||||
RegisterCenter: client,
|
||||
authDatabase: controller.NewAuthDatabase(cache.NewMsgCacheModel(rdb), config.Config.TokenPolicy.AccessSecret, config.Config.TokenPolicy.AccessExpire),
|
||||
authDatabase: controller.NewAuthDatabase(cache.NewMsgCacheModel(rdb), config.Config.Secret, config.Config.TokenPolicy.Expire),
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
if _, err := s.userRpcClient.GetUserInfo(ctx, req.UserID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -48,7 +51,7 @@ func (s *authServer) UserToken(ctx context.Context, req *pbAuth.UserTokenReq) (*
|
||||
return nil, err
|
||||
}
|
||||
resp.Token = token
|
||||
resp.ExpireTimeSeconds = config.Config.TokenPolicy.AccessExpire * 24 * 60 * 60
|
||||
resp.ExpireTimeSeconds = config.Config.TokenPolicy.Expire * 24 * 60 * 60
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@ type conversationServer struct {
|
||||
groupRpcClient *rpcclient.GroupRpcClient
|
||||
conversationDatabase controller.ConversationDatabase
|
||||
conversationNotificationSender *notification.ConversationNotificationSender
|
||||
msgRpcClient *rpcclient.MessageRpcClient
|
||||
}
|
||||
|
||||
func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error {
|
||||
@@ -43,9 +42,8 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e
|
||||
groupRpcClient := rpcclient.NewGroupRpcClient(client)
|
||||
msgRpcClient := rpcclient.NewMessageRpcClient(client)
|
||||
pbConversation.RegisterConversationServer(server, &conversationServer{
|
||||
conversationNotificationSender: notification.NewConversationNotificationSender(client),
|
||||
conversationNotificationSender: notification.NewConversationNotificationSender(&msgRpcClient),
|
||||
groupRpcClient: &groupRpcClient,
|
||||
msgRpcClient: &msgRpcClient,
|
||||
conversationDatabase: controller.NewConversationDatabase(conversationDB, cache.NewConversationRedis(rdb, cache.GetDefaultOpt(), conversationDB), tx.NewGorm(db)),
|
||||
})
|
||||
return nil
|
||||
@@ -120,7 +118,6 @@ func (c *conversationServer) SetRecvMsgOpt(ctx context.Context, req *pbConversat
|
||||
func (c *conversationServer) ModifyConversationField(ctx context.Context, req *pbConversation.ModifyConversationFieldReq) (*pbConversation.ModifyConversationFieldResp, error) {
|
||||
resp := &pbConversation.ModifyConversationFieldResp{}
|
||||
var err error
|
||||
isSyncConversation := true
|
||||
if req.Conversation.ConversationType == constant.GroupChatType {
|
||||
groupInfo, err := c.groupRpcClient.GetGroupInfo(ctx, req.Conversation.GroupID)
|
||||
if err != nil {
|
||||
@@ -151,10 +148,6 @@ func (c *conversationServer) ModifyConversationField(ctx context.Context, req *p
|
||||
filedMap["ex"] = req.Conversation.Ex
|
||||
case constant.FieldAttachedInfo:
|
||||
filedMap["attached_info"] = req.Conversation.AttachedInfo
|
||||
case constant.FieldUnread:
|
||||
isSyncConversation = false
|
||||
filedMap["update_unread_count_time"] = req.Conversation.UpdateUnreadCountTime
|
||||
filedMap["has_read_seq"] = req.Conversation.HasReadSeq
|
||||
case constant.FieldBurnDuration:
|
||||
filedMap["burn_duration"] = req.Conversation.BurnDuration
|
||||
}
|
||||
@@ -162,15 +155,8 @@ func (c *conversationServer) ModifyConversationField(ctx context.Context, req *p
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if isSyncConversation {
|
||||
for _, v := range req.UserIDList {
|
||||
c.conversationNotificationSender.ConversationChangeNotification(ctx, v)
|
||||
}
|
||||
} else {
|
||||
for _, v := range req.UserIDList {
|
||||
c.conversationNotificationSender.ConversationUnreadChangeNotification(ctx, v, req.Conversation.ConversationID, req.Conversation.UpdateUnreadCountTime, req.Conversation.HasReadSeq)
|
||||
}
|
||||
for _, v := range req.UserIDList {
|
||||
c.conversationNotificationSender.ConversationChangeNotification(ctx, v)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
@@ -179,7 +165,6 @@ func (c *conversationServer) SetConversations(ctx context.Context, req *pbConver
|
||||
if req.Conversation == nil {
|
||||
return nil, errs.ErrArgs.Wrap("conversation must not be nil")
|
||||
}
|
||||
isSyncConversation := true
|
||||
if req.Conversation.ConversationType == constant.GroupChatType {
|
||||
groupInfo, err := c.groupRpcClient.GetGroupInfo(ctx, req.Conversation.GroupID)
|
||||
if err != nil {
|
||||
@@ -198,9 +183,6 @@ func (c *conversationServer) SetConversations(ctx context.Context, req *pbConver
|
||||
if req.Conversation.RecvMsgOpt != nil {
|
||||
m["recv_msg_opt"] = req.Conversation.RecvMsgOpt.Value
|
||||
}
|
||||
if req.Conversation.DraftTextTime != nil {
|
||||
m["draft_text_time"] = req.Conversation.DraftTextTime.Value
|
||||
}
|
||||
if req.Conversation.AttachedInfo != nil {
|
||||
m["attached_info"] = req.Conversation.AttachedInfo.Value
|
||||
}
|
||||
@@ -231,24 +213,12 @@ func (c *conversationServer) SetConversations(ctx context.Context, req *pbConver
|
||||
if req.Conversation.BurnDuration != nil {
|
||||
m["burn_duration"] = req.Conversation.BurnDuration.Value
|
||||
}
|
||||
if req.Conversation.HasReadSeq != nil && req.Conversation.UpdateUnreadCountTime != nil {
|
||||
isSyncConversation = false
|
||||
m["has_read_seq"] = req.Conversation.HasReadSeq.Value
|
||||
m["update_unread_count_time"] = req.Conversation.UpdateUnreadCountTime.Value
|
||||
}
|
||||
err := c.conversationDatabase.SetUsersConversationFiledTx(ctx, req.UserIDs, &conversation, m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if isSyncConversation {
|
||||
for _, v := range req.UserIDs {
|
||||
c.conversationNotificationSender.ConversationChangeNotification(ctx, v)
|
||||
}
|
||||
} else {
|
||||
for _, v := range req.UserIDs {
|
||||
c.conversationNotificationSender.ConversationUnreadChangeNotification(ctx, v, req.Conversation.ConversationID, req.Conversation.UpdateUnreadCountTime.Value, req.Conversation.HasReadSeq.Value)
|
||||
}
|
||||
for _, v := range req.UserIDs {
|
||||
c.conversationNotificationSender.ConversationChangeNotification(ctx, v)
|
||||
}
|
||||
return &pbConversation.SetConversationsResp{}, nil
|
||||
}
|
||||
|
||||
@@ -45,7 +45,8 @@ func Start(client registry.SvcDiscoveryRegistry, server *grpc.Server) error {
|
||||
blackDB := relation.NewBlackGorm(db)
|
||||
friendDB := relation.NewFriendGorm(db)
|
||||
userRpcClient := rpcclient.NewUserRpcClient(client)
|
||||
notificationSender := notification.NewFriendNotificationSender(client, notification.WithRpcFunc(userRpcClient.GetUsersInfo))
|
||||
msgRpcClient := rpcclient.NewMessageRpcClient(client)
|
||||
notificationSender := notification.NewFriendNotificationSender(&msgRpcClient, notification.WithRpcFunc(userRpcClient.GetUsersInfo))
|
||||
pbfriend.RegisterFriendServer(server, &friendServer{
|
||||
friendDatabase: controller.NewFriendDatabase(friendDB, relation.NewFriendRequestGorm(db), cache.NewFriendCacheRedis(rdb, friendDB, cache.GetDefaultOpt()), tx.NewGorm(db)),
|
||||
blackDatabase: controller.NewBlackDatabase(blackDB, cache.NewBlackCacheRedis(rdb, blackDB, cache.GetDefaultOpt())),
|
||||
|
||||
@@ -48,20 +48,22 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
user := rpcclient.NewUserRpcClient(client)
|
||||
userRpcClient := rpcclient.NewUserRpcClient(client)
|
||||
msgRpcClient := rpcclient.NewMessageRpcClient(client)
|
||||
conversationRpcClient := rpcclient.NewConversationRpcClient(client)
|
||||
database := controller.InitGroupDatabase(db, rdb, mongo.GetDatabase())
|
||||
pbGroup.RegisterGroupServer(server, &groupServer{
|
||||
GroupDatabase: database,
|
||||
User: user,
|
||||
Notification: notification.NewGroupNotificationSender(database, client, func(ctx context.Context, userIDs []string) ([]notification.CommonUser, error) {
|
||||
users, err := user.GetUsersInfo(ctx, userIDs)
|
||||
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
|
||||
}),
|
||||
conversationRpcClient: rpcclient.NewConversationRpcClient(client),
|
||||
msgRpcClient: rpcclient.NewMessageRpcClient(client),
|
||||
conversationRpcClient: conversationRpcClient,
|
||||
msgRpcClient: msgRpcClient,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
@@ -865,19 +867,7 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
|
||||
if req.GroupInfoForSet.Notification != "" {
|
||||
num++
|
||||
s.Notification.GroupInfoSetAnnouncementNotification(ctx, &sdkws.GroupInfoSetAnnouncementTips{Group: tips.Group, OpUser: tips.OpUser})
|
||||
//args := &pbConversation.ModifyConversationFieldReq{
|
||||
// Conversation: &pbConversation.Conversation{
|
||||
// OwnerUserID: mcontext.GetOpUserID(ctx),
|
||||
// ConversationID: utils.GetConversationIDBySessionType(constant.GroupChatType, group.GroupID),
|
||||
// ConversationType: constant.SuperGroupChatType,
|
||||
// GroupID: group.GroupID,
|
||||
// },
|
||||
// FieldType: constant.FieldGroupAtType,
|
||||
// UserIDList: userIDs,
|
||||
//}
|
||||
//if err := s.conversationRpcClient.ModifyConversationField(ctx, args); err != nil {
|
||||
// log.ZWarn(ctx, "modifyConversationField failed", err, "args", args)
|
||||
//}
|
||||
|
||||
}
|
||||
switch len(data) - num {
|
||||
case 0:
|
||||
|
||||
@@ -77,8 +77,8 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e
|
||||
MsgDatabase: msgDatabase,
|
||||
ExtendMsgDatabase: extendMsgDatabase,
|
||||
RegisterCenter: client,
|
||||
GroupLocalCache: localcache.NewGroupLocalCache(client),
|
||||
ConversationLocalCache: localcache.NewConversationLocalCache(client),
|
||||
GroupLocalCache: localcache.NewGroupLocalCache(&groupRpcClient),
|
||||
ConversationLocalCache: localcache.NewConversationLocalCache(&conversationClient),
|
||||
friend: &friendRpcClient,
|
||||
MessageLocker: NewLockerMessage(cacheModel),
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -55,17 +56,17 @@ func Start(client registry.SvcDiscoveryRegistry, server *grpc.Server) error {
|
||||
cache := cache.NewUserCacheRedis(rdb, userDB, cache.GetDefaultOpt())
|
||||
database := controller.NewUserDatabase(userDB, cache, tx.NewGorm(db))
|
||||
friendRpcClient := rpcclient.NewFriendRpcClient(client)
|
||||
msgRpcClient := rpcclient.NewMessageRpcClient(client)
|
||||
u := &userServer{
|
||||
UserDatabase: database,
|
||||
RegisterCenter: client,
|
||||
friendRpcClient: &friendRpcClient,
|
||||
notificationSender: notification.NewFriendNotificationSender(client, notification.WithDBFunc(database.FindWithError)),
|
||||
notificationSender: notification.NewFriendNotificationSender(&msgRpcClient, notification.WithDBFunc(database.FindWithError)),
|
||||
}
|
||||
pbuser.RegisterUserServer(server, u)
|
||||
return u.UserDatabase.InitOnce(context.Background(), users)
|
||||
}
|
||||
|
||||
// ok
|
||||
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)
|
||||
@@ -79,7 +80,6 @@ func (s *userServer) GetDesignateUsers(ctx context.Context, req *pbuser.GetDesig
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// ok
|
||||
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)
|
||||
@@ -105,7 +105,6 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbuser.UpdateUserI
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// ok
|
||||
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 {
|
||||
@@ -120,7 +119,6 @@ func (s *userServer) SetGlobalRecvMessageOpt(ctx context.Context, req *pbuser.Se
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// ok
|
||||
func (s *userServer) AccountCheck(ctx context.Context, req *pbuser.AccountCheckReq) (resp *pbuser.AccountCheckResp, err error) {
|
||||
resp = &pbuser.AccountCheckResp{}
|
||||
if utils.Duplicate(req.CheckUserIDs) {
|
||||
@@ -150,7 +148,6 @@ func (s *userServer) AccountCheck(ctx context.Context, req *pbuser.AccountCheckR
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// ok
|
||||
func (s *userServer) GetPaginationUsers(ctx context.Context, req *pbuser.GetPaginationUsersReq) (resp *pbuser.GetPaginationUsersResp, err error) {
|
||||
var pageNumber, showNumber int32
|
||||
if req.Pagination != nil {
|
||||
@@ -164,12 +161,15 @@ func (s *userServer) GetPaginationUsers(ctx context.Context, req *pbuser.GetPagi
|
||||
return &pbuser.GetPaginationUsersResp{Total: int32(total), Users: convert.UsersDB2Pb(users)}, err
|
||||
}
|
||||
|
||||
// ok
|
||||
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")
|
||||
}
|
||||
if utils.DuplicateAny(req.Users, func(e *sdkws.UserInfo) string { return e.UserID }) {
|
||||
return nil, errs.ErrArgs.Wrap("userID repeated")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user