Merge remote-tracking branch 'origin/v2.3.0release' into v2.3.0release

This commit is contained in:
Gordon
2022-08-08 17:42:39 +08:00
18 changed files with 365 additions and 129 deletions
+11
View File
@@ -289,3 +289,14 @@ type SetGroupMemberInfoReq struct {
type SetGroupMemberInfoResp struct {
CommResp
}
type GetGroupAbstractInfoReq struct {
OperationID string `json:"operationID"`
GroupID string `json:"groupID"`
}
type GetGroupAbstractInfoResp struct {
CommResp
GroupMemberNumber int32 `json:"groupMemberNumber"`
GroupMemberListHash uint64 `json:"groupMemberListHash"`
}
+2 -2
View File
@@ -383,8 +383,8 @@ func (d *DataBases) SetGetuiToken(token string, expireTime int64) error {
}
func (d *DataBases) GetGetuiToken() (string, error) {
result := d.RDB.Get(context.Background(), getuiToken)
return result.String(), result.Err()
result, err := d.RDB.Get(context.Background(), getuiToken).Result()
return result, err
}
func (d *DataBases) SetSendMsgFailedFlag(operationID string) error {
+41
View File
@@ -46,6 +46,7 @@ type MsgInfo struct {
type UserChat struct {
UID string
//ListIndex int `bson:"index"`
Msg []MsgInfo
}
@@ -258,6 +259,45 @@ func (d *DataBases) GetMsgBySeqList(uid string, seqList []uint32, operationID st
return seqMsg, nil
}
func (d *DataBases) GetUserMsgListByIndex(ID string, index int64) (msg *UserChat, err error) {
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cChat)
regex := fmt.Sprintf("^%s", ID)
findOpts := options.Find().SetLimit(1).SetSkip(index).SetSort(bson.M{"$regex": regex})
msg = &UserChat{}
cursor, err := c.Find(ctx, bson.M{"uid": bson.M{"$regex": regex}}, findOpts)
if err != nil {
return nil, err
}
err = cursor.Decode(&msg)
return msg, err
}
func (d *DataBases) DelMongoMsgs(IDList []string) error {
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cChat)
_, err := c.DeleteMany(ctx, bson.M{"uid": bson.M{"$in": IDList}})
return err
}
func (d *DataBases) ReplaceMsgToBlankByIndex(suffixID string, index int) error {
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cChat)
userChat := &UserChat{}
err := c.FindOne(ctx, bson.M{"uid": suffixID}).Decode(&userChat)
if err != nil {
return err
}
for i, msg := range userChat.Msg {
if i <= index {
msg.Msg = nil
msg.SendTime = 0
}
}
_, err = c.UpdateOne(ctx, bson.M{"uid": suffixID}, userChat)
return err
}
func (d *DataBases) GetMsgBySeqListMongo2(uid string, seqList []uint32, operationID string) (seqMsg []*open_im_sdk.MsgData, err error) {
var hasSeqList []uint32
singleCount := 0
@@ -1192,6 +1232,7 @@ func isNotContainInt32(target uint32, List []uint32) bool {
func indexGen(uid string, seqSuffix uint32) string {
return uid + ":" + strconv.FormatInt(int64(seqSuffix), 10)
}
func superGroupIndexGen(groupID string, seqSuffix uint32) string {
return "super_group_" + groupID + ":" + strconv.FormatInt(int64(seqSuffix), 10)
}
+44 -5
View File
@@ -10,6 +10,9 @@ import (
"encoding/json"
"errors"
"fmt"
"math/big"
"sort"
"strconv"
"time"
)
@@ -27,6 +30,8 @@ const (
allDepartmentCache = "ALL_DEPARTMENT_CACHE:"
allDepartmentMemberCache = "ALL_DEPARTMENT_MEMBER_CACHE:"
joinedSuperGroupListCache = "JOINED_SUPER_GROUP_LIST_CACHE:"
groupMemberListHashCache = "GROUP_MEMBER_LIST_HASH_CACHE:"
groupMemberNumCache = "GROUP_MEMBER_NUM_CACHE:"
)
func init() {
@@ -374,7 +379,7 @@ func GetJoinedSuperGroupListFromCache(userID string) ([]string, error) {
bytes, err := json.Marshal(userToSuperGroup.GroupIDList)
return string(bytes), utils.Wrap(err, "")
}
joinedSuperGroupListStr, err := db.DB.Rc.Fetch(joinedSuperGroupListCache+userID, time.Second, getJoinedSuperGroupIDList)
joinedSuperGroupListStr, err := db.DB.Rc.Fetch(joinedSuperGroupListCache+userID, time.Second*30*60, getJoinedSuperGroupIDList)
var joinedSuperGroupList []string
err = json.Unmarshal([]byte(joinedSuperGroupListStr), &joinedSuperGroupList)
return joinedSuperGroupList, err
@@ -385,10 +390,44 @@ func DelJoinedSuperGroupIDListFromCache(userID string) error {
return err
}
func GetSuperGroupMemberIDListFromCache(groupID string) ([]string, error) {
return GetGroupMemberIDListFromCache(groupID)
func GetGroupMemberListHashFromCache(groupID string) (uint64, error) {
generateHash := func() (string, error) {
groupMemberIDList, err := GetGroupMemberIDListFromCache(groupID)
if err != nil {
return "", utils.Wrap(err, "GetGroupMemberIDListFromCache failed")
}
sort.Strings(groupMemberIDList)
var all string
for _, v := range groupMemberIDList {
all += v
}
bi := big.NewInt(0)
bi.SetString(utils.Md5(all)[0:8], 16)
return strconv.Itoa(int(bi.Uint64())), nil
}
hashCode, err := db.DB.Rc.Fetch(groupMemberListHashCache+groupID, time.Second*30*60, generateHash)
hashCodeUint64, err := strconv.Atoi(hashCode)
return uint64(hashCodeUint64), err
}
func DelSuperGroupMemberIDListFromCache(groupID string) error {
return DelGroupMemberIDListFromCache(groupID)
func DelGroupMemberListHashFromCache(groupID string) error {
err := db.DB.Rc.TagAsDeleted(groupMemberListHashCache + groupID)
return err
}
func GetGroupMemberNumFromCache(groupID string) (int64, error) {
getGroupMemberNum := func() (string, error) {
num, err := imdb.GetGroupMemberNumByGroupID(groupID)
if err != nil {
return "", utils.Wrap(err, "")
}
return strconv.Itoa(int(num)), nil
}
groupMember, err := db.DB.Rc.Fetch(groupMemberNumCache+groupID, time.Second*30*60, getGroupMemberNum)
num, err := strconv.Atoi(groupMember)
return int64(num), err
}
func DelGroupMemberNumFromCache(groupID string) error {
return db.DB.Rc.TagAsDeleted(groupMemberNumCache + groupID)
}