twilio-chat
Advanced tools
Comparing version 3.3.7 to 3.3.8-rc1
@@ -39,6 +39,10 @@ /// <reference types="node" /> | ||
declare namespace Channel { | ||
type UpdateReason = 'attributes' | 'createdBy' | 'dateCreated' | 'dateUpdated' | 'friendlyName' | 'lastConsumedMessageIndex' | 'status' | 'uniqueName' | 'lastMessage' | 'notificationLevel'; | ||
type UpdateReason = 'attributes' | 'createdBy' | 'dateCreated' | 'dateUpdated' | 'friendlyName' | 'lastConsumedMessageIndex' | 'status' | 'uniqueName' | 'lastMessage' | 'notificationLevel' | 'state'; | ||
type Status = 'unknown' | 'known' | 'invited' | 'joined'; | ||
type Type = 'public' | 'private'; | ||
type NotificationLevel = 'default' | 'muted'; | ||
type State = { | ||
current: 'active' | 'inactive' | 'closed'; | ||
dateUpdated: Date; | ||
}; | ||
interface UpdatedEventArgs { | ||
@@ -72,2 +76,3 @@ channel: Channel; | ||
* @property {String} uniqueName - The Channel's unique name (tag) | ||
* @property {Channel#State} state - The Channel's state | ||
* @fires Channel#memberJoined | ||
@@ -87,3 +92,3 @@ * @fires Channel#memberLeft | ||
private services; | ||
private state; | ||
private channelState; | ||
private statusSource; | ||
@@ -124,2 +129,8 @@ private entityPromise; | ||
*/ | ||
/** | ||
* The Channel's state. | ||
* @typedef {Object} Channel#State | ||
* @property {('active' | 'inactive' | 'closed')} current - the current state | ||
* @property {Date} dateUpdated - date at which the latest update happened | ||
*/ | ||
constructor(services: ChannelServices, descriptor: ChannelDescriptor, sid: string); | ||
@@ -138,2 +149,3 @@ get status(): Channel.Status; | ||
get notificationLevel(): Channel.NotificationLevel; | ||
get state(): Channel.State; | ||
/** | ||
@@ -140,0 +152,0 @@ * The Channel's last message's information. |
@@ -22,3 +22,4 @@ "use strict"; | ||
type: 'type', | ||
uniqueName: 'uniqueName' | ||
uniqueName: 'uniqueName', | ||
state: 'state' | ||
}; | ||
@@ -57,2 +58,3 @@ function parseTime(timeString) { | ||
* @property {String} uniqueName - The Channel's unique name (tag) | ||
* @property {Channel#State} state - The Channel's state | ||
* @fires Channel#memberJoined | ||
@@ -98,2 +100,8 @@ * @fires Channel#memberLeft | ||
*/ | ||
/** | ||
* The Channel's state. | ||
* @typedef {Object} Channel#State | ||
* @property {('active' | 'inactive' | 'closed')} current - the current state | ||
* @property {Date} dateUpdated - date at which the latest update happened | ||
*/ | ||
constructor(services, descriptor, sid) { | ||
@@ -117,3 +125,3 @@ super(); | ||
this.entityName = descriptor.channel; | ||
this.state = { | ||
this.channelState = { | ||
uniqueName, | ||
@@ -130,3 +138,3 @@ status: 'known', | ||
if (descriptor.notificationLevel) { | ||
this.state.notificationLevel = descriptor.notificationLevel; | ||
this.channelState.notificationLevel = descriptor.notificationLevel; | ||
} | ||
@@ -143,14 +151,15 @@ this.members = new Map(); | ||
} | ||
get status() { return this.state.status; } | ||
get type() { return this.state.type; } | ||
get uniqueName() { return this.state.uniqueName; } | ||
get isPrivate() { return this.state.type === 'private'; } | ||
get friendlyName() { return this.state.friendlyName; } | ||
get dateUpdated() { return this.state.dateUpdated; } | ||
get dateCreated() { return this.state.dateCreated; } | ||
get createdBy() { return this.state.createdBy; } | ||
get attributes() { return this.state.attributes; } | ||
get lastConsumedMessageIndex() { return this.state.lastConsumedMessageIndex; } | ||
get lastMessage() { return this.state.lastMessage; } | ||
get notificationLevel() { return this.state.notificationLevel; } | ||
get status() { return this.channelState.status; } | ||
get type() { return this.channelState.type; } | ||
get uniqueName() { return this.channelState.uniqueName; } | ||
get isPrivate() { return this.channelState.type === 'private'; } | ||
get friendlyName() { return this.channelState.friendlyName; } | ||
get dateUpdated() { return this.channelState.dateUpdated; } | ||
get dateCreated() { return this.channelState.dateCreated; } | ||
get createdBy() { return this.channelState.createdBy; } | ||
get attributes() { return this.channelState.attributes; } | ||
get lastConsumedMessageIndex() { return this.channelState.lastConsumedMessageIndex; } | ||
get lastMessage() { return this.channelState.lastMessage; } | ||
get notificationLevel() { return this.channelState.notificationLevel; } | ||
get state() { return this.channelState.state; } | ||
/** | ||
@@ -240,6 +249,6 @@ * The Channel's last message's information. | ||
this.statusSource = source; | ||
if (this.state.status === status) { | ||
if (this.channelState.status === status) { | ||
return; | ||
} | ||
this.state.status = status; | ||
this.channelState.status = status; | ||
if (status === 'joined') { | ||
@@ -326,71 +335,77 @@ this._subscribeStreams() | ||
_update(update) { | ||
var _a, _b, _c, _d, _e; | ||
log.trace('_update', update); | ||
let updateReasons = []; | ||
Channel.preprocessUpdate(update, this.sid); | ||
for (let key in update) { | ||
let localKey = fieldMappings[key]; | ||
const updateReasons = new Set(); | ||
for (const key of Object.keys(update)) { | ||
const localKey = fieldMappings[key]; | ||
if (!localKey) { | ||
continue; | ||
} | ||
if (localKey === fieldMappings.status) { | ||
if (update.status && update.status != 'unknown' && | ||
this.state.status !== filterStatus(update.status)) { | ||
this.state.status = filterStatus(update.status); | ||
updateReasons.push(localKey); | ||
} | ||
} | ||
else if (localKey === fieldMappings.attributes) { | ||
if (!util_1.isDeepEqual(this.state.attributes, update.attributes)) { | ||
this.state.attributes = update.attributes; | ||
updateReasons.push(localKey); | ||
} | ||
} | ||
else if (localKey === fieldMappings.lastConsumedMessageIndex) { | ||
if (!(typeof update.lastConsumedMessageIndex === 'undefined') && | ||
update.lastConsumedMessageIndex !== this.state.lastConsumedMessageIndex) { | ||
this.state.lastConsumedMessageIndex = update.lastConsumedMessageIndex; | ||
updateReasons.push(localKey); | ||
} | ||
} | ||
else if (localKey === fieldMappings.lastMessage) { | ||
let updated = false; | ||
if (this.state.lastMessage && !update.lastMessage) { | ||
delete this.state.lastMessage; | ||
updated = true; | ||
} | ||
else { | ||
if (!this.state.lastMessage) { | ||
this.state.lastMessage = {}; | ||
switch (localKey) { | ||
case fieldMappings.status: | ||
if (!update.status || update.status === 'unknown' | ||
|| this.channelState.status === filterStatus(update.status)) { | ||
break; | ||
} | ||
if (update.lastMessage && (typeof update.lastMessage.index !== 'undefined') && | ||
update.lastMessage.index !== this.state.lastMessage.index) { | ||
this.state.lastMessage.index = update.lastMessage.index; | ||
updated = true; | ||
this.channelState.status = filterStatus(update.status); | ||
updateReasons.add(localKey); | ||
break; | ||
case fieldMappings.attributes: | ||
if (util_1.isDeepEqual(this.channelState.attributes, update.attributes)) { | ||
break; | ||
} | ||
if (update.lastMessage && update.lastMessage.timestamp && | ||
(!this.state.lastMessage.timestamp || this.state.lastMessage.timestamp.getTime() !== update.lastMessage.timestamp.getTime())) { | ||
this.state.lastMessage.timestamp = update.lastMessage.timestamp; | ||
updated = true; | ||
this.channelState.attributes = update.attributes; | ||
updateReasons.add(localKey); | ||
break; | ||
case fieldMappings.lastConsumedMessageIndex: | ||
if (update.lastConsumedMessageIndex === undefined | ||
|| update.lastConsumedMessageIndex === this.channelState.lastConsumedMessageIndex) { | ||
break; | ||
} | ||
if (util_1.isDeepEqual(this.state.lastMessage, {})) { | ||
delete this.state.lastMessage; | ||
this.channelState.lastConsumedMessageIndex = update.lastConsumedMessageIndex; | ||
updateReasons.add(localKey); | ||
break; | ||
case fieldMappings.lastMessage: | ||
if (this.channelState.lastMessage && !update.lastMessage) { | ||
delete this.channelState.lastMessage; | ||
updateReasons.add(localKey); | ||
break; | ||
} | ||
} | ||
if (updated) { | ||
updateReasons.push(localKey); | ||
} | ||
this.channelState.lastMessage = this.channelState.lastMessage || {}; | ||
if (((_a = update.lastMessage) === null || _a === void 0 ? void 0 : _a.index) !== undefined | ||
&& update.lastMessage.index !== this.channelState.lastMessage.index) { | ||
this.channelState.lastMessage.index = update.lastMessage.index; | ||
updateReasons.add(localKey); | ||
} | ||
if (((_b = update.lastMessage) === null || _b === void 0 ? void 0 : _b.timestamp) !== undefined | ||
&& ((_d = (_c = this.channelState.lastMessage) === null || _c === void 0 ? void 0 : _c.timestamp) === null || _d === void 0 ? void 0 : _d.getTime()) !== update.lastMessage.timestamp.getTime()) { | ||
this.channelState.lastMessage.timestamp = update.lastMessage.timestamp; | ||
updateReasons.add(localKey); | ||
} | ||
if (util_1.isDeepEqual(this.channelState.lastMessage, {})) { | ||
delete this.channelState.lastMessage; | ||
} | ||
break; | ||
case fieldMappings.state: | ||
const state = update.state ? update.state : undefined; | ||
if (state !== undefined) { | ||
state.dateUpdated = new Date(state.dateUpdated); | ||
} | ||
this.channelState.state = state; | ||
updateReasons.add(localKey); | ||
break; | ||
default: | ||
const isDate = update[key] instanceof Date; | ||
const keysMatchAsDates = isDate && ((_e = this.channelState[localKey]) === null || _e === void 0 ? void 0 : _e.getTime()) === update[key].getTime(); | ||
const keysMatchAsNonDates = !isDate && this[localKey] === update[key]; | ||
if (keysMatchAsDates || keysMatchAsNonDates) { | ||
break; | ||
} | ||
this.channelState[localKey] = update[key]; | ||
updateReasons.add(localKey); | ||
} | ||
else if (update[key] instanceof Date) { | ||
if (!this.state[localKey] || this.state[localKey].getTime() !== update[key].getTime()) { | ||
this.state[localKey] = update[key]; | ||
updateReasons.push(localKey); | ||
} | ||
} | ||
else if (this[localKey] !== update[key]) { | ||
this.state[localKey] = update[key]; | ||
updateReasons.push(localKey); | ||
} | ||
} | ||
if (updateReasons.length > 0) { | ||
this.emit('updated', { channel: this, updateReasons: updateReasons }); | ||
if (updateReasons.size > 0) { | ||
this.emit('updated', { channel: this, updateReasons: [...updateReasons] }); | ||
} | ||
@@ -592,3 +607,3 @@ } | ||
async leave() { | ||
if (this.state.status === 'joined') { | ||
if (this.channelState.status === 'joined') { | ||
await this.services.session.addCommand('leaveChannel', { channelSid: this.sid }); | ||
@@ -700,3 +715,3 @@ } | ||
async updateFriendlyName(name) { | ||
if (this.state.friendlyName !== name) { | ||
if (this.channelState.friendlyName !== name) { | ||
await this.services.session.addCommand('editFriendlyName', { | ||
@@ -728,3 +743,3 @@ channelSid: this.sid, | ||
async updateUniqueName(uniqueName) { | ||
if (this.state.uniqueName !== uniqueName) { | ||
if (this.channelState.uniqueName !== uniqueName) { | ||
if (!uniqueName) { | ||
@@ -731,0 +746,0 @@ uniqueName = ''; |
{ | ||
"name": "twilio-chat", | ||
"version": "3.3.7", | ||
"version": "3.3.8-rc1", | ||
"description": "Twilio Chat service client library", | ||
@@ -69,2 +69,3 @@ "main": "lib/index.js", | ||
"nyc": "^14.1.1", | ||
"node-fetch": "^2.6.0", | ||
"path": "^0.12.7", | ||
@@ -71,0 +72,0 @@ "sinon": "^7.5.0", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6129702
170767
58
4