@evo/chat-core
Advanced tools
Comparing version 0.7.20 to 0.8.0
@@ -43,7 +43,7 @@ 'use strict'; | ||
var Besida = exports.Besida = function () { | ||
function Besida(swindonObj, userRole) { | ||
function Besida(swindonObj, userRole, komoraUrl) { | ||
var _c$BESIDA_ROLE_BUYER, _c$BESIDA_ROLE_COMPAN, _chatsLoadOffset; | ||
var debug = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; | ||
var mutableStore = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; | ||
var debug = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; | ||
var mutableStore = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false; | ||
@@ -88,2 +88,4 @@ _classCallCheck(this, Besida); | ||
this.saveFiles = (0, _utils.initSaveFiles)(komoraUrl); | ||
// subscribe for chat rooms meta-data | ||
@@ -496,5 +498,13 @@ this.guard.lattice(this.roomsSpace, '', this.roster); | ||
} | ||
/** | ||
* Retry save file in komora and then send file message via websocket | ||
* @param roomIdent | ||
* @param msgId | ||
* @returns {*} | ||
*/ | ||
}, { | ||
key: 'sendContext', | ||
value: function sendContext(roomIdent, contextItemId, contextItemType, contextItemPrice, contextItemCurrency, contextSource, contextDescription, contextMeta, platform, source, device) { | ||
key: 'retrySendFile', | ||
value: function retrySendFile(roomIdent, msgId) { | ||
var _this11 = this; | ||
@@ -507,2 +517,118 @@ | ||
var updReceiveRoom = receiveRoom; | ||
var roomPath = [setInEntity, setInIndex]; | ||
var sendingMessage = (0, _utils.getMessageById)(updReceiveRoom, msgId); | ||
sendingMessage = sendingMessage.set('isTemporaryMessage', true); | ||
updReceiveRoom = (0, _utils.updateMessageById)(baseStore.getIn(roomPath), msgId, sendingMessage); | ||
baseStore = baseStore.setIn(roomPath, updReceiveRoom); | ||
baseStore = baseStore.setIn(roomPath.concat('isErrorOnFilesSave'), false); | ||
this.message && this.message(roomIdent, this.dataFormatter(sendingMessage)); | ||
return this.saveFiles([sendingMessage.get('body')]).then(function (_ref3) { | ||
var metadata = _ref3.metadata; | ||
var file = metadata[0]; | ||
sendingMessage = sendingMessage.set('context_item_uid', file.uid); | ||
return file; | ||
}).catch(function (e) { | ||
baseStore = baseStore.setIn(roomPath.concat('isErrorOnFilesSave'), true); | ||
sendingMessage = sendingMessage.set('isErrorOnSending', true); | ||
updReceiveRoom = (0, _utils.updateMessageById)(baseStore.getIn(roomPath), msgId, sendingMessage); | ||
baseStore = baseStore.setIn(roomPath, updReceiveRoom); | ||
_this11.message && _this11.message(roomIdent, _this11.dataFormatter(sendingMessage)); | ||
return _this11.handleFilesSaveErrors(e); | ||
}).then(function (file) { | ||
return _this11.oSwindon.call('chat.send_context', [], { | ||
temporary_id: msgId, | ||
room_ident: roomIdent, | ||
context_item_id: null, | ||
context_item_uid: file.uid, | ||
context_item_type: sendingMessage.get('context_item_type'), | ||
context_source: sendingMessage.get('context_source'), | ||
context_description: file.name, | ||
platform: sendingMessage.get('platform'), | ||
source: sendingMessage.get('source'), | ||
device: sendingMessage.get('device') | ||
}); | ||
}).then(function (data) { | ||
sendingMessage = sendingMessage.set('id', data.message_id); | ||
sendingMessage = sendingMessage.set('isTemporaryMessage', false); | ||
updReceiveRoom = (0, _utils.updateMessageById)(baseStore.getIn(roomPath), msgId, sendingMessage); | ||
baseStore = baseStore.setIn(roomPath, updReceiveRoom); | ||
return _this11.message && _this11.message(roomIdent, _this11.dataFormatter(sendingMessage)); | ||
}).catch(function (error) { | ||
sendingMessage = sendingMessage.set('isErrorOnSending', true); | ||
updReceiveRoom = (0, _utils.updateMessageById)(baseStore.getIn(roomPath), msgId, sendingMessage); | ||
baseStore = baseStore.setIn(roomPath, updReceiveRoom); | ||
_this11.message && _this11.message(roomIdent, _this11.dataFormatter(sendingMessage)); | ||
return _this11.handleRequestErrors(error); | ||
}); | ||
} | ||
/** | ||
* Retry send file message via websocket | ||
* @param roomIdent | ||
* @param msgId | ||
* @returns {*} | ||
*/ | ||
}, { | ||
key: 'retrySendFileCtx', | ||
value: function retrySendFileCtx(roomIdent, msgId) { | ||
var _this12 = this; | ||
var _getRoomData6 = (0, _utils.getRoomData)(baseStore, roomIdent), | ||
receiveRoom = _getRoomData6.room, | ||
setInEntity = _getRoomData6.setInEntity, | ||
setInIndex = _getRoomData6.setInIndex; | ||
var updReceiveRoom = receiveRoom; | ||
var roomPath = [setInEntity, setInIndex]; | ||
var sendingMessage = (0, _utils.getMessageById)(updReceiveRoom, msgId); | ||
sendingMessage = sendingMessage.set('isTemporaryMessage', true); | ||
updReceiveRoom = (0, _utils.updateMessageById)(baseStore.getIn(roomPath), msgId, sendingMessage); | ||
baseStore = baseStore.setIn(roomPath, updReceiveRoom); | ||
baseStore = baseStore.setIn(roomPath.concat('isErrorOnFilesSave'), false); | ||
this.message && this.message(roomIdent, this.dataFormatter(sendingMessage)); | ||
return this.oSwindon.call('chat.send_context', [], { | ||
temporary_id: msgId, | ||
room_ident: roomIdent, | ||
context_item_id: null, | ||
context_item_uid: sendingMessage.get('context_item_uid'), | ||
context_item_type: sendingMessage.get('context_item_type'), | ||
context_source: sendingMessage.get('context_source'), | ||
context_description: sendingMessage.get('context_description'), | ||
platform: sendingMessage.get('platform'), | ||
source: sendingMessage.get('source'), | ||
device: sendingMessage.get('device') | ||
}).then(function (data) { | ||
sendingMessage = sendingMessage.set('id', data.message_id); | ||
sendingMessage = sendingMessage.set('isTemporaryMessage', false); | ||
updReceiveRoom = (0, _utils.updateMessageById)(baseStore.getIn(roomPath), msgId, sendingMessage); | ||
baseStore = baseStore.setIn(roomPath, updReceiveRoom); | ||
return _this12.message && _this12.message(roomIdent, _this12.dataFormatter(sendingMessage)); | ||
}).catch(function (error) { | ||
sendingMessage = sendingMessage.set('isErrorOnSending', true); | ||
updReceiveRoom = (0, _utils.updateMessageById)(baseStore.getIn(roomPath), msgId, sendingMessage); | ||
baseStore = baseStore.setIn(roomPath, updReceiveRoom); | ||
_this12.message && _this12.message(roomIdent, _this12.dataFormatter(sendingMessage)); | ||
return _this12.handleRequestErrors(error); | ||
}); | ||
} | ||
}, { | ||
key: 'sendContext', | ||
value: function sendContext(roomIdent, contextItemId, contextItemType, contextItemPrice, contextItemCurrency, contextSource, contextDescription, contextMeta, platform, source, device) { | ||
var _this13 = this; | ||
var _getRoomData7 = (0, _utils.getRoomData)(baseStore, roomIdent), | ||
receiveRoom = _getRoomData7.room, | ||
setInEntity = _getRoomData7.setInEntity, | ||
setInIndex = _getRoomData7.setInIndex; | ||
var isTemporaryMessage = true; | ||
@@ -542,3 +668,3 @@ var updReceiveRoom = receiveRoom; | ||
} | ||
return _this11.message && _this11.message(roomIdent, _this11.dataFormatter(sendingMessage)); | ||
return _this13.message && _this13.message(roomIdent, _this13.dataFormatter(sendingMessage)); | ||
}).catch(function (error) { | ||
@@ -550,11 +676,129 @@ sendingMessage = sendingMessage.set('isErrorOnSending', true); | ||
} | ||
_this11.message && _this11.message(roomIdent, _this11.dataFormatter(sendingMessage)); | ||
_this13.message && _this13.message(roomIdent, _this13.dataFormatter(sendingMessage)); | ||
return _this11.handleRequestErrors(error); | ||
return _this13.handleRequestErrors(error); | ||
}); | ||
} | ||
}, { | ||
key: 'sendFilesContext', | ||
value: function sendFilesContext(roomIdent, contextSource, platform, source, device, files) { | ||
var _this14 = this; | ||
var contextItemType = 'file'; | ||
var _getRoomData8 = (0, _utils.getRoomData)(baseStore, roomIdent), | ||
receiveRoom = _getRoomData8.room, | ||
setInEntity = _getRoomData8.setInEntity, | ||
setInIndex = _getRoomData8.setInIndex; | ||
var isTemporaryMessage = true; | ||
var updReceiveRoom = receiveRoom; | ||
var roomPath = [setInEntity, setInIndex]; | ||
var msgIds = []; | ||
var sendingMessagesMap = {}; | ||
var filesToSend = []; | ||
files.forEach(function (file) { | ||
var msgId = (0, _uuid2.default)(); | ||
var sendingMessage = (0, _utils.prepareContextMessage)(baseStore, msgId, roomIdent, platform, source, device, isTemporaryMessage, null, null, contextItemType, null, null, contextSource, file.name, null, file); | ||
var oversizedFile = file.size > c.MAX_FILE_SIZE_LIMIT; | ||
if (!oversizedFile) { | ||
msgIds.push(msgId); | ||
filesToSend.push(file); | ||
sendingMessagesMap[msgId] = sendingMessage; | ||
} else { | ||
sendingMessage = sendingMessage.set('isErrorOnSending', true); | ||
sendingMessage = sendingMessage.set('oversized', true); | ||
} | ||
// pre-send images in history as previews | ||
updReceiveRoom = (0, _utils.insertMessage)(updReceiveRoom, sendingMessage); | ||
baseStore = baseStore.setIn(roomPath, updReceiveRoom); | ||
_this14.message && _this14.message(roomIdent, _this14.dataFormatter(sendingMessage)); | ||
}); | ||
return this.saveFiles(filesToSend).then(function (_ref4) { | ||
var metadata = _ref4.metadata; | ||
// objects in meta are always in the same order as the were sent | ||
metadata.forEach(function (fileMeta, index) { | ||
var msgId = msgIds[index]; | ||
sendingMessagesMap[msgId] = sendingMessagesMap[msgId].set('context_item_uid', fileMeta.uid); | ||
}); | ||
return metadata; | ||
}).catch(function (e) { | ||
// all files failed to save | ||
baseStore = baseStore.setIn(roomPath.concat('isErrorOnFilesSave'), true); | ||
Object.values(sendingMessagesMap).forEach(function (message) { | ||
var sendingMessage = message.set('isErrorOnSending', true); | ||
updReceiveRoom = (0, _utils.updateMessageById)(baseStore.getIn(roomPath), sendingMessage.get('id'), sendingMessage); | ||
baseStore = baseStore.setIn(roomPath, updReceiveRoom); | ||
_this14.message && _this14.message(roomIdent, _this14.dataFormatter(sendingMessage)); | ||
}); | ||
_this14.handleFilesSaveErrors(e); | ||
return Promise.reject(e); | ||
}).then(function (metadata) { | ||
var promises = []; | ||
metadata.forEach(function (file, index) { | ||
var msgId = msgIds[index]; | ||
promises.push(_this14.oSwindon.call('chat.send_context', [], { | ||
temporary_id: msgId, | ||
room_ident: roomIdent, | ||
context_item_id: null, | ||
context_item_uid: file.uid, | ||
context_item_type: contextItemType, | ||
context_source: contextSource, | ||
context_description: file.name, | ||
platform: platform, | ||
source: source, | ||
device: device | ||
}) | ||
// wait until all promises have completed even when some reject | ||
.catch(function (e) { | ||
e.msgId = msgId; | ||
return e; | ||
})); | ||
}); | ||
return Promise.all(promises); | ||
}).then(function (results) { | ||
var errors = []; | ||
results.forEach(function (data) { | ||
if (data instanceof Error) { | ||
errors.push(data); | ||
return; | ||
} | ||
var sendingMessage = sendingMessagesMap[data.temporary_id]; | ||
sendingMessage = sendingMessage.set('id', data.message_id); | ||
sendingMessage = sendingMessage.set('isTemporaryMessage', false); | ||
updReceiveRoom = (0, _utils.updateMessageById)(baseStore.getIn(roomPath), data.temporary_id, sendingMessage); | ||
baseStore = baseStore.setIn(roomPath, updReceiveRoom); | ||
_this14.message && _this14.message(roomIdent, _this14.dataFormatter(sendingMessage)); | ||
}); | ||
if (errors.length) { | ||
var resolveError = new Error('Error: failed to send file message'); | ||
resolveError.data = errors; | ||
throw resolveError; | ||
} | ||
}).catch(function (_ref5) { | ||
var errors = _ref5.data; | ||
errors && errors.forEach(function (error) { | ||
var msgId = error.msgId; | ||
var sendingMessage = sendingMessagesMap[msgId]; | ||
sendingMessage = sendingMessage.set('isErrorOnSending', true); | ||
updReceiveRoom = (0, _utils.updateMessageById)(baseStore.getIn(roomPath), msgId, sendingMessage); | ||
baseStore = baseStore.setIn(roomPath, updReceiveRoom); | ||
_this14.message && _this14.message(roomIdent, _this14.dataFormatter(sendingMessage)); | ||
_this14.handleRequestErrors(error); | ||
}); | ||
}); | ||
} | ||
}, { | ||
key: 'sendChatMeta', | ||
value: function sendChatMeta(roomIdent) { | ||
var _this12 = this; | ||
var _this15 = this; | ||
@@ -564,6 +808,6 @@ return this.oSwindon.call('chat.room', [], { room_ident: roomIdent }).then(function (response) { | ||
var _getRoomData6 = (0, _utils.getRoomData)(baseStore, roomIdent), | ||
newChatRoom = _getRoomData6.room, | ||
setInEntity = _getRoomData6.setInEntity, | ||
setInIndex = _getRoomData6.setInIndex; | ||
var _getRoomData9 = (0, _utils.getRoomData)(baseStore, roomIdent), | ||
newChatRoom = _getRoomData9.room, | ||
setInEntity = _getRoomData9.setInEntity, | ||
setInIndex = _getRoomData9.setInIndex; | ||
@@ -581,3 +825,3 @@ if (!newChatRoom) return roomIdent; | ||
return _this12.dataFormatter(updChat); | ||
return _this15.dataFormatter(updChat); | ||
}).catch(this.handleRequestErrors); | ||
@@ -588,3 +832,3 @@ } | ||
value: function markMsgRead(roomIdent, msgId) { | ||
var _this13 = this; | ||
var _this16 = this; | ||
@@ -601,3 +845,3 @@ return this.oSwindon.call('chat.mark_read', [], { | ||
baseStore = baseStore.setIn([setInEntity, setInIndex, 'last_read_counter'], msgId); | ||
return Promise.resolve(_this13.dataFormatter(_immutable2.default.fromJS({ | ||
return Promise.resolve(_this16.dataFormatter(_immutable2.default.fromJS({ | ||
room_ident: roomIdent, | ||
@@ -635,6 +879,6 @@ message_id: msgId | ||
var _getRoomData7 = (0, _utils.getRoomData)(baseStore, topic), | ||
receiveRoom = _getRoomData7.room, | ||
setInEntity = _getRoomData7.setInEntity, | ||
setInIndex = _getRoomData7.setInIndex; | ||
var _getRoomData10 = (0, _utils.getRoomData)(baseStore, topic), | ||
receiveRoom = _getRoomData10.room, | ||
setInEntity = _getRoomData10.setInEntity, | ||
setInIndex = _getRoomData10.setInIndex; | ||
@@ -670,5 +914,5 @@ var updReceiveRoom = receiveRoom; | ||
var _getRoomData8 = (0, _utils.getRoomData)(baseStore, topic), | ||
setInEntity = _getRoomData8.setInEntity, | ||
setInIndex = _getRoomData8.setInIndex; | ||
var _getRoomData11 = (0, _utils.getRoomData)(baseStore, topic), | ||
setInEntity = _getRoomData11.setInEntity, | ||
setInIndex = _getRoomData11.setInIndex; | ||
@@ -701,5 +945,5 @@ var bansImmPath = [setInEntity, setInIndex, 'room_bans']; | ||
var _getRoomData9 = (0, _utils.getRoomData)(baseStore, topic), | ||
setInEntity = _getRoomData9.setInEntity, | ||
setInIndex = _getRoomData9.setInIndex; | ||
var _getRoomData12 = (0, _utils.getRoomData)(baseStore, topic), | ||
setInEntity = _getRoomData12.setInEntity, | ||
setInIndex = _getRoomData12.setInIndex; | ||
@@ -726,5 +970,5 @@ var lastReadImmPath = [setInEntity, setInIndex, 'last_read_messages']; | ||
value: function clearTypingById(topic, typingId) { | ||
var _getRoomData10 = (0, _utils.getRoomData)(baseStore, topic), | ||
setInEntity = _getRoomData10.setInEntity, | ||
setInIndex = _getRoomData10.setInIndex; | ||
var _getRoomData13 = (0, _utils.getRoomData)(baseStore, topic), | ||
setInEntity = _getRoomData13.setInEntity, | ||
setInIndex = _getRoomData13.setInIndex; | ||
@@ -741,5 +985,5 @@ var typingImmPath = [setInEntity, setInIndex, 'typing']; | ||
value: function clearTypingByUserIdent(topic, userIdent) { | ||
var _getRoomData11 = (0, _utils.getRoomData)(baseStore, topic), | ||
setInEntity = _getRoomData11.setInEntity, | ||
setInIndex = _getRoomData11.setInIndex; | ||
var _getRoomData14 = (0, _utils.getRoomData)(baseStore, topic), | ||
setInEntity = _getRoomData14.setInEntity, | ||
setInIndex = _getRoomData14.setInIndex; | ||
@@ -756,9 +1000,9 @@ var typingImmPath = [setInEntity, setInIndex, 'typing']; | ||
value: function doTyping(topic, data) { | ||
var _this14 = this; | ||
var _this17 = this; | ||
if (this.debug) console.log('Swindon typing', topic, data); | ||
var _getRoomData12 = (0, _utils.getRoomData)(baseStore, topic), | ||
setInEntity = _getRoomData12.setInEntity, | ||
setInIndex = _getRoomData12.setInIndex; | ||
var _getRoomData15 = (0, _utils.getRoomData)(baseStore, topic), | ||
setInEntity = _getRoomData15.setInEntity, | ||
setInIndex = _getRoomData15.setInIndex; | ||
@@ -772,3 +1016,3 @@ var typingImmPath = [setInEntity, setInIndex, 'typing']; | ||
setTimeout(function () { | ||
return _this14.clearTypingById(topic, typingId); | ||
return _this17.clearTypingById(topic, typingId); | ||
}, c.BESIDA_TYPING_DELAY); | ||
@@ -779,2 +1023,11 @@ | ||
}, { | ||
key: 'handleFilesSaveErrors', | ||
value: function handleFilesSaveErrors(error) { | ||
if (this.debug) console.error('Komora error response', error); | ||
var errorData = error && (error.data || { message: error.message }) || {}; | ||
this.error && this.error(null, this.dataFormatter(_immutable2.default.fromJS(errorData))); | ||
} | ||
}, { | ||
key: 'handleRequestErrors', | ||
@@ -781,0 +1034,0 @@ value: function handleRequestErrors(error) { |
@@ -49,2 +49,3 @@ 'use strict'; | ||
var CONTEXT_TYPE_ORDER = exports.CONTEXT_TYPE_ORDER = 3; | ||
var CONTEXT_TYPE_FILE = exports.CONTEXT_TYPE_FILE = 4; | ||
@@ -59,2 +60,8 @@ // messages types | ||
// file content types | ||
var ALLOWED_CONTENT_TYPES = exports.ALLOWED_CONTENT_TYPES = ["image/png", "image/jpeg"]; | ||
var MAX_FILE_SIZE_LIMIT = exports.MAX_FILE_SIZE_LIMIT = 10485760; // 10 MB | ||
var MAX_PARALLEL_FILES_UPLOADS = exports.MAX_PARALLEL_FILES_UPLOADS = 10; | ||
// events | ||
@@ -61,0 +68,0 @@ var BESIDA_EVENT_START_TYPING = exports.BESIDA_EVENT_START_TYPING = 'startTyping'; |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.MESSAGE_TYPE_NOTIFICATION = exports.MESSAGE_TYPE_CONTEXT = exports.MESSAGE_TYPE_MESSAGE = exports.MESSAGE_STATUS_READ = exports.MESSAGE_STATUS_SENDING = exports.MESSAGE_STATUS_NOT_DELIVERED = exports.MESSAGE_STATUS_DELIVERED = exports.ERROR_UNIQUE_USERS = exports.ERROR_TYPE_CAPS_LOCK = exports.ERROR_TYPE_STOP_WORD = exports.REGISTRY_STATUS_OFFLINE = exports.REGISTRY_STATUS_INACTIVE = exports.REGISTRY_STATUS_ACTIVE = exports.CONTEXT_TYPE_ORDER = exports.CONTEXT_TYPE_OPINION = exports.CONTEXT_TYPE_PRODUCT = exports.CONTEXT_TYPE_COMPANY = exports.CHAT_STATUS_ARCHIVE = exports.CHAT_STATUS_BANNED = exports.CHAT_STATUS_ACTIVE = exports.BESIDA_TYPING_DELAY = exports.BESIDA_ROLE_BUYER = exports.BESIDA_ROLE_COMPANY = exports.getUserRoleInRoom = exports.getCurrentUserIdent = exports.getRoom = exports.getAllChats = exports.Besida = undefined; | ||
exports.MAX_PARALLEL_FILES_UPLOADS = exports.MAX_FILE_SIZE_LIMIT = exports.ALLOWED_CONTENT_TYPES = exports.MESSAGE_TYPE_NOTIFICATION = exports.MESSAGE_TYPE_CONTEXT = exports.MESSAGE_TYPE_MESSAGE = exports.MESSAGE_STATUS_READ = exports.MESSAGE_STATUS_SENDING = exports.MESSAGE_STATUS_NOT_DELIVERED = exports.MESSAGE_STATUS_DELIVERED = exports.ERROR_UNIQUE_USERS = exports.ERROR_TYPE_CAPS_LOCK = exports.ERROR_TYPE_STOP_WORD = exports.REGISTRY_STATUS_OFFLINE = exports.REGISTRY_STATUS_INACTIVE = exports.REGISTRY_STATUS_ACTIVE = exports.CONTEXT_TYPE_FILE = exports.CONTEXT_TYPE_ORDER = exports.CONTEXT_TYPE_OPINION = exports.CONTEXT_TYPE_PRODUCT = exports.CONTEXT_TYPE_COMPANY = exports.CHAT_STATUS_ARCHIVE = exports.CHAT_STATUS_BANNED = exports.CHAT_STATUS_ACTIVE = exports.BESIDA_TYPING_DELAY = exports.BESIDA_ROLE_BUYER = exports.BESIDA_ROLE_COMPANY = exports.getUserRoleInRoom = exports.getCurrentUserIdent = exports.getRoom = exports.getAllChats = exports.Besida = undefined; | ||
@@ -71,2 +71,8 @@ var _constants = require('./constants'); | ||
}); | ||
Object.defineProperty(exports, 'CONTEXT_TYPE_FILE', { | ||
enumerable: true, | ||
get: function get() { | ||
return _constants.CONTEXT_TYPE_FILE; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'REGISTRY_STATUS_ACTIVE', { | ||
@@ -150,2 +156,20 @@ enumerable: true, | ||
}); | ||
Object.defineProperty(exports, 'ALLOWED_CONTENT_TYPES', { | ||
enumerable: true, | ||
get: function get() { | ||
return _constants.ALLOWED_CONTENT_TYPES; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'MAX_FILE_SIZE_LIMIT', { | ||
enumerable: true, | ||
get: function get() { | ||
return _constants.MAX_FILE_SIZE_LIMIT; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'MAX_PARALLEL_FILES_UPLOADS', { | ||
enumerable: true, | ||
get: function get() { | ||
return _constants.MAX_PARALLEL_FILES_UPLOADS; | ||
} | ||
}); | ||
@@ -152,0 +176,0 @@ var _besida = require('./besida'); |
@@ -39,2 +39,3 @@ 'use strict'; | ||
exports.isSpellingError = isSpellingError; | ||
exports.initSaveFiles = initSaveFiles; | ||
@@ -45,2 +46,4 @@ var _immutable = require('immutable'); | ||
var _fetchIo = require('@evo/fetch-io'); | ||
var _swindon = require('swindon'); | ||
@@ -305,8 +308,10 @@ | ||
var contextItemId = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : null; | ||
var contextItemType = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : null; | ||
var contextItemPrice = arguments.length > 9 && arguments[9] !== undefined ? arguments[9] : null; | ||
var contextItemCurrency = arguments.length > 10 && arguments[10] !== undefined ? arguments[10] : null; | ||
var contextSource = arguments.length > 11 && arguments[11] !== undefined ? arguments[11] : null; | ||
var contextDescription = arguments.length > 12 && arguments[12] !== undefined ? arguments[12] : null; | ||
var contextMeta = arguments.length > 13 && arguments[13] !== undefined ? arguments[13] : null; | ||
var contextItemUid = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : null; | ||
var contextItemType = arguments.length > 9 && arguments[9] !== undefined ? arguments[9] : null; | ||
var contextItemPrice = arguments.length > 10 && arguments[10] !== undefined ? arguments[10] : null; | ||
var contextItemCurrency = arguments.length > 11 && arguments[11] !== undefined ? arguments[11] : null; | ||
var contextSource = arguments.length > 12 && arguments[12] !== undefined ? arguments[12] : null; | ||
var contextDescription = arguments.length > 13 && arguments[13] !== undefined ? arguments[13] : null; | ||
var contextMeta = arguments.length > 14 && arguments[14] !== undefined ? arguments[14] : null; | ||
var file = arguments.length > 15 && arguments[15] !== undefined ? arguments[15] : null; | ||
@@ -329,2 +334,5 @@ var body = ''; | ||
break; | ||
case 'file': | ||
cntxType = c.CONTEXT_TYPE_FILE; | ||
break; | ||
default: | ||
@@ -338,2 +346,3 @@ cntxType = null; | ||
context_item_id: contextItemId, | ||
context_item_uid: contextItemUid, | ||
context_item_type: cntxType, | ||
@@ -345,3 +354,3 @@ context_item_price: contextItemPrice, | ||
context_meta: contextMeta, | ||
body: body, | ||
body: file || body, | ||
isTemporaryMessage: isTemporaryMessage, | ||
@@ -356,2 +365,18 @@ platform: platform, | ||
return [c.ERROR_TYPE_STOP_WORD, c.ERROR_TYPE_CAPS_LOCK].includes(error); | ||
} | ||
function initSaveFiles(KOMORA_URL) { | ||
return function (files) { | ||
var width = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 150; | ||
var height = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 150; | ||
var formData = new FormData(); | ||
files.forEach(function (file) { | ||
if (width && height) { | ||
formData.append('metadata', JSON.stringify({ width: width, height: height })); | ||
} | ||
formData.append('file', file, file.name); | ||
}); | ||
return (0, _fetchIo.POST)(KOMORA_URL + '/upload', formData, { multipart: true }); | ||
}; | ||
} |
{ | ||
"name": "@evo/chat-core", | ||
"version": "0.7.20", | ||
"version": "0.8.0", | ||
"description": "core Besida module with base functional set for chat", | ||
@@ -5,0 +5,0 @@ "author": "d.medvinskiy", |
@@ -16,6 +16,8 @@ Evo package, that controls all data mutations that are common for chat (message send, history, read counters etc), | ||
} from '@evo/chat-core'; | ||
import { Config } from './path/to/core/config'; | ||
const { KOMORA_URL } = Config.data.appState | ||
const swindonObj = Swindon('/ws'); | ||
const besida = new Besida(swindonObj, BESIDA_ROLE_COMPANY, IS_DEBUG); | ||
const besida = new Besida(swindonObj, BESIDA_ROLE_COMPANY, KOMORA_URL, IS_DEBUG); | ||
@@ -22,0 +24,0 @@ besida.registerHandler('message', (topic, message) => action()); |
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
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
76988
1403
43