mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-28 04:48:44 +08:00
Merge remote-tracking branch 'origin/superGroup' into superGroup
This commit is contained in:
commit
a4a7ce51ad
@ -197,6 +197,11 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
|
|||||||
log.NewInfo(req.OperationID, "rpc CreateGroup return ", resp.String())
|
log.NewInfo(req.OperationID, "rpc CreateGroup return ", resp.String())
|
||||||
if req.GroupInfo.GroupType != constant.SuperGroup {
|
if req.GroupInfo.GroupType != constant.SuperGroup {
|
||||||
chat.GroupCreatedNotification(req.OperationID, req.OpUserID, groupId, okUserIDList)
|
chat.GroupCreatedNotification(req.OperationID, req.OpUserID, groupId, okUserIDList)
|
||||||
|
} else {
|
||||||
|
for _, userID := range okUserIDList {
|
||||||
|
chat.SuperGroupNotification(req.OperationID, req.OpUserID, userID)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return resp, nil
|
return resp, nil
|
||||||
} else {
|
} else {
|
||||||
@ -377,6 +382,10 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
|
|||||||
|
|
||||||
if groupInfo.GroupType != constant.SuperGroup {
|
if groupInfo.GroupType != constant.SuperGroup {
|
||||||
chat.MemberInvitedNotification(req.OperationID, req.GroupID, req.OpUserID, req.Reason, okUserIDList)
|
chat.MemberInvitedNotification(req.OperationID, req.GroupID, req.OpUserID, req.Reason, okUserIDList)
|
||||||
|
} else {
|
||||||
|
for _, userID := range okUserIDList {
|
||||||
|
chat.SuperGroupNotification(req.OperationID, req.OpUserID, userID)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.NewInfo(req.OperationID, "InviteUserToGroup rpc return ")
|
log.NewInfo(req.OperationID, "InviteUserToGroup rpc return ")
|
||||||
@ -562,6 +571,10 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
|
|||||||
}
|
}
|
||||||
if groupInfo.GroupType != constant.SuperGroup {
|
if groupInfo.GroupType != constant.SuperGroup {
|
||||||
chat.MemberKickedNotification(req, okUserIDList)
|
chat.MemberKickedNotification(req, okUserIDList)
|
||||||
|
} else {
|
||||||
|
for _, userID := range okUserIDList {
|
||||||
|
chat.SuperGroupNotification(req.OperationID, req.OpUserID, userID)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
log.NewInfo(req.OperationID, "GetGroupMemberList rpc return ", resp.String())
|
log.NewInfo(req.OperationID, "GetGroupMemberList rpc return ", resp.String())
|
||||||
return &resp, nil
|
return &resp, nil
|
||||||
|
@ -1,20 +1,38 @@
|
|||||||
package group
|
package group
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"Open_IM/pkg/common/constant"
|
||||||
"Open_IM/pkg/common/db"
|
"Open_IM/pkg/common/db"
|
||||||
|
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||||
"Open_IM/pkg/common/log"
|
"Open_IM/pkg/common/log"
|
||||||
pbGroup "Open_IM/pkg/proto/group"
|
pbGroup "Open_IM/pkg/proto/group"
|
||||||
|
commonPb "Open_IM/pkg/proto/sdk_ws"
|
||||||
"Open_IM/pkg/utils"
|
"Open_IM/pkg/utils"
|
||||||
"context"
|
"context"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *groupServer) GetJoinedSuperGroupList(ctx context.Context, req *pbGroup.GetJoinedSuperGroupListReq) (*pbGroup.GetJoinedSuperGroupListResp, error) {
|
func (s *groupServer) GetJoinedSuperGroupList(ctx context.Context, req *pbGroup.GetJoinedSuperGroupListReq) (*pbGroup.GetJoinedSuperGroupListResp, error) {
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||||
resp := &pbGroup.GetJoinedSuperGroupListResp{}
|
resp := &pbGroup.GetJoinedSuperGroupListResp{CommonResp: &pbGroup.CommonResp{}}
|
||||||
_, err := db.DB.GetSuperGroupByUserID(req.UserID)
|
userToSuperGroup, err := db.DB.GetSuperGroupByUserID(req.UserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetSuperGroupByUserID failed", err.Error())
|
||||||
|
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
||||||
|
resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
for _, groupID := range userToSuperGroup.GroupIDList {
|
||||||
|
groupInfoDB, err := imdb.GetGroupInfoByGroupID(groupID)
|
||||||
|
if err != nil {
|
||||||
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupInfoByGroupID failed", groupID, err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
groupInfo := &commonPb.GroupInfo{}
|
||||||
|
if err := utils.CopyStructFields(groupInfo, groupInfoDB); err != nil {
|
||||||
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
|
||||||
|
}
|
||||||
|
resp.GroupList = append(resp.GroupList, groupInfo)
|
||||||
|
}
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
36
internal/rpc/msg/super_group_notification.go
Normal file
36
internal/rpc/msg/super_group_notification.go
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package msg
|
||||||
|
|
||||||
|
import (
|
||||||
|
"Open_IM/pkg/common/constant"
|
||||||
|
"Open_IM/pkg/common/log"
|
||||||
|
sdk "Open_IM/pkg/proto/sdk_ws"
|
||||||
|
"Open_IM/pkg/utils"
|
||||||
|
"github.com/golang/protobuf/jsonpb"
|
||||||
|
"github.com/golang/protobuf/proto"
|
||||||
|
)
|
||||||
|
|
||||||
|
func SuperGroupNotification(operationID, sendID, recvID string) {
|
||||||
|
//var tips sdk.TipsComm
|
||||||
|
//var err error
|
||||||
|
//marshaler := jsonpb.Marshaler{
|
||||||
|
// OrigName: true,
|
||||||
|
// EnumsAsInts: false,
|
||||||
|
// EmitDefaults: false,
|
||||||
|
//}
|
||||||
|
//tips.JsonDetail, _ = marshaler.MarshalToString(m)
|
||||||
|
n := &NotificationMsg{
|
||||||
|
SendID: sendID,
|
||||||
|
RecvID: recvID,
|
||||||
|
MsgFrom: constant.UserMsgType,
|
||||||
|
ContentType: constant.SuperGroupUpdateNotification,
|
||||||
|
SessionType: constant.SingleChatType,
|
||||||
|
OperationID: operationID,
|
||||||
|
}
|
||||||
|
//n.Content, err = proto.Marshal(&tips)
|
||||||
|
//if err != nil {
|
||||||
|
// log.NewError(operationID, utils.GetSelfFuncName(), "proto.Marshal failed")
|
||||||
|
// return
|
||||||
|
//}
|
||||||
|
log.NewInfo(operationID, utils.GetSelfFuncName(), string(n.Content))
|
||||||
|
Notification(n)
|
||||||
|
}
|
@ -98,7 +98,7 @@ const (
|
|||||||
WorkMomentNotificationBegin = 1900
|
WorkMomentNotificationBegin = 1900
|
||||||
WorkMomentNotification = 1901
|
WorkMomentNotification = 1901
|
||||||
|
|
||||||
NotificationEnd = 2000
|
NotificationEnd = 3000
|
||||||
|
|
||||||
//status
|
//status
|
||||||
MsgNormal = 1
|
MsgNormal = 1
|
||||||
|
@ -957,11 +957,36 @@ type UserToSuperGroup struct {
|
|||||||
func (d *DataBases) CreateSuperGroup(groupID string, initMemberIDList []string, memberNumCount int) error {
|
func (d *DataBases) CreateSuperGroup(groupID string, initMemberIDList []string, memberNumCount int) error {
|
||||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||||
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cSuperGroup)
|
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cSuperGroup)
|
||||||
|
session, err := d.mongoClient.StartSession()
|
||||||
|
if err != nil {
|
||||||
|
return utils.Wrap(err, "start session failed")
|
||||||
|
}
|
||||||
|
defer session.EndSession(ctx)
|
||||||
|
sCtx := mongo.NewSessionContext(ctx, session)
|
||||||
|
if err != nil {
|
||||||
|
return utils.Wrap(err, "start transaction failed")
|
||||||
|
}
|
||||||
superGroup := SuperGroup{
|
superGroup := SuperGroup{
|
||||||
GroupID: groupID,
|
GroupID: groupID,
|
||||||
MemberIDList: initMemberIDList,
|
MemberIDList: initMemberIDList,
|
||||||
}
|
}
|
||||||
_, err := c.InsertOne(ctx, superGroup)
|
_, err = c.InsertOne(sCtx, superGroup)
|
||||||
|
if err != nil {
|
||||||
|
session.AbortTransaction(ctx)
|
||||||
|
return utils.Wrap(err, "transaction failed")
|
||||||
|
}
|
||||||
|
var users []UserToSuperGroup
|
||||||
|
for _, v := range initMemberIDList {
|
||||||
|
users = append(users, UserToSuperGroup{
|
||||||
|
UserID: v,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
_, err = c.UpdateOne(sCtx, users, bson.M{"$addToSet": bson.M{"group_id_list": groupID}})
|
||||||
|
if err != nil {
|
||||||
|
session.AbortTransaction(ctx)
|
||||||
|
return utils.Wrap(err, "transaction failed")
|
||||||
|
}
|
||||||
|
session.CommitTransaction(ctx)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1016,6 +1041,10 @@ func (d *DataBases) RemoverUserFromSuperGroup(groupID string, userIDList []strin
|
|||||||
defer session.EndSession(ctx)
|
defer session.EndSession(ctx)
|
||||||
sCtx := mongo.NewSessionContext(ctx, session)
|
sCtx := mongo.NewSessionContext(ctx, session)
|
||||||
_, err = c.UpdateOne(ctx, bson.M{"group_id": groupID}, bson.M{"$pull": bson.M{"member_id_list": bson.M{"$in": userIDList}}})
|
_, err = c.UpdateOne(ctx, bson.M{"group_id": groupID}, bson.M{"$pull": bson.M{"member_id_list": bson.M{"$in": userIDList}}})
|
||||||
|
if err != nil {
|
||||||
|
session.AbortTransaction(ctx)
|
||||||
|
return utils.Wrap(err, "transaction failed")
|
||||||
|
}
|
||||||
err = d.RemoveGroupFromUser(ctx, sCtx, groupID, userIDList)
|
err = d.RemoveGroupFromUser(ctx, sCtx, groupID, userIDList)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
session.AbortTransaction(ctx)
|
session.AbortTransaction(ctx)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user