TopicMe

TopicMe

new TopicMe(callbacks)

Special case of Tinode.Topic for managing data of the current user, including contact list.
Source:
Parameters:
Name Type Description
callbacks TopicMe.Callbacks Callbacks to receive various events.

Extends

Methods

alias() → {string}

Get alias value (unique tag with alias: prefix), if present. The prefix is stripped off.
Inherited From:
Source:
Returns:
Type:
string
alias or undefined.

archive(arch) → {Promise}

Archive or un-archive the topic. Wrapper for Tinode#setMeta.
Inherited From:
Source:
Parameters:
Name Type Description
arch boolean true to archive the topic, false otherwise.
Returns:
Type:
Promise
Promise to be resolved/rejected when the server responds to request.

aux(key) → {Object}

Get auxiliary entry by key.
Inherited From:
Source:
Parameters:
Name Type Description
key string auxiliary data key to retrieve.
Returns:
Type:
Object
value for the key or undefined.

cancelSend(seqId) → {boolean}

Attempt to stop message from being sent.
Inherited From:
Source:
Parameters:
Name Type Description
seqId number id of the message to stop sending and remove from cache.
Returns:
Type:
boolean
true if message was cancelled, false otherwise.

contacts(callback, filteropt, contextopt)

Iterate over cached contacts.
Source:
Parameters:
Name Type Attributes Description
callback TopicMe.ContactCallback Callback to call for each contact.
filter contactFilter <optional>
Optionally filter contacts; include all if filter is false-ish, otherwise include those for which filter returns true-ish.
context Object <optional>
Context to use for calling the `callback`, i.e. the value of `this` inside the callback.

createMessage(data, noEchoopt) → {Object}

Create a draft of a message without sending it to the server.
Inherited From:
Source:
Parameters:
Name Type Attributes Description
data string | Object Content to wrap in a draft.
noEcho boolean <optional>
If true server will not echo message back to originating session. Otherwise the server will send a copy of the message to sender.
Returns:
Type:
Object
message draft.

delCredential(method, value) → {Promise}

Delete validation credential.
Source:
Parameters:
Name Type Description
method string Validation method such as 'email' or 'tel'.
value string Credential value to delete.
Returns:
Type:
Promise
Promise which will be resolved/rejected on receiving server reply.

delMessages(ranges, hardopt) → {Promise}

Delete messages. Hard-deleting messages requires Deleter (D) permission. Wrapper for Tinode#delMessages.
Inherited From:
Source:
Parameters:
Name Type Attributes Description
ranges Array.<Tinode.SeqRange> Ranges of message IDs to delete.
hard boolean <optional>
Hard or soft delete
Returns:
Type:
Promise
Promise to be resolved/rejected when the server responds to request.

delMessagesAll(hardDel) → {Promise}

Delete all messages. Hard-deleting messages requires Deleter permission.
Inherited From:
Source:
Parameters:
Name Type Description
hardDel boolean true if messages should be hard-deleted.
Returns:
Type:
Promise
Promise to be resolved/rejected when the server responds to request.

delMessagesEdits(seq, hardDelopt) → {Promise}

Delete original message and edited variants. Hard-deleting messages requires Deleter permission.
Inherited From:
Source:
Parameters:
Name Type Attributes Description
seq number original seq ID of the message to delete.
hardDel boolean <optional>
true if messages should be hard-deleted.
Returns:
Type:
Promise
Promise to be resolved/rejected when the server responds to the request.

delMessagesList(list, hardDelopt) → {Promise}

Delete multiple messages defined by their IDs. Hard-deleting messages requires Deleter permission.
Inherited From:
Source:
Parameters:
Name Type Attributes Description
list Array.<number> list of seq IDs to delete.
hardDel boolean <optional>
true if messages should be hard-deleted.
Returns:
Type:
Promise
Promise to be resolved/rejected when the server responds to request.

delSubscription(user) → {Promise}

