db

package
v0.0.0-...-05e4c81 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRedisPool

func NewRedisPool(options conf.RedisConf) *redis.Pool

Types

type Bus

type Bus interface {
	Receive() chan map[string][]byte

	Subscribe(id string) error

	Unsubscribe(id string) error

	Publish(id string, msg []byte) error
}

type Chat

type Chat interface {
	OpenedRoomsCount(memberID string) (int, *conf.ApiError)

	CreateRoom(room models.Room) (*models.Room, *conf.ApiError)

	GetRooms(memberID string) ([]models.Room, *conf.ApiError)

	GetRoomsIn(roomIDs []string) ([]models.Room, *conf.ApiError)

	GetRoom(memberID string, roomID string) (*models.Room, *conf.ApiError)

	DeleteRoom(roomID string) *conf.ApiError

	AddRoomMember(roomID string, memberID string) *conf.ApiError

	RemoveRoomMember(roomID string, memberID string) *conf.ApiError

	IsRoomMember(roomID string, memberID string) *conf.ApiError
}

type ChatLog

type ChatLog interface {
	AddMessage(message models.Message) (*models.Message, *conf.ApiError)

	GetMessages(profileID string, roomID string, from time.Time, limit int) ([]models.Message, *conf.ApiError)

	AddReaction(profileID string, messageID string, reaction string) *conf.ApiError

	EditMessage(profileID string, messageID string, body string) *conf.ApiError
}

type MemberInfo

type MemberInfo interface {
	CreateMemberInfo(memberInfo models.MemberInfo) (*models.MemberInfo, *conf.ApiError)

	GetMemberInfo(roomID string, memberID string) (*models.MemberInfo, *conf.ApiError)

	GetAllMembersInfo(roomID string) ([]models.MemberInfo, *conf.ApiError)

	UpdateLastReadTime(roomID string, memberID string) *conf.ApiError

	DeleteMemberInfo(roomID string, memberID string) *conf.ApiError

	DeleteAllMembersInfo(roomID string) *conf.ApiError

	GetAllRoomsInfo(memberID string) ([]models.MemberInfo, *conf.ApiError)
}

type MongoChat

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

Chat Service manages chat rooms and their members.

func NewMongoChat

func NewMongoChat(mongoOptions conf.MongoConf) *MongoChat

Creates Chat Service. Initialises MongoDB connection.

func (*MongoChat) AddMessage

func (c *MongoChat) AddMessage(message models.Message) (*models.Message, *conf.ApiError)

Adds message to chat log to a given chat room by a given member.

func (*MongoChat) AddReaction

func (c *MongoChat) AddReaction(profileID string, messageID string, reaction string) *conf.ApiError

func (*MongoChat) AddRoomMember

func (c *MongoChat) AddRoomMember(roomID string, memberID string) *conf.ApiError

Adds new member to a given chat room. Actual member info retrieved from account service. Additionally checks that current user is an owner of that room to update it.

func (*MongoChat) CreateMemberInfo

func (c *MongoChat) CreateMemberInfo(memberInfo models.MemberInfo) (*models.MemberInfo, *conf.ApiError)

Creates Member Info and returns last version

func (*MongoChat) CreateRoom

func (c *MongoChat) CreateRoom(room models.Room) (*models.Room, *conf.ApiError)

Save new RoomID into the MongoDB by setting current profile ID as an owner. Automatically adds current user to the chat room members.

func (*MongoChat) DeleteAllMembersInfo

func (c *MongoChat) DeleteAllMembersInfo(roomID string) *conf.ApiError

Cleanup Members Info by roomID

func (*MongoChat) DeleteMemberInfo

func (c *MongoChat) DeleteMemberInfo(roomID string, memberID string) *conf.ApiError

Deletes Member Info by id

func (*MongoChat) DeleteRoom

func (c *MongoChat) DeleteRoom(roomID string) *conf.ApiError

Deletes RoomID from the MongoDB by its owner.

func (*MongoChat) EditMessage

func (c *MongoChat) EditMessage(profileID string, messageID string, body string) *conf.ApiError

func (*MongoChat) GetAllMembersInfo

