unrelation

package
v3.5.0-rc.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 15, 2023 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SubscriptionPrefix = "subscription_prefix"
	SubscribedPrefix   = "subscribed_prefix"
)

prefixes and suffixes.

View Source
const (
	MaximumSubscription = 3000
)

MaximumSubscription Maximum number of subscriptions.

Variables

View Source
var ErrMsgListNotExist = errors.New("user not have msg in mongoDB")

Functions

func NewMsgMongoDriver

func NewMsgMongoDriver(database *mongo.Database) table.MsgDocModelInterface

func NewUserMongoDriver

func NewUserMongoDriver(database *mongo.Database) unrelation.UserModelInterface

Types

type Mongo

type Mongo struct {
	// contains filtered or unexported fields
}

func NewMongo

func NewMongo() (*Mongo, error)

NewMongo Initialize MongoDB connection.

func (*Mongo) CreateMsgIndex

func (m *Mongo) CreateMsgIndex() error

CreateMsgIndex creates an index for messages in MongoDB.

func (*Mongo) GetClient

func (m *Mongo) GetClient() *mongo.Client

GetClient returns the MongoDB client.

func (*Mongo) GetDatabase

func (m *Mongo) GetDatabase() *mongo.Database

GetDatabase returns the specific database from MongoDB.

type MsgMongoDriver

type MsgMongoDriver struct {
	MsgCollection *mongo.Collection
	// contains filtered or unexported fields
}

func (*MsgMongoDriver) ConvertMsgsDocLen

func (m *MsgMongoDriver) ConvertMsgsDocLen(ctx context.Context, conversationIDs []string)

func (*MsgMongoDriver) Create

func (m *MsgMongoDriver) Create(ctx context.Context, model *table.MsgDocModel) error

func (*MsgMongoDriver) DeleteDocs

func (m *MsgMongoDriver) DeleteDocs(ctx context.Context, docIDs []string) error

func (*MsgMongoDriver) DeleteMsgsInOneDocByIndex

func (m *MsgMongoDriver) DeleteMsgsInOneDocByIndex(ctx context.Context, docID string, indexes []int) error

func (*MsgMongoDriver) FindOneByDocID

func (m *MsgMongoDriver) FindOneByDocID(ctx context.Context, docID string) (*table.MsgDocModel, error)

func (*MsgMongoDriver) GetMsgBySeqIndexIn1Doc

func (m *MsgMongoDriver) GetMsgBySeqIndexIn1Doc(
	ctx context.Context,
	userID string,
	docID string,
	seqs []int64,
) (msgs []*table.MsgInfoModel, err error)

func (*MsgMongoDriver) GetMsgDocModelByIndex

func (m *MsgMongoDriver) GetMsgDocModelByIndex(
	ctx context.Context,
	conversationID string,
	index, sort int64,
) (*table.MsgDocModel, error)

func (*MsgMongoDriver) GetNewestMsg

func (m *MsgMongoDriver) GetNewestMsg(ctx context.Context, conversationID string) (*table.MsgInfoModel, error)

func (*MsgMongoDriver) GetOldestMsg

func (m *MsgMongoDriver) GetOldestMsg(ctx context.Context, conversationID string) (*table.MsgInfoModel, error)

func (*MsgMongoDriver) IsExistDocID

func (m *MsgMongoDriver) IsExistDocID(ctx context.Context, docID string) (bool, error)

func (*MsgMongoDriver) MarkSingleChatMsgsAsRead

func (m *MsgMongoDriver) MarkSingleChatMsgsAsRead(
	ctx context.Context,
	userID string,
	docID string,
	indexes []int64,
) error

func (*MsgMongoDriver) PushMsgsToDoc

func (m *MsgMongoDriver) PushMsgsToDoc(ctx context.Context, docID string, msgsToMongo []table.MsgInfoModel) error

func (*MsgMongoDriver) PushUnique

func (m *MsgMongoDriver) PushUnique(
	ctx context.Context,
	docID string,
	index int64,
	key string,
	value any,
) (*mongo.UpdateResult, error)

PushUnique value must slice.

func (*MsgMongoDriver) RangeGroupSendCount

func (m *MsgMongoDriver) RangeGroupSendCount(
	ctx context.Context,
	start time.Time,
	end time.Time,
	ase bool,
	pageNumber int32,
	showNumber int32,
) (msgCount int64, userCount int64, groups []*table.GroupCount, dateCount map[string]int64, err error)

func (*MsgMongoDriver) RangeUserSendCount

func (m *MsgMongoDriver) RangeUserSendCount(
	ctx context.Context,
	start time.Time,
	end time.Time,
	group bool,
	ase bool,
	pageNumber int32,
	showNumber int32,
) (msgCount int64, userCount int64, users []*table.UserCount, dateCount map[string]int64, err error)

