You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Open-IM-Server/internal/cms_api/group/group.go

200 lines
5.6 KiB

3 years ago
package group
import (
3 years ago
"Open_IM/pkg/cms_api_struct"
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
openIMHttp "Open_IM/pkg/common/http"
3 years ago
"Open_IM/pkg/common/log"
3 years ago
"Open_IM/pkg/grpc-etcdv3/getcdv3"
"Open_IM/pkg/utils"
3 years ago
"context"
3 years ago
"fmt"
"strings"
pbGroup "Open_IM/pkg/proto/group"
3 years ago
3 years ago
"github.com/gin-gonic/gin"
)
3 years ago
func GetGroups(c *gin.Context) {
var (
3 years ago
req cms_api_struct.GetGroupsRequest
resp cms_api_struct.GetGroupsResponse
3 years ago
reqPb pbGroup.GetGroupsReq
)
if err := c.ShouldBindQuery(&req); err != nil {
log.NewError("0", "ShouldBindQuery failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
return
}
3 years ago
utils.CopyStructFields(&reqPb.Pagination, req)
3 years ago
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
client := pbGroup.NewGroupClient(etcdConn)
respPb, err := client.GetGroups(context.Background(), &reqPb)
if err != nil {
log.NewError("s", "GetUserInfo failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrServer, nil)
return
}
3 years ago
for _, v := range respPb.GroupInfo {
resp.Groups = append(resp.Groups, cms_api_struct.GroupResponse{
GroupName: v.GroupName,
GroupID: v.GroupID,
GroupMasterName: v.OwnerUserID,
GroupMasterId: v.OwnerUserID,
CreateTime: (utils.UnixSecondToTime(int64(v.CreateTime))).String(),
IsBanChat: false,
IsBanPrivateChat: false,
ProfilePhoto: v.FaceURL,
})
}
3 years ago
openIMHttp.RespHttp200(c, constant.OK, resp)
3 years ago
3 years ago
}
3 years ago
func GetGroup(c *gin.Context) {
var (
3 years ago
req cms_api_struct.GetGroupRequest
resp cms_api_struct.GetGroupResponse
3 years ago
reqPb pbGroup.GetGroupReq
)
if err := c.ShouldBindQuery(&req); err != nil {
log.NewError("0", "ShouldBindQuery failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
return
}
3 years ago
reqPb.GroupName = req.GroupName
fmt.Println(reqPb)
3 years ago
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
client := pbGroup.NewGroupClient(etcdConn)
respPb, err := client.GetGroup(context.Background(), &reqPb)
if err != nil {
log.NewError("s", "GetUserInfo failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrServer, nil)
return
}
3 years ago
for _, v := range respPb.GroupInfo {
resp.Groups = append(resp.Groups, cms_api_struct.GroupResponse{
GroupName: v.GroupName,
GroupID: v.GroupID,
GroupMasterName: v.OwnerUserID,
GroupMasterId: v.OwnerUserID,
CreateTime: (utils.UnixSecondToTime(int64(v.CreateTime))).String(),
IsBanChat: false,
IsBanPrivateChat: false,
ProfilePhoto: v.FaceURL,
})
}
3 years ago
openIMHttp.RespHttp200(c, constant.OK, resp)
3 years ago
}
func CreateGroup(c *gin.Context) {
3 years ago
var (
3 years ago
req cms_api_struct.CreateGroupRequest
resp cms_api_struct.CreateGroupResponse
3 years ago
reqPb pbGroup.CreateGroupReq
)
if err := c.BindJSON(&req); err != nil {
log.NewError("0", "ShouldBindQuery failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
return
}
reqPb.GroupInfo.GroupName = req.GroupName
3 years ago
reqPb.GroupInfo.CreatorUserID = ""
3 years ago
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
client := pbGroup.NewGroupClient(etcdConn)
respPb, err := client.CreateGroup(context.Background(), &reqPb)
if err != nil {
log.NewError("s", "GetUserInfo failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrServer, nil)
return
}
3 years ago
fmt.Println(respPb)
3 years ago
openIMHttp.RespHttp200(c, constant.OK, resp)
}
3 years ago
func BanGroupChat(c *gin.Context) {
var (
req cms_api_struct.BanGroupChatRequest
3 years ago
reqPb pbGroup.BanGroupChatReq
3 years ago
)
3 years ago
if err := c.BindJSON(&req); err != nil {
log.NewError("0", "ShouldBindQuery failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
return
}
reqPb.GroupId = req.GroupId
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
client := pbGroup.NewGroupClient(etcdConn)
_, err := client.BanGroupChat(context.Background(), &reqPb)
if err != nil {
log.NewError("s", "GetUserInfo failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrServer, nil)
return
}
openIMHttp.RespHttp200(c, constant.OK, nil)
3 years ago
}
3 years ago
func BanPrivateChat(c *gin.Context) {
var (
req cms_api_struct.BanPrivateChatRequest
3 years ago
reqPb pbGroup.BanPrivateChatReq
3 years ago
)
3 years ago
if err := c.BindJSON(&req); err != nil {
log.NewError("0", "BindJSON failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
return
}
reqPb.GroupId = req.GroupId
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
client := pbGroup.NewGroupClient(etcdConn)
_, err := client.BanPrivateChat(context.Background(), &reqPb)
if err != nil {
log.NewError("s", "GetUserInfo failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrServer, nil)
return
}
openIMHttp.RespHttp200(c, constant.OK, nil)
3 years ago
}
3 years ago
func GetGroupsMember(c *gin.Context) {
var (
req cms_api_struct.GetGroupMembersRequest
_ cms_api_struct.GetGroupMembersResponse
)
if err := c.BindJSON(&req); err != nil {
log.NewError("0", "BindJSON failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
return
}
3 years ago
}
3 years ago
3 years ago
func InquireMember(c *gin.Context) {
}
func InquireGroup(c *gin.Context) {
}
func AddMembers(c *gin.Context) {
}
func RemoveUser(c *gin.Context) {
}
func Withdraw(c *gin.Context) {
}
func SearchMessage(g *gin.Context) {
}