mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-08 02:55:58 +08:00
Merge remote-tracking branch 'origin/v2.3.0release' into v2.3.0release
This commit is contained in:
@@ -410,15 +410,19 @@ func (d *DataBases) GetSendMsgStatus(operationID string) (int, error) {
|
||||
return status, err
|
||||
}
|
||||
|
||||
func (d *DataBases) SetFcmToken(account string, platformid int, fcmToken string, expireTime int64) (err error) {
|
||||
key := FcmToken + account + ":" + strconv.Itoa(platformid)
|
||||
func (d *DataBases) SetFcmToken(account string, platformID int, fcmToken string, expireTime int64) (err error) {
|
||||
key := FcmToken + account + ":" + strconv.Itoa(platformID)
|
||||
return d.RDB.Set(context.Background(), key, fcmToken, time.Duration(expireTime)*time.Second).Err()
|
||||
}
|
||||
|
||||
func (d *DataBases) GetFcmToken(account string, platformid int) (string, error) {
|
||||
key := FcmToken + account + ":" + strconv.Itoa(platformid)
|
||||
func (d *DataBases) GetFcmToken(account string, platformID int) (string, error) {
|
||||
key := FcmToken + account + ":" + strconv.Itoa(platformID)
|
||||
return d.RDB.Get(context.Background(), key).Result()
|
||||
}
|
||||
func (d *DataBases) DelFcmToken(account string, platformID int) error {
|
||||
key := FcmToken + account + ":" + strconv.Itoa(platformID)
|
||||
return d.RDB.Del(context.Background(), key).Err()
|
||||
}
|
||||
func (d *DataBases) IncrUserBadgeUnreadCountSum(uid string) (int, error) {
|
||||
key := userBadgeUnreadCountSum + uid
|
||||
seq, err := d.RDB.Incr(context.Background(), key).Result()
|
||||
|
||||
@@ -125,23 +125,6 @@ func init() {
|
||||
fmt.Println("createMongoIndex success")
|
||||
DB.mongoClient = mongoClient
|
||||
|
||||
// redis pool init
|
||||
//DB.redisPool = &redis.Pool{
|
||||
// MaxIdle: config.Config.Redis.DBMaxIdle,
|
||||
// MaxActive: config.Config.Redis.DBMaxActive,
|
||||
// IdleTimeout: time.Duration(config.Config.Redis.DBIdleTimeout) * time.Second,
|
||||
// Dial: func() (redis.Conn, error) {
|
||||
// return redis.Dial(
|
||||
// "tcp",
|
||||
// config.Config.Redis.DBAddress,
|
||||
// redis.DialReadTimeout(time.Duration(1000)*time.Millisecond),
|
||||
// redis.DialWriteTimeout(time.Duration(1000)*time.Millisecond),
|
||||
// redis.DialConnectTimeout(time.Duration(1000)*time.Millisecond),
|
||||
// redis.DialDatabase(0),
|
||||
// redis.DialPassword(config.Config.Redis.DBPassWord),
|
||||
// )
|
||||
// },
|
||||
//}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
if config.Config.Redis.EnableCluster {
|
||||
|
||||
+25
-12
@@ -12,6 +12,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/go-redis/redis/v8"
|
||||
"github.com/gogo/protobuf/sortkeys"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
"math/rand"
|
||||
@@ -55,6 +56,8 @@ type GroupMember_x struct {
|
||||
UIDList []string
|
||||
}
|
||||
|
||||
var ErrMsgListNotExist = errors.New("user not have msg in mongoDB")
|
||||
|
||||
func (d *DataBases) GetMinSeqFromMongo(uid string) (MinSeq uint32, err error) {
|
||||
return 1, nil
|
||||
//var i, NB uint32
|
||||
@@ -265,18 +268,19 @@ func (d *DataBases) GetUserMsgListByIndex(ID string, index int64) (*UserChat, er
|
||||
regex := fmt.Sprintf("^%s", ID)
|
||||
findOpts := options.Find().SetLimit(1).SetSkip(index).SetSort(bson.M{"uid": 1})
|
||||
var msgs []UserChat
|
||||
cursor, err := c.Find(ctx, bson.M{"uid": bson.M{"$regex": regex}}, findOpts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = cursor.Decode(&msgs)
|
||||
//primitive.Regex{Pattern: regex}
|
||||
cursor, err := c.Find(ctx, bson.M{"uid": primitive.Regex{Pattern: regex}}, findOpts)
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "")
|
||||
}
|
||||
err = cursor.All(context.Background(), &msgs)
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, fmt.Sprintf("cursor is %s", cursor.Current.String()))
|
||||
}
|
||||
if len(msgs) > 0 {
|
||||
return &msgs[0], err
|
||||
return &msgs[0], nil
|
||||
} else {
|
||||
return nil, errors.New("get msg list failed")
|
||||
return nil, ErrMsgListNotExist
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,11 +301,20 @@ func (d *DataBases) ReplaceMsgToBlankByIndex(suffixID string, index int) error {
|
||||
}
|
||||
for i, msg := range userChat.Msg {
|
||||
if i <= index {
|
||||
msg.Msg = nil
|
||||
msgPb := &open_im_sdk.MsgData{}
|
||||
if err = proto.Unmarshal(msg.Msg, msgPb); err != nil {
|
||||
continue
|
||||
}
|
||||
newMsgPb := &open_im_sdk.MsgData{Seq: msgPb.Seq}
|
||||
bytes, err := proto.Marshal(newMsgPb)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
msg.Msg = bytes
|
||||
msg.SendTime = 0
|
||||
}
|
||||
}
|
||||
_, err = c.UpdateOne(ctx, bson.M{"uid": suffixID}, userChat)
|
||||
_, err = c.UpdateOne(ctx, bson.M{"uid": suffixID}, bson.M{"$set": bson.M{"msg": userChat.Msg}})
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -315,17 +328,17 @@ func (d *DataBases) GetNewestMsg(ID string) (msg *MsgInfo, err error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = cursor.Decode(&userChats)
|
||||
err = cursor.All(ctx, &userChats)
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "")
|
||||
}
|
||||
if len(userChats) > 0 {
|
||||
if len(userChats[0].Msg) > 0 {
|
||||
return &userChats[0].Msg[len(userChats[0].Msg)], nil
|
||||
return &userChats[0].Msg[len(userChats[0].Msg)-1], nil
|
||||
}
|
||||
return nil, errors.New("len(userChats[0].Msg) < 0")
|
||||
}
|
||||
return nil, errors.New("len(userChats) < 0")
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (d *DataBases) GetMsgBySeqListMongo2(uid string, seqList []uint32, operationID string) (seqMsg []*open_im_sdk.MsgData, err error) {
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"Open_IM/pkg/utils"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -116,10 +115,10 @@ func GetUsers(showNumber, pageNumber int32) ([]db.User, error) {
|
||||
return users, err
|
||||
}
|
||||
|
||||
func AddUser(userID string, phoneNumber string, name string, email string, gender int32, faceURL string, birth uint32) error {
|
||||
_birth, _err := time.ParseInLocation("2006-01-02", strconv.Itoa(int(birth)), time.Local)
|
||||
if _err != nil {
|
||||
_birth = time.Now()
|
||||
func AddUser(userID string, phoneNumber string, name string, email string, gender int32, faceURL string, birth string) error {
|
||||
_birth, err := utils.TimeStringToTime(birth)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
user := db.User{
|
||||
UserID: userID,
|
||||
|
||||
Reference in New Issue
Block a user