Merge branch 'errcode' of github.com:OpenIMSDK/Open-IM-Server into errcode

test-errcode
wangchuxiao 1 year ago
commit 6a23a0dde9

@ -88,11 +88,12 @@ func (s *Server) SuperGroupOnlineBatchPushOneMsg(ctx context.Context, req *msgga
} }
clients, ok := s.LongConnServer.GetUserAllCons(v) clients, ok := s.LongConnServer.GetUserAllCons(v)
if !ok { if !ok {
log.ZDebug(ctx, "push user not online", "userID", v)
tempT.Resp = resp tempT.Resp = resp
singleUserResult = append(singleUserResult, tempT) singleUserResult = append(singleUserResult, tempT)
continue continue
} }
log.ZDebug(ctx, "SuperGroupOnlineBatchPushOneMsg", "clients", clients) log.ZDebug(ctx, "push user online", "clients", clients, "userID", v)
for _, client := range clients { for _, client := range clients {
if client != nil { if client != nil {
temp := &msggateway.SingleMsgToUserPlatform{ temp := &msggateway.SingleMsgToUserPlatform{

@ -1,6 +1,7 @@
package msggateway package msggateway
import ( import (
context2 "context"
"errors" "errors"
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry" "github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
"net/http" "net/http"
@ -124,11 +125,13 @@ func (ws *WsServer) registerClient(client *Client) {
) )
cli, userOK, clientOK = ws.clients.Get(client.userID, client.platformID) cli, userOK, clientOK = ws.clients.Get(client.userID, client.platformID)
if !userOK { if !userOK {
log.ZDebug(client.ctx, "user not exist", "userID", client.userID, "platformID", client.platformID)
ws.clients.Set(client.userID, client) ws.clients.Set(client.userID, client)
atomic.AddInt64(&ws.onlineUserNum, 1) atomic.AddInt64(&ws.onlineUserNum, 1)
atomic.AddInt64(&ws.onlineUserConnNum, 1) atomic.AddInt64(&ws.onlineUserConnNum, 1)
} else { } else {
log.ZDebug(client.ctx, "user exist", "userID", client.userID, "platformID", client.platformID)
if clientOK { //已经有同平台的连接存在 if clientOK { //已经有同平台的连接存在
ws.clients.Set(client.userID, client) ws.clients.Set(client.userID, client)
ws.multiTerminalLoginChecker(cli) ws.multiTerminalLoginChecker(cli)
@ -147,7 +150,7 @@ func getRemoteAdders(client []*Client) string {
if i == 0 { if i == 0 {
ret = c.ctx.GetRemoteAddr() ret = c.ctx.GetRemoteAddr()
} else { } else {
ret += "@" + c.ctx.GetRemoteAddr() ret += " @ " + c.ctx.GetRemoteAddr()
} }
} }
return ret return ret
@ -158,7 +161,7 @@ func (ws *WsServer) multiTerminalLoginChecker(client []*Client) {
} }
func (ws *WsServer) unregisterClient(client *Client) { func (ws *WsServer) unregisterClient(client *Client) {
defer ws.clientPool.Put(client) defer ws.clientPool.Put(client)
isDeleteUser := ws.clients.delete(client.userID, client.platformID) isDeleteUser := ws.clients.delete(client.userID, client.ctx.GetRemoteAddr())
if isDeleteUser { if isDeleteUser {
atomic.AddInt64(&ws.onlineUserNum, -1) atomic.AddInt64(&ws.onlineUserNum, -1)
} }
@ -195,6 +198,7 @@ func (ws *WsServer) wsHandler(w http.ResponseWriter, r *http.Request) {
httpError(context, errs.ErrConnArgsErr) httpError(context, errs.ErrConnArgsErr)
return return
} }
log.ZDebug(context2.Background(), "conn", "platformID", platformID)
err := tokenverify.WsVerifyToken(token, userID, platformID) err := tokenverify.WsVerifyToken(token, userID, platformID)
if err != nil { if err != nil {
httpError(context, err) httpError(context, err)

@ -1,6 +1,10 @@
package msggateway package msggateway
import "sync" import (
"context"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
"sync"
)
type UserMap struct { type UserMap struct {
m sync.Map m sync.Map
@ -36,22 +40,24 @@ func (u *UserMap) Get(key string, platformID int) ([]*Client, bool, bool) {
func (u *UserMap) Set(key string, v *Client) { func (u *UserMap) Set(key string, v *Client) {
allClients, existed := u.m.Load(key) allClients, existed := u.m.Load(key)
if existed { if existed {
log.ZDebug(context.Background(), "Set existed", "user_id", key, "client", v)
oldClients := allClients.([]*Client) oldClients := allClients.([]*Client)
oldClients = append(oldClients, v) oldClients = append(oldClients, v)
u.m.Store(key, oldClients) u.m.Store(key, oldClients)
} else { } else {
log.ZDebug(context.Background(), "Set not existed", "user_id", key, "client", v)
var clients []*Client var clients []*Client
clients = append(clients, v) clients = append(clients, v)
u.m.Store(key, clients) u.m.Store(key, clients)
} }
} }
func (u *UserMap) delete(key string, platformID int) (isDeleteUser bool) { func (u *UserMap) delete(key string, connRemoteAddr string) (isDeleteUser bool) {
allClients, existed := u.m.Load(key) allClients, existed := u.m.Load(key)
if existed { if existed {
oldClients := allClients.([]*Client) oldClients := allClients.([]*Client)
var a []*Client var a []*Client
for _, client := range oldClients { for _, client := range oldClients {
if client.platformID != platformID { if client.ctx.GetRemoteAddr() != connRemoteAddr {
a = append(a, client) a = append(a, client)
} }
} }

@ -257,6 +257,21 @@ func (s *groupServer) FindGroupMember(ctx context.Context, groupIDs []string, us
return members, nil return members, nil
} }
func (s *groupServer) TakeGroupOwner(ctx context.Context, groupID string) (*relationTb.GroupMemberModel, error) {
owner, err := s.GroupDatabase.TakeGroupOwner(ctx, groupID)
if err != nil {
return nil, err
}
if owner.Nickname == "" {
user, err := s.User.GetUserInfo(ctx, owner.UserID)
if err != nil {
return nil, err
}
owner.Nickname = user.Nickname
}
return owner, 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{} resp := &pbGroup.GetJoinedGroupListResp{}
if err := tokenverify.CheckAccessV3(ctx, req.FromUserID); err != nil { if err := tokenverify.CheckAccessV3(ctx, req.FromUserID); err != nil {
@ -711,10 +726,10 @@ func (s *groupServer) GroupApplicationResponse(ctx context.Context, req *pbGroup
if groupRequest.HandleResult != 0 { if groupRequest.HandleResult != 0 {
return nil, errs.ErrArgs.Wrap("group request already processed") return nil, errs.ErrArgs.Wrap("group request already processed")
} }
var join bool var inGroup bool
_, err = s.GroupDatabase.TakeGroupMember(ctx, req.GroupID, req.FromUserID) _, err = s.GroupDatabase.TakeGroupMember(ctx, req.GroupID, req.FromUserID)
if err == nil { if err == nil {
join = true // 已经在群里了 inGroup = true // 已经在群里了
} else if !s.IsNotFound(err) { } else if !s.IsNotFound(err) {
return nil, err return nil, err
} }
@ -723,7 +738,7 @@ func (s *groupServer) GroupApplicationResponse(ctx context.Context, req *pbGroup
return nil, err return nil, err
} }
var member *relationTb.GroupMemberModel var member *relationTb.GroupMemberModel
if (!join) && req.HandleResult == constant.GroupResponseAgree { if (!inGroup) && req.HandleResult == constant.GroupResponseAgree {
member = &relationTb.GroupMemberModel{ member = &relationTb.GroupMemberModel{
GroupID: req.GroupID, GroupID: req.GroupID,
UserID: user.UserID, UserID: user.UserID,
@ -744,13 +759,31 @@ func (s *groupServer) GroupApplicationResponse(ctx context.Context, req *pbGroup
if err := s.GroupDatabase.HandlerGroupRequest(ctx, req.GroupID, req.FromUserID, req.HandledMsg, req.HandleResult, member); err != nil { if err := s.GroupDatabase.HandlerGroupRequest(ctx, req.GroupID, req.FromUserID, req.HandledMsg, req.HandleResult, member); err != nil {
return nil, err return nil, err
} }
if !join { switch req.HandleResult {
if req.HandleResult == constant.GroupResponseAgree { case constant.GroupResponseAgree:
s.Notification.GroupApplicationAcceptedNotification(ctx, req) s.Notification.GroupApplicationAcceptedNotification(ctx, req)
if !inGroup {
groupMember := &relationTb.GroupMemberModel{}
groupMember.GroupID = group.GroupID
groupMember.RoleLevel = constant.GroupOrdinaryUsers
groupMember.OperatorUserID = mcontext.GetOpUserID(ctx)
groupMember.JoinSource = groupRequest.JoinSource
groupMember.InviterUserID = groupRequest.InviterUserID
groupMember.JoinTime = time.Now()
groupMember.MuteEndTime = time.Unix(0, 0)
if err := CallbackBeforeMemberJoinGroup(ctx, groupMember, group.Ex); err != nil && err != errs.ErrCallbackContinue {
return nil, err
}
if err := s.GroupDatabase.CreateGroup(ctx, nil, []*relationTb.GroupMemberModel{groupMember}); err != nil {
return nil, err
}
if err := s.conversationRpcClient.GroupChatFirstCreateConversation(ctx, req.GroupID, []string{req.FromUserID}); err != nil {
return nil, err
}
s.Notification.MemberEnterNotification(ctx, req) s.Notification.MemberEnterNotification(ctx, req)
} else if req.HandleResult == constant.GroupResponseRefuse {
s.Notification.GroupApplicationRejectedNotification(ctx, req)
} }
case constant.GroupResponseRefuse:
s.Notification.GroupApplicationRejectedNotification(ctx, req)
} }
return &pbGroup.GroupApplicationResponseResp{}, nil return &pbGroup.GroupApplicationResponseResp{}, nil
} }
@ -886,7 +919,7 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
if err != nil { if err != nil {
return nil, err return nil, err
} }
owner, err := s.GroupDatabase.TakeGroupOwner(ctx, group.GroupID) owner, err := s.TakeGroupOwner(ctx, group.GroupID)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -1086,7 +1119,7 @@ func (s *groupServer) GetUserReqApplicationList(ctx context.Context, req *pbGrou
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") defer log.ZInfo(ctx, "DismissGroup.return")
resp := &pbGroup.DismissGroupResp{} resp := &pbGroup.DismissGroupResp{}
owner, err := s.GroupDatabase.TakeGroupOwner(ctx, req.GroupID) owner, err := s.TakeGroupOwner(ctx, req.GroupID)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -1099,9 +1132,8 @@ func (s *groupServer) DismissGroup(ctx context.Context, req *pbGroup.DismissGrou
if err != nil { if err != nil {
return nil, err return nil, err
} }
userIDs, err := s.GroupDatabase.FindGroupMemberUserID(ctx, req.GroupID) if req.DeleteMember == false && group.Status == constant.GroupStatusDismissed {
if err != nil { return nil, errs.ErrDismissedAlready.Wrap("group status is dismissed")
return nil, err
} }
//if group.Status == constant.GroupStatusDismissed { //if group.Status == constant.GroupStatusDismissed {
// return nil, errs.ErrArgs.Wrap("group status is dismissed") // return nil, errs.ErrArgs.Wrap("group status is dismissed")
@ -1115,6 +1147,10 @@ func (s *groupServer) DismissGroup(ctx context.Context, req *pbGroup.DismissGrou
} }
} else { } else {
if !req.DeleteMember { if !req.DeleteMember {
userIDs, err := s.GroupDatabase.FindGroupMemberUserID(ctx, req.GroupID)
if err != nil {
return nil, err
}
//s.Notification.GroupDismissedNotification(ctx, req) //s.Notification.GroupDismissedNotification(ctx, req)
tips := &sdkws.GroupDismissedTips{ tips := &sdkws.GroupDismissedTips{
Group: s.groupDB2PB(group, owner.UserID, uint32(len(userIDs))), Group: s.groupDB2PB(group, owner.UserID, uint32(len(userIDs))),

Loading…
Cancel
Save