Methods
alias() → {string}
Get alias value (unique tag with alias: prefix), if present.
The prefix is stripped off.
Returns:
- Type:
-
string
alias or
undefined.
archive(arch) → {Promise}
Archive or un-archive the topic. Wrapper for Tinode#setMeta.
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.
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.
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.
createMessage(data, noEchoopt) → {Object}
Create a draft of a message without sending it to the server.
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.
delMessages(ranges, hardopt) → {Promise}
Delete messages. Hard-deleting messages requires Deleter (D) permission.
Wrapper for Tinode#delMessages.
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.
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.
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.
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.
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.
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).
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.
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.
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() → {Tinode.AccessMode}
Get current user's access mode of the topic.
getDefaultAccess() → {Tinode.DefAcs}
Get topic's default access mode.
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).
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.
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.
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...
Returns:
- Type:
-
string
One of 'me', 'p2p', 'grp', 'fnd', 'sys' or
undefined.
invite(uid, modeopt) → {Promise}
Create new topic subscription. Wrapper for Tinode#setMeta.
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() → {boolean}
Check if topic is archived, i.e. private.arch == true.
Returns:
- Type:
-
boolean
-
true if topic is archived, false otherwise.
isChannelType() → {boolean}
Check if topic is a channel.
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.
Returns:
- Type:
-
boolean
-
true if topic is a p2p or group topic, false otherwise.
isGroupType() → {boolean}
Check if topic is a group topic.
Returns:
- Type:
-
boolean
-
true if topic is a group, false otherwise.
isMeType() → {boolean}
Check if topic is a 'me' topic.
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.
Parameters:
| Name | Type | Description |
|---|---|---|
seqId |
number
|
id of the message to check |
isP2PType() → {boolean}
Check if topic is a p2p topic.
Returns:
- Type:
-
boolean
-
true if topic is a p2p topic, false otherwise.
isSelfType() → {boolean}
Check if topic is a 'slf' topic.
Returns:
- Type:
-
boolean
-
true if topic is a 'slf' topic, false otherwise.
latestMessage() → {Object}
Get the most recent non-deleted message from cache.
Returns:
- Type:
-
Object
the most recent cached message or
undefined, if no messages are cached.
latestMsgVersion(seq) → {Object}
Get the latest version for message.
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.
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.
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.
Returns:
- Type:
-
number
the greatest deletion ID.
maxMsgSeq() → {number}
Get the maximum cached seq ID.
Returns:
- Type:
-
number
the greatest seq ID in cache.
messageCount() → {number}
Get the number of messages in the cache.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
noteRead(seq)
Send a 'read' receipt. Wrapper for Tinode#noteRead.
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.
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.
Parameters:
| Name | Type | Description |
|---|---|---|
seq |
number
|
ID of the message to acknowledge. |
p2pPeerDesc() → {Object}
Get description of the p2p peer from subscription cache.
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.
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.
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.
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(data, noEchoopt) → {Promise}
Immediately publish data to topic. Wrapper for Tinode#publish.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
data |
string
|
Object
|
Message to publish, either plain string or a Drafty object. | |
noEcho |
boolean
|
<optional> |
If true server will not echo message back to originating
|
Returns:
- Type:
-
Promise
Promise to be resolved/rejected when the server responds to the request.
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.
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.
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.
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.
Parameters:
| Name | Type | Description |
|---|---|---|
acs |
AccessMode
|
Object
|
access mode to set. |
setMeta(params) → {Promise}
Update topic metadata.
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.
subscriber(uid)
Get cached subscription for the given user ID.
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.
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.
Parameters:
| Name | Type | Description |
|---|---|---|
pub |
Object
|
message object. |
newSeqId |
number
|
new seq id for pub. |
tags() → {Array.<string>}
Get a copy of cached tags.
Returns:
- Type:
-
Array.<string>
a copy of tags
updateMode(uid, update) → {Promise}
Update access mode of the current user or of another topic subscriber.
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.