ws

package
v0.0.0-...-692b726 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2024 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Channel

type Channel struct {
	ID              gocql.UUID `json:"id"`
	ChannelName     string     `json:"channel_name"`
	Room            gocql.UUID `json:"room_id"`
	Members         []string   `json:"members"`
	IsDirectChannel bool       `json:"is_direct"`
	CreatedAt       time.Time  `json:"created_at"`

	Clients map[gocql.UUID]*Client
}

type Client

type Client struct {
	Conn      *websocket.Conn
	Message   chan *Message
	ID        gocql.UUID `json:"id"`
	RoomID    gocql.UUID `json:"room_id"`
	ChannelID gocql.UUID `json:"channel_id"`
	Username  string     `json:"username"`
}

type CreateChannelReq

type CreateChannelReq struct {
	RoomID      gocql.UUID `json:"room_id"`
	Admin       string     `json:"admin"`
	Username    string     `json:"username"`
	ChannelName string     `json:"channel_name"`
}

type CreateDirectChannelReq

type CreateDirectChannelReq struct {
	Sender          string     `json:"sender"`
	Reciever        string     `json:"reciever"`
	ChannelID       gocql.UUID `json:"channel_id"`
	IsDirectChannel bool
}

type CreateRoomReq

type CreateRoomReq struct {
	RoomName string `json:"room_name"`
	Admin    string `json:"admin"`
}

type DeleteChannelReq

type DeleteChannelReq struct {
	RoomID    gocql.UUID `json:"room_id"`
	Admin     string     `json:"admin"`
	ChannelID gocql.UUID `json:"channel_id"`
}

type DeleteRoomReq

type DeleteRoomReq struct {
	ID       gocql.UUID `json:"room_id"`
	UserID   gocql.UUID `json:"user_id"`
	Username string     `json:"username"`
}

type FetchRoomsReq

type FetchRoomsReq struct {
	UserID   gocql.UUID `json:"user_id"`
	Username string     `json:"username"`
	Email    string     `json:"email"`
}

type FetchRoomsRes

type FetchRoomsRes struct {
	DirectChannels []gocql.UUID `json:"direct_channels"`
	Rooms          []gocql.UUID `json:"rooms"`
	Channels       []gocql.UUID `json:"channels"`
}

type Handler

type Handler struct {
	SERVICE
	Hub *Hub
}

func NewHandler

func NewHandler(hub *Hub, s SERVICE) *Handler

func (*Handler) CreateChannel

func (h *Handler) CreateChannel(w http.ResponseWriter, r *http.Request)

func (*Handler) CreateDirectChannel

func (h *Handler) CreateDirectChannel(w http.ResponseWriter, r *http.Request)

func (*Handler) CreateRoom

func (h *Handler) CreateRoom(w http.ResponseWriter, r *http.Request)

func (*Handler) DeleteChannel

func (h *Handler) DeleteChannel(w http.ResponseWriter, r *http.Request)

func (*Handler) DeleteRoom

func (h *Handler) DeleteRoom(w http.ResponseWriter, r *http.Request)

func (*Handler) FetchAllMessages

func (h *Handler) FetchAllMessages(w http.ResponseWriter, r *http.Request)

func (*Handler) GetRoomDetails

func (h *Handler) GetRoomDetails(w http.ResponseWriter, r *http.Request)

func (*Handler) JoinChannel

func (h *Handler) JoinChannel(w http.ResponseWriter, r *http.Request)

func (*Handler) JoinRoom

func (h *Handler) JoinRoom(w http.ResponseWriter, r *http.Request)

func (*Handler) LeaveRoom

func (h *Handler) LeaveRoom(w http.ResponseWriter, r *http.Request)

type Hub

type Hub struct {
	// map of room id to room struct
	Rooms           map[gocql.UUID]*Room
	Register        chan *Client
	Unregister      chan *Client
	Broadcast       chan *Message
	NotifyTheSender chan *Message
}

func NewHub

func NewHub(repo REPOSITORY) *Hub

func (*Hub) Run

func (h *Hub) Run()

type JoinChannelReq

type JoinChannelReq struct {
	ChannelID       gocql.UUID `json:"channel_id"`
	RoomID          gocql.UUID `json:"room_id"`
	UserID          gocql.UUID `json:"user_id"`
	Username        string     `json:"username"`
	IsDirectChannel bool       `json:"is_direct_channel"`
}

