mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-03 08:35:59 +08:00
Merge remote-tracking branch 'origin/v2.3.0release' into v2.3.0release
This commit is contained in:
@@ -138,6 +138,7 @@ type config struct {
|
||||
OpenImOrganizationPort []int `yaml:"openImOrganizationPort"`
|
||||
OpenImConversationPort []int `yaml:"openImConversationPort"`
|
||||
OpenImCachePort []int `yaml:"openImCachePort"`
|
||||
OpenImRealTimeCommPort []int `yaml:"openImRealTimeCommPort"`
|
||||
}
|
||||
RpcRegisterName struct {
|
||||
OpenImStatisticsName string `yaml:"openImStatisticsName"`
|
||||
|
||||
@@ -11,11 +11,12 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
go_redis "github.com/go-redis/redis/v8"
|
||||
"github.com/golang/protobuf/jsonpb"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -230,16 +231,14 @@ func (d *DataBases) SetMessageToCache(msgList []*pbChat.MsgDataToMQ, uid string,
|
||||
}
|
||||
func (d *DataBases) DeleteMessageFromCache(msgList []*pbChat.MsgDataToMQ, uid string, operationID string) error {
|
||||
ctx := context.Background()
|
||||
var keys []string
|
||||
for _, msg := range msgList {
|
||||
key := messageCache + uid + "_" + strconv.Itoa(int(msg.MsgData.Seq))
|
||||
keys = append(keys, key)
|
||||
err := d.RDB.Del(ctx, key).Err()
|
||||
if err != nil {
|
||||
log2.NewWarn(operationID, utils.GetSelfFuncName(), "redis failed", "args:", key, uid, err.Error(), msgList)
|
||||
}
|
||||
}
|
||||
err := d.RDB.Del(ctx, keys...).Err()
|
||||
if err != nil {
|
||||
log2.NewWarn(operationID, utils.GetSelfFuncName(), "redis failed", "args:", keys, uid, err.Error(), msgList)
|
||||
}
|
||||
return err
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *DataBases) CleanUpOneUserAllMsgFromRedis(userID string, operationID string) error {
|
||||
|
||||
@@ -6,16 +6,18 @@ import (
|
||||
"Open_IM/pkg/utils"
|
||||
)
|
||||
|
||||
func SetConversation(conversation db.Conversation) error {
|
||||
func SetConversation(conversation db.Conversation) (bool, error) {
|
||||
var isUpdate bool
|
||||
newConversation := conversation
|
||||
if db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 {
|
||||
log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "not exist in db, create")
|
||||
return db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Create(conversation).Error
|
||||
return isUpdate, db.DB.MysqlDB.DefaultGormDB().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 db.DB.MysqlDB.DefaultGormDB().Model(conversation).Where("owner_user_id = ? and conversation_id = ?", conversation.OwnerUserID, conversation.ConversationID).
|
||||
isUpdate = true
|
||||
return isUpdate, db.DB.MysqlDB.DefaultGormDB().Model(conversation).Where("owner_user_id = ? and conversation_id = ?", conversation.OwnerUserID, conversation.ConversationID).
|
||||
Updates(map[string]interface{}{"recv_msg_opt": conversation.RecvMsgOpt, "is_pinned": conversation.IsPinned, "is_private_chat": conversation.IsPrivateChat,
|
||||
"group_at_type": conversation.GroupAtType, "is_not_in_group": conversation.IsNotInGroup}).Error
|
||||
}
|
||||
@@ -83,12 +85,20 @@ func GetConversations(OwnerUserID string, conversationIDs []string) ([]db.Conver
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Where("conversation_id IN (?) and owner_user_id=?", conversationIDs, OwnerUserID).Find(&conversations).Error
|
||||
return conversations, err
|
||||
}
|
||||
|
||||
func GetConversationsByConversationIDMultipleOwner(OwnerUserIDList []string, conversationID string) ([]db.Conversation, error) {
|
||||
var conversations []db.Conversation
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Where("owner_user_id IN (?) and conversation_id=?", OwnerUserIDList, conversationID).Find(&conversations).Error
|
||||
return conversations, err
|
||||
}
|
||||
|
||||
func UpdateColumnsConversations(ownerUserIDList []string, conversationID string, args map[string]interface{}) error {
|
||||
return db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Where("owner_user_id IN (?) and conversation_id=?", ownerUserIDList, conversationID).Updates(args).Error
|
||||
|
||||
}
|
||||
|
||||
func GetConversationIDListByUserID(userID string) ([]string, error) {
|
||||
var IDList []string
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Where("user_id=?", userID).Pluck("conversation_id", &IDList).Error
|
||||
return IDList, err
|
||||
}
|
||||
|
||||
@@ -12,6 +12,11 @@ func GetRegister(account, areaCode, userID string) (*db.Register, error) {
|
||||
userID, "", account, account, areaCode).Take(&r).Error
|
||||
}
|
||||
|
||||
func GetRegisterInfo(userID string) (*db.Register, error) {
|
||||
var r db.Register
|
||||
return &r, db.DB.MysqlDB.DefaultGormDB().Table("registers").Where("user_id = ?", userID).Take(&r).Error
|
||||
}
|
||||
|
||||
func SetPassword(account, password, ex, userID, areaCode, ip string) error {
|
||||
r := db.Register{
|
||||
Account: account,
|
||||
|
||||
@@ -32,6 +32,8 @@ const (
|
||||
joinedSuperGroupListCache = "JOINED_SUPER_GROUP_LIST_CACHE:"
|
||||
groupMemberListHashCache = "GROUP_MEMBER_LIST_HASH_CACHE:"
|
||||
groupMemberNumCache = "GROUP_MEMBER_NUM_CACHE:"
|
||||
conversationCache = "CONVERSATION_CACHE:"
|
||||
conversationIDListCache = "CONVERSATION_ID_LIST_CACHE:"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -431,3 +433,75 @@ func GetGroupMemberNumFromCache(groupID string) (int64, error) {
|
||||
func DelGroupMemberNumFromCache(groupID string) error {
|
||||
return db.DB.Rc.TagAsDeleted(groupMemberNumCache + groupID)
|
||||
}
|
||||
|
||||
func GetUserConversationIDListFromCache(userID string) ([]string, error) {
|
||||
getConversationIDList := func() (string, error) {
|
||||
conversationIDList, err := imdb.GetConversationIDListByUserID(userID)
|
||||
if err != nil {
|
||||
return "", utils.Wrap(err, "getConversationIDList failed")
|
||||
}
|
||||
bytes, err := json.Marshal(conversationIDList)
|
||||
return string(bytes), utils.Wrap(err, "")
|
||||
}
|
||||
conversationIDListStr, err := db.DB.Rc.Fetch(conversationIDListCache+userID, time.Second*30*60, getConversationIDList)
|
||||
var conversationIDList []string
|
||||
err = json.Unmarshal([]byte(conversationIDListStr), &conversationIDList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return conversationIDList, nil
|
||||
}
|
||||
|
||||
func DelUserConversationIDListFromCache(userID string) error {
|
||||
return db.DB.Rc.TagAsDeleted(conversationIDListCache + userID)
|
||||
}
|
||||
|
||||
func GetConversationFromCache(ownerUserID, conversationID string) (*db.Conversation, error) {
|
||||
getConversation := func() (string, error) {
|
||||
conversation, err := imdb.GetConversation(ownerUserID, conversationID)
|
||||
if err != nil {
|
||||
return "", utils.Wrap(err, "")
|
||||
}
|
||||
bytes, err := json.Marshal(conversation)
|
||||
return string(bytes), utils.Wrap(err, "")
|
||||
}
|
||||
conversationStr, err := db.DB.Rc.Fetch(conversationCache+ownerUserID+":"+conversationID, time.Second*30*60, getConversation)
|
||||
conversation := db.Conversation{}
|
||||
err = json.Unmarshal([]byte(conversationStr), &conversation)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &conversation, nil
|
||||
}
|
||||
|
||||
func GetConversationsFromCache(ownerUserID string, conversationIDList []string) ([]db.Conversation, error) {
|
||||
var conversationList []db.Conversation
|
||||
for _, conversationID := range conversationIDList {
|
||||
conversation, err := GetConversationFromCache(ownerUserID, conversationID)
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "GetConversationFromCache failed")
|
||||
}
|
||||
conversationList = append(conversationList, *conversation)
|
||||
}
|
||||
return conversationList, nil
|
||||
}
|
||||
|
||||
func GetUserAllConversationList(ownerUserID string) ([]db.Conversation, error) {
|
||||
IDList, err := GetUserConversationIDListFromCache(ownerUserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var conversationList []db.Conversation
|
||||
for _, conversationID := range IDList {
|
||||
conversation, err := GetConversationFromCache(ownerUserID, conversationID)
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "GetConversationFromCache failed")
|
||||
}
|
||||
conversationList = append(conversationList, *conversation)
|
||||
}
|
||||
return conversationList, nil
|
||||
}
|
||||
|
||||
func DelConversationFromCache(ownerUserID, conversationID string) error {
|
||||
return db.DB.Rc.TagAsDeleted(conversationCache + ownerUserID + ":" + conversationID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user