Identity

Identity

The Identity is associated with a handle. The handle can be used as the sender or recipient of messages, and can be used to add friends.

During signup the user provides a handle which is used to create a default Identity for the user. That handle is accessible in the Account and is used as the default argument for Client methods that expect a handle argument for the currently logged in user.

Many chat applications will have a single Identity for each Account. If your chat application uses one identity per account you can skip the rest of this paragraph. Some applications may have multiple Identities for a single Account. For example, some email application allow users to login with a single set of credentials, but send and receive messages from multiple email addresses. For these types of applications, you can create multiple Identities using the Client. Just be sure to sepcify the correct handle when calling methods such as sendMessage.

Constructor

# new Identity(options)

import Identity from "https://designftw.github.io/chat-lib/src/models/Identity.js";

Identity model constructor.

Parameters:
Name Type Description
options Object
Properties
Name Type Description
id string

see BaseModel's id property

createdAt Date

see BaseModel's createdAt property

updatedAt Date

see BaseModel's updatedAt property

handle string

see Identity's handle property

data string

see Identity's data property

Members

# data :Object

Public readable object containing data associated with this identity. The Account that owns this Identity can set this data using Client#updateIdentity.

The data can be any shape but it must be an object.

Practical Examples

The data could be a user's profile picture:

{image: "https://example.com/profile.png"}

The data could be a user's status:

{status: "I'm online!"}

The data could be a user's location:

{location: {lat: 42.3601, lng: 71.0942}}
Type:
  • Object

# handle :string

The unique handle associated with the identity. Used to specify the sender or recipient of messages and to add and remove friends.

Must be unique across all identities.

Type:
  • string

Methods

# toJSON() → {Object}

Convert this identity to a JSON object that could be fed to its constructor to create another object with the same data

Returns:
Type
Object

# toString() → {string}

When this identity is coerced to a string, just return the handle.

Returns:

This identity's handle

Type
string