Delete subscription. Requires Share permission. Wrapper for Tinode#delSubscription.
Inherited From:
Source:
Parameters:
Name Type Description
user string ID of the user to remove subscription for.
Returns:
Type:
Promise
Promise to be resolved/rejected when the server responds to request.

delTopic(hard) → {Promise}

Delete topic. Requires Owner permission. Wrapper for Tinode#delTopic.
Inherited From:
Source:
Parameters:
Name Type Description
hard boolean hard-delete topic.
Returns:
Type:
Promise
Promise to be resolved/rejected when the server responds to the request.

findMessage(seq) → {Object}

Get the message from cache by literal seq (does not resolve message edits).
Inherited From:
Source:
Parameters:
Name Type Description
seq number message seqId to search for.
Returns:
Type:
Object
the message with the given seq or undefined, if no such message is found.

flushMessage(seqId) → {Message}

Remove one message from local cache.
Inherited From:
Source:
Parameters:
Name Type Description
seqId number id of the message to remove from cache.
Returns:
Type:
Message
removed message or undefined if such message was not found.

flushMessageRange(fromId, untilId) → {Array.<Message>}

Remove a range of messages from the local cache.
Inherited From:
Source:
Parameters:
Name Type Description
fromId number seq ID of the first message to remove (inclusive).
untilId number seqID of the last message to remove (exclusive).
Returns:
Type:
Array.<Message>
array of removed messages (could be empty).

getAccessMode(name) → {string}

Get access mode of a given contact from cache.
Overrides:
Source:
Parameters:
Name Type Description
name string Name of the contact to get access mode for, either a UID (for p2p topics) or a topic name; if missing, access mode for the 'me' topic itself.
Returns:
Type:
string
- access mode, such as `RWP`.

getContact(name) → {Tinode.Contact}

Get a contact from cache.
Source:
Parameters:
Name Type Description
name string Name of the contact to get, either a UID (for p2p topics) or a topic name.
Returns:
Type:
Tinode.Contact
- Contact or `undefined`.

getCredentials() → {Array.<Tinode.Credential>}

Get the user's credentials: email, phone, etc.
Source:
Returns:
Type:
Array.<Tinode.Credential>
- array of credentials.

getDefaultAccess() → {Tinode.DefAcs}

Get topic's default access mode.
Inherited From:
Source:
Returns:
Type:
Tinode.DefAcs
- access mode, such as {auth: `RWP`, anon: `N`}.

getMessagesPage(limit, gaps, min, max, newer) → {Promise}

Request more messages from the server. The goal is to load continous range of messages covering at least between 'min' and 'max' + one full page forward (newer = true) or backwards (newer=false).
Inherited From:
Source:
Parameters:
Name Type Description
limit number number of messages to get.
gaps Array.<Range> ranges of messages to load.
min number if non-negative, request newer messages with seq >= min.
max number if positive, request older messages with seq < max.
newer boolean if true, fetch newer messages; if false, fetch older messages.
Returns:
Type:
Promise
Promise to be resolved/rejected when the server responds to request.

getMeta(params) → {Promise}

Request topic metadata from the local cache or from the server.
Inherited From:
Source:
Parameters:
Name Type Description
params Tinode.GetQuery request parameters
Returns:
Type:
Promise
Promise to be resolved/rejected when the server responds to request.

getPinnedMessages() → {Promise}

Request to get pinned messages from the local cache or from the server.
Inherited From:
Source:
Returns:
Type:
Promise
Promise to be resolved/rejected when the server responds to request.

getType() → {string}

Get type of the topic: me, p2p, grp, fnd...
Inherited From:
Source:
Returns:
Type:
string
One of 'me', 'p2p', 'grp', 'fnd', 'sys' or undefined.

invite(uid, modeopt) → {Promise}