type JoinOrLeaveRoomReq

type JoinOrLeaveRoomReq struct {
	ID       gocql.UUID `json:"room_id"`
	UserID   gocql.UUID `json:"user_id"`
	Username string     `json:"username"`
	Email    string     `json:"email"`
}

type Message

type Message struct {
	RoomID         gocql.UUID `json:"room_id"`
	SenderID       gocql.UUID `json:"sender_id"`
	SenderUsername string     `json:"sender_username"`
	ChannelID      gocql.UUID `json:"channel_id"`
	Content        string     `json:"content"`
	Timestamp      time.Time  `json:"timestamp"`
	Type           string     `json:"type"`
}

type REPOSITORY

type REPOSITORY interface {
	CreateRoom(ctx context.Context, room *Room, default_channel *Channel) (*Room, error)
	JoinRoom(ctx context.Context, room_id gocql.UUID, user_id gocql.UUID, username string, email string) (*Room, error)
	LeaveRoom(ctx context.Context, room_id gocql.UUID, user_id gocql.UUID, username string, email string) (*Room, error)
	DeleteRoom(ctx context.Context, room_id gocql.UUID, user_id gocql.UUID) (*Room, error)
	CreateChannel(ctx context.Context, new_channel *Channel, admin string) (*Room, *Channel, error)
	DeleteChannel(ctx context.Context, chn *Channel, admin string) (*Room, gocql.UUID, error)
	FetchAllRooms() (map[gocql.UUID]*Room, error)
	WriteMessageToDB(ctx context.Context, msg *Message) error
	CheckChannelMembership(ctx context.Context, username string, roomID, channelID gocql.UUID) (bool, error)
	CreateDirectChannel(ctx context.Context, new_channel *Channel, admin gocql.UUID, reciever string) (gocql.UUID, *Channel, error)
	CheckIfChannelExists(ctx context.Context, req *CreateDirectChannelReq) (*Channel, error)
	FetchAllMessages(ctx context.Context, chn_id gocql.UUID, user_id gocql.UUID, limit int, pg_state []byte) ([]Message, []byte, error)
	GetAllRoomDetails(ctx context.Context, room_id gocql.UUID) (*RoomDetails, error)
}

func NewRepository

func NewRepository(db *gocql.Session) REPOSITORY

type Repository

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

func (*Repository) CheckChannelMembership

func (r *Repository) CheckChannelMembership(ctx context.Context, username string, roomID, channelID gocql.UUID) (bool, error)

func (*Repository) CheckIfChannelExists

func (r *Repository) CheckIfChannelExists(ctx context.Context, req *CreateDirectChannelReq) (*Channel, error)

func (*Repository) CreateChannel

func (r *Repository) CreateChannel(ctx context.Context, new_channel *Channel, admin string) (*Room, *Channel, error)

func (*Repository) CreateDirectChannel

func (r *Repository) CreateDirectChannel(ctx context.Context, new_channel *Channel, admin gocql.UUID, reciever string) (gocql.UUID, *Channel, error)

func (*Repository) CreateRoom

func (r *Repository) CreateRoom(ctx context.Context, room *Room, default_channel *Channel) (*Room, error)

func (*Repository) DeleteChannel

func (r *Repository) DeleteChannel(ctx context.Context, chn *Channel, admin string) (*Room, gocql.UUID, error)

func (*Repository) DeleteRoom

func (r *Repository) DeleteRoom(ctx context.Context, room_id gocql.UUID, user_id gocql.UUID) (*Room, error)

func (*Repository) FetchAllMessages

func (r *Repository) FetchAllMessages(ctx context.Context, chn_id gocql.UUID, user_id gocql.UUID, limit int, pg_state []byte) ([]Message, []byte, error)

func (*Repository) FetchAllRooms

func (r *Repository) FetchAllRooms() (map[gocql.UUID]*Room, error)

func (*Repository) GetAllRoomDetails

func (r *Repository) GetAllRoomDetails(ctx context.Context, room_id gocql.UUID) (*RoomDetails, error)

func (*Repository) JoinRoom

func (r *Repository) JoinRoom(ctx context.Context, room_id gocql.UUID, user_id gocql.UUID, username string, email string) (*Room, error)

func (*Repository) LeaveRoom

func (r *Repository) LeaveRoom(ctx context.Context, room_id gocql.UUID, user_id gocql.UUID, username string, email string) (*Room, error)

