chat

package
v0.0.0-...-8de5691 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeChannel = "channel"
	TypeGroup   = "group"
	TypeDirect  = "direct"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ChannelChatDetail

type ChannelChatDetail struct {
	Title        string               `bson:"title" json:"title"`
	Members      []primitive.ObjectID `bson:"members" json:"members"`
	Admins       []primitive.ObjectID `bson:"admins" json:"admins"`
	Owner        primitive.ObjectID   `bson:"owner"         json:"owner"`
	RemovedUsers []primitive.ObjectID `bson:"removed_users" json:"removedUsers"`
	Username     string               `bson:"username" json:"username"`
	Description  string               `bson:"description" json:"description"`
}

type Chat

type Chat struct {
	ChatID     primitive.ObjectID `bson:"id"          json:"chatId"`
	ChatType   string             `bson:"chat_type"   json:"chatType"`
	ChatDetail interface{}        `bson:"chat_detail" json:"chatDetail"`
	Messages   []*message.Message `bson:"messages"    json:"messages"`
}

func NewChat

func NewChat(chatType string, chatDetail interface{}) *Chat

func (*Chat) IsAdmin

func (c *Chat) IsAdmin(staticID primitive.ObjectID) bool

func (*Chat) IsMember

func (c *Chat) IsMember(staticID primitive.ObjectID) bool

type DirectChatDetail

type DirectChatDetail struct {
	// ID of the users that chats with each other
	Sides [2]primitive.ObjectID `json:"sides"`
}

func (*DirectChatDetail) HasSide

func (d *DirectChatDetail) HasSide(staticID primitive.ObjectID) bool

type GroupChatDetail

type GroupChatDetail struct {
	Title        string               `json:"title"`
	Members      []primitive.ObjectID `json:"members"`
	Admins       []primitive.ObjectID `json:"admins"`
	Owner        primitive.ObjectID   `bson:"owner"         json:"owner"`
	RemovedUsers []primitive.ObjectID `bson:"removed_users" json:"removedUsers"`
	Username     string               `json:"username"`
	Description  string               `json:"description"`
}

type Repository

type Repository interface {
	Create(newChat Chat) (*Chat, error)
	Where(filter bson.M) ([]Chat, error)
	Destroy(chatID primitive.ObjectID) error
	FindByID(staticID primitive.ObjectID) (*Chat, error)
	FindChatOrSidesByStaticID(staticID primitive.ObjectID) (*Chat, error)
}

type Service

type Service interface {
	GetChat(staticID primitive.ObjectID) (Chat, error)
	CreateDirect(userStaticID primitive.ObjectID, targetStaticID primitive.ObjectID) (Chat, error)
	CreateGroup(userStaticID primitive.ObjectID, title string, username string, description string) (Chat, error)
	CreateChannel(userStaticID primitive.ObjectID, title string, username string, description string) (Chat, error)
}

Jump to

Keyboard shortcuts

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