mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-11 04:25:59 +08:00
fix bug
This commit is contained in:
@@ -34,7 +34,7 @@ func GetGroupById(c *gin.Context) {
|
||||
respPb, err := client.GetGroupById(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetGroupById failed ", err.Error())
|
||||
openIMHttp.RespHttp200(c, constant.ErrServer, nil)
|
||||
openIMHttp.RespHttp200(c, err, nil)
|
||||
return
|
||||
}
|
||||
resp.GroupName = respPb.CMSGroup.GroupInfo.GroupName
|
||||
@@ -64,7 +64,7 @@ func GetGroups(c *gin.Context) {
|
||||
respPb, err := client.GetGroups(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetUserInfo failed ", err.Error())
|
||||
openIMHttp.RespHttp200(c, constant.ErrServer, nil)
|
||||
openIMHttp.RespHttp200(c, err, nil)
|
||||
return
|
||||
}
|
||||
for _, v := range respPb.CMSGroups {
|
||||
@@ -175,7 +175,7 @@ func BanGroupChat(c *gin.Context) {
|
||||
_, err := client.OperateGroupStatus(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "BanGroupChat failed ", err.Error())
|
||||
openIMHttp.RespHttp200(c, constant.ErrServer, nil)
|
||||
openIMHttp.RespHttp200(c, err, nil)
|
||||
return
|
||||
}
|
||||
openIMHttp.RespHttp200(c, constant.OK, nil)
|
||||
@@ -199,7 +199,7 @@ func BanPrivateChat(c *gin.Context) {
|
||||
_, err := client.OperateGroupStatus(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "OperateGroupStatus failed", err.Error())
|
||||
openIMHttp.RespHttp200(c, constant.ErrServer, nil)
|
||||
openIMHttp.RespHttp200(c, err, nil)
|
||||
return
|
||||
}
|
||||
openIMHttp.RespHttp200(c, constant.OK, nil)
|
||||
@@ -222,7 +222,7 @@ func OpenGroupChat(c *gin.Context) {
|
||||
_, err := client.OperateGroupStatus(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "OperateGroupStatus failed ", err.Error())
|
||||
openIMHttp.RespHttp200(c, constant.ErrServer, nil)
|
||||
openIMHttp.RespHttp200(c, err, nil)
|
||||
return
|
||||
}
|
||||
openIMHttp.RespHttp200(c, constant.OK, nil)
|
||||
@@ -245,7 +245,7 @@ func OpenPrivateChat(c *gin.Context) {
|
||||
_, err := client.OperateGroupStatus(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "OperateGroupStatus failed ", err.Error())
|
||||
openIMHttp.RespHttp200(c, constant.ErrServer, nil)
|
||||
openIMHttp.RespHttp200(c, err, nil)
|
||||
return
|
||||
}
|
||||
openIMHttp.RespHttp200(c, constant.OK, nil)
|
||||
@@ -311,7 +311,7 @@ func AddGroupMembers(c *gin.Context) {
|
||||
respPb, err := client.AddGroupMembersCMS(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(reqPb.OperationId, utils.GetSelfFuncName(), "AddGroupMembersCMS failed", err.Error())
|
||||
openIMHttp.RespHttp200(c, constant.ErrServer, nil)
|
||||
openIMHttp.RespHttp200(c, err, nil)
|
||||
return
|
||||
}
|
||||
resp.Success = respPb.Success
|
||||
@@ -337,7 +337,7 @@ func RemoveGroupMembers(c *gin.Context) {
|
||||
respPb, err := client.RemoveGroupMembersCMS(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "RemoveGroupMembersCMS failed", err.Error())
|
||||
openIMHttp.RespHttp200(c, constant.ErrServer, nil)
|
||||
openIMHttp.RespHttp200(c, err, nil)
|
||||
return
|
||||
}
|
||||
resp.Success = respPb.Success
|
||||
@@ -362,7 +362,7 @@ func DeleteGroup(c *gin.Context) {
|
||||
_, err := client.DeleteGroup(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "DeleteGroup failed", err.Error())
|
||||
openIMHttp.RespHttp200(c, constant.ErrServer, nil)
|
||||
openIMHttp.RespHttp200(c, err, nil)
|
||||
return
|
||||
}
|
||||
openIMHttp.RespHttp200(c, constant.OK, nil)
|
||||
|
||||
@@ -33,10 +33,32 @@ func BroadcastMessage(c *gin.Context) {
|
||||
}
|
||||
|
||||
func MassSendMassage(c *gin.Context) {
|
||||
var (
|
||||
reqPb pbMessage.MassSendMessageReq
|
||||
)
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMessageCMSName)
|
||||
client := pbMessage.NewMessageCMSClient(etcdConn)
|
||||
_, err := client.MassSendMessage(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetChatLogs rpc failed", err.Error())
|
||||
openIMHttp.RespHttp200(c, err, nil)
|
||||
return
|
||||
}
|
||||
openIMHttp.RespHttp200(c, constant.OK, nil)
|
||||
}
|
||||
|
||||
func WithdrawMessage(c *gin.Context) {
|
||||
var (
|
||||
reqPb pbMessage.WithdrawMessageReq
|
||||
)
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMessageCMSName)
|
||||
client := pbMessage.NewMessageCMSClient(etcdConn)
|
||||
_, err := client.WithdrawMessage(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetChatLogs rpc failed", err.Error())
|
||||
openIMHttp.RespHttp200(c, err, nil)
|
||||
return
|
||||
}
|
||||
openIMHttp.RespHttp200(c, constant.OK, nil)
|
||||
}
|
||||
|
||||
@@ -64,6 +86,24 @@ func GetChatLogs(c *gin.Context) {
|
||||
openIMHttp.RespHttp200(c, err, resp)
|
||||
return
|
||||
}
|
||||
utils.CopyStructFields(&resp, &respPb)
|
||||
//utils.CopyStructFields(&resp, &respPb)
|
||||
for _, chatLog := range respPb.ChatLogs {
|
||||
resp.ChatLogs = append(resp.ChatLogs, cms_api_struct.ChatLog{
|
||||
SessionType: int(chatLog.SessionType),
|
||||
ContentType: int(chatLog.ContentType),
|
||||
SenderNickName: chatLog.SenderNickName,
|
||||
SenderId: chatLog.SenderId,
|
||||
SearchContent: chatLog.SearchContent,
|
||||
WholeContent: chatLog.WholeContent,
|
||||
ReceiverNickName: chatLog.ReciverNickName,
|
||||
ReceiverID: chatLog.ReciverId,
|
||||
GroupName: chatLog.GroupName,
|
||||
GroupId: chatLog.GroupId,
|
||||
Date: chatLog.Date,
|
||||
})
|
||||
}
|
||||
resp.ShowNumber = int(respPb.Pagination.ShowNumber)
|
||||
resp.CurrentPage = int(respPb.Pagination.CurrentPage)
|
||||
resp.ChatLogsNum = int(respPb.ChatLogsNum)
|
||||
openIMHttp.RespHttp200(c, constant.OK, resp)
|
||||
}
|
||||
|
||||
@@ -66,20 +66,16 @@ func (s *adminCMSServer) Run() {
|
||||
func (s *adminCMSServer) AdminLogin(_ context.Context, req *pbAdminCMS.AdminLoginReq) (*pbAdminCMS.AdminLoginResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp := &pbAdminCMS.AdminLoginResp{}
|
||||
for _, adminID := range config.Config.Manager.AppManagerUid{
|
||||
if adminID == req.AdminID {
|
||||
for _, secret := range config.Config.Manager.Secrets {
|
||||
if secret == req.Secret {
|
||||
token, expTime, err := token_verify.CreateToken(adminID,9843)
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "generate token success", "token: ", token, "expTime:", expTime)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "generate token failed", "adminID: ", adminID, err.Error())
|
||||
return resp, openIMHttp.WrapError(constant.ErrTokenUnknown)
|
||||
}
|
||||
resp.Token = token
|
||||
break
|
||||
}
|
||||
for i, adminID := range config.Config.Manager.AppManagerUid{
|
||||
if adminID == req.AdminID && config.Config.Manager.Secrets[i] == req.Secret {
|
||||
token, expTime, err := token_verify.CreateToken(adminID, constant.SingleChatType)
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "generate token success", "token: ", token, "expTime:", expTime)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "generate token failed", "adminID: ", adminID, err.Error())
|
||||
return resp, openIMHttp.WrapError(constant.ErrTokenUnknown)
|
||||
}
|
||||
resp.Token = token
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -87,13 +87,13 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
|
||||
err := imdb.InsertIntoGroup(groupInfo)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "InsertIntoGroup failed, ", err.Error(), groupInfo)
|
||||
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
|
||||
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, http.WrapError(constant.ErrDB)
|
||||
}
|
||||
|
||||
us, err := imdb.GetUserByUserID(req.OwnerUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetUserByUserID failed ", err.Error(), req.OwnerUserID)
|
||||
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
|
||||
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, http.WrapError(constant.ErrDB)
|
||||
}
|
||||
|
||||
//to group member
|
||||
@@ -102,7 +102,7 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
|
||||
err = imdb.InsertIntoGroupMember(groupMember)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "InsertIntoGroupMember failed ", err.Error(), groupMember)
|
||||
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
|
||||
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, http.WrapError(constant.ErrDB)
|
||||
}
|
||||
|
||||
err = db.DB.AddGroupMember(groupId, req.OwnerUserID)
|
||||
@@ -830,6 +830,14 @@ func (s *groupServer) RemoveGroupMembersCMS(_ context.Context, req *pbGroup.Remo
|
||||
resp.Success = append(resp.Success, userId)
|
||||
}
|
||||
}
|
||||
reqKick := &pbGroup.KickGroupMemberReq{
|
||||
GroupID: req.GroupId,
|
||||
KickedUserIDList: resp.Success,
|
||||
Reason: "admin kick",
|
||||
OperationID: req.OperationID,
|
||||
OpUserID: req.OpUserId,
|
||||
}
|
||||
chat.MemberKickedNotification(reqKick, resp.Success)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -864,7 +872,9 @@ func (s *groupServer) AddGroupMembersCMS(_ context.Context, req *pbGroup.AddGrou
|
||||
resp.Failed = append(resp.Failed, userId)
|
||||
} else {
|
||||
resp.Success = append(resp.Success, userId)
|
||||
chat.MemberInvitedNotification(req.OperationId, req.GroupId, req.OpUserId, "admin add", resp.Success)
|
||||
}
|
||||
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
@@ -899,8 +909,6 @@ func (s *groupServer) GetUserReqApplicationList(_ context.Context, req *pbGroup.
|
||||
cp.GroupDBCopyOpenIM(node.GroupInfo, group)
|
||||
resp.GroupRequestList = append(resp.GroupRequestList, &node)
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), groupRequests)
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "output:", resp)
|
||||
resp.CommonResp = &pbGroup.CommonResp{
|
||||
ErrCode: 0,
|
||||
ErrMsg: "",
|
||||
|
||||
@@ -86,6 +86,20 @@ func (s *messageCMSServer) GetChatLogs(_ context.Context, req *pbMessageCMS.GetC
|
||||
chatLog := db.ChatLog{
|
||||
Content: req.Content,
|
||||
SendTime: time,
|
||||
ContentType: req.ContentType,
|
||||
SessionType: req.SessionType,
|
||||
}
|
||||
switch chatLog.SessionType {
|
||||
case constant.SingleChatType:
|
||||
chatLog.SendID = req.UserId
|
||||
case constant.GroupChatType:
|
||||
chatLog.RecvID = req.GroupId
|
||||
chatLog.SendID = req.UserId
|
||||
}
|
||||
nums, err := imdb.GetChatLogCount(chatLog)
|
||||
resp.ChatLogsNum = int32(nums)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetChatLogCount", err.Error())
|
||||
}
|
||||
chatLogs, err := imdb.GetChatLog(chatLog, req.Pagination.PageNumber, req.Pagination.ShowNumber)
|
||||
if err != nil {
|
||||
@@ -96,11 +110,19 @@ func (s *messageCMSServer) GetChatLogs(_ context.Context, req *pbMessageCMS.GetC
|
||||
pbChatLog := &pbMessageCMS.ChatLogs{
|
||||
SessionType: chatLog.SessionType,
|
||||
ContentType: chatLog.ContentType,
|
||||
SenderNickName: chatLog.SenderNickname,
|
||||
SenderId: chatLog.SendID,
|
||||
SearchContent: req.Content,
|
||||
WholeContent: chatLog.Content,
|
||||
Date: chatLog.CreateTime.String(),
|
||||
SenderNickName: chatLog.SenderNickname,
|
||||
SenderId: chatLog.SendID,
|
||||
}
|
||||
if chatLog.SenderNickname == "" {
|
||||
sendUser, err := imdb.GetUserByUserID(chatLog.SendID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserByUserID failed", err.Error())
|
||||
continue
|
||||
}
|
||||
pbChatLog.SenderNickName = sendUser.Nickname
|
||||
}
|
||||
switch chatLog.SessionType {
|
||||
case constant.SingleChatType:
|
||||
@@ -111,6 +133,7 @@ func (s *messageCMSServer) GetChatLogs(_ context.Context, req *pbMessageCMS.GetC
|
||||
}
|
||||
pbChatLog.ReciverId = recvUser.UserID
|
||||
pbChatLog.ReciverNickName = recvUser.Nickname
|
||||
|
||||
case constant.GroupChatType:
|
||||
group, err := imdb.GetGroupById(chatLog.RecvID)
|
||||
if err != nil {
|
||||
@@ -126,6 +149,7 @@ func (s *messageCMSServer) GetChatLogs(_ context.Context, req *pbMessageCMS.GetC
|
||||
CurrentPage: req.Pagination.PageNumber,
|
||||
ShowNumber: req.Pagination.ShowNumber,
|
||||
}
|
||||
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp output: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -219,7 +219,6 @@ func (s *statisticsServer) GetGroupStatistics(_ context.Context, req *pbStatisti
|
||||
wg := &sync.WaitGroup{}
|
||||
resp.IncreaseGroupNumList = make([]*pbStatistics.DateNumList, len(times), len(times))
|
||||
resp.TotalGroupNumList = make([]*pbStatistics.DateNumList, len(times), len(times))
|
||||
log.NewInfo(req.OperationID, resp.TotalGroupNumList, resp.TotalGroupNumList)
|
||||
wg.Add(len(times))
|
||||
for i, v := range times {
|
||||
go func(wg *sync.WaitGroup, index int, v [2]time.Time) {
|
||||
@@ -232,7 +231,7 @@ func (s *statisticsServer) GetGroupStatistics(_ context.Context, req *pbStatisti
|
||||
Date: v[0].String(),
|
||||
Num: num,
|
||||
}
|
||||
num, err = imdb.GetGroupNum(v[0])
|
||||
num, err = imdb.GetGroupNum(v[1])
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetIncreaseGroupNum", v, err.Error())
|
||||
}
|
||||
@@ -273,6 +272,7 @@ func (s *statisticsServer) GetMessageStatistics(_ context.Context, req *pbStatis
|
||||
for i, v := range times {
|
||||
go func(wg *sync.WaitGroup, index int, v [2]time.Time) {
|
||||
defer wg.Done()
|
||||
|
||||
num, err := imdb.GetPrivateMessageNum(v[0], v[1])
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetIncreaseGroupNum", v, err.Error())
|
||||
@@ -338,7 +338,8 @@ func (s *statisticsServer) GetUserStatistics(_ context.Context, req *pbStatistic
|
||||
Date: v[0].String(),
|
||||
Num: num,
|
||||
}
|
||||
num, err = imdb.GetTotalUserNumByDate(v[0])
|
||||
|
||||
num, err = imdb.GetTotalUserNumByDate(v[1])
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetTotalUserNumByDate", v, err.Error())
|
||||
}
|
||||
|
||||
@@ -357,6 +357,7 @@ func (s *userServer) AlterUser(ctx context.Context, req *pbUser.AlterUserReq) (*
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "UpdateUserInfo", err.Error())
|
||||
return resp, errors.WrapError(constant.ErrDB)
|
||||
}
|
||||
chat.UserInfoUpdatedNotification(req.OperationID, req.UserId, req.OpUserId)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user