mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-25 11:06:43 +08:00
Merge remote-tracking branch 'origin/superGroup' into superGroup
This commit is contained in:
commit
b108e5bf45
@ -5,7 +5,8 @@ import (
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbMsg "Open_IM/pkg/proto/chat"
|
||||
pbChat "Open_IM/pkg/proto/chat"
|
||||
sdk_ws "Open_IM/pkg/proto/sdk_ws"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
@ -31,11 +32,11 @@ func GetSeq(c *gin.Context) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "token validate err" + err.Error()})
|
||||
return
|
||||
}
|
||||
pbData := pbMsg.GetMaxAndMinSeqReq{}
|
||||
pbData := sdk_ws.GetMaxAndMinSeqReq{}
|
||||
pbData.UserID = params.SendID
|
||||
pbData.OperationID = params.OperationID
|
||||
grpcConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfflineMessageName)
|
||||
msgClient := pbMsg.NewChatClient(grpcConn)
|
||||
msgClient := pbChat.NewChatClient(grpcConn)
|
||||
reply, err := msgClient.GetMaxAndMinSeq(context.Background(), &pbData)
|
||||
if err != nil {
|
||||
log.NewError(params.OperationID, "UserGetSeq rpc failed, ", params, err.Error())
|
||||
|
@ -197,6 +197,11 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
|
||||
log.NewInfo(req.OperationID, "rpc CreateGroup return ", resp.String())
|
||||
if req.GroupInfo.GroupType != constant.SuperGroup {
|
||||
chat.GroupCreatedNotification(req.OperationID, req.OpUserID, groupId, okUserIDList)
|
||||
} else {
|
||||
for _, userID := range okUserIDList {
|
||||
chat.SuperGroupNotification(req.OperationID, req.OpUserID, userID)
|
||||
}
|
||||
|
||||
}
|
||||
return resp, nil
|
||||
} else {
|
||||
@ -377,6 +382,10 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
|
||||
|
||||
if groupInfo.GroupType != constant.SuperGroup {
|
||||
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 ")
|
||||
@ -562,6 +571,10 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
|
||||
}
|
||||
if groupInfo.GroupType != constant.SuperGroup {
|
||||
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())
|
||||
return &resp, nil
|
||||
|
@ -1,20 +1,44 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
pbGroup "Open_IM/pkg/proto/group"
|
||||
commonPb "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *groupServer) GetJoinedSuperGroupList(ctx context.Context, req *pbGroup.GetJoinedSuperGroupListReq) (*pbGroup.GetJoinedSuperGroupListResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp := &pbGroup.GetJoinedSuperGroupListResp{}
|
||||
_, err := db.DB.GetSuperGroupByUserID(req.UserID)
|
||||
resp := &pbGroup.GetJoinedSuperGroupListResp{CommonResp: &pbGroup.CommonResp{}}
|
||||
userToSuperGroup, err := db.DB.GetSuperGroupByUserID(req.UserID)
|
||||
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
|
||||
}
|
||||
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())
|
||||
}
|
||||
group, err := db.DB.GetSuperGroup(groupID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetSuperGroup failed", groupID, err.Error())
|
||||
continue
|
||||
}
|
||||
groupInfo.MemberCount = uint32(len(group.MemberIDList))
|
||||
resp.GroupList = append(resp.GroupList, groupInfo)
|
||||
}
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
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
|
||||
WorkMomentNotification = 1901
|
||||
|
||||
NotificationEnd = 2000
|
||||
NotificationEnd = 3000
|
||||
|
||||
//status
|
||||
MsgNormal = 1
|
||||
|
@ -957,11 +957,40 @@ type UserToSuperGroup struct {
|
||||
func (d *DataBases) CreateSuperGroup(groupID string, initMemberIDList []string, memberNumCount int) error {
|
||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||
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{
|
||||
GroupID: groupID,
|
||||
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,
|
||||
})
|
||||
}
|
||||
upsert := true
|
||||
opts := &options.UpdateOptions{
|
||||
Upsert: &upsert,
|
||||
}
|
||||
_, err = c.UpdateMany(sCtx, bson.M{"user_id": bson.M{"$in": initMemberIDList}}, bson.M{"$addToSet": bson.M{"group_id_list": groupID}}, opts)
|
||||
if err != nil {
|
||||
session.AbortTransaction(ctx)
|
||||
return utils.Wrap(err, "transaction failed")
|
||||
}
|
||||
session.CommitTransaction(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -1016,6 +1045,10 @@ func (d *DataBases) RemoverUserFromSuperGroup(groupID string, userIDList []strin
|
||||
defer session.EndSession(ctx)
|
||||
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}}})
|
||||
if err != nil {
|
||||
session.AbortTransaction(ctx)
|
||||
return utils.Wrap(err, "transaction failed")
|
||||
}
|
||||
err = d.RemoveGroupFromUser(ctx, sCtx, groupID, userIDList)
|
||||
if err != nil {
|
||||
session.AbortTransaction(ctx)
|
||||
|
Loading…
x
Reference in New Issue
Block a user