Skip to content

Client module to implement the tria messenger in any node.js application

License

Notifications You must be signed in to change notification settings

WhySoBad/tria-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

78 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

client_banner

Client

Related Projects

Usage

Installation

npm install https://github.com/WhySoBad/tria-client

Create Client Instance

const client: Client = new Client({ log: true, credentials: { username: MAIL_ADDRESS, password: PASSWORD });

or

const client: Client = new Client({ log: true, credentials: { token: AUTH_JWT });

Client

A client instance represents a logged in user

Credentials

The credentials are null when the user logs in with an auth token

client.credentials.username; //mail address of the user
client.credentials.password; //password of the user

Token

User auth token to send requests to the server

client.token;

Connected

Boolean whether the user is already connected to the server

client.connected;

User

Get the relatead ClientUser instance

client.user;

Connect

Method to connect the client to the server

client.connect().then(() => ...).catch(() => ...)

Disconnect

Method to disconnect the client from the server

client.disconnect().then(() => ...).catch(() => ...)

Login

Method to log the user in [generate auth token, validate current token]

Gets called automatically in connect

client.login().then(() => ...).catch(() => ...)

Delete

Method to delete the logged in user

client.delete().then(() => ...).catch(() => ...)

Create private chat

Method to create a new private chat

client.createPrivateChat(participantUuid).then((chatUuid) => ...).catch(() => ...)

Create group chat

Method to create a new group chat

client.createGroupChat({ name: groupName,
  tag: groupTag,
  description: groupDescription,
  type: groupType,
  members: [memberUuids]}).then((chatUuid) => ...).catch(() => ...)

Join group

Method to join an existing group

client.joinGroup(groupUuid).then(() => ...).catch(() => ...)

Leave group

Method to leave an existing group

client.leaveGroup(groupUuid).then(() => ...).catch(() => ...)

Change password

Method to change the password of the user

client.changePassword(oldPassword, newPassword).then(() => ...).catch(() => ...)

Search

Method to search for other users and public group chats

client.search(searchOptions).then((results) => ...).catch(() => ...)

ClientUser

The user instance of the logged in user

Client

The client which initialized the clientuser

client.user.client;

Uuid

The uuid of the logged in user

client.user.uuid;

CreatedAt

The timestamp when the user was created

client.user.createdAt;

Name

The name of the user

client.user.name;

Tag

The tag of the user

client.user.tag;

Description

The discription of the user

client.user.description;

Mail

The mail address of the user

client.user.mail;

LastSeen

The timestamp when the user was last seen

client.user.lastSeen;

Online

Boolean whether the user is currently online

client.user.online;

Locale

The locale of the logged in user

client.user.locale;

AvatarURL

The url to the avatar of the user

client.user.avatarURL;

Chats

The chats of the user

client.user.chats;

Color

The color of the user

client.user.color;

SetName

Method to change the user's name

client.user.setName(newName).then(() => ...).catch(() => ...)

SetTag

Method to change the user's tag

client.user.setTag(newTag).then(() => ...).catch(() => ...)

SetDescription

Method to change the user's description

client.user.setDescription(newDescription).then(() => ...).catch(() => ...)

SetLocale

Method to change the user's locale

client.user.setLocale(newLocale).then(() => ...).catch(() => ...)

SetSettings

Shorthand method for setName, setTag, setDescription and setLocale

Multiple parameters can be changed within one method call

client.user.setSettings(newSettings).then(() => ...).catch(() => ...)

SetAvatar

Method to upload a new avatar

client.user.setAvatar(newAvatar).then(() => ...).catch(() => ...)

DeleteAvatar

Method to delete the existing avatar

client.user.deleteAvatar().then(() => ...).catch(() => ...)

User

User instance representing an user

Important: The logged in user is represented by a ClientUser instance

Client

The currently logged in client

user.client;

Uuid

The uuid of the user

user.uuid;

CreatedAt

The timestamp when the user was created

user.createdAt;

Name

The name of the user

user.name;

Tag

The tag of the user

user.tag;

Description

The discription of the user

user.description;

LastSeen

The timestamp when the user was last seen

user.lastSeen;

Online

Boolean whether the user is currently online

user.online;

Locale

The locale of the logged in user

user.locale;

AvatarURL

The url to the avatar of the user

user.avatarURL;

Color

The color of the user

user.color;

Chat

Chat instance representing an user

Client

The currently logged in client

chat.client;

Uuid

Uuid of the chat

chat.uuid;

CreatedAt

Timestamp when the chat was created

chat.createdAt;

Color

Color of the chat

chat.color;

Type

Type of the chat

chat.type;

LastRead

Timestamp of the last message read by the logged in user in this chat

chat.lastRead;

Members

All members of the chat

chat.members;

Writable

Boolean whether the logged in user is member of the chat

chat.writeable;

Messages

All currently fetched messages of the chat

chat.messages;

LastFetched

Boolean whether the last message of the chat was fetched

chat.lastFetched;

MemberLog

MemberLog of the chat

chat.memberLog;

Delete

Method to delete the chat

chat.delete().then(() => ...).catch(() => ...)

SendMessage

Method to send a message in the chat

chat.sendMessage(message).then(() => ...).catch(() => ...)

FetchMessages

Method to fetch a specific amount of messages after a given timestamp

chat.fetchMessages(timestamp, amount).then(() => ...).catch(() => ...)

ReadUntil

Mark messages until a given timestamp as read

chat.readUntil(timestamp).then(() => ...).catch(() => ...)

Group

Group instance representing a group chat

Extends chat

Name

Name of the group

group.name;

Tag

Tag of the group

group.tag;

Description

Description of the group

group.description;

AvatarURL

Url to the avatar of the group

group.avatarURL;

Public

Boolean whether the group is public or private

group.public;

CanEditGroup

Boolean whether the logged in user can edit the group

group.canEditGroup;

CanEditMembers

Boolean whether the logged in user can edit group members

group.canEditMembers;

CanBan

Boolean whether the logged in user can ban group members

group.canBan;

CanUnban

Boolean whether the logged in user can unban banned members

group.canUnban;

CanKick

Boolean whether the logged in user can kick group members

group.canKick;

CanDelete

Boolean whether the logged in user can delete the chat

group.canDelete;

BannedMembers

All banned members of the group

group.bannedMembers;

Delete

Method to delete the group

group.delete().then(() => ...).catch(() => ...)

SetName

Method to change the name of the group

group.setName(newName).then(() => ...).catch(() => ...)

SetTag

Method to change the tag of the group

group.setTag(newTag).then(() => ...).catch(() => ...)

SetDescription

Method to change the description of the group

group.setDescription(newDescription).then(() => ...).catch(() => ...)

SetType

Method to change the type of the group

group.setType(newType).then(() => ...).catch(() => ...)

SetName

Shorthand method for setName, setTag, setDescription and setType

The method can edit multiple parameters with one method call

group.setSettings(newSettings).then(() => ...).catch(() => ...)

SetAvatar

Method to change the avatar of the group

group.setAvatar(newAvatar).then(() => ...).catch(() => ...)

DeleteAvatar

Method to delete the avatar of the group

group.deleteAvatar().then(() => ...).catch(() => ...)

BanMember

Method to ban a group member

group.banMember(member).then(() => ...).catch(() => ...)

UnbanMember

Method to unban a group member

group.unbanMember(userUuid).then(() => ...).catch(() => ...)

KickMember

Method to kick a group member

group.kickMember(member).then(() => ...).catch(() => ...)

EditMember

Method to edit a group member

group.editMember(member, options).then(() => ...).catch(() => ...)

PrivateChat

PrivateChat instance represents a private chat

Extends chat

Participant

Participant of the private chat

chat.participant;

Member

Member instance represents a member in a chat

User

User of the member

member.user;

JoinedAt

Timestamp when the member joined the group

member.joinedAt;

Role

Role of the member

member.role;

Owner

Owner instance represents an owner in a group

Extends member

Admin

Admin instance represents an admin in a group

Extends member

PromotedAt

Timestamp when the admin was promoted

admin.promotedAt;

Permissions

Permissions of the admin

admin.permissions;

CanBan

Boolean whether the admin can ban members

admin.canBan;

CanUnban

Boolean whether the admin can unban banned members

admin.canUnban;

CanEditGroup

Boolean whether the admin can edit the group

admin.canEditGroup;

CanKick

Boolean whether the admin can kick group members

admin.canKick;

License

MIT © WhySoBad

About

Client module to implement the tria messenger in any node.js application

Topics

Resources

License

Stars

Watchers

Forks