mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
Merge remote-tracking branch 'origin/v3dev' into v3dev
This commit is contained in:
commit
4ca3e757bd
1
.gitignore
vendored
1
.gitignore
vendored
@ -162,6 +162,7 @@ go.work
|
|||||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||||
|
|
||||||
# User-specific stuff
|
# User-specific stuff
|
||||||
|
.idea/
|
||||||
.idea/**/workspace.xml
|
.idea/**/workspace.xml
|
||||||
.idea/**/tasks.xml
|
.idea/**/tasks.xml
|
||||||
.idea/**/usage.statistics.xml
|
.idea/**/usage.statistics.xml
|
||||||
|
@ -3,7 +3,6 @@ package msg
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/google/uuid"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
|
||||||
@ -79,7 +78,6 @@ func (m *msgServer) RevokeMsg(ctx context.Context, req *msg.RevokeMsgReq) (*msg.
|
|||||||
}
|
}
|
||||||
now := time.Now().UnixMilli()
|
now := time.Now().UnixMilli()
|
||||||
err = m.MsgDatabase.RevokeMsg(ctx, req.ConversationID, req.Seq, &unRelationTb.RevokeModel{
|
err = m.MsgDatabase.RevokeMsg(ctx, req.ConversationID, req.Seq, &unRelationTb.RevokeModel{
|
||||||
ID: uuid.New().String(),
|
|
||||||
Role: role,
|
Role: role,
|
||||||
UserID: req.UserID,
|
UserID: req.UserID,
|
||||||
Nickname: user.Nickname,
|
Nickname: user.Nickname,
|
||||||
|
@ -21,7 +21,6 @@ type MsgDocModel struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type RevokeModel struct {
|
type RevokeModel struct {
|
||||||
ID string `bson:"id"`
|
|
||||||
Role int32 `bson:"role"`
|
Role int32 `bson:"role"`
|
||||||
UserID string `bson:"user_id"`
|
UserID string `bson:"user_id"`
|
||||||
Nickname string `bson:"nickname"`
|
Nickname string `bson:"nickname"`
|
||||||
@ -68,6 +67,11 @@ type MsgInfoModel struct {
|
|||||||
IsRead bool `bson:"is_read"`
|
IsRead bool `bson:"is_read"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type UserCount struct {
|
||||||
|
UserID string `bson:"user_id"`
|
||||||
|
Count int64 `bson:"count"`
|
||||||
|
}
|
||||||
|
|
||||||
type MsgDocModelInterface interface {
|
type MsgDocModelInterface interface {
|
||||||
PushMsgsToDoc(ctx context.Context, docID string, msgsToMongo []MsgInfoModel) error
|
PushMsgsToDoc(ctx context.Context, docID string, msgsToMongo []MsgInfoModel) error
|
||||||
Create(ctx context.Context, model *MsgDocModel) error
|
Create(ctx context.Context, model *MsgDocModel) error
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
|
||||||
|
|
||||||
@ -247,7 +248,7 @@ func (m *MsgMongoDriver) GetMsgBySeqIndexIn1Doc(ctx context.Context, userID stri
|
|||||||
}
|
}
|
||||||
if msg.Revoke != nil {
|
if msg.Revoke != nil {
|
||||||
revokeContent := sdkws.MessageRevokedContent{
|
revokeContent := sdkws.MessageRevokedContent{
|
||||||
RevokerID: msg.Revoke.ID,
|
RevokerID: msg.Revoke.UserID,
|
||||||
RevokerRole: msg.Revoke.Role,
|
RevokerRole: msg.Revoke.Role,
|
||||||
ClientMsgID: msg.Msg.ClientMsgID,
|
ClientMsgID: msg.Msg.ClientMsgID,
|
||||||
RevokerNickname: msg.Revoke.Nickname,
|
RevokerNickname: msg.Revoke.Nickname,
|
||||||
@ -308,3 +309,168 @@ func (m *MsgMongoDriver) MarkSingleChatMsgsAsRead(ctx context.Context, userID st
|
|||||||
_, err := m.MsgCollection.BulkWrite(ctx, updates)
|
_, err := m.MsgCollection.BulkWrite(ctx, updates)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *MsgMongoDriver) RangeCount(ctx context.Context, start time.Time, end time.Time) (int64, error) {
|
||||||
|
type Total struct {
|
||||||
|
Total int64 `bson:"total"`
|
||||||
|
}
|
||||||
|
pipeline := bson.A{
|
||||||
|
bson.M{
|
||||||
|
"$addFields": bson.M{
|
||||||
|
"msgs": bson.M{
|
||||||
|
"$filter": bson.M{
|
||||||
|
"input": "$msgs",
|
||||||
|
"as": "item",
|
||||||
|
"cond": bson.M{
|
||||||
|
"$and": bson.A{
|
||||||
|
bson.M{
|
||||||
|
"$gte": bson.A{
|
||||||
|
"$$item.msg.send_time", start.UnixMilli(),
|
||||||
|
},
|
||||||
|
"$lt": bson.A{
|
||||||
|
"$$item.msg.send_time", end.UnixMilli(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
bson.M{
|
||||||
|
"$group": bson.M{
|
||||||
|
"_id": nil,
|
||||||
|
"total": bson.M{
|
||||||
|
"$sum": bson.M{
|
||||||
|
"$size": "$msgs",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
cur, err := m.MsgCollection.Aggregate(ctx, pipeline)
|
||||||
|
if err != nil {
|
||||||
|
return 0, errs.Wrap(err)
|
||||||
|
}
|
||||||
|
defer cur.Close(ctx)
|
||||||
|
var total []Total
|
||||||
|
if err := cur.All(ctx, &total); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
if len(total) == 0 {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
return total[0].Total, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MsgMongoDriver) RangeUserSendCount(ctx context.Context, ase bool, start time.Time, end time.Time) (int64, []*table.UserCount, error) {
|
||||||
|
var sort int
|
||||||
|
if ase {
|
||||||
|
sort = -1
|
||||||
|
} else {
|
||||||
|
sort = 1
|
||||||
|
}
|
||||||
|
type Result struct {
|
||||||
|
Total int64 `bson:"result"`
|
||||||
|
Result []struct {
|
||||||
|
UserID string `bson:"_id"`
|
||||||
|
Count int64 `bson:"count"`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pipeline := bson.A{
|
||||||
|
bson.M{
|
||||||
|
"$addFields": bson.M{
|
||||||
|
"msgs": bson.M{
|
||||||
|
"$filter": bson.M{
|
||||||
|
"input": "$msgs",
|
||||||
|
"as": "item",
|
||||||
|
"cond": bson.M{
|
||||||
|
"$and": bson.A{
|
||||||
|
bson.M{
|
||||||
|
"$gte": bson.A{
|
||||||
|
"$$item.msg.send_time", start.UnixMilli(),
|
||||||
|
},
|
||||||
|
"$lt": bson.A{
|
||||||
|
"$$item.msg.send_time", end.UnixMilli(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
bson.M{
|
||||||
|
"project": bson.M{
|
||||||
|
"_id": 0,
|
||||||
|
"doc_id": 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
bson.M{
|
||||||
|
"$project": bson.M{
|
||||||
|
"msgs": bson.M{
|
||||||
|
"$map": bson.M{
|
||||||
|
"input": "$msgs",
|
||||||
|
"as": "item",
|
||||||
|
"in": "$$item.msg.send_id",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
bson.M{
|
||||||
|
"$unwind": "$msgs",
|
||||||
|
},
|
||||||
|
bson.M{
|
||||||
|
"$sortByCount": "$msgs",
|
||||||
|
},
|
||||||
|
bson.M{
|
||||||
|
"sort": bson.M{
|
||||||
|
"count": sort,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
bson.M{
|
||||||
|
"$group": bson.M{
|
||||||
|
"_id": nil,
|
||||||
|
"result": bson.M{
|
||||||
|
"$push": "$$ROOT",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
bson.M{
|
||||||
|
"addFields": bson.M{
|
||||||
|
"result": bson.M{
|
||||||
|
"$size": "$result",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
bson.M{
|
||||||
|
"$addFields": bson.M{
|
||||||
|
"result": bson.M{
|
||||||
|
"$slice": bson.A{
|
||||||
|
"$result", 0, 10,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
cur, err := m.MsgCollection.Aggregate(ctx, pipeline)
|
||||||
|
if err != nil {
|
||||||
|
return 0, nil, errs.Wrap(err)
|
||||||
|
}
|
||||||
|
defer cur.Close(ctx)
|
||||||
|
var result []Result
|
||||||
|
if err := cur.All(ctx, &result); err != nil {
|
||||||
|
return 0, nil, err
|
||||||
|
}
|
||||||
|
if len(result) == 0 {
|
||||||
|
return 0, nil, nil
|
||||||
|
}
|
||||||
|
res := make([]*table.UserCount, len(result[0].Result))
|
||||||
|
for i, r := range result[0].Result {
|
||||||
|
res[i] = &table.UserCount{
|
||||||
|
UserID: r.UserID,
|
||||||
|
Count: r.Count,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result[0].Total, res, nil
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user