mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
groupServer
This commit is contained in:
parent
405a9b75b0
commit
711c4878a8
45
internal/rpc/group/convert.go
Normal file
45
internal/rpc/group/convert.go
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
package group
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
|
||||||
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (g *groupServer) groupDB2PB(group *relation.GroupModel, ownerUserID string, memberCount uint32) *sdkws.GroupInfo {
|
||||||
|
return &sdkws.GroupInfo{
|
||||||
|
GroupID: group.GroupID,
|
||||||
|
GroupName: group.GroupName,
|
||||||
|
Notification: group.Notification,
|
||||||
|
Introduction: group.Introduction,
|
||||||
|
FaceURL: group.FaceURL,
|
||||||
|
OwnerUserID: ownerUserID,
|
||||||
|
CreateTime: group.CreateTime.UnixMilli(),
|
||||||
|
MemberCount: memberCount,
|
||||||
|
Ex: group.Ex,
|
||||||
|
Status: group.Status,
|
||||||
|
CreatorUserID: group.CreatorUserID,
|
||||||
|
GroupType: group.GroupType,
|
||||||
|
NeedVerification: group.NeedVerification,
|
||||||
|
LookMemberInfo: group.LookMemberInfo,
|
||||||
|
ApplyMemberFriend: group.ApplyMemberFriend,
|
||||||
|
NotificationUpdateTime: group.NotificationUpdateTime.UnixMilli(),
|
||||||
|
NotificationUserID: group.NotificationUserID,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *groupServer) groupMemberDB2PB(member *relation.GroupMemberModel, appMangerLevel int32) *sdkws.GroupMemberFullInfo {
|
||||||
|
return &sdkws.GroupMemberFullInfo{
|
||||||
|
GroupID: member.GroupID,
|
||||||
|
UserID: member.UserID,
|
||||||
|
RoleLevel: member.RoleLevel,
|
||||||
|
JoinTime: member.JoinTime.UnixMilli(),
|
||||||
|
Nickname: member.Nickname,
|
||||||
|
FaceURL: member.FaceURL,
|
||||||
|
AppMangerLevel: appMangerLevel,
|
||||||
|
JoinSource: member.JoinSource,
|
||||||
|
OperatorUserID: member.OperatorUserID,
|
||||||
|
Ex: member.Ex,
|
||||||
|
MuteEndTime: member.MuteEndTime.UnixMilli(),
|
||||||
|
InviterUserID: member.InviterUserID,
|
||||||
|
}
|
||||||
|
}
|
@ -142,7 +142,8 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
|
|||||||
return nil, errs.ErrArgs.Wrap("no group owner")
|
return nil, errs.ErrArgs.Wrap("no group owner")
|
||||||
}
|
}
|
||||||
userIDs := append(append(req.InitMembers, req.AdminUserIDs...), req.OwnerUserID)
|
userIDs := append(append(req.InitMembers, req.AdminUserIDs...), req.OwnerUserID)
|
||||||
if opUserID := mcontext.GetOpUserID(ctx); !utils.Contain(opUserID, userIDs...) {
|
opUserID := mcontext.GetOpUserID(ctx)
|
||||||
|
if !utils.Contain(opUserID, userIDs...) {
|
||||||
userIDs = append(userIDs, opUserID)
|
userIDs = append(userIDs, opUserID)
|
||||||
}
|
}
|
||||||
if utils.Duplicate(userIDs) {
|
if utils.Duplicate(userIDs) {
|
||||||
@ -208,8 +209,27 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
} else {
|
} else {
|
||||||
s.Notification.GroupCreatedNotification(ctx, group, groupMembers, userMap)
|
//s.Notification.GroupCreatedNotification(ctx, group, groupMembers, userMap)
|
||||||
|
tips := &sdkws.GroupCreatedTips{
|
||||||
|
Group: resp.GroupInfo,
|
||||||
|
OperationTime: group.CreateTime.UnixMilli(),
|
||||||
|
GroupOwnerUser: s.groupMemberDB2PB(groupMembers[0], userMap[groupMembers[0].UserID].AppMangerLevel),
|
||||||
|
}
|
||||||
|
for _, member := range groupMembers {
|
||||||
|
tips.MemberList = append(tips.MemberList, s.groupMemberDB2PB(member, userMap[member.UserID].AppMangerLevel))
|
||||||
|
}
|
||||||
|
for _, member := range groupMembers {
|
||||||
|
if member.UserID == opUserID {
|
||||||
|
tips.OpUser = s.groupMemberDB2PB(member, userMap[member.UserID].AppMangerLevel)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if tips.OpUser == nil {
|
||||||
|
tips.OpUser = &sdkws.GroupMemberFullInfo{UserID: opUserID, AppMangerLevel: userMap[opUserID].AppMangerLevel}
|
||||||
|
}
|
||||||
|
s.Notification.GroupCreatedNotification(ctx, tips)
|
||||||
}
|
}
|
||||||
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -808,12 +828,14 @@ func (s *groupServer) deleteMemberAndSetConversationSeq(ctx context.Context, gro
|
|||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
if !tokenverify.IsAppManagerUid(ctx) {
|
||||||
groupMember, err := s.GroupDatabase.TakeGroupMember(ctx, req.GroupInfoForSet.GroupID, mcontext.GetOpUserID(ctx))
|
var err error
|
||||||
|
opMember, err = s.GroupDatabase.TakeGroupMember(ctx, req.GroupInfoForSet.GroupID, mcontext.GetOpUserID(ctx))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if !(groupMember.RoleLevel == constant.GroupOwner || groupMember.RoleLevel == constant.GroupAdmin) {
|
if !(opMember.RoleLevel == constant.GroupOwner || opMember.RoleLevel == constant.GroupAdmin) {
|
||||||
return nil, errs.ErrNoPermission.Wrap("no group owner or admin")
|
return nil, errs.ErrNoPermission.Wrap("no group owner or admin")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -825,6 +847,14 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
|
|||||||
return nil, utils.Wrap(errs.ErrDismissedAlready, "")
|
return nil, utils.Wrap(errs.ErrDismissedAlready, "")
|
||||||
}
|
}
|
||||||
resp := &pbGroup.SetGroupInfoResp{}
|
resp := &pbGroup.SetGroupInfoResp{}
|
||||||
|
userIDs, err := s.GroupDatabase.FindGroupMemberUserID(ctx, group.GroupID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
owner, err := s.GroupDatabase.TakeGroupOwner(ctx, group.GroupID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
data := UpdateGroupInfoMap(req.GroupInfoForSet)
|
data := UpdateGroupInfoMap(req.GroupInfoForSet)
|
||||||
if len(data) == 0 {
|
if len(data) == 0 {
|
||||||
return resp, nil
|
return resp, nil
|
||||||
@ -836,12 +866,17 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
members, err := s.GroupDatabase.FindGroupMember(ctx, []string{group.GroupID}, nil, nil)
|
tips := &sdkws.GroupInfoSetTips{
|
||||||
if err != nil {
|
Group: s.groupDB2PB(group, owner.UserID, uint32(len(userIDs))),
|
||||||
return nil, err
|
MuteTime: 0,
|
||||||
|
OpUser: &sdkws.GroupMemberFullInfo{},
|
||||||
}
|
}
|
||||||
userIDs := utils.Slice(members, func(e *relationTb.GroupMemberModel) string { return e.GroupID })
|
if opMember == nil {
|
||||||
s.Notification.GroupInfoSetNotification(ctx, group, members, req.GroupInfoForSet.NeedVerification.GetValuePtr())
|
tips.OpUser = &sdkws.GroupMemberFullInfo{UserID: mcontext.GetOpUserID(ctx)}
|
||||||
|
} else {
|
||||||
|
tips.OpUser = s.groupMemberDB2PB(opMember, 0)
|
||||||
|
}
|
||||||
|
s.Notification.GroupInfoSetNotification(ctx, tips)
|
||||||
if req.GroupInfoForSet.Notification != "" {
|
if req.GroupInfoForSet.Notification != "" {
|
||||||
args := &pbConversation.ModifyConversationFieldReq{
|
args := &pbConversation.ModifyConversationFieldReq{
|
||||||
Conversation: &pbConversation.Conversation{
|
Conversation: &pbConversation.Conversation{
|
||||||
|
@ -228,15 +228,21 @@ func (g *GroupNotificationSender) mergeGroupFull(ctx context.Context, groupID st
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ms == nil {
|
||||||
|
var temp []*relation.GroupMemberModel
|
||||||
|
ms = &temp
|
||||||
|
}
|
||||||
|
if users == nil {
|
||||||
|
temp := make(map[string]*sdkws.UserInfo)
|
||||||
|
users = &temp
|
||||||
|
}
|
||||||
var members []*relation.GroupMemberModel
|
var members []*relation.GroupMemberModel
|
||||||
if ms == nil || len(*ms) == 0 {
|
if len(*ms) == 0 {
|
||||||
members, err = g.db.FindGroupMember(ctx, []string{groupID}, nil, nil)
|
members, err = g.db.FindGroupMember(ctx, []string{groupID}, nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if ms != nil {
|
*ms = members
|
||||||
*ms = members
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
members = *ms
|
members = *ms
|
||||||
}
|
}
|
||||||
@ -284,30 +290,46 @@ func (g *GroupNotificationSender) mergeGroupFull(ctx context.Context, groupID st
|
|||||||
return groupInfo, nil
|
return groupInfo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GroupNotificationSender) GroupCreatedNotification(ctx context.Context, group *relation.GroupModel, members []*relation.GroupMemberModel, userMap map[string]*sdkws.UserInfo) (err error) {
|
//func (g *GroupNotificationSender) GroupCreatedNotification(ctx context.Context, group *relation.GroupModel, members []*relation.GroupMemberModel, userMap map[string]*sdkws.UserInfo) (err error) {
|
||||||
defer log.ZDebug(ctx, "GroupCreatedNotification.return")
|
// defer log.ZDebug(ctx, "GroupCreatedNotification.return")
|
||||||
defer func() {
|
// defer func() {
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
log.ZError(ctx, utils.GetFuncName(1)+" failed", err)
|
// log.ZError(ctx, utils.GetFuncName(1)+" failed", err)
|
||||||
}
|
// }
|
||||||
}()
|
// }()
|
||||||
groupInfo, err := g.mergeGroupFull(ctx, group.GroupID, group, &members, &userMap)
|
// groupInfo, err := g.mergeGroupFull(ctx, group.GroupID, group, &members, &userMap)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return err
|
// return err
|
||||||
}
|
// }
|
||||||
return g.msgClient.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupCreatedNotification, groupInfo)
|
// return g.msgClient.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupCreatedNotification, groupInfo)
|
||||||
|
//}
|
||||||
|
|
||||||
|
func (g *GroupNotificationSender) GroupCreatedNotification(ctx context.Context, tips *sdkws.GroupCreatedTips) (err error) {
|
||||||
|
return g.msgClient.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.GroupCreatedNotification, tips)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GroupNotificationSender) GroupInfoSetNotification(ctx context.Context, group *relation.GroupModel, members []*relation.GroupMemberModel, needVerification *int32) (err error) {
|
//func (g *GroupNotificationSender) GroupInfoSetNotification(ctx context.Context, group *relation.GroupModel, members []*relation.GroupMemberModel, needVerification *int32) (err error) {
|
||||||
groupInfo, err := g.mergeGroupFull(ctx, group.GroupID, group, &members, nil)
|
// groupInfo, err := g.mergeGroupFull(ctx, group.GroupID, group, &members, nil)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return err
|
// return err
|
||||||
}
|
// }
|
||||||
tips := &sdkws.GroupInfoSetTips{Group: groupInfo.Group, OpUser: groupInfo.GroupOwnerUser}
|
// tips := &sdkws.GroupInfoSetTips{Group: groupInfo.Group, OpUser: groupInfo.GroupOwnerUser}
|
||||||
if needVerification != nil {
|
// if needVerification != nil {
|
||||||
tips.Group.NeedVerification = *needVerification
|
// tips.Group.NeedVerification = *needVerification
|
||||||
}
|
// }
|
||||||
return g.msgClient.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupInfoSetNotification, tips)
|
// return g.msgClient.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupInfoSetNotification, tips)
|
||||||
|
//}
|
||||||
|
|
||||||
|
func (g *GroupNotificationSender) GroupInfoSetNotification(ctx context.Context, tips *sdkws.GroupInfoSetTips) (err error) {
|
||||||
|
//groupInfo, err := g.mergeGroupFull(ctx, group.GroupID, group, &members, nil)
|
||||||
|
//if err != nil {
|
||||||
|
// return err
|
||||||
|
//}
|
||||||
|
//tips := &sdkws.GroupInfoSetTips{Group: groupInfo.Group, OpUser: groupInfo.GroupOwnerUser}
|
||||||
|
//if needVerification != nil {
|
||||||
|
// tips.Group.NeedVerification = *needVerification
|
||||||
|
//}
|
||||||
|
return g.msgClient.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.GroupInfoSetNotification, tips)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GroupNotificationSender) JoinGroupApplicationNotification(ctx context.Context, req *pbGroup.JoinGroupReq) (err error) {
|
func (g *GroupNotificationSender) JoinGroupApplicationNotification(ctx context.Context, req *pbGroup.JoinGroupReq) (err error) {
|
||||||
|
@ -509,3 +509,14 @@ func NotNilReplace[T any](old, new_ *T) {
|
|||||||
}
|
}
|
||||||
*old = *new_
|
*old = *new_
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Batch[T any, V any](fn func(T) V, ts []T) []V {
|
||||||
|
if ts == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
res := make([]V, 0, len(ts))
|
||||||
|
for i := range ts {
|
||||||
|
res = append(res, fn(ts[i]))
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user