Merge remote-tracking branch 'origin/tuoyun' into tuoyun

pull/218/head
Gordon 3 years ago
commit 96be2e6262

@ -97,14 +97,19 @@ func main() {
}
//Conversation
conversationGroup := r.Group("/conversation")
{
conversationGroup.POST("/set_receive_message_opt", conversation.SetReceiveMessageOpt) //1
conversationGroup.POST("/get_receive_message_opt", conversation.GetReceiveMessageOpt) //1
conversationGroup.POST("/get_all_conversation_message_opt", conversation.GetAllConversationMessageOpt) //1
{ //1
conversationGroup.POST("/get_all_conversations", conversation.GetAllConversations)
conversationGroup.POST("/get_conversation", conversation.GetConversation)
conversationGroup.POST("/get_conversations", conversation.GetConversations)
conversationGroup.POST("/set_conversation", conversation.SetConversation)
conversationGroup.POST("/batch_set_conversation", conversation.BatchSetConversations)
}
apiThird.MinioInit()
log.NewPrivateLog("api")
ginPort := flag.Int("port", 10000, "get ginServerPort from cmd,default 10000 as port")
flag.Parse()
r.Run(":" + strconv.Itoa(*ginPort))
err := r.Run(":" + strconv.Itoa(*ginPort))
if err != nil {
log.NewError("", utils.GetSelfFuncName(), "start gin failed", err.Error())
}
}

@ -133,7 +133,7 @@ log:
rotationTime: 24
remainRotationCount: 3 #日志数量
#日志级别 6表示全都打印测试阶段建议设置为6
remainLogLevel: 4
remainLogLevel: 6
elasticSearchSwitch: false
elasticSearchAddr: [ 127.0.0.1:9201 ]
elasticSearchUser: ""
@ -200,21 +200,21 @@ callback:
callbackbeforeSendSingleMsg:
enable: false # 回调是否启用
callbackTimeOut: 2 # 回调超时时间
CallbackFailedContinue: true # 回调超时是否继续执行代码
callbackFailedContinue: true # 回调超时是否继续执行代码
callbackAfterSendSingleMsg:
enable: false
callbackTimeOut: 2
callbackBeforeSendGroupMsg:
enable: false
callbackTimeOut: 2
CallbackFailedContinue: true
callbackFailedContinue: true
callbackAfterSendGroupMsg:
enable: false
callbackTimeOut: 2
callbackWordFilter:
enable: false
callbackTimeOut: 2
CallbackFailedContinue: true
callbackFailedContinue: true
notification:

