mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-04 09:05:59 +08:00
group hash cache
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/convert"
|
||||
pbGroup "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/group"
|
||||
)
|
||||
|
||||
func (s *groupServer) GetGroupInfoCache(ctx context.Context, req *pbGroup.GetGroupInfoCacheReq) (resp *pbGroup.GetGroupInfoCacheResp, err error) {
|
||||
group, err := s.GroupDatabase.TakeGroup(ctx, req.GroupID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp = &pbGroup.GetGroupInfoCacheResp{GroupInfo: convert.Db2PbGroupInfo(group, "", 0)}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) GetGroupMemberCache(ctx context.Context, req *pbGroup.GetGroupMemberCacheReq) (resp *pbGroup.GetGroupMemberCacheResp, err error) {
|
||||
members, err := s.GroupDatabase.TakeGroupMember(ctx, req.GroupID, req.GroupMemberID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp = &pbGroup.GetGroupMemberCacheResp{Member: convert.Db2PbGroupMember(members)}
|
||||
return resp, nil
|
||||
}
|
||||
@@ -445,7 +445,7 @@ func (s *groupServer) GetGroupAllMember(ctx context.Context, req *pbGroup.GetGro
|
||||
if e.Nickname == "" {
|
||||
e.Nickname = nameMap[e.UserID]
|
||||
}
|
||||
return convert.Db2PbGroupMembersCMSResp(e)
|
||||
return convert.Db2PbGroupMember(e)
|
||||
})
|
||||
return resp, nil
|
||||
}
|
||||
@@ -471,7 +471,7 @@ func (s *groupServer) GetGroupMemberList(ctx context.Context, req *pbGroup.GetGr
|
||||
if e.Nickname == "" {
|
||||
e.Nickname = nameMap[e.UserID]
|
||||
}
|
||||
return convert.Db2PbGroupMembersCMSResp(e)
|
||||
return convert.Db2PbGroupMember(e)
|
||||
})
|
||||
log.ZDebug(ctx, "GetGroupMemberList", "resp", resp, "length", len(resp.Members))
|
||||
return resp, nil
|
||||
@@ -572,7 +572,7 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
|
||||
tips.Group.OwnerUserID = owner[0].UserID
|
||||
}
|
||||
if opMember, ok := memberMap[opUserID]; ok {
|
||||
tips.OpUser = convert.Db2PbGroupMembersCMSResp(opMember)
|
||||
tips.OpUser = convert.Db2PbGroupMember(opMember)
|
||||
} else {
|
||||
tips.OpUser = &sdkws.GroupMemberFullInfo{
|
||||
GroupID: group.GroupID,
|
||||
@@ -580,7 +580,7 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
|
||||
}
|
||||
}
|
||||
for _, userID := range req.KickedUserIDs {
|
||||
tips.KickedUserList = append(tips.KickedUserList, convert.Db2PbGroupMembersCMSResp(memberMap[userID]))
|
||||
tips.KickedUserList = append(tips.KickedUserList, convert.Db2PbGroupMember(memberMap[userID]))
|
||||
}
|
||||
s.Notification.MemberKickedNotification(ctx, tips)
|
||||
}
|
||||
@@ -612,7 +612,7 @@ func (s *groupServer) GetGroupMembersInfo(ctx context.Context, req *pbGroup.GetG
|
||||
if e.Nickname == "" {
|
||||
e.Nickname = nameMap[e.UserID]
|
||||
}
|
||||
return convert.Db2PbGroupMembersCMSResp(e)
|
||||
return convert.Db2PbGroupMember(e)
|
||||
})
|
||||
return resp, nil
|
||||
}
|
||||
@@ -1059,7 +1059,7 @@ func (s *groupServer) GetGroupMembersCMS(ctx context.Context, req *pbGroup.GetGr
|
||||
if e.Nickname == "" {
|
||||
e.Nickname = nameMap[e.UserID]
|
||||
}
|
||||
return convert.Db2PbGroupMembersCMSResp(e)
|
||||
return convert.Db2PbGroupMember(e)
|
||||
})
|
||||
return resp, nil
|
||||
}
|
||||
@@ -1449,7 +1449,7 @@ func (s *groupServer) GetUserInGroupMembers(ctx context.Context, req *pbGroup.Ge
|
||||
if e.Nickname == "" {
|
||||
e.Nickname = nameMap[e.UserID]
|
||||
}
|
||||
return convert.Db2PbGroupMembersCMSResp(e)
|
||||
return convert.Db2PbGroupMember(e)
|
||||
})
|
||||
return resp, nil
|
||||
}
|
||||
@@ -1482,7 +1482,7 @@ func (s *groupServer) GetGroupMemberRoleLevel(ctx context.Context, req *pbGroup.
|
||||
if e.Nickname == "" {
|
||||
e.Nickname = nameMap[e.UserID]
|
||||
}
|
||||
return convert.Db2PbGroupMembersCMSResp(e)
|
||||
return convert.Db2PbGroupMember(e)
|
||||
})
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ func (m *msgServer) SendMsg(ctx context.Context, req *pbMsg.SendMsgReq) (resp *p
|
||||
func (m *msgServer) sendMsgSuperGroupChat(ctx context.Context, req *pbMsg.SendMsgReq) (resp *pbMsg.SendMsgResp, err error) {
|
||||
resp = &pbMsg.SendMsgResp{}
|
||||
promePkg.Inc(promePkg.WorkSuperGroupChatMsgRecvSuccessCounter)
|
||||
if _, err = m.messageVerification(ctx, req); err != nil {
|
||||
if err = m.messageVerification(ctx, req); err != nil {
|
||||
promePkg.Inc(promePkg.WorkSuperGroupChatMsgProcessFailedCounter)
|
||||
return nil, err
|
||||
}
|
||||
@@ -70,8 +70,7 @@ func (m *msgServer) sendMsgNotification(ctx context.Context, req *pbMsg.SendMsgR
|
||||
|
||||
func (m *msgServer) sendMsgSingleChat(ctx context.Context, req *pbMsg.SendMsgReq) (resp *pbMsg.SendMsgResp, err error) {
|
||||
promePkg.Inc(promePkg.SingleChatMsgRecvSuccessCounter)
|
||||
_, err = m.messageVerification(ctx, req)
|
||||
if err != nil {
|
||||
if err := m.messageVerification(ctx, req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var isSend bool = true
|
||||
|
||||
+34
-71
@@ -35,112 +35,75 @@ type MessageRevoked struct {
|
||||
Seq uint32 `json:"seq"`
|
||||
}
|
||||
|
||||
func (m *msgServer) userIsMuteAndIsAdminInGroup(ctx context.Context, groupID, userID string) (isMute bool, err error) {
|
||||
groupMemberInfo, err := m.Group.GetGroupMemberInfo(ctx, groupID, userID)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if groupMemberInfo.MuteEndTime >= time.Now().Unix() {
|
||||
return true, nil
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// 如果禁言了,再看下是否群管理员
|
||||
func (m *msgServer) groupIsMuted(ctx context.Context, groupID string, userID string) (bool, bool, error) {
|
||||
groupInfo, err := m.Group.GetGroupInfo(ctx, groupID)
|
||||
if err != nil {
|
||||
return false, false, err
|
||||
}
|
||||
|
||||
if groupInfo.Status == constant.GroupStatusMuted {
|
||||
groupMemberInfo, err := m.Group.GetGroupMemberInfo(ctx, groupID, userID)
|
||||
if err != nil {
|
||||
return false, false, err
|
||||
}
|
||||
return true, groupMemberInfo.RoleLevel > constant.GroupOrdinaryUsers, nil
|
||||
}
|
||||
return false, false, nil
|
||||
}
|
||||
|
||||
func (m *msgServer) GetGroupMemberIDs(ctx context.Context, groupID string) (groupMemberIDs []string, err error) {
|
||||
return m.GroupLocalCache.GetGroupMemberIDs(ctx, groupID)
|
||||
}
|
||||
|
||||
func (m *msgServer) messageVerification(ctx context.Context, data *msg.SendMsgReq) ([]string, error) {
|
||||
func (m *msgServer) messageVerification(ctx context.Context, data *msg.SendMsgReq) error {
|
||||
switch data.MsgData.SessionType {
|
||||
case constant.SingleChatType:
|
||||
if utils.IsContain(data.MsgData.SendID, config.Config.Manager.AppManagerUid) {
|
||||
return nil, nil
|
||||
return nil
|
||||
}
|
||||
if data.MsgData.ContentType <= constant.NotificationEnd && data.MsgData.ContentType >= constant.NotificationBegin {
|
||||
return nil, nil
|
||||
return nil
|
||||
}
|
||||
black, err := m.black.IsBlocked(ctx, data.MsgData.SendID, data.MsgData.RecvID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
if black {
|
||||
return nil, errs.ErrBlockedByPeer.Wrap()
|
||||
return errs.ErrBlockedByPeer.Wrap()
|
||||
}
|
||||
if *config.Config.MessageVerify.FriendVerify {
|
||||
friend, err := m.friend.IsFriend(ctx, data.MsgData.SendID, data.MsgData.RecvID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
if !friend {
|
||||
return nil, errs.ErrNotPeersFriend.Wrap()
|
||||
return errs.ErrNotPeersFriend.Wrap()
|
||||
}
|
||||
return nil, nil
|
||||
return nil
|
||||
}
|
||||
return nil, nil
|
||||
return nil
|
||||
case constant.SuperGroupChatType:
|
||||
groupInfo, err := m.Group.GetGroupInfo(ctx, data.MsgData.GroupID)
|
||||
groupInfo, err := m.Group.GetGroupInfoCache(ctx, data.MsgData.GroupID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
if groupInfo.Status == constant.GroupStatusDismissed && data.MsgData.ContentType != constant.GroupDismissedNotification {
|
||||
return nil, errs.ErrDismissedAlready.Wrap()
|
||||
return errs.ErrDismissedAlready.Wrap()
|
||||
}
|
||||
if groupInfo.GroupType == constant.SuperGroup {
|
||||
return nil, nil
|
||||
}
|
||||
userIDList, err := m.GetGroupMemberIDs(ctx, data.MsgData.GroupID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil
|
||||
}
|
||||
if utils.IsContain(data.MsgData.SendID, config.Config.Manager.AppManagerUid) {
|
||||
return nil, nil
|
||||
return nil
|
||||
}
|
||||
if data.MsgData.ContentType <= constant.NotificationEnd && data.MsgData.ContentType >= constant.NotificationBegin {
|
||||
return userIDList, nil
|
||||
return nil
|
||||
} else {
|
||||
if !utils.IsContain(data.MsgData.SendID, userIDList) {
|
||||
return nil, errs.ErrNotInGroupYet.Wrap()
|
||||
memberIDs, err := m.GroupLocalCache.GetGroupMemberIDs(ctx, data.MsgData.GroupID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !utils.IsContain(data.MsgData.SendID, memberIDs) {
|
||||
return errs.ErrNotInGroupYet.Wrap()
|
||||
}
|
||||
}
|
||||
isMute, err := m.userIsMuteAndIsAdminInGroup(ctx, data.MsgData.GroupID, data.MsgData.SendID)
|
||||
groupMemberInfo, err := m.Group.GetGroupMemberCache(ctx, data.MsgData.GroupID, data.MsgData.SendID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
if isMute {
|
||||
return nil, errs.ErrMutedInGroup.Wrap()
|
||||
if groupMemberInfo.RoleLevel > constant.GroupOrdinaryUsers {
|
||||
return nil
|
||||
} else {
|
||||
if groupMemberInfo.MuteEndTime >= time.Now().Unix() {
|
||||
return errs.ErrMutedInGroup.Wrap()
|
||||
}
|
||||
if groupInfo.Status == constant.GroupStatusMuted {
|
||||
return errs.ErrMutedGroup.Wrap()
|
||||
}
|
||||
}
|
||||
|
||||
isMute, isAdmin, err := m.groupIsMuted(ctx, data.MsgData.GroupID, data.MsgData.SendID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if isAdmin {
|
||||
return userIDList, nil
|
||||
}
|
||||
if isMute {
|
||||
return nil, errs.ErrMutedGroup.Wrap()
|
||||
}
|
||||
return userIDList, nil
|
||||
|
||||
return nil
|
||||
default:
|
||||
return nil, nil
|
||||
return nil
|
||||
}
|
||||
}
|
||||
func (m *msgServer) encapsulateMsgData(msg *sdkws.MsgData) {
|
||||
|
||||
Reference in New Issue
Block a user