client

package
v0.0.0-...-9cc13de Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2024 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrServerValidation = errors.New("server validation error")
	ErrExpiredOTP       = errors.New("expired otp")
	ErrNonActiveUser    = errors.New("not activated")
	ErrUnauthorized     = errors.New("invalid credentials")
	// ErrApplication code is 0
	ErrApplication = errors.New("your side of application have encountered an error, if the error persists you may report this issue to the developer at https://github.com/M0hammadUsman/letschat")
)
View Source
var (
	ErrMsgNotSent = errors.New("message not sent, 2 sec ctx timed out")
)

Functions

func Init

func Init(key int) error

Init initializes Storage Dirs, keyringManager to support access token storage at OS level, also opens a connection to sqlite DB, runs idempotent migrations, starts a goroutine to listen for user login, a goroutine to connect to Ws and listen for recvMsgs to get instance to a client use Get

Types

type Client

type Client struct {
	// If zero valued -> requires login
	// then we set this AuthToken in the OS credential manager of respected Operating systems
	AuthToken string
	// it's where all the application related files will live on the client side from db, logging anything
	FilesDir string
	// currently logged-in user we fetch and populates this once there is a read from UsrLogin chan
	CurrentUsr  *domain.User
	WsConnState *WsConnBroadcaster
	LoginState  *LoginBroadcaster
	RecvMsgs    *RecvMsgsBroadcaster
	// these are the conversations of the user displayed on the left side of the Conversations tab
	// once there is a ws conn they will be updated by current online status updates
	// if the connection is offline they will be fetched by the local db for offline view
	// we've to wait for state change to get updated conversations, they will be auto updated on WsConnState changes
	Conversations *ConvosBroadcaster
	// runs the tasks that needs a graceful shutdown, using BackgroundTask.Run
	BT *common.BackgroundTask
	// RunStartupProcesses runs long living processes, which dies on shutdown, some chores and
	// will be called from main method after there is write on RunningTui chan from tui.TabContainerModel
	// initialized in Init func
	RunStartupProcesses func()
	// contains filtered or unexported fields
}

func Get

func Get() *Client

Get returns singleton instance of a Client

func (*Client) ActivateUser

func (c *Client) ActivateUser(otp string) error

func (*Client) DeleteForMeAllMsgsForConversation

func (c *Client) DeleteForMeAllMsgsForConversation(senderId, receiverId string) error

func (*Client) DeleteMsgForEveryone

func (c *Client) DeleteMsgForEveryone(msg *domain.Message) error

func (*Client) DeleteMsgForMe

func (c *Client) DeleteMsgForMe(msgId string) error

func (*Client) GetCurrentActiveUser

func (c *Client) GetCurrentActiveUser() (*domain.User, int, error)

func (*Client) GetMessagesAsPageAndMarkAsRead

func (c *Client) GetMessagesAsPageAndMarkAsRead(senderID string, page int) ([]*domain.Message, *domain.Metadata, error)

func (*Client) Login

func (c *Client) Login(u domain.UserAuth) error

func (*Client) Register

func (*Client) Register(u *domain.UserRegister) error

Register will register the user & populate the *domain.UserRegister with validation errors in case of http.StatusUnprocessableEntity

func (*Client) ResendOtp

func (c *Client) ResendOtp(email string) error

func (*Client) SearchUser

func (c *Client) SearchUser(param string, page int) (*PagedUserResponse, int, error)

func (*Client) SendMessage

func (c *Client) SendMessage(msg domain.Message) error

func (*Client) SendTypingStatus

func (c *Client) SendTypingStatus(msg domain.Message)

func (*Client) SetMsgAsRead

func (c *Client) SetMsgAsRead(msg *domain.Message) error

func (*Client) UpdateUser

func (c *Client) UpdateUser(u domain.UserUpdate) (*domain.ErrValidation, int, error)

type Convos

type Convos []*domain.Conversation

type ConvosBroadcaster

type ConvosBroadcaster = sync.Broadcaster[Convos]

type LoginBroadcaster

type LoginBroadcaster = sync.Broadcaster[LoginState]

type LoginState

type LoginState bool

LoginState true -> successful login, false -> unauthorized requires login

type PagedUserResponse

type PagedUserResponse struct {
	Metadata domain.Metadata `json:"metadata"`
	Users    []domain.User   `json:"users"`
}

type RecvMsgsBroadcaster

type RecvMsgsBroadcaster = sync.Broadcaster[*domain.Message]

type WsConnBroadcaster

type WsConnBroadcaster = sync.Broadcaster[WsConnState]

type WsConnState

type WsConnState int

WsConnState will be switch cased by tui.TabContainerModel, so making it unique

const (
	Disconnected WsConnState = iota - 1
	WaitingForConnection
	Connecting
	Connected
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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