prot

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: AGPL-3.0 Imports: 0 Imported by: 0

Documentation

Index

Constants

View Source
const ChatMetadataRequestCreate = "CHATMD_CREATE"

ChatMetadataRequestCreate creates a new chat with the provided chat metadata, with the user who made the request initially being its sole member

View Source
const ChatMetadataRequestGet = "CHATMD_GET"

ChatMetadataRequestGet gives the client the metadata for the chats its user is a member of

View Source
const ChatMetadataRequestJoin = "CHATMD_JOIN"

ChatMetadataRequestJoin makes the user of the client who made the request a member of the specified chat along with giving the client the metadata for that chat

View Source
const ChatMetadataRequestLeave = "CHATMD_LEAVE"

ChatMetadataRequestLeave revokes the user of the client who made the resquest's membership of the specified chat

View Source
const NONE_INT = -1

Shows that an integer field in a request or response is empty

View Source
const NONE_STRING = "##"

Shows that a string field in a request or response is empty

View Source
const PROTOCOL_VER_LATEST = "4"
View Source
const UserRequestRegister = "REGISTER"

UserRequestRegister registers a username on a new connection.

View Source
const UserVisibilityFriendsOnly = 1
View Source
const UserVisibilityPrivate = 0
View Source
const UserVisibilityPublic = 2

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatMetadataRaw added in v0.4.0

type ChatMetadataRaw struct {
	// Number of messages there are in a block
	BlockSize int `json:"blk_size"`
	// Username of who created the chat
	Creator string `json:"creator"`
	// A description of what the chat is about
	Description string `json:"desc"`
	// ID of the chat
	ID int `json:"id"`
	// Is the chat public?
	IsPublic bool `json:"public"`
	// ID of the last block in the chat. Should be set to -1 and not 0 when creating a chat to prevent and off by 1 error
	LastBlockID int `json:"last_blk"`

	LastMessageID int `json:"last_msg"`
	// Usernames of everyone who has access to the chat
	Members []string `json:"members"`
	// The name of the chat
	Name string `json:"name"`
	// Total number of blocks in the chat. This should not be updated while the chat is loaded and instead should be calculated from the field `LastBlockID` when saving metadata
	NumberOfBlocks int `json:"blks"`
	// Total number of messages in the chat. This should not be updated while the chat is loaded and instead should be calculated from the field `LastMessageID` when saving metadata
	NumberOfMessages int `json:"msgs"`
}

Information about a chat

type ChatMetadataRequest added in v0.3.0

type ChatMetadataRequest struct {
	// IDs of the chats involved
	ChatID []int `json:"id"`
	// New chat description
	Description string `json:"desc"`
	// New chat viewability
	IsPublic bool `json:"public"`
	// New chat name
	Name string `json:"name"`
	// What the request is (e.g., creating new chat, getting metadata, etc.)
	Type RequestWhat `json:"req_what"`
	// ID of user the request is from
	Username string `json:"username"`
}

type ChatMetadataResponse added in v0.3.0

type ChatMetadataResponse struct {
	// IDs of the chats involved
	ChatID []int  `json:"id"`
	Error  string `json:"err"`
	// Chat metadata the client may have requested
	Metadata []ChatMetadataRaw `json:"metadata"`
	// Action that this response fulfilled
	Type RequestWhat `json:"req_what"`
}

type ChatRaw

type ChatRaw struct {
	// Protocol version
	Version string `json:"ver"`
	// Array of all messages in chat
	Messages []MessageRaw `json:"msgs"`
}

Collection of raw messages, used for saving and loading messages, not for communication between the client and server

type ChatRequest

type ChatRequest struct {
	// ID of the chat involved
	ChatID int `json:"chat_id"`
	// Content to be assigned to the given message for editing and adding messages, is empty for `REQ_DEL` and `REQ_GET`
	MessageContent string `json:"content"`
	// ID of the message involved, is -1 for `REQ_ADD`
	MessageID int `json:"msg_id"`
	// IDs of the messages the message sent in this chat request is replying to, is non nil only for REQ_ADD and REQ_EDIT
	RepliedIDs []int `json:"replied_ids"`
	// What the request is (e.g., message deletion, editing)
	Type RequestWhat `json:"chatreq_what"`
	// Username of who sent the request
	Username string `json:"username"`
}

A request to change something about or get information from a chat (e.g., add a message, delete a message, load and receive a message)

type ChatResponse

type ChatResponse struct {
	// ID of the chat involved
	ChatID int `json:"chat_id"`
	// An error that prevented the request from being fulfilled. Is empty if no error occurred
	Error string `json:"err"`
	// ID of the message involved
	MessageID int `json:"msg_id"`
	// Messages that the client may have requested
	Messages []MessageRaw `json:"msgs"`
	// Usernames of users who sent the messages in the Messages field
	Users []string `json:"users"`
	// Action that this response fulfilled
	Type RequestWhat `json:"chatresp_what"`
}

