fix delete

This commit is contained in:
wangchuxiao 2022-08-10 19:31:57 +08:00
parent cdc60ef5f0
commit 6bfa8643d6
7 changed files with 114 additions and 8 deletions

View File

@ -15,6 +15,8 @@ import (
_ "github.com/minio/minio-go/v7" _ "github.com/minio/minio-go/v7"
cr "github.com/minio/minio-go/v7/pkg/credentials" cr "github.com/minio/minio-go/v7/pkg/credentials"
"net/http" "net/http"
"strconv"
"strings"
) )
// @Summary minio上传文件(web api) // @Summary minio上传文件(web api)
@ -218,6 +220,13 @@ func UploadUpdateApp(c *gin.Context) {
c.JSON(http.StatusOK, resp) c.JSON(http.StatusOK, resp)
} }
func version2Int(version string) (int, error) {
versions := strings.Split(version, ".")
s := strings.Join(versions, "")
versionInt, err := strconv.Atoi(s)
return versionInt, err
}
func GetDownloadURL(c *gin.Context) { func GetDownloadURL(c *gin.Context) {
var ( var (
req api.GetDownloadURLReq req api.GetDownloadURLReq
@ -238,7 +247,13 @@ func GetDownloadURL(c *gin.Context) {
} }
log.Debug(req.OperationID, utils.GetSelfFuncName(), "app: ", app) log.Debug(req.OperationID, utils.GetSelfFuncName(), "app: ", app)
if app != nil { if app != nil {
if app.Version != req.Version && app.Version != "" { appVersion, err := version2Int(app.Version)
reqVersion, err := version2Int(req.Version)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), "req version", req.Version, "app version", app.Version)
}
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "req version:", reqVersion, "app version:", appVersion)
if appVersion > reqVersion && app.Version != "" {
resp.Data.HasNewVersion = true resp.Data.HasNewVersion = true
if app.ForceUpdate == true { if app.ForceUpdate == true {
resp.Data.ForceUpdate = true resp.Data.ForceUpdate = true

View File

@ -2,11 +2,13 @@ package cronTask
import ( import (
"Open_IM/pkg/common/config" "Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db" "Open_IM/pkg/common/db"
"Open_IM/pkg/common/log" "Open_IM/pkg/common/log"
server_api_params "Open_IM/pkg/proto/sdk_ws" server_api_params "Open_IM/pkg/proto/sdk_ws"
"Open_IM/pkg/utils" "Open_IM/pkg/utils"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"math"
) )
const oldestList = 0 const oldestList = 0
@ -19,6 +21,7 @@ func ResetUserGroupMinSeq(operationID, groupID string, userIDList []string) erro
log.NewError(operationID, utils.GetSelfFuncName(), groupID, "deleteMongoMsg failed") log.NewError(operationID, utils.GetSelfFuncName(), groupID, "deleteMongoMsg failed")
return utils.Wrap(err, "") return utils.Wrap(err, "")
} }
log.NewDebug(operationID, utils.GetSelfFuncName(), "delMsgIDList:", delMsgIDList, "minSeq", minSeq)
for _, userID := range userIDList { for _, userID := range userIDList {
userMinSeq, err := db.DB.GetGroupUserMinSeq(groupID, userID) userMinSeq, err := db.DB.GetGroupUserMinSeq(groupID, userID)
if err != nil { if err != nil {
@ -43,7 +46,7 @@ func DeleteMongoMsgAndResetRedisSeq(operationID, userID string) error {
if err != nil { if err != nil {
return utils.Wrap(err, "") return utils.Wrap(err, "")
} }
log.NewDebug(operationID, utils.GetSelfFuncName(), "delMsgIDMap: ", userID, delMsgIDList) log.NewDebug(operationID, utils.GetSelfFuncName(), "delMsgIDMap: ", delMsgIDList, "minSeq", minSeq)
err = db.DB.SetUserMinSeq(userID, minSeq) err = db.DB.SetUserMinSeq(userID, minSeq)
return err return err
} }
@ -123,3 +126,29 @@ func getDelMaxSeqByIDList(delMsgIDList [][2]interface{}) uint32 {
} }
return delMsgIDList[len(delMsgIDList)-1][1].(uint32) return delMsgIDList[len(delMsgIDList)-1][1].(uint32)
} }
func checkMaxSeqWithMongo(operationID, ID string, diffusionType int) error {
var maxSeq uint64
var err error
if diffusionType == constant.WriteDiffusion {
maxSeq, err = db.DB.GetUserMaxSeq(ID)
} else {
maxSeq, err = db.DB.GetGroupMaxSeq(ID)
}
if err != nil {
return utils.Wrap(err, "GetUserMaxSeq failed")
}
msg, err := db.DB.GetNewestMsg(ID)
if err != nil {
return utils.Wrap(err, "GetNewestMsg failed")
}
msgPb := &server_api_params.MsgData{}
err = proto.Unmarshal(msg.Msg, msgPb)
if err != nil {
return utils.Wrap(err, "")
}
if math.Abs(float64(msgPb.Seq-uint32(maxSeq))) > 10 {
log.NewWarn(operationID, utils.GetSelfFuncName(), maxSeq, msgPb.Seq, "redis maxSeq is different with msg.Seq")
}
return nil
}

View File

@ -28,6 +28,9 @@ func StartCronTask() {
if err := DeleteMongoMsgAndResetRedisSeq(operationID, userID); err != nil { if err := DeleteMongoMsgAndResetRedisSeq(operationID, userID); err != nil {
log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), userID) log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), userID)
} }
if err := checkMaxSeqWithMongo(operationID, userID, constant.WriteDiffusion); err != nil {
log.NewError(operationID, utils.GetSelfFuncName(), userID, err)
}
} }
} else { } else {
log.NewError(operationID, utils.GetSelfFuncName(), err.Error()) log.NewError(operationID, utils.GetSelfFuncName(), err.Error())
@ -45,7 +48,9 @@ func StartCronTask() {
if err := ResetUserGroupMinSeq(operationID, groupID, userIDList); err != nil { if err := ResetUserGroupMinSeq(operationID, groupID, userIDList); err != nil {
log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), groupID, userIDList) log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), groupID, userIDList)
} }
if err := checkMaxSeqWithMongo(operationID, groupID, constant.ReadDiffusion); err != nil {
log.NewError(operationID, utils.GetSelfFuncName(), groupID, err)
}
} }
} else { } else {
log.NewError(operationID, utils.GetSelfFuncName(), err.Error()) log.NewError(operationID, utils.GetSelfFuncName(), err.Error())
@ -56,6 +61,7 @@ func StartCronTask() {
fmt.Println("start cron failed", err.Error()) fmt.Println("start cron failed", err.Error())
panic(err) panic(err)
} }
c.Start() c.Start()
fmt.Println("start cron task success") fmt.Println("start cron task success")
for { for {

View File

@ -0,0 +1,3 @@
package main
func main() {}

View File

@ -83,6 +83,7 @@ type Alert struct {
type Android struct { type Android struct {
Ups struct { Ups struct {
Notification Notification `json:"notification"` Notification Notification `json:"notification"`
Options Options `json:"options"`
} `json:"ups"` } `json:"ups"`
} }
@ -92,6 +93,18 @@ type Notification struct {
ClickType string `json:"click_type"` ClickType string `json:"click_type"`
} }
type Options struct {
HW struct {
DefaultSound bool `json:"/message/android/notification/default_sound"`
ChannelID string `json:"/message/android/notification/channel_id"`
Sound string `json:"/message/android/notification/sound"`
Importance string `json:"/message/android/notification/importance"`
} `json:"HW"`
XM struct {
ChannelID string `json:"/extra.channel_id"`
} `json:""`
}
type PushResp struct { type PushResp struct {
} }
@ -133,6 +146,17 @@ func (g *Getui) Push(userIDList []string, alert, detailContent, operationID stri
Body: alert, Body: alert,
ClickType: "startapp", ClickType: "startapp",
} }
pushReq.PushChannel.Android.Ups.Options = Options{
HW: struct {
DefaultSound bool `json:"/message/android/notification/default_sound"`
ChannelID string `json:"/message/android/notification/channel_id"`
Sound string `json:"/message/android/notification/sound"`
Importance string `json:"/message/android/notification/importance"`
}{ChannelID: "RingRing4", Sound: "/raw/ring001", Importance: "importance"},
XM: struct {
ChannelID string `json:"/extra.channel_id"`
}{ChannelID: "Default"},
}
pushResp := PushResp{} pushResp := PushResp{}
err = g.request(PushURL, pushReq, token, &pushResp, operationID) err = g.request(PushURL, pushReq, token, &pushResp, operationID)
switch err { switch err {

View File

@ -227,6 +227,11 @@ const (
WorkMomentAtUserNotification = 2 WorkMomentAtUserNotification = 2
) )
const (
WriteDiffusion = 0
ReadDiffusion = 1
)
const ( const (
AtAllString = "AtAllTag" AtAllString = "AtAllTag"
AtNormal = 0 AtNormal = 0

View File

@ -259,18 +259,22 @@ func (d *DataBases) GetMsgBySeqList(uid string, seqList []uint32, operationID st
return seqMsg, nil return seqMsg, nil
} }
func (d *DataBases) GetUserMsgListByIndex(ID string, index int64) (msg *UserChat, err error) { func (d *DataBases) GetUserMsgListByIndex(ID string, index int64) (*UserChat, 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)
regex := fmt.Sprintf("^%s", ID) regex := fmt.Sprintf("^%s", ID)
findOpts := options.Find().SetLimit(1).SetSkip(index).SetSort(bson.M{"$regex": regex}) findOpts := options.Find().SetLimit(1).SetSkip(index).SetSort(bson.M{"$regex": regex}).SetSort(bson.M{"uid": 1})
msg = &UserChat{} var msgs []UserChat
cursor, err := c.Find(ctx, bson.M{"uid": bson.M{"$regex": regex}}, findOpts) cursor, err := c.Find(ctx, bson.M{"uid": bson.M{"$regex": regex}}, findOpts)
if err != nil { if err != nil {
return nil, err return nil, err
} }
err = cursor.Decode(&msg) err = cursor.Decode(&msgs)
return msg, err if len(msgs) > 0 {
return &msgs[0], err
} else {
return nil, errors.New("get msg list failed")
}
} }
func (d *DataBases) DelMongoMsgs(IDList []string) error { func (d *DataBases) DelMongoMsgs(IDList []string) error {
@ -298,6 +302,26 @@ func (d *DataBases) ReplaceMsgToBlankByIndex(suffixID string, index int) error {
return err return err
} }
func (d *DataBases) GetNewestMsg(ID string) (msg *MsgInfo, 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).SetSort(bson.M{"$regex": regex}).SetSort(bson.M{"uid": -1})
var userChats []UserChat
cursor, err := c.Find(ctx, bson.M{"uid": bson.M{"$regex": regex}}, findOpts)
if err != nil {
return nil, err
}
err = cursor.Decode(&userChats)
if len(userChats) > 0 {
if len(userChats[0].Msg) > 0 {
return &userChats[0].Msg[len(userChats[0].Msg)], nil
}
return nil, errors.New("len(userChats[0].Msg) < 0")
}
return nil, errors.New("len(userChats) < 0")
}
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