This commit is contained in:
wangchuxiao 2022-03-16 18:02:26 +08:00
parent fa21ae6161
commit b0aa168c9a
9 changed files with 916 additions and 691 deletions

View File

@ -103,6 +103,7 @@ func main() {
conversationGroup.POST("/get_conversations", conversation.GetConversations) conversationGroup.POST("/get_conversations", conversation.GetConversations)
conversationGroup.POST("/set_conversation", conversation.SetConversation) conversationGroup.POST("/set_conversation", conversation.SetConversation)
conversationGroup.POST("/batch_set_conversation", conversation.BatchSetConversations) conversationGroup.POST("/batch_set_conversation", conversation.BatchSetConversations)
conversationGroup.POST("/set_recv_msg_opt", conversation.SetRecvMsgOpt)
} }
apiThird.MinioInit() apiThird.MinioInit()
log.NewPrivateLog("api") log.NewPrivateLog("api")

View File

@ -141,7 +141,6 @@ func GetConversation(c *gin.Context) {
c.JSON(http.StatusOK, resp) c.JSON(http.StatusOK, resp)
} }
func GetConversations(c *gin.Context) { func GetConversations(c *gin.Context) {
var ( var (
req api.GetConversationsReq req api.GetConversationsReq
@ -174,33 +173,31 @@ func GetConversations(c *gin.Context) {
c.JSON(http.StatusOK, resp) c.JSON(http.StatusOK, resp)
} }
func SetRecvMsgOpt(c *gin.Context) {
func GetAllConversationMessageOpt(c *gin.Context) {
var ( var (
_ api.GetAllConversationMessageOptReq req api.SetRecvMsgOptReq
resp api.GetAllConversationMessageOptResp resp api.SetRecvMsgOptResp
) reqPb pbUser.SetRecvMsgOptReq
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
) )
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 := pbUser.NewUserClient(etcdConn)
respPb, err := client.SetRecvMsgOpt(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
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
c.JSON(http.StatusOK, resp) c.JSON(http.StatusOK, resp)
} }

View File

@ -0,0 +1,15 @@
package msg
import (
"Open_IM/pkg/common/log"
commonPb "Open_IM/pkg/proto/sdk_ws"
"Open_IM/pkg/utils"
"context"
)
func (rpc *rpcChat) DelMsgList(_ context.Context, req *commonPb.DelMsgListReq) (*commonPb.DelMsgListResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &commonPb.DelMsgListResp{}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
return resp, nil
}

View File

@ -94,7 +94,6 @@ func (s *userServer) GetUserInfo(ctx context.Context, req *pbUser.GetUserInfoReq
return &pbUser.GetUserInfoResp{CommonResp: &pbUser.CommonResp{}, UserInfoList: userInfoList}, nil return &pbUser.GetUserInfoResp{CommonResp: &pbUser.CommonResp{}, UserInfoList: userInfoList}, nil
} }
func (s *userServer) BatchSetConversations(ctx context.Context, req *pbUser.BatchSetConversationsReq) (*pbUser.BatchSetConversationsResp, error) { func (s *userServer) BatchSetConversations(ctx context.Context, req *pbUser.BatchSetConversationsReq) (*pbUser.BatchSetConversationsResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &pbUser.BatchSetConversationsResp{} resp := &pbUser.BatchSetConversationsResp{}
@ -196,56 +195,29 @@ func (s *userServer) SetConversation(ctx context.Context, req *pbUser.SetConvers
return resp, nil return resp, nil
} }
//func (s *userServer) SetReceiveMessageOpt(ctx context.Context, req *pbUser.SetReceiveMessageOptReq) (*pbUser.SetReceiveMessageOptResp, error) { func (s *userServer) SetRecvMsgOpt(ctx context.Context, req *pbUser.SetRecvMsgOptReq) (*pbUser.SetRecvMsgOptResp, error) {
// log.NewInfo(req.OperationID, "SetReceiveMessageOpt args ", req.String()) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
// m := make(map[string]int, len(req.ConversationIDList)) resp := &pbUser.SetRecvMsgOptResp{}
// for _, v := range req.ConversationIDList { var conversation db.Conversation
// m[v] = int(req.Opt) if err := utils.CopyStructFields(&conversation, req); err != nil {
// } log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", *req, err.Error())
// err := db.DB.SetMultiConversationMsgOpt(req.FromUserID, m) }
// if err != nil { if err := db.DB.SetSingleConversationRecvMsgOpt(req.OwnerUserID, req.ConversationID, req.RecvMsgOpt); err != nil {
// log.NewError(req.OperationID, "SetMultiConversationMsgOpt failed ", err.Error(), req) log.NewError(req.OperationID, utils.GetSelfFuncName(), "cache failed, rpc return", err.Error())
// return &pbUser.SetReceiveMessageOptResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
// } return resp, nil
// resp := pbUser.SetReceiveMessageOptResp{CommonResp: &pbUser.CommonResp{}} }
// err := imdb.SetRecvMsgOpt(conversation)
// for _, v := range req.ConversationIDList { if err != nil {
// resp.ConversationOptResultList = append(resp.ConversationOptResultList, &pbUser.OptResult{ConversationID: v, Result: req.Opt}) log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation error", err.Error())
// } resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
// chat.SetReceiveMessageOptNotification(req.OperationID, req.OpUserID, req.FromUserID) return resp, nil
// log.NewInfo(req.OperationID, "SetReceiveMessageOpt rpc return ", resp.String()) }
// return &resp, nil chat.SetConversationNotification(req.OperationID, req.OwnerUserID)
//} log.NewError(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
// resp.CommonResp = &pbUser.CommonResp{}
//func (s *userServer) GetReceiveMessageOpt(ctx context.Context, req *pbUser.GetReceiveMessageOptReq) (*pbUser.GetReceiveMessageOptResp, error) { return resp, nil
// 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) { func (s *userServer) DeleteUsers(_ context.Context, req *pbUser.DeleteUsersReq) (*pbUser.DeleteUsersResp, error) {
log.NewInfo(req.OperationID, "DeleteUsers args ", req.String()) log.NewInfo(req.OperationID, "DeleteUsers args ", req.String())

View File

@ -38,10 +38,10 @@ type Conversation struct {
ConversationType int32 `json:"conversationType"` ConversationType int32 `json:"conversationType"`
UserID string `json:"userID"` UserID string `json:"userID"`
GroupID string `json:"groupID"` GroupID string `json:"groupID"`
RecvMsgOpt int32 `json:"recvMsgOpt"` RecvMsgOpt int32 `json:"recvMsgOpt" binding:"omitempty,oneof=0 1 2"`
UnreadCount int32 `json:"unreadCount"` UnreadCount int32 `json:"unreadCount" binding:"omitempty"`
DraftTextTime int64 `json:"draftTextTime"` DraftTextTime int64 `json:"draftTextTime"`
IsPinned bool `json:"isPinned"` IsPinned bool `json:"isPinned" binding:"omitempty"`
IsPrivateChat bool `json:"isPrivateChat"` IsPrivateChat bool `json:"isPrivateChat"`
AttachedInfo string `json:"attachedInfo"` AttachedInfo string `json:"attachedInfo"`
Ex string `json:"ex"` Ex string `json:"ex"`
@ -101,3 +101,14 @@ type GetConversationsResp struct {
CommResp CommResp
Conversations []Conversation `json:"data"` Conversations []Conversation `json:"data"`
} }
type SetRecvMsgOptReq struct {
OwnerUserID string `json:"ownerUserID" binding:"required"`
ConversationID string `json:"conversationID"`
RecvMsgOpt int32 `json:"recvMsgOpt" binding:"omitempty,oneof=0 1 2"`
OperationID string `json:"operationID" binding:"required"`
}
type SetRecvMsgOptResp struct {
CommResp
}

View File

@ -125,7 +125,6 @@ func (d *DataBases) GetMsgBySeqList(uid string, seqList []uint32, operationID st
return seqMsg, nil return seqMsg, nil
} }
func (d *DataBases) GetMsgBySeqListMongo2(uid string, seqList []uint32, operationID string) (seqMsg []*open_im_sdk.MsgData, err error) { func (d *DataBases) GetMsgBySeqListMongo2(uid string, seqList []uint32, operationID string) (seqMsg []*open_im_sdk.MsgData, err error) {
var hasSeqList []uint32 var hasSeqList []uint32
singleCount := 0 singleCount := 0
@ -178,7 +177,6 @@ func (d *DataBases) GetMsgBySeqListMongo2(uid string, seqList []uint32, operatio
return seqMsg, nil return seqMsg, nil
} }
func genExceptionMessageBySeqList(seqList []uint32) (exceptionMsg []*open_im_sdk.MsgData) { func genExceptionMessageBySeqList(seqList []uint32) (exceptionMsg []*open_im_sdk.MsgData) {
for _, v := range seqList { for _, v := range seqList {
msg := new(open_im_sdk.MsgData) msg := new(open_im_sdk.MsgData)
@ -258,7 +256,6 @@ func (d *DataBases) SaveUserChat(uid string, sendTime int64, m *pbMsg.MsgDataToD
return nil return nil
} }
func (d *DataBases) DelUserChat(uid string) error { func (d *DataBases) DelUserChat(uid string) error {
return nil return nil
//session := d.mgoSession.Clone() //session := d.mgoSession.Clone()
@ -277,7 +274,6 @@ func (d *DataBases) DelUserChat(uid string) error {
//return nil //return nil
} }
func (d *DataBases) DelUserChatMongo2(uid string) error { func (d *DataBases) DelUserChatMongo2(uid string) error {
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second) ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cChat) c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cChat)
@ -290,8 +286,6 @@ func (d *DataBases) DelUserChatMongo2(uid string) error {
return nil return nil
} }
func (d *DataBases) MgoUserCount() (int, error) { func (d *DataBases) MgoUserCount() (int, error) {
return 0, nil return 0, nil
//session := d.mgoSession.Clone() //session := d.mgoSession.Clone()

View File

@ -307,11 +307,30 @@ func SetConversation(conversation db.Conversation) error {
} else { } else {
log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "exist in db, update") log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "exist in db, update")
//force update //force update
return dbConn.Model(&db.Conversation{}).Update(conversation). return dbConn.Model(conversation).Where("owner_user_id = ? and conversation_id = ?", conversation.OwnerUserID, conversation.ConversationID).
Update(map[string]interface{}{"recv_msg_opt": conversation.RecvMsgOpt, "is_pinned": conversation.IsPinned, "is_private_chat": conversation.IsPrivateChat}).Error Update(map[string]interface{}{"recv_msg_opt": conversation.RecvMsgOpt, "is_pinned": conversation.IsPinned, "is_private_chat": conversation.IsPrivateChat}).Error
} }
} }
func SetRecvMsgOpt(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(conversation).Where("owner_user_id = ? and conversation_id = ?", conversation.OwnerUserID, conversation.ConversationID).
Update(map[string]interface{}{"recv_msg_opt": conversation.RecvMsgOpt}).Error
}
}
func GetUserAllConversations(ownerUserID string) ([]db.Conversation, error) { func GetUserAllConversations(ownerUserID string) ([]db.Conversation, error) {
var conversations []db.Conversation var conversations []db.Conversation
dbConn, err := db.DB.MysqlDB.DefaultGormDB() dbConn, err := db.DB.MysqlDB.DefaultGormDB()

File diff suppressed because it is too large Load Diff

View File

@ -91,6 +91,17 @@ message SetConversationResp{
CommonResp commonResp = 1; CommonResp commonResp = 1;
} }
message SetRecvMsgOptReq {
string OwnerUserID = 1;
string ConversationID = 2;
int32 RecvMsgOpt = 3;
string OperationID = 4;
}
message SetRecvMsgOptResp {
CommonResp commonResp = 1;
}
message GetConversationReq{ message GetConversationReq{
string ConversationID = 1; string ConversationID = 1;
string OwnerUserID = 2; string OwnerUserID = 2;
@ -272,6 +283,8 @@ message DeleteUserResp {
CommonResp CommonResp = 1; CommonResp CommonResp = 1;
} }
service user { service user {
rpc GetUserInfo(GetUserInfoReq) returns(GetUserInfoResp); rpc GetUserInfo(GetUserInfoReq) returns(GetUserInfoResp);
rpc UpdateUserInfo(UpdateUserInfoReq) returns(UpdateUserInfoResp); rpc UpdateUserInfo(UpdateUserInfoReq) returns(UpdateUserInfoResp);
@ -284,6 +297,7 @@ service user {
rpc GetConversations(GetConversationsReq)returns(GetConversationsResp); rpc GetConversations(GetConversationsReq)returns(GetConversationsResp);
rpc BatchSetConversations(BatchSetConversationsReq)returns(BatchSetConversationsResp); rpc BatchSetConversations(BatchSetConversationsReq)returns(BatchSetConversationsResp);
rpc SetConversation(SetConversationReq)returns(SetConversationResp); rpc SetConversation(SetConversationReq)returns(SetConversationResp);
rpc SetRecvMsgOpt(SetRecvMsgOptReq)returns(SetRecvMsgOptResp);
rpc GetUserById(GetUserByIdReq) returns (GetUserByIdResp); rpc GetUserById(GetUserByIdReq) returns (GetUserByIdResp);
rpc GetUsersByName(GetUsersByNameReq) returns (GetUsersByNameResp); rpc GetUsersByName(GetUsersByNameReq) returns (GetUsersByNameResp);