Create new topic subscription. Wrapper for Tinode#setMeta.
Inherited From:
Source:
Parameters:
Name Type Attributes Description
uid string ID of the user to invite
mode string <optional>
Access mode. null means to use default.
Returns:
Type:
Promise
Promise to be resolved/rejected when the server responds to request.

isArchived(name) → {boolean}

Check if contact is archived, i.e. contact.private.arch == true.
Overrides:
Source:
Parameters:
Name Type Description
name string Name of the contact to check archived status, either a UID (for p2p topics) or a topic name.
Returns:
Type:
boolean
- true if contact is archived, false otherwise.

isChannelType() → {boolean}

Check if topic is a channel.
Inherited From:
Source:
Returns:
Type:
boolean
- true if topic is a channel, false otherwise.

isCommType() → {boolean}

Check if topic is a communication topic, i.e. a group or p2p topic.
Inherited From:
Source:
Returns:
Type:
boolean
- true if topic is a p2p or group topic, false otherwise.

isGroupType() → {boolean}

Check if topic is a group topic.
Inherited From:
Source:
Returns:
Type:
boolean
- true if topic is a group, false otherwise.

isMeType() → {boolean}

Check if topic is a 'me' topic.
Inherited From:
Source:
Returns:
Type:
boolean
- true if topic is a 'me' topic, false otherwise.

isNewMessage(seqId)

Check if the given seq Id is id of the most recent message.
Inherited From:
Source:
Parameters:
Name Type Description
seqId number id of the message to check

isP2PType() → {boolean}

Check if topic is a p2p topic.
Inherited From:
Source:
Returns:
Type:
boolean
- true if topic is a p2p topic, false otherwise.

isSelfType() → {boolean}

Check if topic is a 'slf' topic.
Inherited From:
Source:
Returns:
Type:
boolean
- true if topic is a 'slf' topic, false otherwise.

latestMessage() → {Object}

Get the most recent non-deleted message from cache.
Inherited From:
Source:
Returns:
Type:
Object
the most recent cached message or undefined, if no messages are cached.

latestMsgVersion(seq) → {Object}

Get the latest version for message.
Inherited From:
Source:
Parameters:
Name Type Description
seq number original seq ID of the message.
Returns:
Type:
Object
the latest version of the message or null if message not found.

leave(unsubopt) → {Promise}

Leave the topic, optionally unsibscribe. Leaving the topic means the topic will stop receiving updates from the server. Unsubscribing will terminate user's relationship with the topic. Wrapper for Tinode#leave.
Inherited From:
Source:
Parameters:
Name Type Attributes Description
unsub boolean <optional>
If true, unsubscribe, otherwise just leave.
Returns:
Type:
Promise
Promise to be resolved/rejected when the server responds to the request.

leaveDelayed(unsub, delay)

Leave the topic, optionally unsibscribe after a delay. Leaving the topic means the topic will stop receiving updates from the server. Unsubscribing will terminate user's relationship with the topic. Wrapper for Tinode#leave.
Inherited From:
Source:
Parameters:
Name Type Description
unsub boolean If true, unsubscribe, otherwise just leave.
delay number time in milliseconds to delay leave request.

maxClearId() → {number}

Get the maximum deletion ID.
Inherited From:
Source:
Returns:
Type:
number
the greatest deletion ID.

maxMsgSeq() → {number}

Get the maximum cached seq ID.
Inherited From:
Source:
Returns:
Type:
number
the greatest seq ID in cache.

messageCount() → {number}

Get the number of messages in the cache.
Inherited From:
Source:
Returns:
Type:
number
count of cached messages.

messages(callback, sinceId, beforeId, context)

Iterate over cached messages: call callback for each message in the range [sinceIdx, beforeIdx). If callback is undefined, use this.onData.
Inherited From:
Source:
Parameters:
Name Type Description
callback Tinode.ForEachCallbackType Callback which will receive messages one by one. See Tinode.CBuffer#forEach
sinceId number Optional seqId to start iterating from (inclusive).
beforeId number Optional seqId to stop iterating before it is reached (exclusive).
context Object Value of `this` inside the `callback`.