@ -4,10 +4,8 @@ import (
api "Open_IM/pkg/base_info"
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/log"
"Open_IM/pkg/common/token_verify"
"Open_IM/pkg/grpc-etcdv3/getcdv3"
"Open_IM/pkg/proto/user"
rpc "Open_IM/pkg/proto/user"
pbUser "Open_IM/pkg/proto/user"
"Open_IM/pkg/utils"
"context"
"github.com/gin-gonic/gin"
@ -15,111 +13,194 @@ import (
"strings"
)
func GetAllConversationMessageOpt(c *gin.Context) {
params := api.GetAllConversationMessageOptReq{}
if err := c.BindJSON(&params); err != nil {
func SetConversation(c *gin.Context) {
var (
req api.SetConversationReq
resp api.SetConversationResp
reqPb pbUser.SetConversationReq
)
if err := c.BindJSON(&req); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "bind json failed", err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()})
return
}
req := &rpc.GetAllConversationMsgOptReq{}
utils.CopyStructFields(req, &params)
var ok bool
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
if !ok {
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed or not set token in header"})
reqPb.Conversation = &pbUser.Conversation{}
err := utils.CopyStructFields(&reqPb, req)
err = utils.CopyStructFields(reqPb.Conversation, req.Conversation)
if err != nil {
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", reqPb.String())
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
client := pbUser.NewUserClient(etcdConn)
respPb, err := client.SetConversation(context.Background(), &reqPb)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation rpc failed, ", reqPb.String(), err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": "GetAllConversationMsgOpt rpc failed, " + err.Error()})
return
}
log.NewInfo(params.OperationID, "GetAllConversationMessageOpt args ", req.String())
resp.ErrMsg = respPb.CommonResp.ErrMsg
resp.ErrCode = respPb.CommonResp.ErrCode
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
c.JSON(http.StatusOK, resp)
}
func BatchSetConversations(c *gin.Context) {
var (
req api.BatchSetConversationsReq
resp api.BatchSetConversationsResp
reqPb pbUser.BatchSetConversationsReq
)
if err := c.BindJSON(&req); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "bind json failed", err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()})
return
}
if err := utils.CopyStructFields(&reqPb, req); err != nil {
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", reqPb.String())
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
client := user.NewUserClient(etcdConn)
RpcResp, err := client.GetAllConversationMsgOpt(context.Background(), req)
client := pbUser.NewUserClient(etcdConn)
respPb, err := client.BatchSetConversations(context.Background(), &reqPb)
if err != nil {
log.NewError(params.OperationID, "GetAllConversationMsgOpt rpc failed, ", req, err.Error())
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation rpc failed, ", reqPb.String(), err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": "GetAllConversationMsgOpt rpc failed, " + err.Error()})
return
}
optResult := make([]*api.OptResult, 0)
for _, v := range RpcResp.ConversationOptResultList {
temp := new(api.OptResult)
temp.ConversationID = v.ConversationID
temp.Result = &v.Result
optResult = append(optResult, temp)
if err := utils.CopyStructFields(&resp.Data, respPb); err != nil {
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
}
resp := api.GetAllConversationMessageOptResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}, ConversationOptResultList: optResult}
log.NewInfo(req.OperationID, "GetAllConversationMsgOpt api return: ", resp)
resp.ErrMsg = respPb.CommonResp.ErrMsg
resp.ErrCode = respPb.CommonResp.ErrCode
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
c.JSON(http.StatusOK, resp)
}
func GetReceiveMessageOpt(c *gin.Context) {
params := api.GetReceiveMessageOptReq{}
if err := c.BindJSON(&params); err != nil {
func GetAllConversations(c *gin.Context) {
var (
req api.GetAllConversationsReq
resp api.GetAllConversationsResp
reqPb pbUser.GetAllConversationsReq
)
if err := c.BindJSON(&req); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "bind json failed", err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()})
return
}
req := &rpc.GetReceiveMessageOptReq{}
utils.CopyStructFields(req, &params)
var ok bool
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
if !ok {
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
return
if err := utils.CopyStructFields(&reqPb, req); err != nil {
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
}
log.NewInfo(params.OperationID, "GetReceiveMessageOpt args ", req.String())
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", reqPb.String())
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
client := user.NewUserClient(etcdConn)
RpcResp, err := client.GetReceiveMessageOpt(context.Background(), req)
client := pbUser.NewUserClient(etcdConn)
respPb, err := client.GetAllConversations(context.Background(), &reqPb)
if err != nil {
log.NewError(params.OperationID, "GetReceiveMessageOpt rpc failed, ", req, err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": "GetReceiveMessageOpt rpc failed, " + err.Error()})
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation rpc failed, ", reqPb.String(), err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": "GetAllConversationMsgOpt rpc failed, " + err.Error()})
return
}
optResult := make([]*api.OptResult, 0)
for _, v := range RpcResp.ConversationOptResultList {
temp := new(api.OptResult)
temp.ConversationID = v.ConversationID
temp.Result = &v.Result
optResult = append(optResult, temp)
resp.ErrMsg = respPb.CommonResp.ErrMsg
resp.ErrCode = respPb.CommonResp.ErrCode
if err := utils.CopyStructFields(&resp.Conversations, respPb.Conversations); err != nil {
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed, ", err.Error())
}
resp := api.GetReceiveMessageOptResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}, ConversationOptResultList: optResult}
log.NewInfo(req.OperationID, "GetReceiveMessageOpt api return: ", resp)
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
c.JSON(http.StatusOK, resp)
}
func SetReceiveMessageOpt(c *gin.Context) {
params := api.SetReceiveMessageOptReq{}
if err := c.BindJSON(&params); err != nil {
log.NewError(params.OperationID, utils.GetSelfFuncName(), "bind json failed", err.Error())
func GetConversation(c *gin.Context) {
var (
req api.GetConversationReq
resp api.GetConversationResp
reqPb pbUser.GetConversationReq
)
if err := c.BindJSON(&req); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "bind json failed", err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()})
return
}
req := &rpc.SetReceiveMessageOptReq{}
utils.CopyStructFields(req, &params)
var ok bool
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
if !ok {
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
if err := utils.CopyStructFields(&reqPb, req); err != nil {
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", reqPb.String())
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
client := pbUser.NewUserClient(etcdConn)
respPb, err := client.GetConversation(context.Background(), &reqPb)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation rpc failed, ", reqPb.String(), err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": "GetAllConversationMsgOpt rpc failed, " + err.Error()})
return
}
resp.ErrMsg = respPb.CommonResp.ErrMsg
resp.ErrCode = respPb.CommonResp.ErrCode
if err := utils.CopyStructFields(&resp.Conversation, respPb.Conversation); err != nil {
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
c.JSON(http.StatusOK, resp)
}
func GetConversations(c *gin.Context) {
var (
req api.GetConversationsReq
resp api.GetConversationsResp
reqPb pbUser.GetConversationsReq
)
if err := c.BindJSON(&req); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "bind json failed", err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()})
return
}
log.NewInfo(params.OperationID, "SetReceiveMessageOpt args ", req.String())
if err := utils.CopyStructFields(&reqPb, req); err != nil {
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", reqPb.String())
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
client := user.NewUserClient(etcdConn)
RpcResp, err := client.SetReceiveMessageOpt(context.Background(), req)
client := pbUser.NewUserClient(etcdConn)
respPb, err := client.GetConversations(context.Background(), &reqPb)
if err != nil {
log.NewError(params.OperationID, "SetReceiveMessageOpt rpc failed, ", req, err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": "SetReceiveMessageOpt rpc failed, " + err.Error()})
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation rpc failed, ", reqPb.String(), err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": "GetAllConversationMsgOpt rpc failed, " + err.Error()})
return
}
optResult := make([]*api.OptResult, 0)
for _, v := range RpcResp.ConversationOptResultList {
temp := new(api.OptResult)
temp.ConversationID = v.ConversationID
temp.Result = &v.Result
optResult = append(optResult, temp)
resp.ErrMsg = respPb.CommonResp.ErrMsg
resp.ErrCode = respPb.CommonResp.ErrCode
if err := utils.CopyStructFields(&resp.Conversations, respPb.Conversations); err != nil {
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
}
resp := api.SetReceiveMessageOptResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}, ConversationOptResultList: optResult}
log.NewInfo(req.OperationID, "SetReceiveMessageOpt api return: ", resp)
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
c.JSON(http.StatusOK, resp)
}
func GetAllConversationMessageOpt(c *gin.Context) {
var (
_ api.GetAllConversationMessageOptReq
resp api.GetAllConversationMessageOptResp
)
c.JSON(http.StatusOK, resp)
}
func GetReceiveMessageOpt(c *gin.Context) {
var (
_ api.GetReceiveMessageOptReq
resp api.GetReceiveMessageOptResp
)
c.JSON(http.StatusOK, resp)
}
func SetReceiveMessageOpt(c *gin.Context) {
var (
_ api.SetReceiveMessageOptReq
resp api.SetReceiveMessageOptResp
)
c.JSON(http.StatusOK, resp)
}

