pull/218/head
wangchuxiao 3 years ago
parent 1bd8154ac4
commit 18d7aab703

@ -88,12 +88,11 @@ func syncPeerUserConversation(conversation *pbUser.Conversation, operationID str
AttachedInfo: "", AttachedInfo: "",
Ex: "", Ex: "",
} }
err := imdb.CreateConversationIfNotExist(peerUserConversation) err := imdb.PeerUserSetConversation(peerUserConversation)
if err != nil { if err != nil {
log.NewError(operationID, utils.GetSelfFuncName(), "SetConversation error", err.Error()) log.NewError(operationID, utils.GetSelfFuncName(), "SetConversation error", err.Error())
return err return err
} }
chat.SetConversationNotification(operationID, conversation.UserID) chat.SetConversationNotification(operationID, conversation.UserID)
} }
return nil return nil
@ -140,9 +139,9 @@ func (s *userServer) BatchSetConversations(ctx context.Context, req *pbUser.Batc
continue continue
} }
resp.Success = append(resp.Success, v.ConversationID) resp.Success = append(resp.Success, v.ConversationID)
//if err := syncPeerUserConversation(v, req.OperationID); err != nil { if err := syncPeerUserConversation(v, req.OperationID); err != nil {
// log.NewError(req.OperationID, utils.GetSelfFuncName(), "syncPeerUserConversation", err.Error()) log.NewError(req.OperationID, utils.GetSelfFuncName(), "syncPeerUserConversation", err.Error())
//} }
} }
chat.SetConversationNotification(req.OperationID, req.OwnerUserID) chat.SetConversationNotification(req.OperationID, req.OwnerUserID)
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return", resp.String()) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return", resp.String())
@ -219,10 +218,12 @@ func (s *userServer) SetConversation(ctx context.Context, req *pbUser.SetConvers
resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg} resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
return resp, nil return resp, nil
} }
// sync peer user conversation if conversation is singleChatType //sync peer user conversation if conversation is singleChatType
//if err := syncPeerUserConversation(req.Conversation, req.OperationID); err != nil { if err := syncPeerUserConversation(req.Conversation, req.OperationID); err != nil {
// log.NewError(req.OperationID, utils.GetSelfFuncName(), "syncPeerUserConversation", err.Error()) log.NewError(req.OperationID, utils.GetSelfFuncName(), "syncPeerUserConversation", err.Error())
//} resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
return resp, nil
}
chat.SetConversationNotification(req.OperationID, req.Conversation.OwnerUserID) chat.SetConversationNotification(req.OperationID, req.Conversation.OwnerUserID)
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return", resp.String()) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return", resp.String())
resp.CommonResp = &pbUser.CommonResp{} resp.CommonResp = &pbUser.CommonResp{}
@ -241,6 +242,17 @@ func (s *userServer) SetRecvMsgOpt(ctx context.Context, req *pbUser.SetRecvMsgOp
resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg} resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
return resp, nil return resp, nil
} }
stringList := strings.Split(req.ConversationID, "_")
if len(stringList) > 1 {
switch stringList[0] {
case "single_":
conversation.UserID = stringList[1]
conversation.ConversationType = constant.SingleChatType
case "group":
conversation.GroupID = stringList[1]
conversation.ConversationType = constant.GroupChatType
}
}
err := imdb.SetRecvMsgOpt(conversation) err := imdb.SetRecvMsgOpt(conversation)
if err != nil { if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation error", err.Error()) log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation error", err.Error())

@ -325,6 +325,25 @@ func SetConversation(conversation db.Conversation) error {
} }
} }
func PeerUserSetConversation(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
}
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{}{"is_private_chat": conversation.IsPrivateChat}).Error
}
func SetRecvMsgOpt(conversation db.Conversation) error { func SetRecvMsgOpt(conversation db.Conversation) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB() dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil { if err != nil {
@ -377,12 +396,3 @@ func GetConversations(OwnerUserID string, conversationIDs []string) ([]db.Conver
err = dbConn.Model(&db.Conversation{}).Where("conversation_id IN (?) and owner_user_id=?", conversationIDs, OwnerUserID).Find(&conversations).Error err = dbConn.Model(&db.Conversation{}).Where("conversation_id IN (?) and owner_user_id=?", conversationIDs, OwnerUserID).Find(&conversations).Error
return conversations, err return conversations, err
} }
func CreateConversationIfNotExist(conversation db.Conversation) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
err = dbConn.Model(&db.Conversation{}).Create(conversation).Error
return nil
}

Loading…
Cancel
Save