MongoBind

package
v0.0.0-...-bbbc4ea Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2019 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CollDelayMessage           *mongo.Collection // the message for the user when him was offline.
	CollUserChatHistory        *mongo.Collection // the history of the message which between two user.
	CollGroupChatHistory       *mongo.Collection // the history of the message which belong the group chat.
	CollSubscriptionMsgHistory *mongo.Collection // the history of the message which belong the subscription.
	CollUserFriends            *mongo.Collection // the id of user's friends, include the blacklist.
	CollUserGroupChats         *mongo.Collection // the id of the group chat which the user was joined.
	CollUserSubscriptions      *mongo.Collection // the id of the subscription which the user was followed
	CollGroupChatUsers         *mongo.Collection // the id of users whom are belong to the group chat.
	CollSubscriptionUsers      *mongo.Collection // the id of users whom are followed the subscription.
)
View Source
var (
	ErrFoundCount             = errors.New("the found count should be 0 or 1")
	ErrMessageHistoryNotFound = errors.New("the message history not found")
)

Custom errors:

Functions

func GetJoinUserId

func GetJoinUserId(userId1, userId2 int64) string

Return a string joined by two user's id

func UpdateDelayMessage

func UpdateDelayMessage(userId int64, message []byte) error

Update the delay message of the user. If the document not existed, will insert new one with the data.

func UpdateGroupChatHistoryById

func UpdateGroupChatHistoryById(groupId int64, message []byte) error

Update the message history record for the group chat.

func UpdateGroupChatUserToAddOne

func UpdateGroupChatUserToAddOne(groupChatId, managerId, userId int64) error

Update the 'users' array to add one user id.

func UpdateGroupChatUsersToDelOne

func UpdateGroupChatUsersToDelOne(groupChatId, userId int64) error

Update the 'users' array to delete one user id.

func UpdateMakeUserFollowSubscription

func UpdateMakeUserFollowSubscription(userId, subsId int64) error

Update the 'subscription' array in document which in 'user_subscriptions' collection, and the 'users' array in document which in 'subscription_users' collection at the same time.

func UpdateMakeUserUnFollowSubscription

func UpdateMakeUserUnFollowSubscription(userId, subsId int64) error

func UpdateMoveFriendIntoBlacklistPlus

func UpdateMoveFriendIntoBlacklistPlus(userId, friendId int64) error

Update the 'friends' and 'blacklist' array to move a friend id into 'blacklist' from 'friends' .

func UpdateMoveFriendOutFromBlacklistPlus

func UpdateMoveFriendOutFromBlacklistPlus(userId, friendId int64) error

Update the 'friends' and 'blacklist' array to move a friend id into 'friends' from 'blacklist'

func UpdateMoveUserIntoGroupChat

func UpdateMoveUserIntoGroupChat(userId, groupChatId int64) error

Update the 'groups' array in document which in 'user_group_chats' collection, and the 'users' array in document which in 'group_chat_users' collection at the same time.

func UpdateMoveUserOutFromGroupChat

func UpdateMoveUserOutFromGroupChat(userId, groupChatId int64) error

func UpdateSubscriptionHistoryById

func UpdateSubscriptionHistoryById(subsId int64, message []byte) error

Update the message history record for the subscription

func UpdateSubscriptionUsersToAddOne

func UpdateSubscriptionUsersToAddOne(subsId, managerId, userId int64) error

Update the 'users' array to add one user id.

func UpdateSubscriptionUsersToDelOne

func UpdateSubscriptionUsersToDelOne(subsId, userId int64) error

Update the 'users' array to delete one user id.

func UpdateUserBlacklistToAddUser

func UpdateUserBlacklistToAddUser(userId, anotherId int64) error

Update the 'blacklist' array to add one user id.

func UpdateUserBlacklistToDelUser

func UpdateUserBlacklistToDelUser(userId, anotherId int64) error

Update the 'blacklist' array to delete one user id.

func UpdateUserChatHistoryByJoinId

func UpdateUserChatHistoryByJoinId(joinUserId string, message []byte) error

Update the chat history between two users.

func UpdateUserFriendsToAddFriend

func UpdateUserFriendsToAddFriend(userId, friendId int64) error

Update the 'friends' array to add one new friend's id.

func UpdateUserFriendsToDelFriend

func UpdateUserFriendsToDelFriend(userId, friendId int64) error

Update the 'friends' array to delete one friend's id.

func UpdateUserGroupChatsToAddOne

func UpdateUserGroupChatsToAddOne(userId, groupChatId int64) error

Update the 'groups' array to add one group chat id.

func UpdateUserGroupChatsToDelOne

func UpdateUserGroupChatsToDelOne(userId, groupChatId int64) error

Update the 'groups' array to delete one group chat id.

func UpdateUserSubscriptionsToAddOne

func UpdateUserSubscriptionsToAddOne(userId, subsId int64) error

Update the 'subscription' array to add one subscription id.

func UpdateUserSubscriptionsToDelOne

func UpdateUserSubscriptionsToDelOne(userId, subsId int64) error

Update the 'subscription' array to delete one subscription id.

Types

type DocDelayMessage

type DocDelayMessage struct {
	Id      int64    `bson:"_id"`
	Message [][]byte `bson:"messages"`
}
delay_message document eg.:
{
	"_id": <user_id>,
	"messages": [
		<the message bytes data: eg. []byte("test message string")>,
		...
	]
}

information for delay message

func FindAndDeleteDelayMessage

func FindAndDeleteDelayMessage(userId int64) (*DocDelayMessage, error)

Find and delete the delay message of the user from collection.

type DocGroupChatHistory