@ -45,8 +45,8 @@ func MinioInit() {
// 自动化桶public的代码
//err = minioClient.SetBucketPolicy(context.Background(), config.Config.Credential.Minio.Bucket, policy.BucketPolicyReadWrite)
//if err != nil {
// log.NewError("", utils.GetSelfFuncName(), "SetBucketPolicy failed please set in ", err.Error())
// return`z
// log.NewError("", utils.GetSelfFuncName(), "SetBucketPolicy failed please set in web", err.Error())
// return
//}
log.NewInfo("", utils.GetSelfFuncName(), "minio create and set policy success")
}

@ -44,9 +44,8 @@ func conversationNotification(contentType int32, m proto.Message, operationID, u
Notification(&n)
}
// 客户端调用设置opt接口后调用
func SetReceiveMessageOptNotification(operationID, opUserID, userID string) {
log.NewInfo(operationID, utils.GetSelfFuncName(), "operation user: ", opUserID, "operation id: ", userID)
func SetConversationNotification(operationID, userID string) {
log.NewInfo(operationID, utils.GetSelfFuncName(), "userID: ", userID)
conversationUpdateTips := open_im_sdk.ConversationUpdateTips{
UserID: userID,
}

@ -274,7 +274,7 @@ func returnMsg(replay *pbChat.SendMsgResp, pb *pbChat.SendMsgReq, errCode int32,
func modifyMessageByUserMessageReceiveOpt(userID, sourceID string, sessionType int, pb *pbChat.SendMsgReq) bool {
conversationID := utils.GetConversationIDBySessionType(sourceID, sessionType)
opt, err := db.DB.GetSingleConversationMsgOpt(userID, conversationID)
opt, err := db.DB.GetSingleConversationRecvMsgOpt(userID, conversationID)
if err != nil && err != redis.ErrNil {
log.NewError(pb.OperationID, "GetSingleConversationMsgOpt from redis err", conversationID, pb.String(), err.Error())
return true

@ -88,63 +88,165 @@ func (s *userServer) GetUserInfo(ctx context.Context, req *pbUser.GetUserInfoReq
userInfoList = append(userInfoList, &userInfo)
}
} else {
return &pbUser.GetUserInfoResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrArgs.ErrCode, ErrMsg: constant.ErrArgs.ErrMsg}}, nil
}
log.NewInfo(req.OperationID, "GetUserInfo rpc return ", pbUser.GetUserInfoResp{CommonResp: &pbUser.CommonResp{}, UserInfoList: userInfoList})
return &pbUser.GetUserInfoResp{CommonResp: &pbUser.CommonResp{}, UserInfoList: userInfoList}, nil
}
func (s *userServer) SetReceiveMessageOpt(ctx context.Context, req *pbUser.SetReceiveMessageOptReq) (*pbUser.SetReceiveMessageOptResp, error) {
log.NewInfo(req.OperationID, "SetReceiveMessageOpt args ", req.String())
m := make(map[string]int, len(req.ConversationIDList))
for _, v := range req.ConversationIDList {
m[v] = int(req.Opt)
func (s *userServer) BatchSetConversations(ctx context.Context, req *pbUser.BatchSetConversationsReq) (*pbUser.BatchSetConversationsResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &pbUser.BatchSetConversationsResp{}
for _, v := range req.Conversations {
conversation := db.Conversation{}
if err := utils.CopyStructFields(&conversation, v); err != nil {
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), v.String(), "CopyStructFields failed", err.Error())
}
if err := db.DB.SetSingleConversationRecvMsgOpt(req.OwnerUserID, v.ConversationID, v.RecvMsgOpt); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "cache failed, rpc return", err.Error())
resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
return resp, nil
}
if err := imdb.SetConversation(conversation); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation error", err.Error())
resp.Failed = append(resp.Failed, v.ConversationID)
continue
}
resp.Success = append(resp.Success, v.ConversationID)
}
err := db.DB.SetMultiConversationMsgOpt(req.FromUserID, m)
chat.SetConversationNotification(req.OperationID, req.OwnerUserID)
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return", resp.String())
resp.CommonResp = &pbUser.CommonResp{}
return resp, nil
}
func (s *userServer) GetAllConversations(ctx context.Context, req *pbUser.GetAllConversationsReq) (*pbUser.GetAllConversationsResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &pbUser.GetAllConversationsResp{Conversations: []*pbUser.Conversation{}}
conversations, err := imdb.GetUserAllConversations(req.OwnerUserID)
if err != nil {
log.NewError(req.OperationID, "SetMultiConversationMsgOpt failed ", err.Error(), req)
return &pbUser.SetReceiveMessageOptResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetConversations error", err.Error())
resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
return resp, nil
}
resp := pbUser.SetReceiveMessageOptResp{CommonResp: &pbUser.CommonResp{}}
for _, v := range req.ConversationIDList {
resp.ConversationOptResultList = append(resp.ConversationOptResultList, &pbUser.OptResult{ConversationID: v, Result: req.Opt})
if err = utils.CopyStructFields(&resp.Conversations, conversations); err != nil {
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields error", err.Error())
}
chat.SetReceiveMessageOptNotification(req.OperationID, req.OpUserID, req.FromUserID)
log.NewInfo(req.OperationID, "SetReceiveMessageOpt rpc return ", resp.String())
return &resp, nil
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return", resp.String())
resp.CommonResp = &pbUser.CommonResp{}
return resp, nil
}
func (s *userServer) GetReceiveMessageOpt(ctx context.Context, req *pbUser.GetReceiveMessageOptReq) (*pbUser.GetReceiveMessageOptResp, error) {
log.NewInfo(req.OperationID, "GetReceiveMessageOpt args ", req.String())
m, err := db.DB.GetMultiConversationMsgOpt(req.FromUserID, req.ConversationIDList)
func (s *userServer) GetConversation(ctx context.Context, req *pbUser.GetConversationReq) (*pbUser.GetConversationResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &pbUser.GetConversationResp{Conversation: &pbUser.Conversation{}}
conversation, err := imdb.GetConversation(req.OwnerUserID, req.ConversationID)
if err != nil{
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetConversation error", err.Error())
resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
return resp, nil
}
if err := utils.CopyStructFields(resp.Conversation, &conversation); err != nil {
log.Debug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields error", conversation, err.Error())
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
resp.CommonResp = &pbUser.CommonResp{}
return resp, nil
}
func (s *userServer) GetConversations(ctx context.Context, req *pbUser.GetConversationsReq) (*pbUser.GetConversationsResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &pbUser.GetConversationsResp{Conversations: []*pbUser.Conversation{}}
conversations, err := imdb.GetConversations(req.OwnerUserID, req.ConversationIDs)
if err != nil {
log.NewError(req.OperationID, "GetMultiConversationMsgOpt failed ", err.Error(), req.FromUserID, req.ConversationIDList)
return &pbUser.GetReceiveMessageOptResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetConversations error", err.Error())
resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
return resp, nil
}
resp := pbUser.GetReceiveMessageOptResp{CommonResp: &pbUser.CommonResp{}}
for k, v := range m {
resp.ConversationOptResultList = append(resp.ConversationOptResultList, &pbUser.OptResult{ConversationID: k, Result: int32(v)})
if err := utils.CopyStructFields(&resp.Conversations, conversations); err != nil {
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", conversations, err.Error())
}
log.NewInfo(req.OperationID, "GetReceiveMessageOpt rpc return ", resp.String())
return &resp, nil
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
resp.CommonResp = &pbUser.CommonResp{}
return resp, nil
}
func (s *userServer) GetAllConversationMsgOpt(ctx context.Context, req *pbUser.GetAllConversationMsgOptReq) (*pbUser.GetAllConversationMsgOptResp, error) {
log.NewInfo(req.OperationID, "GetAllConversationMsgOpt args ", req.String())
m, err := db.DB.GetAllConversationMsgOpt(req.FromUserID)
if err != nil {
log.NewError(req.OperationID, "GetAllConversationMsgOpt failed ", err.Error(), req.FromUserID)
return &pbUser.GetAllConversationMsgOptResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
func (s *userServer) SetConversation(ctx context.Context, req *pbUser.SetConversationReq) (*pbUser.SetConversationResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &pbUser.SetConversationResp{}
var conversation db.Conversation
if err := utils.CopyStructFields(&conversation, req.Conversation); err != nil {
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", *req.Conversation, err.Error())
}
resp := pbUser.GetAllConversationMsgOptResp{CommonResp: &pbUser.CommonResp{}}
for k, v := range m {
resp.ConversationOptResultList = append(resp.ConversationOptResultList, &pbUser.OptResult{ConversationID: k, Result: int32(v)})
if err := db.DB.SetSingleConversationRecvMsgOpt(req.Conversation.OwnerUserID, req.Conversation.ConversationID, req.Conversation.RecvMsgOpt); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "cache failed, rpc return", err.Error())
resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
return resp, nil
}
log.NewInfo(req.OperationID, "GetAllConversationMsgOpt rpc return ", resp.String())
return &resp, nil
err := imdb.SetConversation(conversation)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation error", err.Error())
resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
return resp, nil
}
chat.SetConversationNotification(req.OperationID, req.Conversation.OwnerUserID)
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return", resp.String())
resp.CommonResp = &pbUser.CommonResp{}
return resp, nil
}
//func (s *userServer) SetReceiveMessageOpt(ctx context.Context, req *pbUser.SetReceiveMessageOptReq) (*pbUser.SetReceiveMessageOptResp, error) {
// log.NewInfo(req.OperationID, "SetReceiveMessageOpt args ", req.String())
// m := make(map[string]int, len(req.ConversationIDList))
// for _, v := range req.ConversationIDList {
// m[v] = int(req.Opt)
// }
// err := db.DB.SetMultiConversationMsgOpt(req.FromUserID, m)
// if err != nil {
// log.NewError(req.OperationID, "SetMultiConversationMsgOpt failed ", err.Error(), req)
// return &pbUser.SetReceiveMessageOptResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
// }
// resp := pbUser.SetReceiveMessageOptResp{CommonResp: &pbUser.CommonResp{}}
//
// for _, v := range req.ConversationIDList {
// resp.ConversationOptResultList = append(resp.ConversationOptResultList, &pbUser.OptResult{ConversationID: v, Result: req.Opt})
// }
// chat.SetReceiveMessageOptNotification(req.OperationID, req.OpUserID, req.FromUserID)
// log.NewInfo(req.OperationID, "SetReceiveMessageOpt rpc return ", resp.String())
// return &resp, nil
//}
//
//func (s *userServer) GetReceiveMessageOpt(ctx context.Context, req *pbUser.GetReceiveMessageOptReq) (*pbUser.GetReceiveMessageOptResp, error) {
// log.NewInfo(req.OperationID, "GetReceiveMessageOpt args ", req.String())
// m, err := db.DB.GetMultiConversationMsgOpt(req.FromUserID, req.ConversationIDList)
// if err != nil {
// log.NewError(req.OperationID, "GetMultiConversationMsgOpt failed ", err.Error(), req.FromUserID, req.ConversationIDList)
// return &pbUser.GetReceiveMessageOptResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
// }
// resp := pbUser.GetReceiveMessageOptResp{CommonResp: &pbUser.CommonResp{}}
// for k, v := range m {
// resp.ConversationOptResultList = append(resp.ConversationOptResultList, &pbUser.OptResult{ConversationID: k, Result: int32(v)})
// }
// log.NewInfo(req.OperationID, "GetReceiveMessageOpt rpc return ", resp.String())
// return &resp, nil
//}
//
//func (s *userServer) GetAllConversationMsgOpt(ctx context.Context, req *pbUser.GetAllConversationMsgOptReq) (*pbUser.GetAllConversationMsgOptResp, error) {
// log.NewInfo(req.OperationID, "GetAllConversationMsgOpt args ", req.String())
// m, err := db.DB.GetAllConversationMsgOpt(req.FromUserID)
// if err != nil {
// log.NewError(req.OperationID, "GetAllConversationMsgOpt failed ", err.Error(), req.FromUserID)
// return &pbUser.GetAllConversationMsgOptResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
// }
// resp := pbUser.GetAllConversationMsgOptResp{CommonResp: &pbUser.CommonResp{}}
// for k, v := range m {
// resp.ConversationOptResultList = append(resp.ConversationOptResultList, &pbUser.OptResult{ConversationID: k, Result: int32(v)})
// }
// log.NewInfo(req.OperationID, "GetAllConversationMsgOpt rpc return ", resp.String())
// return &resp, nil
//}
func (s *userServer) DeleteUsers(_ context.Context, req *pbUser.DeleteUsersReq) (*pbUser.DeleteUsersResp, error) {
log.NewInfo(req.OperationID, "DeleteUsers args ", req.String())
if !token_verify.IsMangerUserID(req.OpUserID) {

@ -32,17 +32,72 @@ type SetReceiveMessageOptResp struct {
ConversationOptResultList []*OptResult `json:"data"`
}
//type Conversation struct {
// OwnerUserID string `gorm:"column:owner_user_id;primary_key;type:char(128)" json:"OwnerUserID"`
// ConversationID string `gorm:"column:conversation_id;primary_key;type:char(128)" json:"conversationID"`
// ConversationType int32 `gorm:"column:conversation_type" json:"conversationType"`
// UserID string `gorm:"column:user_id;type:char(64)" json:"userID"`
// GroupID string `gorm:"column:group_id;type:char(128)" json:"groupID"`
// RecvMsgOpt int32 `gorm:"column:recv_msg_opt" json:"recvMsgOpt"`
// UnreadCount int32 `gorm:"column:unread_count" json:"unreadCount"`
// DraftTextTime int64 `gorm:"column:draft_text_time" json:"draftTextTime"`
// IsPinned bool `gorm:"column:is_pinned" json:"isPinned"`
// AttachedInfo string `gorm:"column:attached_info;type:varchar(1024)" json:"attachedInfo"`
// Ex string `gorm:"column:ex;type:varchar(1024)" json:"ex"`
//}
type Conversation struct {
OwnerUserID string `json:"ownerUserID" binding:"required"`
ConversationID string `json:"conversationID"`
ConversationType int32 `json:"conversationType"`
UserID string `json:"userID"`
GroupID string `json:"groupID"`
RecvMsgOpt int32 `json:"recvMsgOpt"`
UnreadCount int32 `json:"unreadCount"`
DraftTextTime int64 `json:"draftTextTime"`
IsPinned bool `json:"isPinned"`
IsPrivateChat bool `json:"isPrivateChat"`
AttachedInfo string `json:"attachedInfo"`
Ex string `json:"ex"`
}
type SetConversationReq struct {
Conversation
OperationID string `json:"operationID" binding:"required"`
}
type SetConversationResp struct {
CommResp
}
type BatchSetConversationsReq struct {
Conversations []Conversation `json:"conversations" binding:"required"`
OwnerUserID string `json:"ownerUserID" binding:"required"`
OperationID string `json:"operationID" binding:"required"`
}
type BatchSetConversationsResp struct {
CommResp
Data struct{
Success []string `json:"success"`
Failed []string `json:"failed"`
} `json:"data"`
}
type GetConversationReq struct {
ConversationID string `json:"conversationID" binding:"required"`
OwnerUserID string `json:"ownerUserID" binding:"required"`
OperationID string `json:"operationID" binding:"required"`
}
type GetConversationResp struct {
CommResp
Conversation Conversation `json:"data"`
}
type GetAllConversationsReq struct {
OwnerUserID string `json:"ownerUserID" binding:"required"`
OperationID string `json:"operationID" binding:"required"`
}
type GetAllConversationsResp struct {
CommResp
Conversations []Conversation `json:"data"`
}
type GetConversationsReq struct {
ConversationIDs []string `json:"conversationIDs" binding:"required"`
OwnerUserID string `json:"ownerUserID" binding:"required"`
OperationID string `json:"operationID" binding:"required"`
}
type GetConversationsResp struct {
CommResp
Conversations []Conversation `json:"data"`
}

@ -22,7 +22,7 @@ var Config config
type callBackConfig struct {
Enable bool `yaml:"enable"`
CallbackTimeOut int `yaml:"callbackTimeOut"`
CallbackFailedContinue bool `CallbackFailedContinue`
CallbackFailedContinue bool `callbackFailedContinue`
}
type config struct {

@ -213,6 +213,11 @@ type Conversation struct {
UnreadCount int32 `gorm:"column:unread_count" json:"unreadCount"`
DraftTextTime int64 `gorm:"column:draft_text_time" json:"draftTextTime"`
IsPinned bool `gorm:"column:is_pinned" json:"isPinned"`
IsPrivateChat bool `gorm:"column:is_private_chat" json:"isPrivateChat"`
AttachedInfo string `gorm:"column:attached_info;type:varchar(1024)" json:"attachedInfo"`
Ex string `gorm:"column:ex;type:varchar(1024)" json:"ex"`
}
func (Conversation) TableName() string {
return "conversations"
}

@ -2,6 +2,8 @@ package im_mysql_model
import (
"Open_IM/pkg/common/db"
"Open_IM/pkg/common/log"
"Open_IM/pkg/utils"
"fmt"
)
@ -30,7 +32,6 @@ func GetChatLog(chatLog db.ChatLog, pageNumber, showNumber int32) ([]db.ChatLog,
if chatLog.SendTime.Unix() > 0 {
db = db.Where("send_time > ? and send_time < ?", chatLog.SendTime, chatLog.SendTime.AddDate(0, 0, 1))
}
err = db.Find(&chatLogs).Error
return chatLogs, err
}
@ -58,6 +59,7 @@ func GetChatLogCount(chatLog db.ChatLog) (int64, error) {
db = db.Where("recv_id = ?", chatLog.RecvID)
}
if chatLog.SendTime.Unix() > 0 {
log.NewDebug("", utils.GetSelfFuncName(), chatLog.SendTime, chatLog.SendTime.AddDate(0, 0, 1))
db = db.Where("send_time > ? and send_time < ?", chatLog.SendTime, chatLog.SendTime.AddDate(0, 0, 1))
}

@ -4,6 +4,7 @@ import (
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db"
"Open_IM/pkg/common/log"
"Open_IM/pkg/utils"
"fmt"
"time"
@ -291,3 +292,56 @@ func GetBlockUsersNumCount() (int32, error) {
}
return count, nil
}
func SetConversation(conversation db.Conversation) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
dbConn.LogMode(true)
newConversation := conversation
if dbConn.Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 {
log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "not exist in db, create")
return dbConn.Model(&db.Conversation{}).Create(conversation).Error
// if exist, then update record
} else {
log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "exist in db, update")
//force update
return dbConn.Model(&db.Conversation{}).Update(conversation).
Update(map[string]interface{}{"recv_msg_opt": conversation.RecvMsgOpt, "is_pinned": conversation.IsPinned, "is_private_chat": conversation.IsPrivateChat}).Error
}
}
func GetUserAllConversations(ownerUserID string) ([]db.Conversation, error) {
var conversations []db.Conversation
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return conversations, err
}
dbConn.LogMode(true)
err = dbConn.Model(&db.Conversation{}).Where("owner_user_id=?", ownerUserID).Find(&conversations).Error
return conversations, err
}
func GetConversation(OwnerUserID, conversationID string) (db.Conversation, error) {
var conversation db.Conversation
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return conversation, err
}
err = dbConn.Model(&db.Conversation{
OwnerUserID: OwnerUserID,
ConversationID: conversationID,
}).Find(&conversation).Error
return conversation, err
}
func GetConversations(OwnerUserID string, conversationIDs []string) ([]db.Conversation, error) {
var conversations []db.Conversation
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return conversations, err
}
err = dbConn.Model(&db.Conversation{}).Where("conversation_id IN (?) and owner_user_id=?", conversationIDs, OwnerUserID).Find(&conversations).Error
return conversations, err
}

@ -111,12 +111,14 @@ func (d *DataBases) DeleteTokenByUidPid(userID string, platformID int32, fields
_, err := d.Exec("HDEL", key, redis.Args{}.Add().AddFlat(fields)...)
return err
}
func (d *DataBases) SetSingleConversationMsgOpt(userID, conversationID string, opt int) error {
func (d *DataBases) SetSingleConversationRecvMsgOpt(userID, conversationID string, opt int32) error {
key := conversationReceiveMessageOpt + userID
_, err := d.Exec("HSet", key, conversationID, opt)
return err
}
func (d *DataBases) GetSingleConversationMsgOpt(userID, conversationID string) (int, error) {
func (d *DataBases) GetSingleConversationRecvMsgOpt(userID, conversationID string) (int, error) {
key := conversationReceiveMessageOpt + userID
return redis.Int(d.Exec("HGet", key, conversationID))
}

@ -2,7 +2,6 @@ package log
import (
"Open_IM/pkg/common/config"
"bufio"
"fmt"
"os"
"time"
@ -33,13 +32,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",

@ -1,15 +1,14 @@
all_proto=(
message_cms/message_cms.proto
admin_cms/admin_cms.proto
statistics/statistics.proto
auth/auth.proto
friend/friend.proto
group/group.proto
#message_cms/message_cms.proto
#admin_cms/admin_cms.proto
#statistics/statistics.proto
#auth/auth.proto
#friend/friend.proto
#group/group.proto
user/user.proto
chat/chat.proto
push/push.proto
relay/relay.proto
sdk_ws/ws.proto
#chat/chat.proto
#push/push.proto
#relay/relay.proto
#sdk_ws/ws.proto
)

@ -256,15 +256,6 @@ message MemberEnterTips{
}
//////////////////////friend/////////////////////
//message FriendInfo{
// UserInfo OwnerUser = 1;

File diff suppressed because it is too large Load Diff

@ -67,44 +67,72 @@ message UpdateUserInfoResp{
CommonResp commonResp = 1;
}
message Conversation{
string OwnerUserID = 1;
string ConversationID = 2;
int32 RecvMsgOpt = 3;
int32 ConversationType = 4;
string UserID = 5;
string GroupID = 6;
int32 UnreadCount = 7;
int64 DraftTextTime = 8;
bool IsPinned = 9;
string AttachedInfo = 10;
bool IsPrivateChat = 11;
string Ex = 12;
}
message SetConversationReq{
Conversation Conversation = 1;
string OperationID = 2;
}
message SetReceiveMessageOptReq{
string FromUserID = 1;
int32 opt = 2;
repeated string conversationIDList = 3;
string operationID = 4;
string OpUserID = 5;
message SetConversationResp{
CommonResp commonResp = 1;
}
message OptResult{
string conversationID = 1;
int32 result = 2; //-1: failed; 0:default; 1: not receive ; 2: not jpush
message GetConversationReq{
string ConversationID = 1;
string OwnerUserID = 2;
string OperationID = 3;
}
message SetReceiveMessageOptResp{
message GetConversationResp{
CommonResp commonResp = 1;
repeated OptResult conversationOptResultList = 2;
Conversation Conversation = 2;
}
message GetReceiveMessageOptReq{
string FromUserID = 1;
repeated string conversationIDList = 2;
string operationID = 3;
string OpUserID = 4;
message GetConversationsReq{
string OwnerUserID = 1;
repeated string ConversationIDs = 2;
string OperationID = 3;
}
message GetReceiveMessageOptResp{
message GetConversationsResp{
CommonResp commonResp = 1;
repeated OptResult conversationOptResultList = 3;
repeated Conversation Conversations = 2;
}
message GetAllConversationMsgOptReq{
string FromUserID = 1;
string operationID = 2;
string OpUserID = 3;
message GetAllConversationsReq{
string OwnerUserID = 1;
string OperationID = 2;
}
message GetAllConversationMsgOptResp{
message GetAllConversationsResp{
CommonResp commonResp = 1;
repeated OptResult conversationOptResultList = 3;
repeated Conversation Conversations = 2;
}
message BatchSetConversationsReq{
repeated Conversation Conversations = 1;
string OwnerUserID = 2;
string OperationID = 3;
}
message BatchSetConversationsResp{
CommonResp commonResp = 1;
repeated string Success = 2;
repeated string Failed = 3;
}
message ResignUserReq{
@ -130,7 +158,7 @@ message User{
}
message GetUserByIdResp{
CommonResp CommonResp = 1;
CommonResp CommonResp = 1;
User user = 2;
}
@ -241,7 +269,7 @@ message DeleteUserReq {
}
message DeleteUserResp {
CommonResp CommonResp = 1;
}
service user {
@ -249,10 +277,13 @@ service user {
rpc UpdateUserInfo(UpdateUserInfoReq) returns(UpdateUserInfoResp);
rpc DeleteUsers(DeleteUsersReq)returns(DeleteUsersResp);
rpc GetAllUserID(GetAllUserIDReq)returns(GetAllUserIDResp);
rpc SetReceiveMessageOpt(SetReceiveMessageOptReq)returns(SetReceiveMessageOptResp);
rpc GetReceiveMessageOpt(GetReceiveMessageOptReq)returns(GetReceiveMessageOptResp);
rpc GetAllConversationMsgOpt(GetAllConversationMsgOptReq)returns(GetAllConversationMsgOptResp);
rpc AccountCheck(AccountCheckReq)returns(AccountCheckResp);
rpc GetConversation(GetConversationReq)returns(GetConversationResp);
rpc GetAllConversations(GetAllConversationsReq)returns(GetAllConversationsResp);
rpc GetConversations(GetConversationsReq)returns(GetConversationsResp);
rpc BatchSetConversations(BatchSetConversationsReq)returns(BatchSetConversationsResp);
rpc SetConversation(SetConversationReq)returns(SetConversationResp);
rpc GetUserById(GetUserByIdReq) returns (GetUserByIdResp);
rpc GetUsersByName(GetUsersByNameReq) returns (GetUsersByNameResp);

Loading…
Cancel
Save