mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
rpc services update
This commit is contained in:
parent
9db427de70
commit
59522ea387
@ -3,9 +3,9 @@ package rpcAuth
|
||||
import (
|
||||
"Open_IM/src/common/config"
|
||||
log2 "Open_IM/src/common/log"
|
||||
"Open_IM/src/grpc-etcdv3/getcdv3"
|
||||
pbAuth "Open_IM/src/proto/auth"
|
||||
"Open_IM/src/utils"
|
||||
"github.com/skiffer-git/grpc-etcdv3/getcdv3"
|
||||
"google.golang.org/grpc"
|
||||
"net"
|
||||
"strconv"
|
||||
|
@ -4,9 +4,9 @@ import (
|
||||
"Open_IM/src/common/config"
|
||||
"Open_IM/src/common/kafka"
|
||||
log2 "Open_IM/src/common/log"
|
||||
"Open_IM/src/grpc-etcdv3/getcdv3"
|
||||
pbChat "Open_IM/src/proto/chat"
|
||||
"Open_IM/src/utils"
|
||||
"github.com/skiffer-git/grpc-etcdv3/getcdv3"
|
||||
"google.golang.org/grpc"
|
||||
"net"
|
||||
"strconv"
|
||||
|
@ -1,16 +1,18 @@
|
||||
package rpcChat
|
||||
|
||||
import (
|
||||
"Open_IM/src/api/group"
|
||||
"Open_IM/src/common/config"
|
||||
"Open_IM/src/common/constant"
|
||||
http2 "Open_IM/src/common/http"
|
||||
"Open_IM/src/common/log"
|
||||
"Open_IM/src/grpc-etcdv3/getcdv3"
|
||||
pbChat "Open_IM/src/proto/chat"
|
||||
pbGroup "Open_IM/src/proto/group"
|
||||
"Open_IM/src/push/content_struct"
|
||||
"Open_IM/src/utils"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/skiffer-git/grpc-etcdv3/getcdv3"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"strconv"
|
||||
@ -110,11 +112,38 @@ func (rpc *rpcChat) UserSendMsg(_ context.Context, pb *pbChat.UserSendMsgReq) (*
|
||||
log.Error(pbData.Token, pbData.OperationID, "rpc send_msg getGroupInfo failed, err = %s", reply.ErrorMsg)
|
||||
return returnMsg(&replay, pb, reply.ErrorCode, reply.ErrorMsg, "", 0)
|
||||
}
|
||||
var addUidList []string
|
||||
switch pbData.ContentType {
|
||||
case constant.KickGroupMemberTip:
|
||||
var notification content_struct.NotificationContent
|
||||
var kickContent group.KickGroupMemberReq
|
||||
err := utils.JsonStringToStruct(pbData.Content, ¬ification)
|
||||
if err != nil {
|
||||
log.ErrorByKv("json unmarshall err", pbData.OperationID, "err", err.Error())
|
||||
return returnMsg(&replay, pb, 200, err.Error(), "", 0)
|
||||
} else {
|
||||
err := utils.JsonStringToStruct(notification.Detail, &kickContent)
|
||||
if err != nil {
|
||||
log.ErrorByKv("json unmarshall err", pbData.OperationID, "err", err.Error())
|
||||
return returnMsg(&replay, pb, 200, err.Error(), "", 0)
|
||||
}
|
||||
for _, v := range kickContent.UidListInfo {
|
||||
addUidList = append(addUidList, v.UserId)
|
||||
}
|
||||
}
|
||||
case constant.QuitGroupTip:
|
||||
addUidList = append(addUidList, pbData.SendID)
|
||||
default:
|
||||
}
|
||||
groupID := pbData.RecvID
|
||||
for i, v := range reply.MemberList {
|
||||
pbData.RecvID = v.UserId + " " + groupID
|
||||
rpc.sendMsgToKafka(&pbData, utils.IntToString(i))
|
||||
}
|
||||
for i, v := range addUidList {
|
||||
pbData.RecvID = v + " " + groupID
|
||||
rpc.sendMsgToKafka(&pbData, utils.IntToString(i+1))
|
||||
}
|
||||
return returnMsg(&replay, pb, 0, "", serverMsgID, pbData.SendTime)
|
||||
default:
|
||||
|
||||
|
@ -5,11 +5,11 @@ import (
|
||||
"Open_IM/src/common/constant"
|
||||
"Open_IM/src/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/src/common/log"
|
||||
"Open_IM/src/grpc-etcdv3/getcdv3"
|
||||
pbFriend "Open_IM/src/proto/friend"
|
||||
"Open_IM/src/utils"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/skiffer-git/grpc-etcdv3/getcdv3"
|
||||
"google.golang.org/grpc"
|
||||
"net"
|
||||
"strconv"
|
||||
|
@ -3,12 +3,14 @@ package group
|
||||
import (
|
||||
"Open_IM/src/common/config"
|
||||
"Open_IM/src/common/constant"
|
||||
"Open_IM/src/common/db"
|
||||
"Open_IM/src/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/src/common/log"
|
||||
"Open_IM/src/grpc-etcdv3/getcdv3"
|
||||
pbGroup "Open_IM/src/proto/group"
|
||||
"Open_IM/src/utils"
|
||||
"context"
|
||||
"github.com/skiffer-git/grpc-etcdv3/getcdv3"
|
||||
"fmt"
|
||||
"google.golang.org/grpc"
|
||||
"net"
|
||||
"strconv"
|
||||
@ -74,7 +76,7 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
|
||||
return &pbGroup.CreateGroupResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
//Time stamp + MD5 to generate group chat id
|
||||
groupId = utils.Md5(strconv.FormatInt(time.Now().Unix(), 10))
|
||||
groupId = utils.Md5(strconv.FormatInt(time.Now().UnixNano(), 10))
|
||||
err = im_mysql_model.InsertIntoGroup(groupId, req.GroupName, req.Introduction, req.Notification, req.FaceUrl)
|
||||
if err != nil {
|
||||
log.ErrorByKv("create group chat failed", req.OperationID, "err=%s", err.Error())
|
||||
@ -82,17 +84,38 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
|
||||
}
|
||||
|
||||
//Add the group owner to the group first, otherwise the group creation will fail
|
||||
err = im_mysql_model.InsertIntoGroupMember(groupId, claims.UID, "", "", constant.GroupCreator)
|
||||
us, err := im_mysql_model.FindUserByUID(claims.UID)
|
||||
if err != nil {
|
||||
log.Error("", req.OperationID, "find userInfo failed", err.Error())
|
||||
return &pbGroup.CreateGroupResp{ErrorCode: config.ErrCreateGroup.ErrCode, ErrorMsg: config.ErrCreateGroup.ErrMsg}, nil
|
||||
}
|
||||
err = im_mysql_model.InsertIntoGroupMember(groupId, claims.UID, us.Name, us.Icon, constant.GroupOwner)
|
||||
if err != nil {
|
||||
log.Error("", req.OperationID, "create group chat failed,err=%s", err.Error())
|
||||
return &pbGroup.CreateGroupResp{ErrorCode: config.ErrCreateGroup.ErrCode, ErrorMsg: config.ErrCreateGroup.ErrMsg}, nil
|
||||
}
|
||||
|
||||
err = db.DB.AddGroupMember(groupId, claims.UID)
|
||||
if err != nil {
|
||||
log.Error("", "", "create mongo group member failed, db.DB.AddGroupMember fail [err: %s]", err.Error())
|
||||
return &pbGroup.CreateGroupResp{ErrorCode: config.ErrCreateGroup.ErrCode, ErrorMsg: config.ErrCreateGroup.ErrMsg}, nil
|
||||
}
|
||||
|
||||
//Binding group id and member id
|
||||
for _, user := range req.MemberList {
|
||||
err = im_mysql_model.InsertIntoGroupMember(groupId, user.Uid, "", "", user.SetRole)
|
||||
us, err := im_mysql_model.FindUserByUID(user.Uid)
|
||||
if err != nil {
|
||||
log.Error("", req.OperationID, "find userInfo failed,uid=%s", user.Uid, err.Error())
|
||||
continue
|
||||
}
|
||||
err = im_mysql_model.InsertIntoGroupMember(groupId, user.Uid, us.Name, us.Icon, user.SetRole)
|
||||
if err != nil {
|
||||
log.ErrorByArgs("pull %s to group %s failed,err=%s", user.Uid, groupId, err.Error())
|
||||
}
|
||||
err = db.DB.AddGroupMember(groupId, user.Uid)
|
||||
if err != nil {
|
||||
log.Error("", "", "add mongo group member failed, db.DB.AddGroupMember fail [err: %s]", err.Error())
|
||||
}
|
||||
}
|
||||
////Push message when create group chat
|
||||
//logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
|
||||
@ -106,5 +129,10 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
|
||||
// OperationID: req.OperationID,
|
||||
//})
|
||||
log.Info(req.Token, req.OperationID, "rpc create group success return")
|
||||
|
||||
t := db.DB.GetGroupMember(groupId)
|
||||
fmt.Println("YYYYYYYYYYYYYYYYYYYYYYYYYYYYYY")
|
||||
fmt.Println(t)
|
||||
|
||||
return &pbGroup.CreateGroupResp{GroupID: groupId}, nil
|
||||
}
|
||||
|
@ -17,14 +17,9 @@ func (s *groupServer) GetGroupsInfo(ctx context.Context, req *pbGroup.GetGroupsI
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbGroup.GetGroupsInfoResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
log.Info("", req.OperationID, "args:", req.GroupIDList, claims.UID)
|
||||
groupsInfoList := make([]*pbGroup.GroupInfo, 0)
|
||||
for _, groupID := range req.GroupIDList {
|
||||
// Get group information to check whether the current user is in the current group
|
||||
_, err = im_mysql_model.FindGroupMemberInfoByGroupIdAndUserId(groupID, claims.UID)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "find group member failed,err=%s", err.Error())
|
||||
continue
|
||||
}
|
||||
groupInfoFromMysql, err := im_mysql_model.FindGroupInfoByGroupId(groupID)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "find group info failed,err=%s", err.Error())
|
||||
@ -36,6 +31,7 @@ func (s *groupServer) GetGroupsInfo(ctx context.Context, req *pbGroup.GetGroupsI
|
||||
groupInfo.Introduction = groupInfoFromMysql.Introduction
|
||||
groupInfo.Notification = groupInfoFromMysql.Notification
|
||||
groupInfo.FaceUrl = groupInfoFromMysql.FaceUrl
|
||||
groupInfo.OwnerId = im_mysql_model.GetGroupOwnerByGroupId(groupID)
|
||||
groupInfo.MemberCount = uint32(im_mysql_model.GetGroupMemberNumByGroupId(groupID))
|
||||
groupInfo.CreateTime = uint64(groupInfoFromMysql.CreateTime.Unix())
|
||||
|
||||
|
@ -2,15 +2,14 @@ package group
|
||||
|
||||
import (
|
||||
"Open_IM/src/common/config"
|
||||
"Open_IM/src/common/constant"
|
||||
"Open_IM/src/common/db"
|
||||
|
||||
imdb "Open_IM/src/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/src/common/log"
|
||||
pbChat "Open_IM/src/proto/chat"
|
||||
pbGroup "Open_IM/src/proto/group"
|
||||
"Open_IM/src/push/logic"
|
||||
"Open_IM/src/utils"
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"fmt"
|
||||
)
|
||||
|
||||
@ -36,6 +35,7 @@ func (s *groupServer) GetJoinedGroupList(ctx context.Context, req *pbGroup.GetJo
|
||||
owner := imdb.GetGroupOwnerByGroupId(v.GroupId)
|
||||
group, err := imdb.FindGroupInfoByGroupId(v.GroupId)
|
||||
if num > 0 && owner != "" && err == nil {
|
||||
groupNode.GroupId = v.GroupId
|
||||
groupNode.FaceUrl = group.FaceUrl
|
||||
groupNode.CreateTime = uint64(group.CreateTime.Unix())
|
||||
groupNode.GroupName = group.Name
|
||||
@ -58,16 +58,23 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
|
||||
return &pbGroup.InviteUserToGroupResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
log.Info(claims.UID, req.OperationID, "recv req: ", req.String())
|
||||
|
||||
if !imdb.IsExistGroupMember(req.GroupID, claims.UID) {
|
||||
log.Error(req.Token, req.OperationID, "err= invite user not in group")
|
||||
return &pbGroup.InviteUserToGroupResp{ErrorCode: config.ErrAccess.ErrCode, ErrorMsg: config.ErrAccess.ErrMsg}, nil
|
||||
}
|
||||
|
||||
//
|
||||
//from User: invite: applicant
|
||||
//to user: invite: invited
|
||||
//to application
|
||||
var resp pbGroup.InviteUserToGroupResp
|
||||
fromUserInfo, err := imdb.FindUserByUID(claims.UID)
|
||||
if err != nil {
|
||||
log.Error(claims.UID, req.OperationID, "FindUserByUID failed, err: ", err.Error())
|
||||
return &pbGroup.InviteUserToGroupResp{ErrorCode: config.ErrParam.ErrCode, ErrorMsg: config.ErrParam.ErrMsg}, nil
|
||||
}
|
||||
/*
|
||||
fromUserInfo, err := imdb.FindUserByUID(claims.UID)
|
||||
if err != nil {
|
||||
log.Error(claims.UID, req.OperationID, "FindUserByUID failed, err: ", err.Error())
|
||||
return &pbGroup.InviteUserToGroupResp{ErrorCode: config.ErrParam.ErrCode, ErrorMsg: config.ErrParam.ErrMsg}, nil
|
||||
}*/
|
||||
|
||||
for _, v := range req.UidList {
|
||||
var resultNode pbGroup.Id2Result
|
||||
@ -80,14 +87,24 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
|
||||
resp.Id2Result = append(resp.Id2Result, &resultNode)
|
||||
continue
|
||||
}
|
||||
err = imdb.InsertGroupRequest(req.GroupID, fromUserInfo.UID, fromUserInfo.Name, fromUserInfo.Icon, toUserInfo.UID, req.Reason, "invited", 1)
|
||||
if err != nil {
|
||||
log.Error(v, req.OperationID, "InsertGroupRequest failed, err: ", err.Error(), "params: ",
|
||||
req.GroupID, fromUserInfo.UID, fromUserInfo.Name, fromUserInfo.Icon, toUserInfo.UID, req.Reason)
|
||||
|
||||
if imdb.IsExistGroupMember(req.GroupID, v) {
|
||||
log.Error(v, req.OperationID, "user has already in group")
|
||||
resultNode.Result = -1
|
||||
resp.Id2Result = append(resp.Id2Result, &resultNode)
|
||||
continue
|
||||
}
|
||||
/*
|
||||
err = imdb.InsertGroupRequest(req.GroupID, fromUserInfo.UID, fromUserInfo.Name, fromUserInfo.Icon, toUserInfo.UID, req.Reason, "invited", 1)
|
||||
if err != nil {
|
||||
log.Error(v, req.OperationID, "InsertGroupRequest failed, err: ", err.Error(), "params: ",
|
||||
req.GroupID, fromUserInfo.UID, fromUserInfo.Name, fromUserInfo.Icon, toUserInfo.UID, req.Reason)
|
||||
resultNode.Result = -1
|
||||
resp.Id2Result = append(resp.Id2Result, &resultNode)
|
||||
continue
|
||||
}
|
||||
*/
|
||||
|
||||
err = imdb.InsertGroupMember(req.GroupID, toUserInfo.UID, toUserInfo.Name, toUserInfo.Icon, 0)
|
||||
if err != nil {
|
||||
log.Error(v, req.OperationID, "InsertGroupMember failed, ", err.Error(), "params: ",
|
||||
@ -96,21 +113,31 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
|
||||
resp.Id2Result = append(resp.Id2Result, &resultNode)
|
||||
continue
|
||||
}
|
||||
err = db.DB.AddGroupMember(req.GroupID, toUserInfo.UID)
|
||||
if err != nil {
|
||||
log.Error("", "", "add mongo group member failed, db.DB.AddGroupMember fail [err: %s]", err.Error())
|
||||
}
|
||||
|
||||
resp.Id2Result = append(resp.Id2Result, &resultNode)
|
||||
}
|
||||
resp.ErrorCode = 0
|
||||
resp.ErrorMsg = "ok"
|
||||
/*
|
||||
var chatMsg pbChat.WSToMsgSvrChatMsg
|
||||
chatMsg.SendID = claims.UID
|
||||
chatMsg.RecvID = req.GroupID
|
||||
content, _ := json.Marshal(req)
|
||||
chatMsg.Content = string(content)
|
||||
chatMsg.SendTime = utils.GetCurrentTimestampBySecond()
|
||||
chatMsg.MsgFrom = constant.UserMsgType
|
||||
chatMsg.ContentType = constant.InviteUserToGroupTip
|
||||
chatMsg.SessionType = constant.GroupChatType
|
||||
logic.SendMsgByWS(&chatMsg)
|
||||
*/
|
||||
|
||||
var chatMsg pbChat.WSToMsgSvrChatMsg
|
||||
chatMsg.SendID = claims.UID
|
||||
chatMsg.RecvID = req.GroupID
|
||||
content, _ := json.Marshal(req)
|
||||
chatMsg.Content = string(content)
|
||||
chatMsg.SendTime = utils.GetCurrentTimestampBySecond()
|
||||
chatMsg.MsgFrom = constant.UserMsgType
|
||||
chatMsg.ContentType = constant.InviteUserToGroupTip
|
||||
chatMsg.SessionType = constant.GroupChatType
|
||||
logic.SendMsgByWS(&chatMsg)
|
||||
t := db.DB.GetGroupMember(req.GroupID)
|
||||
fmt.Println("YYYYYYYYYYYYYYYYYYYYYYYYYYYYYY")
|
||||
fmt.Println(t)
|
||||
|
||||
return &resp, nil
|
||||
}
|
||||
@ -139,6 +166,7 @@ func (s *groupServer) GetGroupAllMember(ctx context.Context, req *pbGroup.GetGro
|
||||
node.Role = v.AdministratorLevel
|
||||
node.NickName = v.NickName
|
||||
node.UserId = v.Uid
|
||||
node.FaceUrl = v.UserGroupFaceUrl
|
||||
node.JoinTime = uint64(v.JoinTime.Unix())
|
||||
resp.MemberList = append(resp.MemberList, &node)
|
||||
}
|
||||
@ -211,46 +239,58 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
|
||||
return &pbGroup.KickGroupMemberResp{ErrorCode: config.ErrAccess.ErrCode, ErrorMsg: config.ErrAccess.ErrMsg}, nil
|
||||
}
|
||||
|
||||
if len(req.UidList) == 0 {
|
||||
if len(req.UidListInfo) == 0 {
|
||||
log.Error(claims.UID, req.OperationID, "kick list 0")
|
||||
return &pbGroup.KickGroupMemberResp{ErrorCode: config.ErrParam.ErrCode, ErrorMsg: config.ErrParam.ErrMsg}, nil
|
||||
}
|
||||
//remove
|
||||
var resp pbGroup.KickGroupMemberResp
|
||||
for _, v := range req.UidList {
|
||||
for _, v := range req.UidListInfo {
|
||||
//owner cant kicked
|
||||
if v == claims.UID {
|
||||
log.Error(claims.UID, req.OperationID, v, "cant kick owner")
|
||||
resp.Id2Result = append(resp.Id2Result, &pbGroup.Id2Result{UId: v, Result: -1})
|
||||
if v.UserId == claims.UID {
|
||||
log.Error(claims.UID, req.OperationID, v.UserId, "cant kick owner")
|
||||
resp.Id2Result = append(resp.Id2Result, &pbGroup.Id2Result{UId: v.UserId, Result: -1})
|
||||
continue
|
||||
}
|
||||
err := imdb.RemoveGroupMember(req.GroupID, v)
|
||||
err := imdb.RemoveGroupMember(req.GroupID, v.UserId)
|
||||
if err != nil {
|
||||
log.Error(claims.UID, req.OperationID, v, req.GroupID, "RemoveGroupMember failed ", err.Error())
|
||||
resp.Id2Result = append(resp.Id2Result, &pbGroup.Id2Result{UId: v, Result: -1})
|
||||
log.Error(claims.UID, req.OperationID, v.UserId, req.GroupID, "RemoveGroupMember failed ", err.Error())
|
||||
resp.Id2Result = append(resp.Id2Result, &pbGroup.Id2Result{UId: v.UserId, Result: -1})
|
||||
} else {
|
||||
resp.Id2Result = append(resp.Id2Result, &pbGroup.Id2Result{UId: v, Result: 0})
|
||||
resp.Id2Result = append(resp.Id2Result, &pbGroup.Id2Result{UId: v.UserId, Result: 0})
|
||||
}
|
||||
|
||||
err = db.DB.DelGroupMember(req.GroupID, v.UserId)
|
||||
if err != nil {
|
||||
log.Error("", "", "delete mongo group member failed, db.DB.DelGroupMember fail [err: %s]", err.Error())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var chatMsg pbChat.WSToMsgSvrChatMsg
|
||||
chatMsg.SendID = claims.UID
|
||||
chatMsg.RecvID = req.GroupID
|
||||
content, _ := json.Marshal(req)
|
||||
chatMsg.Content = string(content)
|
||||
chatMsg.SendTime = utils.GetCurrentTimestampBySecond()
|
||||
chatMsg.MsgFrom = constant.UserMsgType
|
||||
chatMsg.ContentType = constant.KickGroupMemberTip
|
||||
chatMsg.SessionType = constant.GroupChatType
|
||||
logic.SendMsgByWS(&chatMsg)
|
||||
/*
|
||||
var chatMsg pbChat.WSToMsgSvrChatMsg
|
||||
chatMsg.SendID = claims.UID
|
||||
chatMsg.RecvID = req.GroupID
|
||||
content, _ := json.Marshal(req)
|
||||
chatMsg.Content = string(content)
|
||||
chatMsg.SendTime = utils.GetCurrentTimestampBySecond()
|
||||
chatMsg.MsgFrom = constant.UserMsgType
|
||||
chatMsg.ContentType = constant.KickGroupMemberTip
|
||||
chatMsg.SessionType = constant.GroupChatType
|
||||
logic.SendMsgByWS(&chatMsg)
|
||||
|
||||
for _, v := range req.UidList {
|
||||
kickChatMsg := chatMsg
|
||||
kickChatMsg.RecvID = v
|
||||
kickChatMsg.SendTime = utils.GetCurrentTimestampBySecond()
|
||||
kickChatMsg.SessionType = constant.SingleChatType
|
||||
logic.SendMsgByWS(&kickChatMsg)
|
||||
}
|
||||
for _, v := range req.UidList {
|
||||
kickChatMsg := chatMsg
|
||||
kickChatMsg.RecvID = v
|
||||
kickChatMsg.SendTime = utils.GetCurrentTimestampBySecond()
|
||||
kickChatMsg.SessionType = constant.SingleChatType
|
||||
logic.SendMsgByWS(&kickChatMsg)
|
||||
}
|
||||
*/
|
||||
|
||||
t := db.DB.GetGroupMember(req.GroupID)
|
||||
fmt.Println("YYYYYYYYYYYYYYYYYYYYYYYYYYYYYY")
|
||||
fmt.Println(t)
|
||||
|
||||
resp.ErrorCode = 0
|
||||
return &resp, nil
|
||||
|
@ -1,16 +1,12 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"Open_IM/src/common/constant"
|
||||
"Open_IM/src/common/db"
|
||||
"Open_IM/src/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/src/common/log"
|
||||
pbChat "Open_IM/src/proto/chat"
|
||||
"Open_IM/src/proto/group"
|
||||
"Open_IM/src/push/content_struct"
|
||||
"Open_IM/src/push/logic"
|
||||
"Open_IM/src/utils"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func (s *groupServer) GroupApplicationResponse(_ context.Context, pb *group.GroupApplicationResponseReq) (*group.GroupApplicationResponseResp, error) {
|
||||
@ -21,70 +17,28 @@ func (s *groupServer) GroupApplicationResponse(_ context.Context, pb *group.Grou
|
||||
log.Error("", "", "rpc GroupApplicationResponse call..., im_mysql_model.GroupApplicationResponse fail [pb: %s] [err: %s]", pb.String(), err.Error())
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if pb.HandleResult == 1 {
|
||||
if pb.ToUserID == "0" {
|
||||
err = db.DB.AddGroupMember(pb.GroupID, pb.FromUserID)
|
||||
if err != nil {
|
||||
log.Error("", "", "rpc GroupApplicationResponse call..., db.DB.AddGroupMember fail [pb: %s] [err: %s]", pb.String(), err.Error())
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
err = db.DB.AddGroupMember(pb.GroupID, pb.ToUserID)
|
||||
if err != nil {
|
||||
log.Error("", "", "rpc GroupApplicationResponse call..., db.DB.AddGroupMember fail [pb: %s] [err: %s]", pb.String(), err.Error())
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
t := db.DB.GetGroupMember(pb.GroupID)
|
||||
fmt.Println("YYYYYYYYYYYYYYYYYYYYYYYYYYYYYY")
|
||||
fmt.Println(t)
|
||||
|
||||
log.Info("", "", "rpc GroupApplicationResponse call..., im_mysql_model.GroupApplicationResponse")
|
||||
|
||||
if pb.HandleResult == 1 {
|
||||
logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
|
||||
SendID: pb.OwnerID,
|
||||
RecvID: pb.GroupID,
|
||||
Content: pb.String(),
|
||||
SendTime: utils.GetCurrentTimestampBySecond(),
|
||||
MsgFrom: constant.SysMsgType,
|
||||
ContentType: constant.AcceptGroupApplicationTip,
|
||||
SessionType: constant.GroupChatType,
|
||||
OperationID: pb.OperationID,
|
||||
})
|
||||
}
|
||||
|
||||
var recvID string
|
||||
if pb.ToUserID == "0" {
|
||||
recvID = pb.FromUserID
|
||||
} else {
|
||||
recvID = pb.ToUserID
|
||||
}
|
||||
|
||||
ownerUser, err := im_mysql_model.FindGroupMemberInfoByGroupIdAndUserId(pb.GroupID, pb.OwnerID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
agreeOrReject := content_struct.AgreeOrRejectGroupMember{
|
||||
GroupId: ownerUser.GroupId,
|
||||
UserId: ownerUser.Uid,
|
||||
Role: int(ownerUser.AdministratorLevel),
|
||||
JoinTime: uint64(ownerUser.JoinTime.Unix()),
|
||||
NickName: ownerUser.NickName,
|
||||
FaceUrl: ownerUser.UserGroupFaceUrl,
|
||||
Reason: pb.HandledMsg,
|
||||
}
|
||||
bAgreeOrReject, err := json.Marshal(agreeOrReject)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if pb.HandleResult == 1 {
|
||||
logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
|
||||
SendID: pb.OwnerID,
|
||||
RecvID: recvID,
|
||||
Content: string(bAgreeOrReject),
|
||||
SendTime: utils.GetCurrentTimestampBySecond(),
|
||||
MsgFrom: constant.SysMsgType,
|
||||
ContentType: constant.AcceptGroupApplicationResultTip,
|
||||
SessionType: constant.SingleChatType,
|
||||
OperationID: pb.OperationID,
|
||||
})
|
||||
} else {
|
||||
logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
|
||||
SendID: pb.OwnerID,
|
||||
RecvID: recvID,
|
||||
Content: string(bAgreeOrReject),
|
||||
SendTime: utils.GetCurrentTimestampBySecond(),
|
||||
MsgFrom: constant.SysMsgType,
|
||||
ContentType: constant.RefuseGroupApplicationResultTip,
|
||||
SessionType: constant.SingleChatType,
|
||||
OperationID: pb.OperationID,
|
||||
})
|
||||
}
|
||||
|
||||
return reply, nil
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package group
|
||||
|
||||
import (
|
||||
"Open_IM/src/common/config"
|
||||
"Open_IM/src/common/constant"
|
||||
"Open_IM/src/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/src/common/log"
|
||||
pbGroup "Open_IM/src/proto/group"
|
||||
@ -23,16 +22,14 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq)
|
||||
log.Error(req.Token, req.OperationID, "No this user,err=%s", err.Error())
|
||||
return &pbGroup.CommonResp{ErrorCode: config.ErrSearchUserInfo.ErrCode, ErrorMsg: config.ErrSearchUserInfo.ErrMsg}, nil
|
||||
}
|
||||
//todo Actively apply or be invited, apply to join the group and keep a record
|
||||
requestUserInfo, err := im_mysql_model.FindGroupRequestUserInfoByUidAndGroupID(req.GroupID, claims.UID)
|
||||
|
||||
_, err = im_mysql_model.FindGroupRequestUserInfoByGroupIDAndUid(req.GroupID, claims.UID)
|
||||
if err == nil {
|
||||
if requestUserInfo.Flag == constant.AgreeApplication {
|
||||
return &pbGroup.CommonResp{ErrorCode: config.ErrJoinGroupApplication.ErrCode, ErrorMsg: config.ErrJoinGroupApplication.ErrMsg}, nil
|
||||
}
|
||||
if requestUserInfo.Flag == constant.Application {
|
||||
err = im_mysql_model.DelGroupRequest(req.GroupID, claims.UID, "0")
|
||||
}
|
||||
err = im_mysql_model.DelGroupRequest(req.GroupID, claims.UID, "0")
|
||||
}
|
||||
|
||||
log.Info(req.Token, req.OperationID, "args: ", req.GroupID, claims.UID, "0", req.Message, applicationUserInfo.Name, applicationUserInfo.Icon)
|
||||
|
||||
if err = im_mysql_model.InsertIntoGroupRequest(req.GroupID, claims.UID, "0", req.Message, applicationUserInfo.Name, applicationUserInfo.Icon); err != nil {
|
||||
log.Error(req.Token, req.OperationID, "Insert into group request failed,er=%s", err.Error())
|
||||
return &pbGroup.CommonResp{ErrorCode: config.ErrJoinGroupApplication.ErrCode, ErrorMsg: config.ErrJoinGroupApplication.ErrMsg}, nil
|
||||
|
@ -2,31 +2,40 @@ package group
|
||||
|
||||
import (
|
||||
"Open_IM/src/common/config"
|
||||
"Open_IM/src/common/db"
|
||||
"Open_IM/src/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/src/common/log"
|
||||
pbGroup "Open_IM/src/proto/group"
|
||||
"Open_IM/src/utils"
|
||||
"context"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func (s *groupServer) QuitGroup(ctx context.Context, req *pbGroup.QuitGroupReq) (*pbGroup.CommonResp, error) {
|
||||
log.InfoByArgs("rpc quit group is server,args=%s", req.String())
|
||||
log.InfoByArgs("rpc quit group is server,args:", req.String())
|
||||
//Parse token, to find current user information
|
||||
claims, err := utils.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbGroup.CommonResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
//Check to see if there is a group and whether there is a user in the group.
|
||||
log.InfoByKv("args:", req.OperationID, req.GetGroupID(), claims.UID)
|
||||
//Check to see whether there is a user in the group.
|
||||
_, err = im_mysql_model.FindGroupMemberInfoByGroupIdAndUserId(req.GroupID, claims.UID)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "no such group or you are not in the group,err=%s", err.Error())
|
||||
log.Error(req.Token, req.OperationID, "no such group or you are not in the group,err=%s", err.Error(), req.OperationID, req.GroupID, claims.UID)
|
||||
return &pbGroup.CommonResp{ErrorCode: config.ErrQuitGroup.ErrCode, ErrorMsg: config.ErrQuitGroup.ErrMsg}, nil
|
||||
}
|
||||
//After the user's verification is successful, user will quit the group chat.
|
||||
err = im_mysql_model.DeleteGroupMemberByGroupIdAndUserId(req.GroupID, claims.UID)
|
||||
if err != nil {
|
||||
log.ErrorByArgs("this user exit the group failed,err=%s", err.Error())
|
||||
log.ErrorByArgs("this user exit the group failed,err=%s", err.Error(), req.OperationID, req.GroupID, claims.UID)
|
||||
return &pbGroup.CommonResp{ErrorCode: config.ErrQuitGroup.ErrCode, ErrorMsg: config.ErrQuitGroup.ErrMsg}, nil
|
||||
}
|
||||
|
||||
err = db.DB.DelGroupMember(req.GroupID, claims.UID)
|
||||
if err != nil {
|
||||
log.Error("", "", "delete mongo group member failed, db.DB.DelGroupMember fail [err: %s]", err.Error())
|
||||
return &pbGroup.CommonResp{ErrorCode: config.ErrQuitGroup.ErrCode, ErrorMsg: config.ErrQuitGroup.ErrMsg}, nil
|
||||
}
|
||||
////Push message when quit group chat
|
||||
@ -42,5 +51,10 @@ func (s *groupServer) QuitGroup(ctx context.Context, req *pbGroup.QuitGroupReq)
|
||||
// OperationID: req.OperationID,
|
||||
//})
|
||||
log.Info(req.Token, req.OperationID, "rpc quit group is success return")
|
||||
|
||||
t := db.DB.GetGroupMember(req.GroupID)
|
||||
fmt.Println("YYYYYYYYYYYYYYYYYYYYYYYYYYYYYY")
|
||||
fmt.Println(t)
|
||||
|
||||
return &pbGroup.CommonResp{}, nil
|
||||
}
|
@ -1,13 +1,9 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"Open_IM/src/common/constant"
|
||||
"Open_IM/src/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/src/common/log"
|
||||
pbChat "Open_IM/src/proto/chat"
|
||||
"Open_IM/src/proto/group"
|
||||
"Open_IM/src/push/logic"
|
||||
"Open_IM/src/utils"
|
||||
"context"
|
||||
)
|
||||
|
||||
@ -21,16 +17,5 @@ func (s *groupServer) TransferGroupOwner(_ context.Context, pb *group.TransferGr
|
||||
}
|
||||
log.Info("", "", "rpc TransferGroupOwner call..., im_mysql_model.TransferGroupOwner")
|
||||
|
||||
logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
|
||||
SendID: pb.OldOwner,
|
||||
RecvID: pb.GroupID,
|
||||
Content: pb.String(),
|
||||
SendTime: utils.GetCurrentTimestampBySecond(),
|
||||
MsgFrom: constant.UserMsgType,
|
||||
ContentType: constant.TransferGroupOwnerTip,
|
||||
SessionType: constant.GroupChatType,
|
||||
OperationID: pb.OperationID,
|
||||
})
|
||||
|
||||
return reply, nil
|
||||
}
|
||||
|
@ -2,9 +2,9 @@ package internal_service
|
||||
|
||||
import (
|
||||
"Open_IM/src/common/config"
|
||||
"Open_IM/src/grpc-etcdv3/getcdv3"
|
||||
pbUser "Open_IM/src/proto/user"
|
||||
"context"
|
||||
"github.com/skiffer-git/grpc-etcdv3/getcdv3"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
@ -4,10 +4,10 @@ import (
|
||||
"Open_IM/src/common/config"
|
||||
"Open_IM/src/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/src/common/log"
|
||||
"Open_IM/src/grpc-etcdv3/getcdv3"
|
||||
pbUser "Open_IM/src/proto/user"
|
||||
"Open_IM/src/utils"
|
||||
"context"
|
||||
"github.com/skiffer-git/grpc-etcdv3/getcdv3"
|
||||
"google.golang.org/grpc"
|
||||
"net"
|
||||
"strconv"
|
||||
|
@ -5,13 +5,13 @@ import (
|
||||
"Open_IM/src/common/constant"
|
||||
"Open_IM/src/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/src/common/log"
|
||||
"Open_IM/src/grpc-etcdv3/getcdv3"
|
||||
pbChat "Open_IM/src/proto/chat"
|
||||
pbFriend "Open_IM/src/proto/friend"
|
||||
pbUser "Open_IM/src/proto/user"
|
||||
"Open_IM/src/push/logic"
|
||||
"Open_IM/src/utils"
|
||||
"context"
|
||||
"github.com/skiffer-git/grpc-etcdv3/getcdv3"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@ -27,37 +27,34 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI
|
||||
log.Error(req.Token, req.OperationID, "update user some attribute failed,err=%s", err.Error())
|
||||
return &pbUser.CommonResp{ErrorCode: config.ErrModifyUserInfo.ErrCode, ErrorMsg: config.ErrModifyUserInfo.ErrMsg}, nil
|
||||
}
|
||||
go func() {
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||
client := pbFriend.NewFriendClient(etcdConn)
|
||||
defer etcdConn.Close()
|
||||
newReq := &pbFriend.GetFriendListReq{
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||
client := pbFriend.NewFriendClient(etcdConn)
|
||||
newReq := &pbFriend.GetFriendListReq{
|
||||
OperationID: req.OperationID,
|
||||
Token: req.Token,
|
||||
}
|
||||
|
||||
RpcResp, err := client.GetFriendList(context.Background(), newReq)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,call get friend list rpc server failed", err)
|
||||
log.ErrorByKv("get friend list rpc server failed", req.OperationID, "err", err.Error(), "req", req.String())
|
||||
}
|
||||
if RpcResp.ErrorCode != 0 {
|
||||
log.ErrorByKv("get friend list rpc server failed", req.OperationID, "err", err.Error(), "req", req.String())
|
||||
}
|
||||
for _, v := range RpcResp.Data {
|
||||
logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
|
||||
SendID: claims.UID,
|
||||
RecvID: v.Uid,
|
||||
Content: claims.UID + "'s info has changed",
|
||||
SendTime: utils.GetCurrentTimestampBySecond(),
|
||||
MsgFrom: constant.SysMsgType,
|
||||
ContentType: constant.SetSelfInfoTip,
|
||||
SessionType: constant.SingleChatType,
|
||||
OperationID: req.OperationID,
|
||||
Token: req.Token,
|
||||
}
|
||||
})
|
||||
|
||||
RpcResp, err := client.GetFriendList(context.Background(), newReq)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,call get friend list rpc server failed", err)
|
||||
log.ErrorByKv("get friend list rpc server failed", req.OperationID, "err", err.Error(), "req", req.String())
|
||||
}
|
||||
if RpcResp.ErrorCode != 0 {
|
||||
log.ErrorByKv("get friend list rpc server failed", req.OperationID, "err", err.Error(), "req", req.String())
|
||||
}
|
||||
for _, v := range RpcResp.Data {
|
||||
logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
|
||||
SendID: claims.UID,
|
||||
RecvID: v.Uid,
|
||||
Content: claims.UID + "'s info has changed",
|
||||
SendTime: utils.GetCurrentTimestampBySecond(),
|
||||
MsgFrom: constant.SysMsgType,
|
||||
ContentType: constant.SetSelfInfoTip,
|
||||
SessionType: constant.SingleChatType,
|
||||
OperationID: req.OperationID,
|
||||
Token: req.Token,
|
||||
})
|
||||
|
||||
}
|
||||
}()
|
||||
}
|
||||
return &pbUser.CommonResp{}, nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user