A response to a chat request after the request is fulfuilled

type MemberRequest added in v0.4.0

type MemberRequest struct {
	// ID of the chat to change whether the user is a member of, is NONE_INT for REQ_GET
	ChatID   int         `json:"chat_id"`
	Type     RequestWhat `json:"memreq_what"`
	Username string      `json:"username"`
}

Request to change user's membership status in a chat

type MemberResponse added in v0.4.0

type MemberResponse struct {
	// IDs of the chats the user is a member of, only used with REQ_GET
	ChatIDs []int       `json:"chat_ids"`
	Error   string      `json:"err"`
	Type    RequestWhat `json:"memresp_what"`
}

Response to MemberRequest

type MessageRaw

type MessageRaw struct {
	// What the message says
	Content string `json:"content"`
	// Unique message identifier (assigned incrementally, is -1 when a message is received from a client until the server assigns it an ID)
	ID int `json:"id"`
	// IDs of the message(s) this message is replying to
	RepliedIDs []int `json:"replied_ids"`
	// Time at which the message was sent (unix format)
	Time int64 `json:"time"`
	// Username of who sent the message
	Username string `json:"username"`
}

Message data sent to and received from the server

type RequestWhat

type RequestWhat string

What action is being requested. What these do differ depending on the RequestWhere

const REQ_ADD RequestWhat = "ADD"

Adds new data provided by the client

REQ_CHAT - Adds a message to the chat
REQ_CHATMETADATA - Creates a new chat
REQ_MEMBER - Makes the user who requested it a member of the specified chat
REQ_USER - Registers a new user
const REQ_DEL RequestWhat = "DEL"

Deletes existing data

REQ_CHAT - Deletes the a message
REQ_CHATMETADATA - Deletes a chat
REQ_MEMBER - Removes the user's membership of the specified chat
REQ_USER - Deletes a user
const REQ_EDIT RequestWhat = "EDIT"

Edits existing data

REQ_CHAT - Edits a message
REQ_CHATMETADATA - Edits a chat's metadata
REQ_USER - Edits user information
const REQ_GET RequestWhat = "GET"

Sends existing data to the client that requested it

REQ_CHAT - Sends a chat block to the client
REQ_CHATMETADATA - Sends a chat's metadata to the client
REQ_MEMBER - Gets IDs of all the chats the user is a member of
REQ_USER - Sends user information to the client

type RequestWhere

type RequestWhere string

What data is the request asking for the action to be done upon

const REQ_CHAT RequestWhere = "CHAT"

Request for chat

const REQ_CHATMETADATA RequestWhere = "CHATMETADATA"

Request for chat metadata

const REQ_MEMBER RequestWhere = "MEMBER"

Request for user's membership of chats

const REQ_USER RequestWhere = "USER"

Request for user

type UserRaw added in v0.4.0

type UserRaw struct {
	// String of text written by the uesr, usually to describe themselves - private by default
	Bio string `json:"bio"`
	// IDs of chats the user is a member of - private by default
	MemberOf []int `json:"memberof"`
	// Number of notifications the user has in each chat - private by default
	//  Key (int) - ChatID
	//  Val (int) - Number of notifications in the chat
	Notifications map[int]int `json:"notif"`
	// Whether or not the user currently has ping open - private by default
	Online bool `json:"online"`
	// Small string of text written by the user, generally to describe their current state - private by default
	Status string `json:"status"`
	// User's username - public
	Username string `json:"username"`
	// Defines which users can access each field of this user
	Visibility UserVisibility `json:"visibility"`
}

UserRaw - Includes profile data along with other data associated with the user, wwhich users can access what data is specified by the Visibility fields

type UserRequest added in v0.3.0

type UserRequest struct {
	Type RequestWhat `json:"userreq_what"`
	// Username of user, only used with REQ_ADD and REQ_EDIT
	Username string `json:"username"`
}

UserRequest is sent before chat traffic to establish a connection identity.

type UserResponse added in v0.3.0

type UserResponse struct {
	Error string      `json:"err"`
	Type  RequestWhat `json:"userresp_what"`
	User  UserRaw     `json:"user"`
}

UserResponse is returned for a UserRequest. Error is empty on success.

type UserVisibility added in v0.4.0

type UserVisibility struct {
	Bio           int `json:"bio"`
	MemberOf      int `json:"memberof"`
	Notifications int `json:"notif"`
	Online        int `json:"online"`
	Status        int `json:"status"`
}

Defines which users should be able to access which fields, each can be either UserVisibilityPrivate, UserVisibilityFriendsOnly, or UserVisibilityPublic. Username is not present here as it must be public

Jump to

Keyboard shortcuts

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