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)
if !ok {
log.ZDebug(ctx, "push user not online", "userID", v)
tempT.Resp = resp
singleUserResult = append(singleUserResult, tempT)
continue
}
log.ZDebug(ctx, "SuperGroupOnlineBatchPushOneMsg", "clients", clients)
log.ZDebug(ctx, "push user online", "clients", clients, "userID", v)
for _, client := range clients {
if client != nil {
temp := &msggateway.SingleMsgToUserPlatform{

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

@ -1,6 +1,10 @@
package msggateway
import "sync"
import (
"context"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
"sync"
)
type UserMap struct {
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) {
allClients, existed := u.m.Load(key)
if existed {
log.ZDebug(context.Background(), "Set existed", "user_id", key, "client", v)
oldClients := allClients.([]*Client)
oldClients = append(oldClients, v)
u.m.Store(key, oldClients)
} else {
log.ZDebug(context.Background(), "Set not existed", "user_id", key, "client", v)
var clients []*Client
clients = append(clients, v)
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)
if existed {
oldClients := allClients.([]*Client)
var a []*Client
for _, client := range oldClients {
if client.platformID != platformID {
if client.ctx.GetRemoteAddr() != connRemoteAddr {
a = append(a, client)
}
}

@ -257,6 +257,21 @@ func (s *groupServer) FindGroupMember(ctx context.Context, groupIDs []string, us
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) {
resp := &pbGroup.GetJoinedGroupListResp{}
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 {
return nil, errs.ErrArgs.Wrap("group request already processed")
}
var join bool
var inGroup bool
_, err = s.GroupDatabase.TakeGroupMember(ctx, req.GroupID, req.FromUserID)
if err == nil {
join = true // 已经在群里了
inGroup = true // 已经在群里了
} else if !s.IsNotFound(err) {
return nil, err
}
@ -723,7 +738,7 @@ func (s *groupServer) GroupApplicationResponse(ctx context.Context, req *pbGroup
return nil, err
}
var member *relationTb.GroupMemberModel
if (!join) && req.HandleResult == constant.GroupResponseAgree {
if (!inGroup) && req.HandleResult == constant.GroupResponseAgree {
member = &relationTb.GroupMemberModel{
GroupID: req.GroupID,
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 {
return nil, err
}
if !join {
if req.HandleResult == constant.GroupResponseAgree {
s.Notification.GroupApplicationAcceptedNotification(ctx, req)
switch req.HandleResult {
case constant.GroupResponseAgree:
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)
} else if req.HandleResult == constant.GroupResponseRefuse {
s.Notification.GroupApplicationRejectedNotification(ctx, req)
}
case constant.GroupResponseRefuse:
s.Notification.GroupApplicationRejectedNotification(ctx, req)
}
return &pbGroup.GroupApplicationResponseResp{}, nil
}
@ -886,7 +919,7 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
if err != nil {
return nil, err
}
owner, err := s.GroupDatabase.TakeGroupOwner(ctx, group.GroupID)
owner, err := s.TakeGroupOwner(ctx, group.GroupID)
if err != nil {
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) {
defer log.ZInfo(ctx, "DismissGroup.return")
resp := &pbGroup.DismissGroupResp{}
owner, err := s.GroupDatabase.TakeGroupOwner(ctx, req.GroupID)
owner, err := s.TakeGroupOwner(ctx, req.GroupID)
if err != nil {
return nil, err
}
@ -1099,9 +1132,8 @@ func (s *groupServer) DismissGroup(ctx context.Context, req *pbGroup.DismissGrou
if err != nil {
return nil, err
}
userIDs, err := s.GroupDatabase.FindGroupMemberUserID(ctx, req.GroupID)
if err != nil {
return nil, err
if req.DeleteMember == false && group.Status == constant.GroupStatusDismissed {
return nil, errs.ErrDismissedAlready.Wrap("group status is dismissed")
}
//if group.Status == constant.GroupStatusDismissed {
// return nil, errs.ErrArgs.Wrap("group status is dismissed")
@ -1115,6 +1147,10 @@ func (s *groupServer) DismissGroup(ctx context.Context, req *pbGroup.DismissGrou
}
} else {
if !req.DeleteMember {
userIDs, err := s.GroupDatabase.FindGroupMemberUserID(ctx, req.GroupID)
if err != nil {
return nil, err
}
//s.Notification.GroupDismissedNotification(ctx, req)
tips := &sdkws.GroupDismissedTips{
Group: s.groupDB2PB(group, owner.UserID, uint32(len(userIDs))),

Loading…
Cancel
Save