mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-06 10:05:58 +08:00
add
This commit is contained in:
+34
-18
@@ -640,6 +640,28 @@ func (s *groupServer) TransferGroupOwner(_ context.Context, req *pbGroup.Transfe
|
||||
|
||||
}
|
||||
|
||||
func (s *groupServer) GetGroupById(_ context.Context, req *pbGroup.GetGroupByIdReq) (*pbGroup.GetGroupByIdResp, error) {
|
||||
log.NewInfo(req.OperationID, "GetGroup ", req.String())
|
||||
resp := &pbGroup.GetGroupByIdResp{}
|
||||
group, err := imdb.GetGroupsById(req.GroupId)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
resp.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,
|
||||
}
|
||||
|
||||
resp.GroupInfo.CreatorUserID = group.CreatorUserID
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) GetGroup(_ context.Context, req *pbGroup.GetGroupReq) (*pbGroup.GetGroupResp, error) {
|
||||
log.NewInfo(req.OperationID, "GetGroup ", req.String())
|
||||
resp := &pbGroup.GetGroupResp{
|
||||
@@ -649,6 +671,10 @@ func (s *groupServer) GetGroup(_ context.Context, req *pbGroup.GetGroupReq) (*pb
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp.Pagination = &open_im_sdk.RequestPagination{
|
||||
PageNumber: req.Pagination.PageNumber,
|
||||
ShowNumber: req.Pagination.ShowNumber,
|
||||
}
|
||||
for _, v := range groups {
|
||||
resp.GroupInfo = append(resp.GroupInfo, &open_im_sdk.GroupInfo{
|
||||
GroupID: v.GroupID,
|
||||
@@ -659,7 +685,6 @@ func (s *groupServer) GetGroup(_ context.Context, req *pbGroup.GetGroupReq) (*pb
|
||||
CreatorUserID: v.CreatorUserID,
|
||||
})
|
||||
}
|
||||
utils.CopyStructFields(resp.GroupInfo, groups)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -695,26 +720,17 @@ func (s *groupServer) GetGroups(_ context.Context, req *pbGroup.GetGroupsReq) (*
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) BanGroupChat(_ context.Context, req *pbGroup.BanGroupChatReq) (*pbGroup.BanGroupChatResp, error) {
|
||||
log.NewInfo(req.OperationID, "BanGroupChat ", req.String())
|
||||
resp := &pbGroup.BanGroupChatResp{}
|
||||
if err := imdb.BanGroupChat(req.GroupId); err != nil {
|
||||
return resp, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) BanPrivateChat(_ context.Context, req *pbGroup.BanPrivateChatReq) (*pbGroup.BanPrivateChatResp, error) {
|
||||
log.NewInfo(req.OperationID, "BanPrivateChat ", req.String())
|
||||
resp := &pbGroup.BanPrivateChatResp{}
|
||||
if err := imdb.BanPrivateChat(req.GroupId); err != 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 {
|
||||
return resp, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) DeleteGroup(_ context.Context, req *pbGroup.DeleteGroupReq) (*pbGroup.DeleteGroupResp, error) {
|
||||
log.NewInfo(req.OperationID, "DeleteGroup ", req.String())
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req.String())
|
||||
resp := &pbGroup.DeleteGroupResp{}
|
||||
if err := imdb.DeleteGroup(req.GroupId); err != nil {
|
||||
return resp, err
|
||||
@@ -722,10 +738,10 @@ func (s *groupServer) DeleteGroup(_ context.Context, req *pbGroup.DeleteGroupReq
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) SetMaster(_ context.Context, req *pbGroup.SetMasterReq) (*pbGroup.SetMasterResp, error) {
|
||||
func (s *groupServer) OperateUserRole(_ context.Context, req *pbGroup.OperateUserRoleReq) (*pbGroup.OperateUserRoleResp, error) {
|
||||
log.NewInfo(req.OperationID, "DeleteGroup ", req.String())
|
||||
resp := &pbGroup.SetMasterResp{}
|
||||
if err := imdb.SetGroupMaster(req.UserId, req.GroupId); err != nil {
|
||||
resp := &pbGroup.OperateUserRoleResp{}
|
||||
if err := imdb.OperateGroupRole(req.UserId, req.GroupId, req.RoleLevel); err != nil {
|
||||
return resp, err
|
||||
}
|
||||
return resp, nil
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package statistics
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
//"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"
|
||||
//cp "Open_IM/pkg/common/utils"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbStatistics "Open_IM/pkg/proto/statistics"
|
||||
//open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
//"context"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type statisticsServer struct {
|
||||
rpcPort int
|
||||
rpcRegisterName string
|
||||
etcdSchema string
|
||||
etcdAddr []string
|
||||
}
|
||||
|
||||
func NewStatisticsGroupServer(port int) *statisticsServer {
|
||||
log.NewPrivateLog("group")
|
||||
return &statisticsServer{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImGroupName,
|
||||
etcdSchema: config.Config.Etcd.EtcdSchema,
|
||||
etcdAddr: config.Config.Etcd.EtcdAddr,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *statisticsServer) Run() {
|
||||
log.NewInfo("0", "group rpc start ")
|
||||
ip := utils.ServerIP
|
||||
registerAddress := ip + ":" + strconv.Itoa(s.rpcPort)
|
||||
//listener network
|
||||
listener, err := net.Listen("tcp", registerAddress)
|
||||
if err != nil {
|
||||
log.NewError("0", "Listen failed ", err.Error(), registerAddress)
|
||||
return
|
||||
}
|
||||
log.NewInfo("0", "listen network success, ", registerAddress, listener)
|
||||
defer listener.Close()
|
||||
//grpc server
|
||||
srv := grpc.NewServer()
|
||||
defer srv.GracefulStop()
|
||||
//Service registers with etcd
|
||||
pbStatistics.RegisterUserServer(srv, s)
|
||||
err = getcdv3.RegisterEtcd(s.etcdSchema, strings.Join(s.etcdAddr, ","), ip, s.rpcPort, s.rpcRegisterName, 10)
|
||||
if err != nil {
|
||||
log.NewError("0", "RegisterEtcd failed ", err.Error())
|
||||
return
|
||||
}
|
||||
err = srv.Serve(listener)
|
||||
if err != nil {
|
||||
log.NewError("0", "Serve failed ", err.Error())
|
||||
return
|
||||
}
|
||||
log.NewInfo("0", "group rpc success")
|
||||
}
|
||||
@@ -250,11 +250,16 @@ func (s *userServer) GetUser(ctx context.Context, req *pbUser.GetUserReq) (*pbUs
|
||||
if err != nil {
|
||||
return resp, nil
|
||||
}
|
||||
isBlock, err := imdb.UserIsBlock(req.UserId)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
resp.User = &pbUser.User{
|
||||
ProfilePhoto: user.FaceURL,
|
||||
Nickname: user.Nickname,
|
||||
UserId: user.UserID,
|
||||
CreateTime: user.CreateTime.String(),
|
||||
IsBlock: isBlock,
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user