twilio-chat
Advanced tools
Comparing version 3.4.0 to 4.0.0-rc1
@@ -15,19 +15,4 @@ "use strict"; | ||
var logger_1 = require("./logger"); | ||
var channel_1 = require("./channel"); | ||
var util_1 = require("./util"); | ||
var log = logger_1.Logger.scope('ChannelDescriptor'); | ||
function parseAttributes(attrs) { | ||
try { | ||
return JSON.parse(attrs); | ||
} catch (e) { | ||
log.warn('Failed to parse channel attributes', e); | ||
} | ||
return {}; | ||
} | ||
function parseTime(timeString) { | ||
try { | ||
return new Date(timeString); | ||
} catch (e) { | ||
return null; | ||
} | ||
} | ||
/** | ||
@@ -38,3 +23,3 @@ * Contains channel information. | ||
* | ||
* @property {Object} attributes - The Channel's custom attributes | ||
* @property {any} attributes - The Channel's custom attributes | ||
* @property {String} createdBy - The identity of the User that created Channel | ||
@@ -74,6 +59,6 @@ * @property {Date} dateCreated - The Date Channel was created | ||
this.friendlyName = descriptor.friendly_name; | ||
this.attributes = parseAttributes(descriptor.attributes); | ||
this.attributes = util_1.parseAttributes(descriptor.attributes, 'Failed to parse channel attributes', log); | ||
this.createdBy = descriptor.created_by; | ||
this.dateCreated = parseTime(descriptor.date_created); | ||
this.dateUpdated = parseTime(descriptor.date_updated); | ||
this.dateCreated = util_1.parseTime(descriptor.date_created); | ||
this.dateUpdated = util_1.parseTime(descriptor.date_updated); | ||
this.messagesCount = descriptor.messages_count; | ||
@@ -88,3 +73,3 @@ this.membersCount = descriptor.members_count; | ||
if (descriptor.status) { | ||
this.status = channel_1.filterStatus(descriptor.status); | ||
this.status = descriptor.status; | ||
} else { | ||
@@ -91,0 +76,0 @@ this.status = 'unknown'; |
@@ -847,4 +847,4 @@ "use strict"; | ||
if (a.lastMessage && b.lastMessage) { | ||
if (a.lastMessage.timestamp && b.lastMessage.timestamp) { | ||
if (a.lastMessage.timestamp.getTime() < b.lastMessage.timestamp.getTime()) { | ||
if (a.lastMessage.dateCreated && b.lastMessage.dateCreated) { | ||
if (a.lastMessage.dateCreated.getTime() < b.lastMessage.dateCreated.getTime()) { | ||
return order === 'ascending' ? -1 : 1; | ||
@@ -855,5 +855,5 @@ } else { | ||
} else { | ||
if (a.lastMessage.timestamp) { | ||
if (a.lastMessage.dateCreated) { | ||
return -1; | ||
} else if (b.lastMessage.timestamp) { | ||
} else if (b.lastMessage.dateCreated) { | ||
return 1; | ||
@@ -860,0 +860,0 @@ } |
@@ -109,20 +109,3 @@ "use strict"; | ||
} | ||
if (!(attributes === null)) { | ||
_context.next = 4; | ||
break; | ||
} | ||
throw new Error('Attributes can\'t be null'); | ||
case 4: | ||
if (!(attributes.constructor !== Object)) { | ||
_context.next = 6; | ||
break; | ||
} | ||
throw new Error('Attributes must be a valid JSON object'); | ||
case 6: | ||
_context.next = 8; | ||
_context.next = 4; | ||
return this.services.session.addCommand('createChannel', { | ||
@@ -135,3 +118,3 @@ friendlyName: options.friendlyName, | ||
case 8: | ||
case 4: | ||
response = _context.sent; | ||
@@ -143,13 +126,13 @@ channelSid = 'channelSid' in response ? response['channelSid'] : null; | ||
if (!existingChannel) { | ||
_context.next = 16; | ||
_context.next = 12; | ||
break; | ||
} | ||
_context.next = 15; | ||
_context.next = 11; | ||
return existingChannel._subscribe(); | ||
case 15: | ||
case 11: | ||
return _context.abrupt("return", existingChannel); | ||
case 16: | ||
case 12: | ||
channel = new channel_1.Channel(this.services, { | ||
@@ -170,10 +153,10 @@ channel: channelDocument, | ||
this.registerForEvents(channel); | ||
_context.next = 21; | ||
_context.next = 17; | ||
return channel._subscribe(); | ||
case 21: | ||
case 17: | ||
this.emit('channelAdded', channel); | ||
return _context.abrupt("return", channel); | ||
case 23: | ||
case 19: | ||
case "end": | ||
@@ -221,3 +204,3 @@ return _context.stop(); | ||
if (channel.status === 'joined' || channel.status === 'invited') { | ||
channel._setStatus('known', 'sync'); | ||
channel._setStatus('notParticipating', 'sync'); | ||
_this3.emit('channelLeft', channel); | ||
@@ -410,4 +393,4 @@ } | ||
}); | ||
} else if (data.status === 'known' && (channel.status === 'invited' || channel.status === 'joined')) { | ||
channel._setStatus('known', source); | ||
} else if (data.status === 'notParticipating' && (channel.status === 'invited' || channel.status === 'joined')) { | ||
channel._setStatus('notParticipating', source); | ||
channel._update(data); | ||
@@ -417,3 +400,3 @@ channel._subscribe().then(function () { | ||
}); | ||
} else if ((data.status === 'notParticipating' || data.status === 'known') && data.type === 'private') { | ||
} else if (data.status === 'notParticipating' && data.type === 'private') { | ||
channel._subscribe(); | ||
@@ -420,0 +403,0 @@ } else { |
@@ -161,3 +161,3 @@ "use strict"; | ||
* @param {String} message - Message to post | ||
* @param {Object} attributes Message attributes | ||
* @param {any} attributes Message attributes | ||
* @returns Returns promise which can fail | ||
@@ -176,19 +176,2 @@ */ | ||
log.debug('Sending text message', message, attributes); | ||
if (!(attributes === null)) { | ||
_context2.next = 3; | ||
break; | ||
} | ||
throw new Error('Attributes can\'t be null'); | ||
case 3: | ||
if (!(attributes.constructor !== Object)) { | ||
_context2.next = 5; | ||
break; | ||
} | ||
throw new Error('Attributes must be a valid JSON object'); | ||
case 5: | ||
return _context2.abrupt("return", this.services.session.addCommand('sendMessage', { | ||
@@ -200,3 +183,3 @@ channelSid: this.channel.sid, | ||
case 6: | ||
case 2: | ||
case "end": | ||
@@ -218,3 +201,3 @@ return _context2.stop(); | ||
* @param {FormData | Channel#SendMediaOptions} mediaContent - Media content to post | ||
* @param {Object} attributes Message attributes | ||
* @param {any} attributes Message attributes | ||
* @returns Returns promise which can fail | ||
@@ -234,15 +217,6 @@ */ | ||
log.debug('Sending media message', mediaContent, attributes); | ||
if (!(attributes.constructor !== Object)) { | ||
_context3.next = 3; | ||
break; | ||
} | ||
throw new Error('Attributes must be a valid JSON object'); | ||
case 3: | ||
media = void 0; | ||
if (!(typeof FormData !== 'undefined' && mediaContent instanceof FormData)) { | ||
_context3.next = 11; | ||
_context3.next = 9; | ||
break; | ||
@@ -252,11 +226,11 @@ } | ||
log.debug('Sending media message as FormData', mediaContent, attributes); | ||
_context3.next = 8; | ||
_context3.next = 6; | ||
return this.services.mcsClient.postFormData(mediaContent); | ||
case 8: | ||
case 6: | ||
media = _context3.sent; | ||
_context3.next = 18; | ||
_context3.next = 16; | ||
break; | ||
case 11: | ||
case 9: | ||
log.debug('Sending media message as SendMediaOptions', mediaContent, attributes); | ||
@@ -266,3 +240,3 @@ mediaOptions = mediaContent; | ||
if (!(!mediaOptions.contentType || !mediaOptions.media)) { | ||
_context3.next = 15; | ||
_context3.next = 13; | ||
break; | ||
@@ -273,10 +247,10 @@ } | ||
case 15: | ||
_context3.next = 17; | ||
case 13: | ||
_context3.next = 15; | ||
return this.services.mcsClient.post(mediaOptions.contentType, mediaOptions.media); | ||
case 17: | ||
case 15: | ||
media = _context3.sent; | ||
case 18: | ||
case 16: | ||
return _context3.abrupt("return", this.services.session.addCommand('sendMediaMessage', { | ||
@@ -288,3 +262,3 @@ channelSid: this.channel.sid, | ||
case 19: | ||
case 17: | ||
case "end": | ||
@@ -291,0 +265,0 @@ return _context3.stop(); |
@@ -45,6 +45,11 @@ "use strict"; | ||
(0, _createClass3.default)(Media, [{ | ||
key: "getContentUrl", | ||
key: "getContentTemporaryUrl", | ||
/** | ||
* Returns direct content URL for the media. | ||
* | ||
* This URL is impermanent, it will expire in several minutes and cannot be cached. | ||
* If the URL becomes expired, you need to request a new one. | ||
* Each call to this function produces a new temporary URL. | ||
* | ||
* @returns {Promise<String>} | ||
@@ -90,7 +95,7 @@ */ | ||
function getContentUrl() { | ||
function getContentTemporaryUrl() { | ||
return _ref.apply(this, arguments); | ||
} | ||
return getContentUrl; | ||
return getContentTemporaryUrl; | ||
}() | ||
@@ -97,0 +102,0 @@ }, { |
@@ -290,3 +290,3 @@ "use strict"; | ||
* Edit member attributes. | ||
* @param {Object} attributes new attributes for Member. | ||
* @param {any} attributes new attributes for Member. | ||
* @returns {Promise<Member|Error|SessionError>} | ||
@@ -304,3 +304,3 @@ */ | ||
if (!(typeof attributes === 'undefined')) { | ||
_context4.next = 4; | ||
_context4.next = 2; | ||
break; | ||
@@ -311,20 +311,4 @@ } | ||
case 4: | ||
if (!(attributes === null)) { | ||
_context4.next = 8; | ||
break; | ||
} | ||
throw new Error('Attributes can\'t be null'); | ||
case 8: | ||
if (!(attributes.constructor !== Object)) { | ||
_context4.next = 10; | ||
break; | ||
} | ||
throw new Error('Attributes must be a valid JSON object'); | ||
case 10: | ||
_context4.next = 12; | ||
case 2: | ||
_context4.next = 4; | ||
return this.services.session.addCommand('editMemberAttributes', { | ||
@@ -336,6 +320,6 @@ channelSid: this.channel.sid, | ||
case 12: | ||
case 4: | ||
return _context4.abrupt("return", this); | ||
case 13: | ||
case 5: | ||
case "end": | ||
@@ -342,0 +326,0 @@ return _context4.stop(); |
@@ -39,14 +39,6 @@ "use strict"; | ||
var events_1 = require("events"); | ||
var index_1 = require("./util/index"); | ||
var util_1 = require("./util"); | ||
var logger_1 = require("./logger"); | ||
var media_1 = require("./media"); | ||
var log = logger_1.Logger.scope('Message'); | ||
function parseAttributes(msgSid, attributes) { | ||
try { | ||
return attributes ? JSON.parse(attributes) : {}; | ||
} catch (e) { | ||
log.warn('Got malformed attributes for the message', msgSid); | ||
return {}; | ||
} | ||
} | ||
/** | ||
@@ -64,3 +56,3 @@ * @classdesc A Message represents a Message in a Channel. | ||
* @property {String} sid - The server-assigned unique identifier for Message | ||
* @property {Date} timestamp - When Message was created | ||
* @property {Date} dateCreated - When Message was created | ||
* @property {'text' | 'media' } type - Type of message: 'text' or 'media' | ||
@@ -92,3 +84,3 @@ * @fires Message#updated | ||
lastUpdatedBy: data.lastUpdatedBy ? data.lastUpdatedBy : null, | ||
attributes: parseAttributes(data.sid, data.attributes), | ||
attributes: util_1.parseAttributes(data.attributes, "Got malformed attributes for the message " + data.sid, log), | ||
type: data.type ? data.type : 'text', | ||
@@ -125,4 +117,4 @@ media: data.type && data.type === 'media' && data.media ? new media_1.Media(data.media, _this.services) : null, | ||
} | ||
var updatedAttributes = parseAttributes(this.sid, data.attributes); | ||
if (!index_1.isDeepEqual(this.state.attributes, updatedAttributes)) { | ||
var updatedAttributes = util_1.parseAttributes(data.attributes, "Got malformed attributes for the message " + this.sid, log); | ||
if (!util_1.isDeepEqual(this.state.attributes, updatedAttributes)) { | ||
this.state.attributes = updatedAttributes; | ||
@@ -306,3 +298,3 @@ updateReasons.push('attributes'); | ||
* Edit message attributes. | ||
* @param {Object} attributes new attributes for Message. | ||
* @param {any} attributes new attributes for Message. | ||
* @returns {Promise<Message|Error|SessionError>} | ||
@@ -320,3 +312,3 @@ */ | ||
if (!(typeof attributes === 'undefined')) { | ||
_context4.next = 4; | ||
_context4.next = 2; | ||
break; | ||
@@ -327,20 +319,4 @@ } | ||
case 4: | ||
if (!(attributes === null)) { | ||
_context4.next = 8; | ||
break; | ||
} | ||
throw new Error('Attributes can\'t be null'); | ||
case 8: | ||
if (!(attributes.constructor !== Object)) { | ||
_context4.next = 10; | ||
break; | ||
} | ||
throw new Error('Attributes must be a valid JSON object'); | ||
case 10: | ||
_context4.next = 12; | ||
case 2: | ||
_context4.next = 4; | ||
return this.services.session.addCommand('editMessageAttributes', { | ||
@@ -352,6 +328,6 @@ channelSid: this.channel.sid, | ||
case 12: | ||
case 4: | ||
return _context4.abrupt("return", this); | ||
case 13: | ||
case 5: | ||
case "end": | ||
@@ -404,3 +380,3 @@ return _context4.stop(); | ||
}, { | ||
key: "timestamp", | ||
key: "dateCreated", | ||
get: function get() { | ||
@@ -407,0 +383,0 @@ return this.state.timestamp; |
@@ -110,8 +110,3 @@ "use strict"; | ||
case 'attributes': | ||
var updateAttributes = {}; | ||
try { | ||
updateAttributes = JSON.parse(value.value); | ||
} catch (e) { | ||
log.warn('Retrieved malformed attributes from the server for user: ' + this.state.identity); | ||
} | ||
var updateAttributes = util_1.parseAttributes(value.value, "Retrieved malformed attributes from the server for user: " + this.state.identity, log); | ||
if (!util_1.isDeepEqual(this.state.attributes, updateAttributes)) { | ||
@@ -218,3 +213,3 @@ this.state.attributes = updateAttributes; | ||
* Updates user attributes. | ||
* @param {Object} attributes - Updated attributes | ||
* @param {any} attributes new attributes for User. | ||
* @returns {Promise<User|Error|SessionError>} | ||
@@ -232,3 +227,3 @@ */ | ||
if (!(typeof attributes === 'undefined')) { | ||
_context2.next = 4; | ||
_context2.next = 2; | ||
break; | ||
@@ -239,21 +234,5 @@ } | ||
case 4: | ||
if (!(attributes === null)) { | ||
_context2.next = 8; | ||
break; | ||
} | ||
throw new Error('Attributes can\'t be null'); | ||
case 8: | ||
if (!(attributes.constructor !== Object)) { | ||
_context2.next = 10; | ||
break; | ||
} | ||
throw new Error('Attributes must be a valid JSON object'); | ||
case 10: | ||
case 2: | ||
if (!(this.subscribed == 'unsubscribed')) { | ||
_context2.next = 12; | ||
_context2.next = 4; | ||
break; | ||
@@ -264,4 +243,4 @@ } | ||
case 12: | ||
_context2.next = 14; | ||
case 4: | ||
_context2.next = 6; | ||
return this.services.session.addCommand('editUserAttributes', { | ||
@@ -272,6 +251,6 @@ username: this.state.identity, | ||
case 14: | ||
case 6: | ||
return _context2.abrupt("return", this); | ||
case 15: | ||
case 7: | ||
case "end": | ||
@@ -278,0 +257,0 @@ return _context2.stop(); |
@@ -15,11 +15,4 @@ "use strict"; | ||
var logger_1 = require("./logger"); | ||
var util_1 = require("./util"); | ||
var log = logger_1.Logger.scope('UserDescriptor'); | ||
function parseAttributes(attrs) { | ||
try { | ||
return JSON.parse(attrs); | ||
} catch (e) { | ||
log.warn('Failed to parse user attributes', e); | ||
} | ||
return {}; | ||
} | ||
/** | ||
@@ -55,3 +48,3 @@ * @classdesc Extended user information. | ||
this.friendlyName = descriptor.friendly_name; | ||
this.attributes = parseAttributes(descriptor.attributes); | ||
this.attributes = util_1.parseAttributes(descriptor.attributes, 'Failed to parse user attributes', log); | ||
this.online = descriptor.is_online; | ||
@@ -58,0 +51,0 @@ this.notifiable = descriptor.is_notifiable; |
@@ -43,2 +43,4 @@ "use strict"; | ||
exports.parseToNumber = parseToNumber; | ||
// timeString cannot be typed `string` because in member.ts | ||
// call to parseTime(data.lastConsumptionTimestamp) uses number not a string for timestamp. | ||
function parseTime(timeString) { | ||
@@ -58,3 +60,3 @@ try { | ||
} catch (e) { | ||
log.warn(warningMessage); | ||
log.warn(warningMessage, e); | ||
} | ||
@@ -61,0 +63,0 @@ } |
@@ -15,3 +15,2 @@ /// <reference types="node" /> | ||
import { Network } from './services/network'; | ||
declare function filterStatus(status: any): any; | ||
export interface ChannelServices { | ||
@@ -41,3 +40,3 @@ session: Session; | ||
type UpdateReason = 'attributes' | 'createdBy' | 'dateCreated' | 'dateUpdated' | 'friendlyName' | 'lastConsumedMessageIndex' | 'state' | 'status' | 'uniqueName' | 'lastMessage' | 'notificationLevel'; | ||
type Status = 'unknown' | 'known' | 'invited' | 'joined'; | ||
type Status = 'unknown' | 'notParticipating' | 'invited' | 'joined'; | ||
type Type = 'public' | 'private'; | ||
@@ -59,3 +58,3 @@ type NotificationLevel = 'default' | 'muted'; | ||
index?: number; | ||
timestamp?: Date; | ||
dateCreated?: Date; | ||
} | ||
@@ -115,5 +114,5 @@ } | ||
* The status of the Channel, relative to the Client: whether the Channel | ||
* is <code>known</code> to local Client, Client is <code>invited</code> to or | ||
* is <code>notParticipating</code> to local Client, Client is <code>invited</code> to or | ||
* is <code>joined</code> to this Channel | ||
* @typedef {('unknown' | 'known' | 'invited' | 'joined')} Channel#Status | ||
* @typedef {('unknown' | 'notParticipating' | 'invited' | 'joined')} Channel#Status | ||
*/ | ||
@@ -154,3 +153,3 @@ /** | ||
* @property {Number} index - Message's index | ||
* @property {Date} timestamp - Message's creation timestamp | ||
* @property {Date} dateCreated - Message's creation timestamp | ||
*/ | ||
@@ -347,6 +346,6 @@ /** | ||
* Update the Channel's attributes. | ||
* @param {Object} attributes - The new attributes object | ||
* @param {any} attributes new attributes for Channel. | ||
* @returns {Promise<Channel|Error|SessionError>} | ||
*/ | ||
updateAttributes(attributes: Object): Promise<this>; | ||
updateAttributes(attributes: any): Promise<this>; | ||
/** | ||
@@ -377,3 +376,3 @@ * Update the Channel's friendlyName. | ||
} | ||
export { ChannelDescriptor, Channel, filterStatus }; | ||
export { ChannelDescriptor, Channel }; | ||
/** | ||
@@ -380,0 +379,0 @@ * Fired when a Member has joined the Channel. |
@@ -33,11 +33,2 @@ "use strict"; | ||
} | ||
function filterStatus(status) { | ||
switch (status) { | ||
case 'notParticipating': | ||
return 'known'; | ||
default: | ||
return status; | ||
} | ||
} | ||
exports.filterStatus = filterStatus; | ||
/** | ||
@@ -85,5 +76,5 @@ * @classdesc A Channel represents a remote channel of communication between multiple Programmable Chat Clients | ||
* The status of the Channel, relative to the Client: whether the Channel | ||
* is <code>known</code> to local Client, Client is <code>invited</code> to or | ||
* is <code>notParticipating</code> to local Client, Client is <code>invited</code> to or | ||
* is <code>joined</code> to this Channel | ||
* @typedef {('unknown' | 'known' | 'invited' | 'joined')} Channel#Status | ||
* @typedef {('unknown' | 'notParticipating' | 'invited' | 'joined')} Channel#Status | ||
*/ | ||
@@ -126,3 +117,3 @@ /** | ||
uniqueName, | ||
status: 'known', | ||
status: 'notParticipating', | ||
type: descriptor.type, | ||
@@ -166,3 +157,3 @@ attributes, | ||
* @property {Number} index - Message's index | ||
* @property {Date} timestamp - Message's creation timestamp | ||
* @property {Date} dateCreated - Message's creation timestamp | ||
*/ | ||
@@ -344,6 +335,6 @@ /** | ||
if (!update.status || update.status === 'unknown' | ||
|| this.channelState.status === filterStatus(update.status)) { | ||
|| this.channelState.status === update.status) { | ||
break; | ||
} | ||
this.channelState.status = filterStatus(update.status); | ||
this.channelState.status = update.status; | ||
updateReasons.add(localKey); | ||
@@ -379,4 +370,4 @@ break; | ||
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; | ||
&& ((_d = (_c = this.channelState.lastMessage) === null || _c === void 0 ? void 0 : _c.dateCreated) === null || _d === void 0 ? void 0 : _d.getTime()) !== update.lastMessage.timestamp.getTime()) { | ||
this.channelState.lastMessage.dateCreated = update.lastMessage.timestamp; | ||
updateReasons.add(localKey); | ||
@@ -690,3 +681,3 @@ } | ||
* Update the Channel's attributes. | ||
* @param {Object} attributes - The new attributes object | ||
* @param {any} attributes new attributes for Channel. | ||
* @returns {Promise<Channel|Error|SessionError>} | ||
@@ -698,8 +689,2 @@ */ | ||
} | ||
else if (attributes === null) { | ||
throw new Error('Attributes can\'t be null'); | ||
} | ||
else if (attributes.constructor !== Object) { | ||
throw new Error('Attributes must be a valid JSON object.'); | ||
} | ||
await this.services.session.addCommand('editAttributes', { | ||
@@ -706,0 +691,0 @@ channelSid: this.sid, |
@@ -8,3 +8,3 @@ import { Channel } from './channel'; | ||
* | ||
* @property {Object} attributes - The Channel's custom attributes | ||
* @property {any} attributes - The Channel's custom attributes | ||
* @property {String} createdBy - The identity of the User that created Channel | ||
@@ -30,3 +30,3 @@ * @property {Date} dateCreated - The Date Channel was created | ||
readonly friendlyName: string; | ||
readonly attributes: Object; | ||
readonly attributes: any; | ||
readonly createdBy: string; | ||
@@ -33,0 +33,0 @@ readonly dateCreated: Date; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const logger_1 = require("./logger"); | ||
const channel_1 = require("./channel"); | ||
const util_1 = require("./util"); | ||
const log = logger_1.Logger.scope('ChannelDescriptor'); | ||
function parseAttributes(attrs) { | ||
try { | ||
return JSON.parse(attrs); | ||
} | ||
catch (e) { | ||
log.warn('Failed to parse channel attributes', e); | ||
} | ||
return {}; | ||
} | ||
function parseTime(timeString) { | ||
try { | ||
return new Date(timeString); | ||
} | ||
catch (e) { | ||
return null; | ||
} | ||
} | ||
/** | ||
@@ -28,3 +11,3 @@ * Contains channel information. | ||
* | ||
* @property {Object} attributes - The Channel's custom attributes | ||
* @property {any} attributes - The Channel's custom attributes | ||
* @property {String} createdBy - The identity of the User that created Channel | ||
@@ -62,6 +45,6 @@ * @property {Date} dateCreated - The Date Channel was created | ||
this.friendlyName = descriptor.friendly_name; | ||
this.attributes = parseAttributes(descriptor.attributes); | ||
this.attributes = util_1.parseAttributes(descriptor.attributes, 'Failed to parse channel attributes', log); | ||
this.createdBy = descriptor.created_by; | ||
this.dateCreated = parseTime(descriptor.date_created); | ||
this.dateUpdated = parseTime(descriptor.date_updated); | ||
this.dateCreated = util_1.parseTime(descriptor.date_created); | ||
this.dateUpdated = util_1.parseTime(descriptor.date_updated); | ||
this.messagesCount = descriptor.messages_count; | ||
@@ -76,3 +59,3 @@ this.membersCount = descriptor.members_count; | ||
if (descriptor.status) { | ||
this.status = channel_1.filterStatus(descriptor.status); | ||
this.status = descriptor.status; | ||
} | ||
@@ -79,0 +62,0 @@ else { |
@@ -349,4 +349,4 @@ "use strict"; | ||
if (a.lastMessage && b.lastMessage) { | ||
if (a.lastMessage.timestamp && b.lastMessage.timestamp) { | ||
if (a.lastMessage.timestamp.getTime() < b.lastMessage.timestamp.getTime()) { | ||
if (a.lastMessage.dateCreated && b.lastMessage.dateCreated) { | ||
if (a.lastMessage.dateCreated.getTime() < b.lastMessage.dateCreated.getTime()) { | ||
return (order === 'ascending') ? -1 : 1; | ||
@@ -359,6 +359,6 @@ } | ||
else { | ||
if (a.lastMessage.timestamp) { | ||
if (a.lastMessage.dateCreated) { | ||
return -1; | ||
} | ||
else if (b.lastMessage.timestamp) { | ||
else if (b.lastMessage.dateCreated) { | ||
return 1; | ||
@@ -365,0 +365,0 @@ } |
@@ -40,8 +40,2 @@ "use strict"; | ||
} | ||
if (attributes === null) { | ||
throw new Error('Attributes can\'t be null'); | ||
} | ||
if (attributes.constructor !== Object) { | ||
throw new Error('Attributes must be a valid JSON object'); | ||
} | ||
let response = await this.services.session.addCommand('createChannel', { | ||
@@ -97,3 +91,3 @@ friendlyName: options.friendlyName, | ||
if (channel.status === 'joined' || channel.status === 'invited') { | ||
channel._setStatus('known', 'sync'); | ||
channel._setStatus('notParticipating', 'sync'); | ||
this.emit('channelLeft', channel); | ||
@@ -221,9 +215,9 @@ } | ||
} | ||
else if (data.status === 'known' && | ||
else if (data.status === 'notParticipating' && | ||
(channel.status === 'invited' || channel.status === 'joined')) { | ||
channel._setStatus('known', source); | ||
channel._setStatus('notParticipating', source); | ||
channel._update(data); | ||
channel._subscribe().then(() => { this.emit('channelLeft', channel); }); | ||
} | ||
else if ((data.status === 'notParticipating' || data.status === 'known') && data.type === 'private') { | ||
else if (data.status === 'notParticipating' && data.type === 'private') { | ||
channel._subscribe(); | ||
@@ -230,0 +224,0 @@ } |
@@ -33,13 +33,13 @@ /// <reference types="node" /> | ||
* @param {String} message - Message to post | ||
* @param {Object} attributes Message attributes | ||
* @param {any} attributes Message attributes | ||
* @returns Returns promise which can fail | ||
*/ | ||
send(message: string, attributes?: Object): Promise<unknown>; | ||
send(message: string, attributes?: any): Promise<unknown>; | ||
/** | ||
* Send Media Message to the channel | ||
* @param {FormData | Channel#SendMediaOptions} mediaContent - Media content to post | ||
* @param {Object} attributes Message attributes | ||
* @param {any} attributes Message attributes | ||
* @returns Returns promise which can fail | ||
*/ | ||
sendMedia(mediaContent: FormData | Channel.SendMediaOptions, attributes?: Object): Promise<unknown>; | ||
sendMedia(mediaContent: FormData | Channel.SendMediaOptions, attributes?: any): Promise<unknown>; | ||
/** | ||
@@ -46,0 +46,0 @@ * Returns messages from channel using paginator interface |
@@ -77,3 +77,3 @@ "use strict"; | ||
* @param {String} message - Message to post | ||
* @param {Object} attributes Message attributes | ||
* @param {any} attributes Message attributes | ||
* @returns Returns promise which can fail | ||
@@ -83,8 +83,2 @@ */ | ||
log.debug('Sending text message', message, attributes); | ||
if (attributes === null) { | ||
throw new Error('Attributes can\'t be null'); | ||
} | ||
if (attributes.constructor !== Object) { | ||
throw new Error('Attributes must be a valid JSON object'); | ||
} | ||
return this.services.session.addCommand('sendMessage', { | ||
@@ -99,3 +93,3 @@ channelSid: this.channel.sid, | ||
* @param {FormData | Channel#SendMediaOptions} mediaContent - Media content to post | ||
* @param {Object} attributes Message attributes | ||
* @param {any} attributes Message attributes | ||
* @returns Returns promise which can fail | ||
@@ -105,5 +99,2 @@ */ | ||
log.debug('Sending media message', mediaContent, attributes); | ||
if (attributes.constructor !== Object) { | ||
throw new Error('Attributes must be a valid JSON object'); | ||
} | ||
let media; | ||
@@ -110,0 +101,0 @@ if (typeof FormData !== 'undefined' && (mediaContent instanceof FormData)) { |
@@ -29,6 +29,11 @@ import { McsClient } from 'twilio-mcs-client'; | ||
* Returns direct content URL for the media. | ||
* | ||
* This URL is impermanent, it will expire in several minutes and cannot be cached. | ||
* If the URL becomes expired, you need to request a new one. | ||
* Each call to this function produces a new temporary URL. | ||
* | ||
* @returns {Promise<String>} | ||
*/ | ||
getContentUrl(): Promise<string>; | ||
getContentTemporaryUrl(): Promise<string>; | ||
} | ||
export { Media }; |
@@ -27,5 +27,10 @@ "use strict"; | ||
* Returns direct content URL for the media. | ||
* | ||
* This URL is impermanent, it will expire in several minutes and cannot be cached. | ||
* If the URL becomes expired, you need to request a new one. | ||
* Each call to this function produces a new temporary URL. | ||
* | ||
* @returns {Promise<String>} | ||
*/ | ||
async getContentUrl() { | ||
async getContentTemporaryUrl() { | ||
if (!this.mcsMedia) { | ||
@@ -32,0 +37,0 @@ if (this.services.mcsClient) { |
@@ -105,6 +105,6 @@ /// <reference types="node" /> | ||
* Edit member attributes. | ||
* @param {Object} attributes new attributes for Member. | ||
* @param {any} attributes new attributes for Member. | ||
* @returns {Promise<Member|Error|SessionError>} | ||
*/ | ||
updateAttributes(attributes: Object): Promise<this>; | ||
updateAttributes(attributes: any): Promise<this>; | ||
} | ||
@@ -111,0 +111,0 @@ export { MemberDescriptor, Member }; |
@@ -168,3 +168,3 @@ "use strict"; | ||
* Edit member attributes. | ||
* @param {Object} attributes new attributes for Member. | ||
* @param {any} attributes new attributes for Member. | ||
* @returns {Promise<Member|Error|SessionError>} | ||
@@ -176,8 +176,2 @@ */ | ||
} | ||
else if (attributes === null) { | ||
throw new Error('Attributes can\'t be null'); | ||
} | ||
else if (attributes.constructor !== Object) { | ||
throw new Error('Attributes must be a valid JSON object'); | ||
} | ||
await this.services.session.addCommand('editMemberAttributes', { | ||
@@ -184,0 +178,0 @@ channelSid: this.channel.sid, |
@@ -35,3 +35,3 @@ /// <reference types="node" /> | ||
* @property {String} sid - The server-assigned unique identifier for Message | ||
* @property {Date} timestamp - When Message was created | ||
* @property {Date} dateCreated - When Message was created | ||
* @property {'text' | 'media' } type - Type of message: 'text' or 'media' | ||
@@ -55,3 +55,3 @@ * @fires Message#updated | ||
get lastUpdatedBy(): string; | ||
get timestamp(): Date; | ||
get dateCreated(): Date; | ||
get attributes(): Object; | ||
@@ -80,6 +80,6 @@ get type(): Message.Type; | ||
* Edit message attributes. | ||
* @param {Object} attributes new attributes for Message. | ||
* @param {any} attributes new attributes for Message. | ||
* @returns {Promise<Message|Error|SessionError>} | ||
*/ | ||
updateAttributes(attributes: Object): Promise<this>; | ||
updateAttributes(attributes: any): Promise<this>; | ||
} | ||
@@ -86,0 +86,0 @@ export { Message }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const events_1 = require("events"); | ||
const index_1 = require("./util/index"); | ||
const util_1 = require("./util"); | ||
const logger_1 = require("./logger"); | ||
const media_1 = require("./media"); | ||
const log = logger_1.Logger.scope('Message'); | ||
function parseAttributes(msgSid, attributes) { | ||
try { | ||
return attributes ? JSON.parse(attributes) : {}; | ||
} | ||
catch (e) { | ||
log.warn('Got malformed attributes for the message', msgSid); | ||
return {}; | ||
} | ||
} | ||
/** | ||
@@ -29,3 +20,3 @@ * @classdesc A Message represents a Message in a Channel. | ||
* @property {String} sid - The server-assigned unique identifier for Message | ||
* @property {Date} timestamp - When Message was created | ||
* @property {Date} dateCreated - When Message was created | ||
* @property {'text' | 'media' } type - Type of message: 'text' or 'media' | ||
@@ -51,3 +42,3 @@ * @fires Message#updated | ||
lastUpdatedBy: data.lastUpdatedBy ? data.lastUpdatedBy : null, | ||
attributes: parseAttributes(data.sid, data.attributes), | ||
attributes: util_1.parseAttributes(data.attributes, `Got malformed attributes for the message ${data.sid}`, log), | ||
type: data.type ? data.type : 'text', | ||
@@ -70,3 +61,3 @@ media: (data.type && data.type === 'media' && data.media) | ||
get lastUpdatedBy() { return this.state.lastUpdatedBy; } | ||
get timestamp() { return this.state.timestamp; } | ||
get dateCreated() { return this.state.timestamp; } | ||
get attributes() { return this.state.attributes; } | ||
@@ -100,4 +91,4 @@ get type() { return this.state.type; } | ||
} | ||
let updatedAttributes = parseAttributes(this.sid, data.attributes); | ||
if (!index_1.isDeepEqual(this.state.attributes, updatedAttributes)) { | ||
let updatedAttributes = util_1.parseAttributes(data.attributes, `Got malformed attributes for the message ${this.sid}`, log); | ||
if (!util_1.isDeepEqual(this.state.attributes, updatedAttributes)) { | ||
this.state.attributes = updatedAttributes; | ||
@@ -178,3 +169,3 @@ updateReasons.push('attributes'); | ||
* Edit message attributes. | ||
* @param {Object} attributes new attributes for Message. | ||
* @param {any} attributes new attributes for Message. | ||
* @returns {Promise<Message|Error|SessionError>} | ||
@@ -186,8 +177,2 @@ */ | ||
} | ||
else if (attributes === null) { | ||
throw new Error('Attributes can\'t be null'); | ||
} | ||
else if (attributes.constructor !== Object) { | ||
throw new Error('Attributes must be a valid JSON object'); | ||
} | ||
await this.services.session.addCommand('editMessageAttributes', { | ||
@@ -194,0 +179,0 @@ channelSid: this.channel.sid, |
@@ -64,3 +64,3 @@ /// <reference types="node" /> | ||
* Updates user attributes. | ||
* @param {Object} attributes - Updated attributes | ||
* @param {any} attributes new attributes for User. | ||
* @returns {Promise<User|Error|SessionError>} | ||
@@ -67,0 +67,0 @@ */ |
@@ -68,9 +68,3 @@ "use strict"; | ||
case 'attributes': | ||
let updateAttributes = {}; | ||
try { | ||
updateAttributes = JSON.parse(value.value); | ||
} | ||
catch (e) { | ||
log.warn('Retrieved malformed attributes from the server for user: ' + this.state.identity); | ||
} | ||
const updateAttributes = util_1.parseAttributes(value.value, `Retrieved malformed attributes from the server for user: ${this.state.identity}`, log); | ||
if (!util_1.isDeepEqual(this.state.attributes, updateAttributes)) { | ||
@@ -144,3 +138,3 @@ this.state.attributes = updateAttributes; | ||
* Updates user attributes. | ||
* @param {Object} attributes - Updated attributes | ||
* @param {any} attributes new attributes for User. | ||
* @returns {Promise<User|Error|SessionError>} | ||
@@ -152,8 +146,2 @@ */ | ||
} | ||
else if (attributes === null) { | ||
throw new Error('Attributes can\'t be null'); | ||
} | ||
else if (attributes.constructor !== Object) { | ||
throw new Error('Attributes must be a valid JSON object'); | ||
} | ||
if (this.subscribed == 'unsubscribed') { | ||
@@ -160,0 +148,0 @@ throw new Error('Can\'t modify unsubscribed object'); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const logger_1 = require("./logger"); | ||
const util_1 = require("./util"); | ||
const log = logger_1.Logger.scope('UserDescriptor'); | ||
function parseAttributes(attrs) { | ||
try { | ||
return JSON.parse(attrs); | ||
} | ||
catch (e) { | ||
log.warn('Failed to parse user attributes', e); | ||
} | ||
return {}; | ||
} | ||
/** | ||
@@ -41,3 +33,3 @@ * @classdesc Extended user information. | ||
this.friendlyName = descriptor.friendly_name; | ||
this.attributes = parseAttributes(descriptor.attributes); | ||
this.attributes = util_1.parseAttributes(descriptor.attributes, 'Failed to parse user attributes', log); | ||
this.online = descriptor.is_online; | ||
@@ -44,0 +36,0 @@ this.notifiable = descriptor.is_notifiable; |
@@ -28,2 +28,4 @@ "use strict"; | ||
exports.parseToNumber = parseToNumber; | ||
// timeString cannot be typed `string` because in member.ts | ||
// call to parseTime(data.lastConsumptionTimestamp) uses number not a string for timestamp. | ||
function parseTime(timeString) { | ||
@@ -45,3 +47,3 @@ try { | ||
catch (e) { | ||
log.warn(warningMessage); | ||
log.warn(warningMessage, e); | ||
} | ||
@@ -48,0 +50,0 @@ } |
{ | ||
"name": "twilio-chat", | ||
"version": "3.4.0", | ||
"version": "4.0.0-rc1", | ||
"description": "Twilio Chat service client library", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
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
6119266
170464
4