func (c *MongoChat) GetAllMembersInfo(roomID string) ([]models.MemberInfo, *conf.ApiError)

Returns all the members metadata by a given roomID

func (*MongoChat) GetAllRoomsInfo

func (c *MongoChat) GetAllRoomsInfo(memberID string) ([]models.MemberInfo, *conf.ApiError)

Returns all the rooms member metadata by a given memberID

func (*MongoChat) GetMemberInfo

func (c *MongoChat) GetMemberInfo(roomID string, memberID string) (*models.MemberInfo, *conf.ApiError)

Returns current member info by id

func (*MongoChat) GetMessages

func (c *MongoChat) GetMessages(profileID string, roomID string, from time.Time, limit int) ([]models.Message, *conf.ApiError)

Returns chat log page by a given start timestamp and limit. Additionally checks that current user is a member of that chat room.

func (*MongoChat) GetRoom

func (c *MongoChat) GetRoom(memberID string, roomID string) (*models.Room, *conf.ApiError)

Returns RoomID by ID and membership

func (*MongoChat) GetRooms

func (c *MongoChat) GetRooms(memberID string) ([]models.Room, *conf.ApiError)

Returns all the ChatRooms by a given member

func (*MongoChat) GetRoomsIn

func (c *MongoChat) GetRoomsIn(roomIDs []string) ([]models.Room, *conf.ApiError)

Returns all the ChatRooms by a given list of IDs

func (*MongoChat) IsRoomMember

func (c *MongoChat) IsRoomMember(roomID string, memberID string) *conf.ApiError

func (*MongoChat) OpenedRoomsCount

func (c *MongoChat) OpenedRoomsCount(memberID string) (int, *conf.ApiError)

Returns number of opened rooms for a given member

func (*MongoChat) RemoveRoomMember

func (c *MongoChat) RemoveRoomMember(roomID string, memberID string) *conf.ApiError

Updates current RoomID by removing a member with a specific id. Additionally checks that current user is an owner of that room to update it.

func (*MongoChat) TouchRoomMember

func (c *MongoChat) TouchRoomMember(roomID string, memberID string) *conf.ApiError

Adds new member to a given chat room. Actual member info retrieved from account service. Additionally checks that current user is an owner of that room to update it.

func (*MongoChat) UpdateLastMessageRoomMember

func (c *MongoChat) UpdateLastMessageRoomMember(roomID string, memberID string) *conf.ApiError

Adds new member to a given chat room. Actual member info retrieved from account service. Additionally checks that current user is an owner of that room to update it.

func (*MongoChat) UpdateLastReadTime

func (c *MongoChat) UpdateLastReadTime(roomID string, memberID string) *conf.ApiError

Updates Member Info last read time

type RedisBus

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

func NewRedisBus

func NewRedisBus(options RedisBusOptions) *RedisBus

func (*RedisBus) Publish

func (bus *RedisBus) Publish(id string, msg []byte) error

func (*RedisBus) Receive

func (bus *RedisBus) Receive() chan map[string][]byte

func (*RedisBus) Subscribe

func (bus *RedisBus) Subscribe(id string) error

func (*RedisBus) Unsubscribe

func (bus *RedisBus) Unsubscribe(id string) error

type RedisBusOptions

type RedisBusOptions struct {
	RedisPool *redis.Pool
}

type RedisCache

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

func NewRedisCache

func NewRedisCache(options RedisCacheOptions) *RedisCache

func (*RedisCache) EvictRoom

func (c *RedisCache) EvictRoom(key string) error

func (*RedisCache) GetRoom

func (c *RedisCache) GetRoom(key string) (*models.Room, error)

func (*RedisCache) PutRoom

func (c *RedisCache) PutRoom(key string, room *models.Room) error

type RedisCacheOptions

type RedisCacheOptions struct {
	RedisPool *redis.Pool
	CacheTTL  time.Duration
}

type RoomCache

type RoomCache interface {
	PutRoom(key string, room *models.Room) error

	GetRoom(key string) (*models.Room, error)

	EvictRoom(key string) error
}

Jump to

Keyboard shortcuts

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