type DocGroupChatHistory struct {
	GroupId int64            `bson:"_id"`
	History []historyMessage `bson:"history"`
}
group_chat_history document eg.:
{
	"_id": <the group chat id>,
	"history": [
		{
			"date": <date number: eg. 20190303>,
			"messages": [
				<the message bytes data eg.: []byte("test message string")>,
				....
			]
		},
	...
	]
}

information for group chat history.

func FindAllGroupChatHistoryById

func FindAllGroupChatHistoryById(groupId int64) (*DocGroupChatHistory, error)

Find the all chat history of the group chat by group id.

func FindGroupChatHistoryByIdAndDate

func FindGroupChatHistoryByIdAndDate(groupId int64, date int32) (*DocGroupChatHistory, error)

Find many group chat history of the group chat by group id and a special date.

func FindGroupChatHistoryByIdAndDateRange

func FindGroupChatHistoryByIdAndDateRange(groupId int64, startDate, endDate int32) (*DocGroupChatHistory, error)

Find many group chat history of the group chat by group id and date range.

type DocGroupChatUsers

type DocGroupChatUsers struct {
	GroupId   int64   `bson:"_id"`
	ManagerId int64   `bson:"manager"`
	Users     []int64 `bson:"users"`
}
group_chat_users document eg.:
{
	"_id": <the group chat id>,
	"manager": <the user id>,
	"users" : [
		<the user id>,
		<the user id>,
		...
	]
}

information for the users which belong to the group chat

func FindGroupChatUsersById

func FindGroupChatUsersById(groupChatId int64) (*DocGroupChatUsers, error)

type DocSubscriptionHistory

type DocSubscriptionHistory struct {
	SubsId  int64            `bson:"_id"`
	History []historyMessage `bson:"history"`
}
subscription_msg_history document eg.:
{
	"_id": <the subscription id>,
	"history": [
		{
			"date": <date number: eg. 20190303>,
			"messages": [
				<the message bytes data eg.: []byte("test message string")>,
				....
			]
		},
	...
	]
}

information for subscription message history.

func FindAllSubscriptionHistoryById

func FindAllSubscriptionHistoryById(subsId int64) (*DocSubscriptionHistory, error)

Find the all subscription message history of the subscription by the id.

func FindSubscriptionHistoryByIdAndDate

func FindSubscriptionHistoryByIdAndDate(subsId int64, date int32) (*DocSubscriptionHistory, error)

Find many subscription history of the subscription by id and a special date.

func FindSubscriptionHistoryByIdAndDateRange

func FindSubscriptionHistoryByIdAndDateRange(subsId int64, startDate, endDate int32) (*DocSubscriptionHistory, error)

Find many subscription history of the subscription by id and date range.

type DocSubscriptionUsers

type DocSubscriptionUsers struct {
	SubsId    int64   `bson:"_id"`
	ManagerId int64   `bson:"manager"`
	Users     []int64 `bson:"users"`
}
subscription_users document eg.:
{
	"_id": <the subscription id>,
	"manager": <the user id>,
	"users" : [
		<the user id>,
		<the user id>,
		...
	]
}

information for the users which followed the subscription.

func FindSubscriptionUsersById

func FindSubscriptionUsersById(subsId int64) (*DocSubscriptionUsers, error)

type DocUserChatHistory

type DocUserChatHistory struct {
	Id      string           `bson:"_id"`
	History []historyMessage `bson:"history"`
}
user_chat_history document eg.:
{
	"_id" : <join_user_id eg.: 1_2>,
	"history": [
		{
			"date": <date number: eg. 20190303>,
			"messages": [
				<the message bytes data eg.: []byte("test message string")>,
				....
			]
		},
	...
	]
}

information for user chat history

func FindUserAllChatHistoryByJoinId

func FindUserAllChatHistoryByJoinId(joinUserId string) (*DocUserChatHistory, error)

Find all chat history between two users by their id.

func FindUserChatHistoryByJoinIdAndDate

func FindUserChatHistoryByJoinIdAndDate(joinUserId string, date int32) (*DocUserChatHistory, error)

Find one chat history between two users by their id and a special date

func FindUserChatHistoryByJoinIdAndDateRange

func FindUserChatHistoryByJoinIdAndDateRange(joinUserId string, startDate, endDate int32) (*DocUserChatHistory, error)

Find many chat history between two users by their id and the date range

type DocUserFriends

type DocUserFriends struct {
	UserId    int64   `bson:"_id"`
	Friends   []int64 `bson:"friends"`
	Blacklist []int64 `bson:"blacklist"`
}
user_friends document eg.:
{
	"_id": <the user id>,
    "friends": [
        <another user id>,
        <another user id>,
		...
    ],
    "blacklist": [
    	<another user id>,
        <another user id>,
		...
    ]
}

information for user's friends.

func FindUserFriendsAndBlacklistById

func FindUserFriendsAndBlacklistById(userId int64) (*DocUserFriends, error)

type DocUserGroupChats

type DocUserGroupChats struct {
	UserId int64   `bson:"_id"`
	Groups []int64 `bson:"groups"`
}
user_group_chats document eg.:
{
	"_id": <the user id>,
	"groups": [
		<the group chat id>,
		<the group chat id>,
		...
	]
}

information for the group chat which the user had joined.

func FindUserGroupChatsById

func FindUserGroupChatsById(userId int64) (*DocUserGroupChats, error)

type DocUserSubscriptions

type DocUserSubscriptions struct {
	UserId        int64   `bson:"_id"`
	Subscriptions []int64 `bson:"subscriptions"`
}
user_subscriptions document eg.:
{
	"_id": <the user id>,
	"subscriptions": [
		<the subscription id>,
		<the subscription id>,
		...
	]
}

information for the subscription which the user had followed.

func FindUserSubscriptionsById

func FindUserSubscriptionsById(userId int64) (*DocUserSubscriptions, error)

Jump to

Keyboard shortcuts

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