messageVersions(origSeq, callback, context)

Iterate over versions of a message: call callback for each version (excluding original). If callback is undefined, does nothing.
Inherited From:
Source:
Parameters:
Name Type Description
origSeq number seq ID of the original message.
callback Tinode.ForEachCallbackType Callback which will receive messages one by one. See Tinode.CBuffer#forEach
context Object Value of `this` inside the `callback`.

minMsgSeq() → {number}

Get the minimum cached seq ID.
Inherited From:
Source:
Returns:
Type:
number
the smallest seq ID in cache or 0.

msgHasMoreMessages(min, max, newer) → {Array.<Range>}

Check if cached message IDs indicate that the server may have more messages.
Inherited From:
Source:
Parameters:
Name Type Description
min number smallest seq ID loaded range.
max number greatest seq ID in loaded range.
newer boolean if true, check for newer messages only.
Returns:
Type:
Array.<Range>
- missing ranges in the selected direction.

msgReadCount(seq) → {number}

Get the number of topic subscribers who marked this message (and all older messages) as read. The current user is excluded from the count.
Inherited From:
Source:
Parameters:
Name Type Description
seq number message id to check.
Returns:
Type:
number
number of subscribers who claim to have received the message.

msgReceiptCount(what, seq) → {number}

Get the number of topic subscribers who marked this message as either recv or read Current user is excluded from the count.
Inherited From:
Source:
Parameters:
Name Type Description
what string what action to consider: received "recv" or read "read".
seq number ID or the message read or received.
Returns:
Type:
number
the number of subscribers who marked the message with the given ID as read or received.

msgRecvCount(seq) → {number}

Get the number of topic subscribers who marked this message (and all older messages) as received. The current user is excluded from the count.
Inherited From:
Source:
Parameters:
Name Type Description
seq number Message id to check.
Returns:
Type:
number
Number of subscribers who claim to have received the message.

msgStatus(msg, upd)

Get status (queued, sent, received etc) of a given message in the context of this topic.
Inherited From:
Source:
Parameters:
Name Type Description
msg Message message to check for status.
upd boolean update chached message status.
Returns:
message status constant.

note(what, seq)

Send a read/recv notification.
Inherited From:
Source:
Parameters:
Name Type Description
what string what notification to send: recv, read.
seq number ID or the message read or received.

noteKeyPress()

Send a key-press notification. Wrapper for Tinode#noteKeyPress.
Inherited From:
Source:

noteRead(seq)

Send a 'read' receipt. Wrapper for Tinode#noteRead.
Inherited From:
Source:
Parameters:
Name Type Description
seq number ID of the message to acknowledge or 0/undefined to acknowledge the latest messages.

noteRecording(audioOnly)

Send a notification that a video or audio message is being recorded. Wrapper for Tinode#noteKeyPress.
Inherited From:
Source:
Parameters:
Name Type Description
audioOnly boolean true if the recording is audio-only, false if it's a video recording.

noteRecv(seq)

Send a 'recv' receipt. Wrapper for Tinode#noteRecv.
Inherited From:
Source:
Parameters:
Name Type Description
seq number ID of the message to acknowledge.

p2pPeerDesc() → {Object}

Get description of the p2p peer from subscription cache.
Inherited From:
Source:
Returns:
Type:
Object
peer's description or undefined.

pinMessage(seq, pin) → {Promise}

Set message as pinned or unpinned by adding it to aux.pins array. Wrapper for Tinode#setMeta.
Inherited From:
Source:
Parameters:
Name Type Description
seq number seq ID of the message to pin or un-pin.
pin boolean true to pin the message, false to un-pin.
Returns:
Type:
Promise
Promise to be resolved/rejected when the server responds to request.

pinnedTopicRank(topic) → {number}

