Merge remote-tracking branch 'origin/superGroup' into superGroup

This commit is contained in:
Gordon
2022-05-30 17:46:15 +08:00
8 changed files with 460 additions and 225 deletions
+41 -3
View File
@@ -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)
}
+26
View File
@@ -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 -3
View File
@@ -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) {