callback kickoff

pull/265/head
wangchuxiao 2 years ago
parent aa7ba6d659
commit c2bd1d0d83

@ -22,7 +22,7 @@ func GetGroupByID(c *gin.Context) {
var (
req cms_api_struct.GetGroupByIDRequest
resp cms_api_struct.GetGroupByIDResponse
reqPb pbGroup.GetGroupByIdReq
reqPb pbGroup.GetGroupByIDReq
)
if err := c.ShouldBindQuery(&req); err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "ShouldBindQuery failed ", err.Error())
@ -46,7 +46,10 @@ func GetGroupByID(c *gin.Context) {
openIMHttp.RespHttp200(c, err, nil)
return
}
utils.CopyStructFields(&resp, respPb)
utils.CopyStructFields(&resp, respPb.CMSGroup.GroupInfo)
resp.GroupOwnerID = respPb.CMSGroup.GroupOwnerUserID
resp.GroupOwnerName = respPb.CMSGroup.GroupOwnerUserName
log.NewInfo("", utils.GetSelfFuncName(), "req: ", resp)
openIMHttp.RespHttp200(c, constant.OK, resp)
}
@ -81,16 +84,11 @@ func GetGroups(c *gin.Context) {
return
}
for _, v := range respPb.CMSGroups {
resp.Groups = append(resp.Groups, cms_api_struct.GroupResponse{
GroupName: v.GroupInfo.GroupName,
GroupID: v.GroupInfo.GroupID,
GroupMasterName: v.GroupMasterName,
GroupMasterId: v.GroupMasterId,
CreateTime: (utils.UnixSecondToTime(int64(v.GroupInfo.CreateTime))).String(),
IsBanChat: constant.GroupIsBanChat(v.GroupInfo.Status),
IsBanPrivateChat: false,
ProfilePhoto: v.GroupInfo.FaceURL,
})
groupResp := cms_api_struct.GroupResponse{}
utils.CopyStructFields(&groupResp, v.GroupInfo)
groupResp.GroupOwnerName = v.GroupOwnerUserName
groupResp.GroupOwnerID = v.GroupOwnerUserID
resp.Groups = append(resp.Groups, groupResp)
}
resp.GroupNums = int(respPb.GroupNum)
resp.CurrentPage = int(respPb.Pagination.PageNumber)
@ -130,16 +128,11 @@ func GetGroupByName(c *gin.Context) {
return
}
for _, v := range respPb.CMSGroups {
resp.Groups = append(resp.Groups, cms_api_struct.GroupResponse{
GroupName: v.GroupInfo.GroupName,
GroupID: v.GroupInfo.GroupID,
GroupMasterName: v.GroupMasterName,
GroupMasterId: v.GroupMasterId,
CreateTime: (utils.UnixSecondToTime(int64(v.GroupInfo.CreateTime))).String(),
IsBanChat: constant.GroupIsBanChat(v.GroupInfo.Status),
IsBanPrivateChat: false,
ProfilePhoto: v.GroupInfo.FaceURL,
})
groupResp := cms_api_struct.GroupResponse{}
utils.CopyStructFields(&groupResp, v.GroupInfo)
groupResp.GroupOwnerName = v.GroupOwnerUserName
groupResp.GroupOwnerID = v.GroupOwnerUserID
resp.Groups = append(resp.Groups, groupResp)
}
resp.CurrentPage = int(respPb.Pagination.PageNumber)
resp.ShowNumber = int(respPb.Pagination.ShowNumber)
@ -189,133 +182,6 @@ func CreateGroup(c *gin.Context) {
openIMHttp.RespHttp200(c, constant.OK, nil)
}
func BanGroupChat(c *gin.Context) {
var (
req cms_api_struct.BanGroupChatRequest
reqPb pbGroup.OperateGroupStatusReq
)
if err := c.BindJSON(&req); err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "BindJSON failed", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
return
}
reqPb.OperationID = utils.OperationIDGenerator()
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
reqPb.GroupId = req.GroupId
reqPb.Status = constant.GroupBanChat
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName, reqPb.OperationID)
if etcdConn == nil {
errMsg := reqPb.OperationID + "getcdv3.GetConn == nil"
log.NewError(reqPb.OperationID, errMsg)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
return
}
client := pbGroup.NewGroupClient(etcdConn)
_, err := client.OperateGroupStatus(context.Background(), &reqPb)
if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "BanGroupChat failed ", err.Error())
openIMHttp.RespHttp200(c, err, nil)
return
}
openIMHttp.RespHttp200(c, constant.OK, nil)
}
func BanPrivateChat(c *gin.Context) {
var (
req cms_api_struct.BanPrivateChatRequest
reqPb pbGroup.OperateGroupStatusReq
)
if err := c.BindJSON(&req); err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "BindJSON failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
return
}
reqPb.OperationID = utils.OperationIDGenerator()
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
reqPb.GroupId = req.GroupId
reqPb.Status = constant.GroupBanPrivateChat
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName, reqPb.OperationID)
if etcdConn == nil {
errMsg := reqPb.OperationID + "getcdv3.GetConn == nil"
log.NewError(reqPb.OperationID, errMsg)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
return
}
client := pbGroup.NewGroupClient(etcdConn)
_, err := client.OperateGroupStatus(context.Background(), &reqPb)
if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "OperateGroupStatus failed", err.Error())
openIMHttp.RespHttp200(c, err, nil)
return
}
openIMHttp.RespHttp200(c, constant.OK, nil)
}
func OpenGroupChat(c *gin.Context) {
var (
req cms_api_struct.BanPrivateChatRequest
reqPb pbGroup.OperateGroupStatusReq
)
if err := c.BindJSON(&req); err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "BindJSON failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
return
}
reqPb.OperationID = utils.OperationIDGenerator()
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
reqPb.GroupId = req.GroupId
reqPb.Status = constant.GroupOk
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName, reqPb.OperationID)
if etcdConn == nil {
errMsg := reqPb.OperationID + "getcdv3.GetConn == nil"
log.NewError(reqPb.OperationID, errMsg)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
return
}
client := pbGroup.NewGroupClient(etcdConn)
_, err := client.OperateGroupStatus(context.Background(), &reqPb)
if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "OperateGroupStatus failed ", err.Error())
openIMHttp.RespHttp200(c, err, nil)
return
}
openIMHttp.RespHttp200(c, constant.OK, nil)
}
func OpenPrivateChat(c *gin.Context) {
var (
req cms_api_struct.BanPrivateChatRequest
reqPb pbGroup.OperateGroupStatusReq
)
if err := c.BindJSON(&req); err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "OpenPrivateChat failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
return
}
reqPb.OperationID = utils.OperationIDGenerator()
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
reqPb.GroupId = req.GroupId
reqPb.Status = constant.GroupOk
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName, reqPb.OperationID)
if etcdConn == nil {
errMsg := reqPb.OperationID + "getcdv3.GetConn == nil"
log.NewError(reqPb.OperationID, errMsg)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
return
}
client := pbGroup.NewGroupClient(etcdConn)
_, err := client.OperateGroupStatus(context.Background(), &reqPb)
if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "OperateGroupStatus failed ", err.Error())
openIMHttp.RespHttp200(c, err, nil)
return
}
openIMHttp.RespHttp200(c, constant.OK, nil)
}
func GetGroupMembers(c *gin.Context) {
var (
req cms_api_struct.GetGroupMembersRequest
@ -333,7 +199,7 @@ func GetGroupMembers(c *gin.Context) {
PageNumber: int32(req.PageNumber),
ShowNumber: int32(req.ShowNumber),
}
reqPb.GroupId = req.GroupId
reqPb.GroupID = req.GroupID
reqPb.UserName = req.UserName
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName, reqPb.OperationID)
if etcdConn == nil {
@ -355,12 +221,7 @@ func GetGroupMembers(c *gin.Context) {
}
resp.MemberNums = int(respPb.MemberNums)
for _, groupMembers := range respPb.Members {
resp.GroupMembers = append(resp.GroupMembers, cms_api_struct.GroupMemberResponse{
MemberPosition: int(groupMembers.RoleLevel),
MemberNickName: groupMembers.Nickname,
MemberId: groupMembers.UserID,
JoinTime: utils.UnixSecondToTime(int64(groupMembers.JoinTime)).String(),
})
resp.GroupMembers = append(resp.GroupMembers, *groupMembers)
}
log.NewInfo("", utils.GetSelfFuncName(), "req: ", resp)
openIMHttp.RespHttp200(c, constant.OK, resp)
@ -373,25 +234,25 @@ func AddGroupMembers(c *gin.Context) {
reqPb pbGroup.AddGroupMembersCMSReq
)
if err := c.BindJSON(&req); err != nil {
log.NewError(reqPb.OperationId, utils.GetSelfFuncName(), "BindJSON failed ", err.Error())
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "BindJSON failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
return
}
reqPb.OperationId = utils.OperationIDGenerator()
reqPb.OperationID = utils.OperationIDGenerator()
log.NewInfo("", utils.GetSelfFuncName(), "req: ", req)
reqPb.UserIds = req.Members
reqPb.GroupId = req.GroupId
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName, reqPb.OperationId)
reqPb.UserIDList = req.Members
reqPb.GroupID = req.GroupId
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName, reqPb.OperationID)
if etcdConn == nil {
errMsg := reqPb.OperationId + "getcdv3.GetConn == nil"
log.NewError(reqPb.OperationId, errMsg)
errMsg := reqPb.OperationID + "getcdv3.GetConn == nil"
log.NewError(reqPb.OperationID, errMsg)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
return
}
client := pbGroup.NewGroupClient(etcdConn)
respPb, err := client.AddGroupMembersCMS(context.Background(), &reqPb)
if err != nil {
log.NewError(reqPb.OperationId, utils.GetSelfFuncName(), "AddGroupMembersCMS failed", err.Error())
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "AddGroupMembersCMS failed", err.Error())
openIMHttp.RespHttp200(c, err, nil)
return
}
@ -414,8 +275,8 @@ func RemoveGroupMembers(c *gin.Context) {
}
reqPb.OperationID = utils.OperationIDGenerator()
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
reqPb.UserIds = req.Members
reqPb.GroupId = req.GroupId
reqPb.UserIDList = req.Members
reqPb.GroupID = req.GroupId
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName, reqPb.OperationID)
if etcdConn == nil {
errMsg := reqPb.OperationID + "getcdv3.GetConn == nil"
@ -436,38 +297,7 @@ func RemoveGroupMembers(c *gin.Context) {
openIMHttp.RespHttp200(c, constant.OK, resp)
}
func DeleteGroup(c *gin.Context) {
var (
req cms_api_struct.DeleteGroupRequest
_ cms_api_struct.DeleteGroupResponse
reqPb pbGroup.DeleteGroupReq
)
if err := c.BindJSON(&req); err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "BindJSON failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
return
}
reqPb.OperationID = utils.OperationIDGenerator()
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
reqPb.GroupId = req.GroupId
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName, reqPb.OperationID)
if etcdConn == nil {
errMsg := reqPb.OperationID + "getcdv3.GetConn == nil"
log.NewError(reqPb.OperationID, errMsg)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
return
}
client := pbGroup.NewGroupClient(etcdConn)
_, err := client.DeleteGroup(context.Background(), &reqPb)
if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "DeleteGroup failed", err.Error())
openIMHttp.RespHttp200(c, err, nil)
return
}
openIMHttp.RespHttp200(c, constant.OK, nil)
}
func SetGroupMaster(c *gin.Context) {
func SetGroupOwner(c *gin.Context) {
var (
req cms_api_struct.SetGroupMasterRequest
_ cms_api_struct.SetGroupMasterResponse
@ -480,8 +310,8 @@ func SetGroupMaster(c *gin.Context) {
}
reqPb.OperationID = utils.OperationIDGenerator()
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
reqPb.GroupId = req.GroupId
reqPb.UserId = req.UserId
reqPb.GroupID = req.GroupId
reqPb.UserID = req.UserId
reqPb.RoleLevel = constant.GroupOwner
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName, reqPb.OperationID)
if etcdConn == nil {
@ -513,8 +343,8 @@ func SetGroupOrdinaryUsers(c *gin.Context) {
}
reqPb.OperationID = utils.OperationIDGenerator()
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
reqPb.GroupId = req.GroupId
reqPb.UserId = req.UserId
reqPb.GroupID = req.GroupId
reqPb.UserID = req.UserId
reqPb.RoleLevel = constant.GroupOrdinaryUsers
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName, reqPb.OperationID)
if etcdConn == nil {
@ -553,7 +383,6 @@ func AlterGroupInfo(c *gin.Context) {
Introduction: req.Introduction,
Notification: req.Notification,
FaceURL: req.ProfilePhoto,
// GroupType: int32(req.GroupType),
}
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName, reqPb.OperationID)
if etcdConn == nil {

@ -54,13 +54,8 @@ func NewGinRouter() *gin.Engine {
groupRouterGroup.POST("/create_group", group.CreateGroup)
groupRouterGroup.POST("/add_members", group.AddGroupMembers)
groupRouterGroup.POST("/remove_members", group.RemoveGroupMembers)
groupRouterGroup.POST("/ban_group_private_chat", group.BanPrivateChat)
groupRouterGroup.POST("/open_group_private_chat", group.OpenPrivateChat)
groupRouterGroup.POST("/ban_group_chat", group.BanGroupChat)
groupRouterGroup.POST("/open_group_chat", group.OpenGroupChat)
groupRouterGroup.POST("/delete_group", group.DeleteGroup)
groupRouterGroup.POST("/get_members_in_group", group.GetGroupMembers)
groupRouterGroup.POST("/set_group_master", group.SetGroupMaster)
groupRouterGroup.POST("/set_group_master", group.SetGroupOwner)
groupRouterGroup.POST("/set_group_ordinary_user", group.SetGroupOrdinaryUsers)
groupRouterGroup.POST("/alter_group_info", group.AlterGroupInfo)
}

@ -1333,35 +1333,32 @@ func (s *groupServer) TransferGroupOwner(_ context.Context, req *pbGroup.Transfe
}
func (s *groupServer) GetGroupById(_ context.Context, req *pbGroup.GetGroupByIdReq) (*pbGroup.GetGroupByIdResp, error) {
func (s *groupServer) GetGroupByID(_ context.Context, req *pbGroup.GetGroupByIDReq) (*pbGroup.GetGroupByIDResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &pbGroup.GetGroupByIdResp{CMSGroup: &pbGroup.CMSGroup{
resp := &pbGroup.GetGroupByIDResp{CMSGroup: &pbGroup.CMSGroup{
GroupInfo: &open_im_sdk.GroupInfo{},
}}
group, err := imdb.GetGroupById(req.GroupId)
group, err := imdb.GetGroupInfoByGroupID(req.GroupID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupById error", err.Error())
return resp, http.WrapError(constant.ErrDB)
}
resp.CMSGroup.GroupInfo = &open_im_sdk.GroupInfo{
GroupID: group.GroupID,
GroupName: group.GroupName,
FaceURL: group.FaceURL,
OwnerUserID: group.CreatorUserID,
MemberCount: 0,
Status: group.Status,
CreatorUserID: group.CreatorUserID,
GroupType: group.GroupType,
CreateTime: uint32(group.CreateTime.Unix()),
}
utils.CopyStructFields(resp.CMSGroup.GroupInfo, group)
groupMember, err := imdb.GetGroupMaster(group.GroupID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMaster", err.Error())
return resp, http.WrapError(constant.ErrDB)
}
resp.CMSGroup.GroupMasterName = groupMember.Nickname
resp.CMSGroup.GroupMasterId = groupMember.UserID
groupMemberNum, err := imdb.GetGroupMemberNumByGroupID(req.GroupID)
if err == nil {
resp.CMSGroup.GroupInfo.MemberCount = uint32(groupMemberNum)
} else {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
}
resp.CMSGroup.GroupOwnerUserName = groupMember.Nickname
resp.CMSGroup.GroupOwnerUserID = groupMember.UserID
resp.CMSGroup.GroupInfo.CreatorUserID = group.CreatorUserID
utils.CopyStructFields(resp.CMSGroup.GroupInfo, group)
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
return resp, nil
}
@ -1373,12 +1370,13 @@ func (s *groupServer) GetGroup(_ context.Context, req *pbGroup.GetGroupReq) (*pb
}
groups, err := imdb.GetGroupsByName(req.GroupName, req.Pagination.PageNumber, req.Pagination.ShowNumber)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupsByName error", req.String())
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupsByName error", req.String(), req.GroupName, req.Pagination.PageNumber, req.Pagination.ShowNumber)
return resp, http.WrapError(constant.ErrDB)
}
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "groups", groups)
nums, err := imdb.GetGroupsCountNum(db.Group{GroupName: req.GroupName})
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupsCountNum error", err.Error())
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupsCountNum error", err.Error(), req.GroupName)
return resp, http.WrapError(constant.ErrDB)
}
resp.GroupNums = nums
@ -1387,24 +1385,16 @@ func (s *groupServer) GetGroup(_ context.Context, req *pbGroup.GetGroupReq) (*pb
ShowNumber: req.Pagination.ShowNumber,
}
for _, v := range groups {
group := &pbGroup.CMSGroup{GroupInfo: &open_im_sdk.GroupInfo{}}
utils.CopyStructFields(group.GroupInfo, v)
groupMember, err := imdb.GetGroupMaster(v.GroupID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMaster error", err.Error())
continue
}
resp.CMSGroups = append(resp.CMSGroups, &pbGroup.CMSGroup{
GroupInfo: &open_im_sdk.GroupInfo{
GroupID: v.GroupID,
GroupName: v.GroupName,
FaceURL: v.FaceURL,
OwnerUserID: v.CreatorUserID,
Status: v.Status,
CreatorUserID: v.CreatorUserID,
CreateTime: uint32(v.CreateTime.Unix()),
},
GroupMasterName: groupMember.Nickname,
GroupMasterId: groupMember.UserID,
})
group.GroupOwnerUserID = groupMember.GroupID
group.GroupOwnerUserName = groupMember.Nickname
resp.CMSGroups = append(resp.CMSGroups, group)
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
return resp, nil
@ -1427,57 +1417,29 @@ func (s *groupServer) GetGroups(_ context.Context, req *pbGroup.GetGroupsReq) (*
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupsCountNum", err.Error())
return resp, http.WrapError(constant.ErrDB)
}
resp.GroupNum = int32(groupsCountNum)
resp.GroupNum = groupsCountNum
resp.Pagination.PageNumber = req.Pagination.PageNumber
resp.Pagination.ShowNumber = req.Pagination.ShowNumber
for _, v := range groups {
group := &pbGroup.CMSGroup{GroupInfo: &open_im_sdk.GroupInfo{}}
utils.CopyStructFields(group.GroupInfo, v)
groupMember, err := imdb.GetGroupMaster(v.GroupID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMaster failed", err.Error(), v)
continue
}
resp.CMSGroups = append(resp.CMSGroups, &pbGroup.CMSGroup{
GroupInfo: &open_im_sdk.GroupInfo{
GroupID: v.GroupID,
GroupName: v.GroupName,
FaceURL: v.FaceURL,
OwnerUserID: v.CreatorUserID,
Status: v.Status,
CreatorUserID: v.CreatorUserID,
CreateTime: uint32(v.CreateTime.Unix()),
},
GroupMasterId: groupMember.UserID,
GroupMasterName: groupMember.Nickname,
})
group.GroupOwnerUserID = groupMember.GroupID
group.GroupOwnerUserName = groupMember.Nickname
resp.CMSGroups = append(resp.CMSGroups, group)
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "GetGroups ", resp.String())
return resp, nil
}
func (s *groupServer) OperateGroupStatus(_ context.Context, req *pbGroup.OperateGroupStatusReq) (*pbGroup.OperateGroupStatusResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req.String())
resp := &pbGroup.OperateGroupStatusResp{}
if err := imdb.OperateGroupStatus(req.GroupId, req.Status); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "OperateGroupStatus", err.Error())
return resp, http.WrapError(constant.ErrDB)
}
return resp, nil
}
func (s *groupServer) DeleteGroup(_ context.Context, req *pbGroup.DeleteGroupReq) (*pbGroup.DeleteGroupResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req.String())
resp := &pbGroup.DeleteGroupResp{}
if err := imdb.DeleteGroup(req.GroupId); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "DeleteGroup error", err.Error())
return resp, http.WrapError(constant.ErrDB)
}
return resp, nil
}
func (s *groupServer) OperateUserRole(_ context.Context, req *pbGroup.OperateUserRoleReq) (*pbGroup.OperateUserRoleResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "args:", req.String())
resp := &pbGroup.OperateUserRoleResp{}
oldOwnerUserID, err := imdb.GetGroupMaster(req.GroupId)
oldOwnerUserID, err := imdb.GetGroupMaster(req.GroupID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMaster failed", err.Error())
return resp, http.WrapError(constant.ErrDB)
@ -1491,8 +1453,8 @@ func (s *groupServer) OperateUserRole(_ context.Context, req *pbGroup.OperateUse
client := pbGroup.NewGroupClient(etcdConn)
var reqPb pbGroup.TransferGroupOwnerReq
reqPb.OperationID = req.OperationID
reqPb.NewOwnerUserID = req.UserId
reqPb.GroupID = req.GroupId
reqPb.NewOwnerUserID = req.UserID
reqPb.GroupID = req.GroupID
reqPb.OpUserID = "cms admin"
reqPb.OldOwnerUserID = oldOwnerUserID.UserID
reply, err := client.TransferGroupOwner(context.Background(), &reqPb)
@ -1508,12 +1470,12 @@ func (s *groupServer) OperateUserRole(_ context.Context, req *pbGroup.OperateUse
func (s *groupServer) GetGroupMembersCMS(_ context.Context, req *pbGroup.GetGroupMembersCMSReq) (*pbGroup.GetGroupMembersCMSResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "args:", req.String())
resp := &pbGroup.GetGroupMembersCMSResp{}
groupMembers, err := imdb.GetGroupMembersByGroupIdCMS(req.GroupId, req.UserName, req.Pagination.ShowNumber, req.Pagination.PageNumber)
groupMembers, err := imdb.GetGroupMembersByGroupIdCMS(req.GroupID, req.UserName, req.Pagination.ShowNumber, req.Pagination.PageNumber)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMembersByGroupIdCMS Error", err.Error())
return resp, http.WrapError(constant.ErrDB)
}
groupMembersCount, err := imdb.GetGroupMembersCount(req.GroupId, req.UserName)
groupMembersCount, err := imdb.GetGroupMembersCount(req.GroupID, req.UserName)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMembersCMS Error", err.Error())
return resp, http.WrapError(constant.ErrDB)
@ -1521,15 +1483,9 @@ func (s *groupServer) GetGroupMembersCMS(_ context.Context, req *pbGroup.GetGrou
log.NewInfo(req.OperationID, groupMembersCount)
resp.MemberNums = int32(groupMembersCount)
for _, groupMember := range groupMembers {
resp.Members = append(resp.Members, &open_im_sdk.GroupMemberFullInfo{
GroupID: req.GroupId,
UserID: groupMember.UserID,
RoleLevel: groupMember.RoleLevel,
JoinTime: int32(groupMember.JoinTime.Unix()),
Nickname: groupMember.Nickname,
FaceURL: groupMember.FaceURL,
JoinSource: groupMember.JoinSource,
})
member := open_im_sdk.GroupMemberFullInfo{}
utils.CopyStructFields(&member, groupMember)
resp.Members = append(resp.Members, &member)
}
resp.Pagination = &open_im_sdk.ResponsePagination{
CurrentPage: req.Pagination.PageNumber,
@ -1542,8 +1498,8 @@ func (s *groupServer) GetGroupMembersCMS(_ context.Context, req *pbGroup.GetGrou
func (s *groupServer) RemoveGroupMembersCMS(_ context.Context, req *pbGroup.RemoveGroupMembersCMSReq) (*pbGroup.RemoveGroupMembersCMSResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "args:", req.String())
resp := &pbGroup.RemoveGroupMembersCMSResp{}
for _, userId := range req.UserIds {
err := imdb.RemoveGroupMember(req.GroupId, userId)
for _, userId := range req.UserIDList {
err := imdb.RemoveGroupMember(req.GroupID, userId)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
resp.Failed = append(resp.Failed, userId)
@ -1552,20 +1508,20 @@ func (s *groupServer) RemoveGroupMembersCMS(_ context.Context, req *pbGroup.Remo
}
}
reqKick := &pbGroup.KickGroupMemberReq{
GroupID: req.GroupId,
GroupID: req.GroupID,
KickedUserIDList: resp.Success,
Reason: "admin kick",
OperationID: req.OperationID,
OpUserID: req.OpUserId,
OpUserID: req.OpUserID,
}
var reqPb pbUser.SetConversationReq
var c pbUser.Conversation
for _, v := range resp.Success {
reqPb.OperationID = req.OperationID
c.OwnerUserID = v
c.ConversationID = utils.GetConversationIDBySessionType(req.GroupId, constant.GroupChatType)
c.ConversationID = utils.GetConversationIDBySessionType(req.GroupID, constant.GroupChatType)
c.ConversationType = constant.GroupChatType
c.GroupID = req.GroupId
c.GroupID = req.GroupID
c.IsNotInGroup = true
reqPb.Conversation = &c
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName, req.OperationID)
@ -1591,7 +1547,7 @@ func (s *groupServer) RemoveGroupMembersCMS(_ context.Context, req *pbGroup.Remo
}
cacheClient := pbCache.NewCacheClient(etcdConn)
cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{
GroupID: req.GroupId,
GroupID: req.GroupID,
OperationID: req.OperationID,
})
if err != nil {
@ -1602,16 +1558,16 @@ func (s *groupServer) RemoveGroupMembersCMS(_ context.Context, req *pbGroup.Remo
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String())
return resp, http.WrapError(constant.ErrDB)
}
if err := rocksCache.DelGroupMemberListHashFromCache(req.GroupId); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupId)
if err := rocksCache.DelGroupMemberListHashFromCache(req.GroupID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
}
if err := rocksCache.DelGroupMemberNumFromCache(req.GroupId); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupId)
if err := rocksCache.DelGroupMemberNumFromCache(req.GroupID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
}
for _, userID := range resp.Success {
if err := rocksCache.DelGroupMemberInfoFromCache(req.GroupId, userID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupId, userID)
if err := rocksCache.DelGroupMemberInfoFromCache(req.GroupID, userID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID, userID)
}
}
@ -1621,22 +1577,22 @@ func (s *groupServer) RemoveGroupMembersCMS(_ context.Context, req *pbGroup.Remo
}
func (s *groupServer) AddGroupMembersCMS(_ context.Context, req *pbGroup.AddGroupMembersCMSReq) (*pbGroup.AddGroupMembersCMSResp, error) {
log.NewInfo(req.OperationId, utils.GetSelfFuncName(), "args:", req.String())
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "args:", req.String())
resp := &pbGroup.AddGroupMembersCMSResp{}
for _, userId := range req.UserIds {
if isExist := imdb.IsExistGroupMember(req.GroupId, userId); isExist {
log.NewError(req.OperationId, utils.GetSelfFuncName(), "user is exist in group", userId, req.GroupId)
for _, userId := range req.UserIDList {
if isExist := imdb.IsExistGroupMember(req.GroupID, userId); isExist {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "user is exist in group", userId, req.GroupID)
resp.Failed = append(resp.Failed, userId)
continue
}
user, err := imdb.GetUserByUserID(userId)
if err != nil {
log.NewError(req.OperationId, utils.GetSelfFuncName(), "GetUserByUserID", err.Error())
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserByUserID", err.Error())
resp.Failed = append(resp.Failed, userId)
continue
}
groupMember := db.GroupMember{
GroupID: req.GroupId,
GroupID: req.GroupID,
UserID: userId,
Nickname: user.Nickname,
FaceURL: "",
@ -1647,40 +1603,40 @@ func (s *groupServer) AddGroupMembersCMS(_ context.Context, req *pbGroup.AddGrou
Ex: "",
}
if err := imdb.InsertIntoGroupMember(groupMember); err != nil {
log.NewError(req.OperationId, utils.GetSelfFuncName(), "InsertIntoGroupMember failed", req.String())
log.NewError(req.OperationID, utils.GetSelfFuncName(), "InsertIntoGroupMember failed", req.String())
resp.Failed = append(resp.Failed, userId)
} else {
resp.Success = append(resp.Success, userId)
}
}
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationId)
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
if etcdConn == nil {
errMsg := req.OperationId + "getcdv3.GetConn == nil"
log.NewError(req.OperationId, errMsg)
errMsg := req.OperationID + "getcdv3.GetConn == nil"
log.NewError(req.OperationID, errMsg)
return resp, http.WrapError(constant.ErrDB)
}
cacheClient := pbCache.NewCacheClient(etcdConn)
cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{
GroupID: req.GroupId,
OperationID: req.OperationId,
GroupID: req.GroupID,
OperationID: req.OperationID,
})
if err != nil {
log.NewError(req.OperationId, "DelGroupMemberIDListFromCache rpc call failed ", err.Error())
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc call failed ", err.Error())
return resp, http.WrapError(constant.ErrDB)
}
if cacheResp.CommonResp.ErrCode != 0 {
log.NewError(req.OperationId, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String())
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String())
return resp, http.WrapError(constant.ErrDB)
}
if err := rocksCache.DelGroupMemberListHashFromCache(req.GroupId); err != nil {
log.NewError(req.OperationId, utils.GetSelfFuncName(), err.Error(), req.GroupId)
if err := rocksCache.DelGroupMemberListHashFromCache(req.GroupID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
}
if err := rocksCache.DelGroupMemberNumFromCache(req.GroupId); err != nil {
log.NewError(req.OperationId, utils.GetSelfFuncName(), err.Error(), req.GroupId)
if err := rocksCache.DelGroupMemberNumFromCache(req.GroupID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
}
chat.MemberInvitedNotification(req.OperationId, req.GroupId, req.OpUserId, "admin add you to group", resp.Success)
chat.MemberInvitedNotification(req.OperationID, req.GroupID, req.OpUserID, "admin add you to group", resp.Success)
return resp, nil
}

@ -1,11 +1,30 @@
package cms_api_struct
import server_api_params "Open_IM/pkg/proto/sdk_ws"
import (
server_api_params "Open_IM/pkg/proto/sdk_ws"
)
type GroupResponse struct {
GroupOwnerName string `json:"GroupOwnerName"`
GroupOwnerID string `json:"GroupOwnerID"`
*server_api_params.GroupInfo
//*server_api_params.GroupInfo
GroupID string `json:"groupID"`
GroupName string `json:"groupName"`
Notification string `json:"notification"`
Introduction string `json:"introduction"`
FaceURL string `json:"faceURL"`
OwnerUserID string `json:"ownerUserID"`
CreateTime uint32 `json:"createTime"`
MemberCount uint32 `json:"memberCount"`
Ex string `json:"ex"`
Status int32 `json:"status"`
CreatorUserID string `json:"creatorUserID"`
GroupType int32 `json:"groupType"`
NeedVerification int32 `json:"needVerification"`
LookMemberInfo int32 `json:"lookMemberInfo"`
ApplyMemberFriend int32 `json:"applyMemberFriend"`
NotificationUpdateTime uint32 `json:"notificationUpdateTime"`
NotificationUserID string `json:"notificationUserID"`
}
type GetGroupByIDRequest struct {
@ -17,13 +36,13 @@ type GetGroupByIDResponse struct {
}
type GetGroupRequest struct {
GroupName string `form:"group_name" binding:"required"`
GroupName string `form:"groupName" binding:"required"`
RequestPagination
}
type GetGroupResponse struct {
Groups []GroupResponse `json:"groups"`
GroupNums int `json:"group_nums"`
GroupNums int `json:"groupNums"`
ResponsePagination
}
@ -33,77 +52,70 @@ type GetGroupsRequest struct {
type GetGroupsResponse struct {
Groups []GroupResponse `json:"groups"`
GroupNums int `json:"group_nums"`
GroupNums int `json:"groupNums"`
ResponsePagination
}
type CreateGroupRequest struct {
GroupName string `json:"group_name" binding:"required"`
GroupMasterId string `json:"group_master_id" binding:"required"`
GroupMembers []string `json:"group_members" binding:"required"`
GroupName string `json:"groupName" binding:"required"`
GroupMasterId string `json:"groupOwnerID" binding:"required"`
GroupMembers []string `json:"groupMembers" binding:"required"`
}
type CreateGroupResponse struct {
}
type SetGroupMasterRequest struct {
GroupId string `json:"group_id" binding:"required"`
UserId string `json:"user_id" binding:"required"`
GroupId string `json:"groupID" binding:"required"`
UserId string `json:"userID" binding:"required"`
}
type SetGroupMasterResponse struct {
}
type SetGroupMemberRequest struct {
GroupId string `json:"group_id" binding:"required"`
UserId string `json:"user_id" binding:"required"`
GroupId string `json:"groupID" binding:"required"`
UserId string `json:"userID" binding:"required"`
}
type SetGroupMemberRespones struct {
}
type BanGroupChatRequest struct {
GroupId string `json:"group_id" binding:"required"`
GroupId string `json:"groupID" binding:"required"`
}
type BanGroupChatResponse struct {
}
type BanPrivateChatRequest struct {
GroupId string `json:"group_id" binding:"required"`
GroupId string `json:"groupID" binding:"required"`
}
type BanPrivateChatResponse struct {
}
type DeleteGroupRequest struct {
GroupId string `json:"group_id" binding:"required"`
GroupId string `json:"groupID" binding:"required"`
}
type DeleteGroupResponse struct {
}
type GetGroupMembersRequest struct {
GroupId string `form:"group_id" binding:"required"`
UserName string `form:"user_name"`
GroupID string `form:"groupID" binding:"required"`
UserName string `form:"userName"`
RequestPagination
}
type GroupMemberResponse struct {
MemberPosition int `json:"member_position"`
MemberNickName string `json:"member_nick_name"`
MemberId string `json:"member_id"`
JoinTime string `json:"join_time"`
}
type GetGroupMembersResponse struct {
GroupMembers []GroupMemberResponse `json:"group_members"`
GroupMembers []server_api_params.GroupMemberFullInfo `json:"groupMembers"`
ResponsePagination
MemberNums int `json:"member_nums"`
MemberNums int `json:"memberNums"`
}
type GroupMemberRequest struct {
GroupId string `json:"group_id" binding:"required"`
GroupId string `json:"groupID" binding:"required"`
Members []string `json:"members" binding:"required"`
}
@ -129,12 +141,12 @@ type RemoveGroupMembersResponse struct {
}
type AlterGroupInfoRequest struct {
GroupID string `json:"group_id"`
GroupName string `json:"group_name"`
GroupID string `json:"groupID"`
GroupName string `json:"groupName"`
Notification string `json:"notification"`
Introduction string `json:"introduction"`
ProfilePhoto string `json:"profile_photo"`
GroupType int `json:"group_type"`
ProfilePhoto string `json:"profilePhoto"`
GroupType int `json:"groupType"`
}
type AlterGroupInfoResponse struct {

@ -2,7 +2,7 @@ package log
import (
"Open_IM/pkg/common/config"
"bufio"
//"bufio"
"fmt"
"os"
"time"
@ -33,13 +33,13 @@ func loggerInit(moduleName string) *Logger {
//All logs will be printed
logger.SetLevel(logrus.Level(config.Config.Log.RemainLogLevel))
//Close std console output
src, err := os.OpenFile(os.DevNull, os.O_APPEND|os.O_WRONLY, os.ModeAppend)
if err != nil {
panic(err.Error())
}
writer := bufio.NewWriter(src)
logger.SetOutput(writer)
//logger.SetOutput(os.Stdout)
//src, err := os.OpenFile(os.DevNull, os.O_APPEND|os.O_WRONLY, os.ModeAppend)
//if err != nil {
// panic(err.Error())
//}
//writer := bufio.NewWriter(src)
//logger.SetOutput(writer)
logger.SetOutput(os.Stdout)
//Log Console Print Style Setting
logger.SetFormatter(&nested.Formatter{
TimestampFormat: "2006-01-02 15:04:05.000",

File diff suppressed because it is too large Load Diff

@ -247,16 +247,6 @@ message GetGroupMemberReq {
string OperationID = 2;
}
message OperateGroupStatusReq {
string GroupID = 1;
int32 Status = 2;
string OperationID = 3;
}
message OperateGroupStatusResp {
}
message OperateUserRoleReq {
string GroupID = 1;
string UserID = 2;
@ -268,15 +258,6 @@ message OperateUserRoleResp {
}
message DeleteGroupReq {
string GroupID = 1;
string OperationID = 2;
}
message DeleteGroupResp {
}
message GetGroupByIDReq {
string GroupID = 1;
string OperationID = 2;
@ -463,12 +444,10 @@ service group{
rpc inviteUserToGroup(InviteUserToGroupReq) returns (InviteUserToGroupResp);
rpc getGroupAllMember(GetGroupAllMemberReq) returns(GetGroupAllMemberResp);
rpc GetGroupById(GetGroupByIDReq) returns(GetGroupByIDResp);
rpc GetGroupByID(GetGroupByIDReq) returns(GetGroupByIDResp);
rpc GetGroup(GetGroupReq) returns(GetGroupResp);
rpc GetGroups(GetGroupsReq) returns(GetGroupsResp);
rpc OperateGroupStatus(OperateGroupStatusReq) returns(OperateGroupStatusResp);
rpc OperateUserRole(OperateUserRoleReq) returns(OperateUserRoleResp);
rpc DeleteGroup(DeleteGroupReq) returns(DeleteGroupResp);
rpc GetGroupMembersCMS(GetGroupMembersCMSReq) returns(GetGroupMembersCMSResp);
rpc RemoveGroupMembersCMS(RemoveGroupMembersCMSReq) returns(RemoveGroupMembersCMSResp);
rpc AddGroupMembersCMS(AddGroupMembersCMSReq) returns(AddGroupMembersCMSResp);

Loading…
Cancel
Save