RangeUserSendCount db.msg.aggregate([

{
    $match: {
        "msgs.msg.send_time": {
            "$gte": 0,
            "$lt": 1788122092317
        }
    }
},
{
    "$addFields": {
        "msgs": {
            "$filter": {
                "input": "$msgs",
                "as": "item",
                "cond": {
                    "$and": [
                        {
                            $gte: ["$$item.msg.send_time", 0]
                        },
                        {
                            $lt: ["$$item.msg.send_time", 1788122092317]
                        }
                    ]
                }
            }
        }
    }
},
{
    "$project": {
        "_id": 0,

    },

},
{
    "$project": {
        "result": {
            "$map": {
                "input": "$msgs",
                "as": "item",
                "in": {
                    user_id: "$$item.msg.send_id",
                    send_date: {
                        $dateToString: {
                            format: "%Y-%m-%d",
                            date: {
                                $toDate: "$$item.msg.send_time"
                            }
                        }
                    }
                }
            }
        }
    },

},
{
    "$unwind": "$result"
},
{
    "$group": {
        _id: "$result.send_date",
        count: {
            $sum: 1
        },
        original: {
            $push: "$$ROOT"
        }
    }
},
{
    "$addFields": {
        "dates": "$$ROOT"
    }
},
{
    "$project": {
        "_id": 0,
        "count": 0,
        "dates.original": 0,

    },

},
{
    "$group": {
        _id: null,
        count: {
            $sum: 1
        },
        dates: {
            $push: "$dates"
        },
        original: {
            $push: "$original"
        },

    }
},
{
    "$unwind": "$original"
},
{
    "$unwind": "$original"
},
{
    "$group": {
        _id: "$original.result.user_id",
        count: {
            $sum: 1
        },
        original: {
            $push: "$dates"
        },

    }
},
{
    "$addFields": {
        "dates": {
            $arrayElemAt: ["$original", 0]
        }
    }
},
{
    "$project": {
        original: 0
    }
},
{
    $sort: {
        count: - 1
    }
},
{
    "$group": {
        _id: null,
        user_count: {
            $sum: 1
        },
        users: {
            $push: "$$ROOT"
        },

    }
},
{
    "$addFields": {
        "dates": {
            $arrayElemAt: ["$users", 0]
        }
    }
},
{
    "$addFields": {
        "dates": "$dates.dates"
    }
},
{
    "$project": {
        _id: 0,
        "users.dates": 0,

    }
},
{
    "$addFields": {
        "msg_count": {
            $sum: "$users.count"
        }
    }
},
{
    "$addFields": {
        users: {
            $slice: ["$users", 0, 10]
        }
    }
}

]).

func (*MsgMongoDriver) SearchMessage

func (m *MsgMongoDriver) SearchMessage(ctx context.Context, req *msg.SearchMessageReq) (int32, []*table.MsgInfoModel, error)

func (*MsgMongoDriver) UpdateMsg

func (m *MsgMongoDriver) UpdateMsg(
	ctx context.Context,
	docID string,
	index int64,
	key string,
	value any,
) (*mongo.UpdateResult, error)

func (*MsgMongoDriver) UpdateMsgContent

func (m *MsgMongoDriver) UpdateMsgContent(ctx context.Context, docID string, index int64, msg []byte) error

func (*MsgMongoDriver) UpdateMsgStatusByIndexInOneDoc

func (m *MsgMongoDriver) UpdateMsgStatusByIndexInOneDoc(
	ctx context.Context,
	docID string,
	msg *sdkws.MsgData,
	seqIndex int,
	status int32,
) error

type UserMongoDriver

type UserMongoDriver struct {
	// contains filtered or unexported fields
}

func (*UserMongoDriver) AddSubscriptionList

func (u *UserMongoDriver) AddSubscriptionList(ctx context.Context, userID string, userIDList []string) error

AddSubscriptionList Subscriber's handling of thresholds.

func (*UserMongoDriver) GetAllSubscribeList

func (u *UserMongoDriver) GetAllSubscribeList(ctx context.Context, userID string) (userIDList []string, err error)

GetAllSubscribeList Get all users subscribed by this user.

func (*UserMongoDriver) GetSubscribedList

func (u *UserMongoDriver) GetSubscribedList(ctx context.Context, userID string) (userIDList []string, err error)

GetSubscribedList Get the user subscribed by those users.

func (*UserMongoDriver) RemoveSubscribedListFromUser

func (u *UserMongoDriver) RemoveSubscribedListFromUser(ctx context.Context, userID string, userIDList []string) error

RemoveSubscribedListFromUser Among the unsubscribed users, delete the user from the subscribed list.

func (*UserMongoDriver) UnsubscriptionList

func (u *UserMongoDriver) UnsubscriptionList(ctx context.Context, userID string, userIDList []string) error

UnsubscriptionList Handling of unsubscribe.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL