model

package
v0.0.0-...-b87ab60 Latest Latest
Warning

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

Go to latest
Published: May 6, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package model @Title friend.go @Description @Author peanut996 @Update peanut996 2021/5/22 10:05

Package model @Title group.go @Description @Author peanut996 @Update peanut996 2021/5/22 17:23

Package model @Title groupuser.go @Description @Author peanut996 @Update peanut996 2021/5/22 17:40

Package model @Title model.go @Description @Author peanut996 @Update peanut996 2021/5/24 9:45

Index

Constants

View Source
const (
	MongoCollectionChatMessage = "ChatMessage"
	MongoCollectionFriend      = "Friend"
	MongoCollectionUser        = "User"
	MongoCollectionGroup       = "Group"
	MongoCollectionGroupUser   = "GroupUser"
	MongoCollectionRoom        = "Room"

	DefaultFriendPageSize = 20
)

Variables

This section is empty.

Functions

func AddNewFriend

func AddNewFriend(friendA, friendB string) error

AddNewFriend Add friends by UID

func CreateGroupUser

func CreateGroupUser(groupID, user string) error

func GetAssociatedUIDsByUID

func GetAssociatedUIDsByUID(uid string) ([]string, error)

func GetFriendUIDsByUID

func GetFriendUIDsByUID(user string) ([]string, error)

func GetFriendsByRoomID

func GetFriendsByRoomID(roomID string) ([]string, error)

func GetGroupIDsByUID

func GetGroupIDsByUID(uid string) ([]string, error)

func GetRoomIDsByUID

func GetRoomIDsByUID(uid string) ([]string, error)

GetRoomIDsByUID Get User-related rooms

func GetUIDFromAccount

func GetUIDFromAccount(account string) (string, error)

func GetUserIDsByGroup

func GetUserIDsByGroup(group *Group) ([]string, error)

func GetUserIDsByGroupID

func GetUserIDsByGroupID(groupID string) ([]string, error)

func GetUserIDsByGroups

func GetUserIDsByGroups(groups ...*Group) ([]string, error)

func InsertChatMessage

func InsertChatMessage(c *ChatMessage) error

func InsertUser

func InsertUser(user *User) error

func UpdateUser

func UpdateUser(user *User) error

Types

type ChatMessage

type ChatMessage struct {
	From     string  `json:"from" bson:"from"`
	To       string  `json:"to,omitempty" bson:"to"`
	Content  string  `json:"content" bson:"content"`
	Time     string  `json:"time,omitempty" bson:"time"`
	Type     string  `json:"type" bson:"type"`
	FileName string  `json:"fileName" bson:"fileName"`
	Size     int     `json:"size" bson:"size"`
	Height   float64 `json:"height" bson:"height"`
	Width    float64 `json:"width" bson:"width"`
}

func ChatMessageFrom

func ChatMessageFrom(from, to, content, Type string, height, width float64, size int, fileName string) *ChatMessage

func GetFriendMessageWithPage

func GetFriendMessageWithPage(friend *Friend, current, pageSize int64) ([]*ChatMessage, error)

GetFriendMessageWithPage pull message with page. !!! Param Friend must have a roomID

func GetGroupMessageWithPage

func GetGroupMessageWithPage(group *Group, current, pageSize int64) ([]*ChatMessage, error)

func NewChatMessage

func NewChatMessage() *ChatMessage

type Friend

type Friend struct {
	FriendA    string `json:"friendA" bson:"userA"`
	FriendB    string `json:"friendB" bson:"userB"`
	RoomID     string `json:"roomID" bson:"roomID"`
	CreateTime string `json:"-" bson:"createTime"`
}

func DeleteFriend

func DeleteFriend(friendA, friendB string) (*Friend, error)

func GetFriend

func GetFriend(friendA, friendB string) (*Friend, error)

func GetFriendsByUID

func GetFriendsByUID(uid string) ([]*Friend, error)

func NewFriend

func NewFriend() *Friend

type FriendData

type FriendData struct {
	User     `json:",inline"`
	RoomID   string         `json:"roomID"`
	Messages []*ChatMessage `json:"messages"`
}

func GetFriendDataByFriend

func GetFriendDataByFriend(friend *Friend) (*FriendData, error)

func GetFriendDataByIDs

func GetFriendDataByIDs(friendA, friendB string) (*FriendData, error)

func GetFriendDatasByUID

func GetFriendDatasByUID(uid string) ([]*FriendData, error)

type FriendWithRoomID

type FriendWithRoomID struct {
	User   `json:",inline"`
	RoomID string `json:"roomID"`
}

func GetFriendWithRoomIDsByUID

func GetFriendWithRoomIDsByUID(uid string) ([]*FriendWithRoomID, error)

func NewFriendWithRoomID

func NewFriendWithRoomID(user *User, roomID string) *FriendWithRoomID

type Group

type Group struct {
	RoomID     string `json:"roomID" bson:"roomID"`
	GroupID    string `json:"groupID" bson:"groupID"`
	GroupName  string `json:"groupName" bson:"groupName"`
	GroupAdmin string `json:"groupAdmin" bson:"groupAdmin"`
	CreateTime string `json:"-" bson:"createTime"`
}

func CreateGroup

func CreateGroup(name, admin string) (*Group, error)

func FindGroupsByGroupName

func FindGroupsByGroupName(groupName string) ([]*Group, error)

func GetGroupByGroupID

func GetGroupByGroupID(groupID string) (*Group, error)

func GetGroupsByUID

func GetGroupsByUID(uid string) ([]*Group, error)

func NewGroup

func NewGroup() *Group

type GroupData

type GroupData struct {
	Group    `json:",inline"`
	Members  []*User        `json:"members"`
	Messages []*ChatMessage `json:"messages"`
}

func GetGroupDataByGroupID

func GetGroupDataByGroupID(groupID string) (*GroupData, error)

func GetGroupDatasByUID

func GetGroupDatasByUID(uid string) ([]*GroupData, error)

type GroupUser

type GroupUser struct {
	GroupID    string `json:"groupID" bson:"groupID"`
	UID        string `json:"uid" bson:"uid"`
	CreateTime string `json:"-" bson:"createTime"`
}

func DeleteGroupUser

func DeleteGroupUser(groupID, user string) (*GroupUser, error)

func NewGroupUser

func NewGroupUser() *GroupUser

type Room

type Room struct {
	RoomID     string `json:"roomID" bson:"roomID"`
	OneToOne   bool   `json:"oneToOne" bson:"oneToOne"`
	Status     string `json:"status" bson:"status"`
	CreateTime string `json:"createTime,omitempty" bson:"createTime"`
}

func GetRoomByID

func GetRoomByID(roomID string) (*Room, error)

func GetRoomsByUID

func GetRoomsByUID(uid string) ([]*Room, error)

func NewFriendRoom

func NewFriendRoom() *Room

func NewGroupRoom

func NewGroupRoom() *Room

type User

type User struct {
	UID        string `json:"uid,omitempty" bson:"uid"`
	Account    string `json:"account" bson:"account"`
	Password   string `json:"-" bson:"password"`
	Avatar     string `json:"avatar,omitempty" bson:"avatar"`
	CreateTime string `json:"-" bson:"createTime"`
}

User means a people who use the system.

func FindUsersByAccount

func FindUsersByAccount(account string) ([]*User, error)

func GetUserByAccount

func GetUserByAccount(account string) (*User, error)

func GetUserByUID

func GetUserByUID(uid string) (*User, error)

func GetUsersByGroup

func GetUsersByGroup(group *Group) ([]*User, error)

func GetUsersByGroups

func GetUsersByGroups(groups ...*Group) ([]*User, error)

func GetUsersFromUIDs

func GetUsersFromUIDs(uids ...string) ([]*User, error)

func NewUser

func NewUser(account string, password string) *User

NewUser returns a User who UID generate by snowflake Algorithm

Jump to

Keyboard shortcuts

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