Get the rank of the pinned topic.
Overrides:
Source:
Parameters:
Name Type Description
topic string Name of the topic to check.
Returns:
Type:
number
numeric rank of the pinned topic in the range 1..N (N being the top, N - the number of pinned topics) or 0 if not pinned.

pinTopic(topic, pinopt) → {Promise}

Pin topic to the top of the contact list.
Overrides:
Source:
Parameters:
Name Type Attributes Default Description
topic string Name of the topic to pin.
pin boolean <optional>
false If true, pin the topic, otherwise unpin.
Returns:
Type:
Promise
Promise to be resolved/rejected when the server responds to request.

publish()

Publishing to TopicMe is not supported. Topic#publish is overridden and throws an {Error} if called.
Overrides:
Source:
Throws:
Always throws an error.
Type
Error

publishDraft(pub, prom) → {Promise}

Add message to local message cache, send to the server when the promise is resolved. If promise is null or undefined, the message will be sent immediately. The message is sent when the The message should be created by Tinode.Topic#createMessage. This is probably not the final API.
Inherited From:
Source:
Parameters:
Name Type Description
pub Object Message to use as a draft.
prom Promise Message will be sent when this promise is resolved, discarded if rejected.
Returns:
Type:
Promise
derived promise.

publishMessage(pub) → {Promise}

Publish message created by Tinode.Topic#createMessage.
Inherited From:
Source:
Parameters:
Name Type Description
pub Object {data} object to publish. Must be created by Tinode.Topic#createMessage
Returns:
Type:
Promise
Promise to be resolved/rejected when the server responds to the request.

queuedMessages(callback, context)

Iterate over cached unsent messages. Wraps Tinode.Topic#messages.
Inherited From:
Source:
Parameters:
Name Type Description
callback function Callback which will receive messages one by one. See Tinode.CBuffer#forEach
context Object Value of this inside the callback.

setAccessMode(acs)

Set current user's access mode of the topic.
Inherited From:
Source:
Parameters:
Name Type Description
acs AccessMode | Object access mode to set.

setMeta(params) → {Promise}

Update topic metadata.
Inherited From:
Source:
Parameters:
Name Type Description
params Tinode.SetParams parameters to update.
Returns:
Type:
Promise
Promise to be resolved/rejected when the server responds to request.

startMetaQuery() → {Tinode.MetaGetBuilder}

Initialize new meta Tinode.GetQuery builder. The query is attched to the current topic. It will not work correctly if used with a different topic.
Inherited From:
Source:
Returns:
Type:
Tinode.MetaGetBuilder
query attached to the current topic.

subscriber(uid)

Get cached subscription for the given user ID.
Inherited From:
Source:
Parameters:
Name Type Description
uid string id of the user to query for
Returns:
user description or undefined.

subscribers(callback, contextopt)

Iterate over cached subscribers. If callback is undefined, use this.onMetaSub.
Inherited From:
Source:
Parameters:
Name Type Attributes Description
callback function Callback which will receive subscribers one by one.
context Object <optional>
Value of `this` inside the `callback`.

swapMessageId(pub, newSeqId)

Update message's seqId.
Inherited From:
Source:
Parameters:
Name Type Description
pub Object message object.
newSeqId number new seq id for pub.

tags() → {Array.<string>}

Get a copy of cached tags.
Inherited From:
Source:
Returns:
Type:
Array.<string>
a copy of tags

updateMode(uid, update) → {Promise}

Update access mode of the current user or of another topic subscriber.
Inherited From:
Source:
Parameters:
Name Type Description
uid string UID of the user to update or null to update current user.
update string the update value, full or delta.
Returns:
Type:
Promise
Promise to be resolved/rejected when the server responds to request.

userDesc(uid) → {Object}

Get user description from global cache. The user does not need to be a subscriber of this topic.
Inherited From:
Source:
Parameters:
Name Type Description
uid string ID of the user to fetch.
Returns:
Type:
Object
user description or undefined.