func (*Repository) WriteMessageToDB

func (r *Repository) WriteMessageToDB(ctx context.Context, msg *Message) error

type Room

type Room struct {
	ID         gocql.UUID              `json:"id"`
	RoomName   string                  `json:"room_name"`
	Channels   []gocql.UUID            `json:"channels"`
	Members    map[gocql.UUID][]string `json:"members"` // map of channel id to Members
	CreatedAt  time.Time               `json:"created_at"`
	Admin      string                  `json:"admin"`
	ChannelMap map[gocql.UUID]*Channel
}

type RoomDetails

type RoomDetails struct {
	ID           gocql.UUID              `json:"id"`
	RoomName     string                  `json:"room_name"`
	ChannelsList []gocql.UUID            `json:"channels_list"`
	Channels     []*Channel              `json:"channels"`
	Members      map[gocql.UUID][]string `json:"members"` // map of channel id to Members
	CreatedAt    time.Time               `json:"created_at"`
	Admin        string                  `json:"admin"`
}

type SERVICE

type SERVICE interface {
	CreateRoom(c context.Context, req *CreateRoomReq) (*Room, error)
	JoinRoom(c context.Context, req *JoinOrLeaveRoomReq) (*Room, error)
	LeaveRoom(c context.Context, req *JoinOrLeaveRoomReq) (*Room, error)
	DeleteRoom(c context.Context, req *DeleteRoomReq) (*Room, error)
	CreateChannel(c context.Context, req *CreateChannelReq) (*Room, *Channel, error)
	DeleteChannel(c context.Context, req *DeleteChannelReq) (*Room, gocql.UUID, error)
	WriteMessageToDB(c context.Context, msg *Message) error
	CheckChannelMembership(c context.Context, join_channel_req *JoinChannelReq) (bool, error)
	CreateDirectChannel(c context.Context, req *CreateDirectChannelReq) (gocql.UUID, *Channel, error)
	CheckIfChannelExists(c context.Context, req *CreateDirectChannelReq) (*Channel, error)
	FetchAllMessages(c context.Context, chn_id gocql.UUID, user_id gocql.UUID, limit int, pg_state []byte) ([]Message, []byte, error)
	GetAllRoomDetails(c context.Context, room_id gocql.UUID) (*RoomDetails, error)
}

func NewService

func NewService(repository REPOSITORY) SERVICE

type Service

type Service struct {
	REPOSITORY
	// contains filtered or unexported fields
}

func (*Service) CheckChannelMembership

func (s *Service) CheckChannelMembership(c context.Context, join_channel_req *JoinChannelReq) (bool, error)

func (*Service) CheckIfChannelExists

func (s *Service) CheckIfChannelExists(c context.Context, req *CreateDirectChannelReq) (*Channel, error)

func (*Service) CreateChannel

func (s *Service) CreateChannel(c context.Context, req *CreateChannelReq) (*Room, *Channel, error)

func (*Service) CreateDirectChannel

func (s *Service) CreateDirectChannel(c context.Context, req *CreateDirectChannelReq) (gocql.UUID, *Channel, error)

func (*Service) CreateRoom

func (s *Service) CreateRoom(c context.Context, req *CreateRoomReq) (*Room, error)

func (*Service) DeleteChannel

func (s *Service) DeleteChannel(c context.Context, req *DeleteChannelReq) (*Room, gocql.UUID, error)

func (*Service) DeleteRoom

func (s *Service) DeleteRoom(c context.Context, req *DeleteRoomReq) (*Room, error)

func (*Service) FetchAllMessages

func (s *Service) FetchAllMessages(c context.Context, chn_id gocql.UUID, user_id gocql.UUID, limit int, pg_state []byte) ([]Message, []byte, error)

func (*Service) GetAllRoomDetails

func (s *Service) GetAllRoomDetails(c context.Context, room_id gocql.UUID) (*RoomDetails, error)

func (*Service) JoinRoom

func (s *Service) JoinRoom(c context.Context, req *JoinOrLeaveRoomReq) (*Room, error)

func (*Service) LeaveRoom

func (s *Service) LeaveRoom(c context.Context, req *JoinOrLeaveRoomReq) (*Room, error)

func (*Service) WriteMessage

func (s *Service) WriteMessage(c context.Context, msg *Message) error

Jump to

Keyboard shortcuts

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