messages

package
v0.0.0-...-927f0f1 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2021 License: LGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteMessage

func DeleteMessage(messageID string)

DeleteMessage deletes the message from database. It does not remove it from any threads it is in. For that use Thread.DeleteMessage()

func DeleteThread

func DeleteThread(threadID string)

DeleteThread removes a thread from database it also removes all messages associated with it

func ReadMessage

func ReadMessage(messageID string, userID string) error

ReadMessage marks the message as read in the database

Types

type Message

type Message struct {
	Sender    string
	Date      int64
	Content   string
	MessageID string
	ThreadID  string
	ReadBy    []string
}

Message represents a text message sent from an user to another

How to send a message:

1. Create the thread with all the users that should recieve the message 2. Create the message with NewMessage and data from user 3. Call the threads SendMessage method with the created message 4. Profit.

func GetMessage

func GetMessage(messageID string) (Message, error)

GetMessage gets message from database based on message id

func NewMessage

func NewMessage(from string, content string, threadID string) Message

NewMessage creates a new message that can then be added to a thread

type Thread

type Thread struct {
	ThreadID string
	Messages []string
	Title    string
	Members  []string
}

Thread represents a thread of messages

func CreateThread

func CreateThread(creator string, recievers []string, title string) (Thread, error)

CreateThread creates a new thread with specified users and saves it to database

func GetThread

func GetThread(ID string) (Thread, error)

GetThread should get a thread based on id

func GetThreadsForUser

func GetThreadsForUser(userID string) ([]Thread, error)

GetThreadsForUser returns all threas for specified user

func (*Thread) AddMember

func (t *Thread) AddMember(userID string)

AddMember adds new user to the threads Members slice.

func (*Thread) DeleteMessage

func (t *Thread) DeleteMessage(messageID string)

DeleteMessage removes a specific message from the thread. Also removes the message from database

func (*Thread) GetMessages

func (t *Thread) GetMessages() ([]Message, error)

GetMessages gets all messages in the thread

func (*Thread) RemoveMember

func (t *Thread) RemoveMember(userID string)

RemoveMember removes an user froms the threads Members slice.

func (*Thread) SendMessage

func (t *Thread) SendMessage(message Message) error

SendMessage sends a response message to all members of the thread.

Basically saves the message to database and appends its id to the threads messages slice. Saves changes to database

Jump to

Keyboard shortcuts

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