mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
Merge remote-tracking branch 'origin/superGroup' into superGroup
This commit is contained in:
commit
1db3ecca22
@ -92,7 +92,8 @@ func main() {
|
||||
}
|
||||
superGroupRouterGroup := r.Group("/super_group")
|
||||
{
|
||||
superGroupRouterGroup.POST("/get_joined_super_group_list", group.GetJoinedSuperGroupList)
|
||||
superGroupRouterGroup.POST("/get_joined_group_list", group.GetJoinedSuperGroupList)
|
||||
superGroupRouterGroup.POST("/get_groups_info", group.GetSuperGroupsInfo)
|
||||
}
|
||||
//certificate
|
||||
authRouterGroup := r.Group("/auth")
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
api "Open_IM/pkg/base_info"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
rpc "Open_IM/pkg/proto/group"
|
||||
"Open_IM/pkg/utils"
|
||||
@ -15,14 +16,21 @@ import (
|
||||
)
|
||||
|
||||
func GetJoinedSuperGroupList(c *gin.Context) {
|
||||
req := api.GetJoinedSuperGroupReq{}
|
||||
req := api.GetJoinedSuperGroupListReq{}
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
reqPb := rpc.GetJoinedSuperGroupListReq{OperationID: req.OperationID}
|
||||
ok, opUserID, errInfo := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
reqPb := rpc.GetJoinedSuperGroupListReq{OperationID: req.OperationID, OpUserID: opUserID, UserID: req.FromUserID}
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := rpc.NewGroupClient(etcdConn)
|
||||
rpcResp, err := client.GetJoinedSuperGroupList(context.Background(), &reqPb)
|
||||
@ -31,8 +39,38 @@ func GetJoinedSuperGroupList(c *gin.Context) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
GroupListResp := api.GetJoinedGroupListResp{CommResp: api.CommResp{ErrCode: rpcResp.CommonResp.ErrCode, ErrMsg: rpcResp.CommonResp.ErrMsg}, GroupInfoList: rpcResp.GroupList}
|
||||
GroupListResp := api.GetJoinedSuperGroupListResp{GetJoinedGroupListResp: api.GetJoinedGroupListResp{CommResp: api.CommResp{ErrCode: rpcResp.CommonResp.ErrCode, ErrMsg: rpcResp.CommonResp.ErrMsg}, GroupInfoList: rpcResp.GroupList}}
|
||||
GroupListResp.Data = jsonData.JsonDataList(GroupListResp.GroupInfoList)
|
||||
log.NewInfo(req.OperationID, "GetJoinedGroupList api return ", GroupListResp)
|
||||
c.JSON(http.StatusOK, GroupListResp)
|
||||
}
|
||||
|
||||
func GetSuperGroupsInfo(c *gin.Context) {
|
||||
req := api.GetSuperGroupsInfoReq{}
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
ok, opUserID, errInfo := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
reqPb := rpc.GetSuperGroupsInfoReq{OperationID: req.OperationID, OpUserID: opUserID, GroupIDList: req.GroupIDList}
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := rpc.NewGroupClient(etcdConn)
|
||||
rpcResp, err := client.GetSuperGroupsInfo(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "InviteUserToGroup failed ", err.Error(), reqPb.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
resp := api.GetSuperGroupsInfoResp{GetGroupInfoResp: api.GetGroupInfoResp{CommResp: api.CommResp{ErrCode: rpcResp.CommonResp.ErrCode, ErrMsg: rpcResp.CommonResp.ErrMsg}, GroupInfoList: rpcResp.GroupInfoList}}
|
||||
resp.Data = jsonData.JsonDataList(resp.GroupInfoList)
|
||||
log.NewInfo(req.OperationID, "GetGroupsInfo api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"Open_IM/pkg/common/db"
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
cp "Open_IM/pkg/common/utils"
|
||||
pbGroup "Open_IM/pkg/proto/group"
|
||||
commonPb "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
@ -31,8 +32,33 @@ func (s *groupServer) GetJoinedSuperGroupList(ctx context.Context, req *pbGroup.
|
||||
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
|
||||
}
|
||||
|
||||
func (s *groupServer) GetSuperGroupsInfo(_ context.Context, req *pbGroup.GetSuperGroupsInfoReq) (resp *pbGroup.GetSuperGroupsInfoResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbGroup.GetSuperGroupsInfoResp{CommonResp: &pbGroup.CommonResp{}}
|
||||
groupsInfoList := make([]*commonPb.GroupInfo, 0)
|
||||
for _, groupID := range req.GroupIDList {
|
||||
groupInfoFromMysql, err := imdb.GetGroupInfoByGroupID(groupID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetGroupInfoByGroupID failed ", err.Error(), groupID)
|
||||
continue
|
||||
}
|
||||
var groupInfo commonPb.GroupInfo
|
||||
cp.GroupDBCopyOpenIM(&groupInfo, groupInfoFromMysql)
|
||||
groupsInfoList = append(groupsInfoList, &groupInfo)
|
||||
}
|
||||
resp.GroupInfoList = groupsInfoList
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
@ -3,10 +3,10 @@ package msg
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
//sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"github.com/golang/protobuf/jsonpb"
|
||||
"github.com/golang/protobuf/proto"
|
||||
//"github.com/golang/protobuf/jsonpb"
|
||||
//"github.com/golang/protobuf/proto"
|
||||
)
|
||||
|
||||
func SuperGroupNotification(operationID, sendID, recvID string) {
|
||||
|
@ -1,9 +1,17 @@
|
||||
package base_info
|
||||
|
||||
type GetJoinedSuperGroupReq struct {
|
||||
type GetJoinedSuperGroupListReq struct {
|
||||
GetJoinedGroupListReq
|
||||
}
|
||||
|
||||
type GetJoinedSuperGroupResp struct {
|
||||
type GetJoinedSuperGroupListResp struct {
|
||||
GetJoinedGroupListResp
|
||||
}
|
||||
|
||||
type GetSuperGroupsInfoReq struct {
|
||||
GetGroupInfoReq
|
||||
}
|
||||
|
||||
type GetSuperGroupsInfoResp struct {
|
||||
GetGroupInfoResp
|
||||
}
|
||||
|
@ -981,10 +981,17 @@ func (d *DataBases) CreateSuperGroup(groupID string, initMemberIDList []string,
|
||||
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")
|
||||
upsert := true
|
||||
opts := &options.UpdateOptions{
|
||||
Upsert: &upsert,
|
||||
}
|
||||
c = d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cUserToSuperGroup)
|
||||
for _, userID := range initMemberIDList {
|
||||
_, err = c.UpdateOne(sCtx, bson.M{"user_id": userID}, 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
|
||||
@ -1022,10 +1029,16 @@ func (d *DataBases) AddUserToSuperGroup(groupID string, userIDList []string) err
|
||||
UserID: v,
|
||||
})
|
||||
}
|
||||
_, err = c.UpdateMany(sCtx, users, bson.M{"$addToSet": bson.M{"group_id_list": groupID}})
|
||||
if err != nil {
|
||||
session.AbortTransaction(ctx)
|
||||
return utils.Wrap(err, "transaction failed")
|
||||
upsert := true
|
||||
opts := &options.UpdateOptions{
|
||||
Upsert: &upsert,
|
||||
}
|
||||
for _, userID := range userIDList {
|
||||
_, err = c.UpdateOne(sCtx, bson.M{"user_id": userID}, 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
|
||||
@ -1093,7 +1106,7 @@ func (d *DataBases) RemoveGroupFromUser(ctx, sCtx context.Context, groupID strin
|
||||
})
|
||||
}
|
||||
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cUserToSuperGroup)
|
||||
_, err := c.UpdateOne(sCtx, bson.M{"user_id": groupID}, bson.M{"$pull": bson.M{"group_id_list": groupID}})
|
||||
_, err := c.UpdateOne(sCtx, bson.M{"user_id": userID}, bson.M{"$pull": bson.M{"group_id_list": groupID}})
|
||||
if err != nil {
|
||||
return utils.Wrap(err, "UpdateOne transaction failed")
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -401,6 +401,16 @@ message GetJoinedSuperGroupListResp {
|
||||
repeated server_api_params.GroupInfo GroupList = 3;
|
||||
}
|
||||
|
||||
message GetSuperGroupsInfoReq {
|
||||
repeated string GroupIDList = 1;
|
||||
string OperationID = 2;
|
||||
string OpUserID = 3; //No verification permission
|
||||
}
|
||||
|
||||
message GetSuperGroupsInfoResp {
|
||||
CommonResp commonResp = 1;
|
||||
repeated server_api_params.GroupInfo GroupInfoList = 3;
|
||||
}
|
||||
|
||||
service group{
|
||||
rpc createGroup(CreateGroupReq) returns(CreateGroupResp);
|
||||
@ -438,6 +448,7 @@ service group{
|
||||
rpc SetGroupMemberNickname(SetGroupMemberNicknameReq) returns (SetGroupMemberNicknameResp);
|
||||
|
||||
rpc GetJoinedSuperGroupList(GetJoinedSuperGroupListReq) returns (GetJoinedSuperGroupListResp);
|
||||
rpc GetSuperGroupsInfo(GetSuperGroupsInfoReq) returns (GetSuperGroupsInfoResp);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user