From aa247e82e131aaa9fb02d0a4efa00656da3b24a6 Mon Sep 17 00:00:00 2001 From: Tes Cha Date: Wed, 11 Aug 2021 19:43:24 +0900 Subject: [PATCH] v1.1.27 --- CHANGELOG.md | 4 ++++ SendBirdSyncManager.min.js | 4 ++-- package.json | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b403972..c8bf33d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v1.1.27(AUG 11, 2021) + +- Improved stability in `AsyncDB` in React Native. + ## v1.1.26(MAY 12, 2021) - Improved stability in React Native. diff --git a/SendBirdSyncManager.min.js b/SendBirdSyncManager.min.js index 2d89ec8..4276785 100644 --- a/SendBirdSyncManager.min.js +++ b/SendBirdSyncManager.min.js @@ -1,6 +1,6 @@ /** * Copyright(c) 2016 SendBird, Inc. - * SendBird SyncManager JavaScript SDK v1.1.26 + * SendBird SyncManager JavaScript SDK v1.1.27 */ -!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e=e||self).SendBirdSyncManager=n()}(this,function(){"use strict";function f(e){return(f="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function h(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}function r(e,n){for(var t=0;te.length)&&(n=e.length);for(var t=0,r=new Array(n);t=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:n}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,i=!0,s=!1;return{s:function(){t=e[Symbol.iterator]()},n:function(){var e=t.next();return i=e.done,e},e:function(e){s=!0,a=e},f:function(){try{i||null==t.return||t.return()}finally{if(s)throw a}}}}var t=64,y=200,m=128,p=32,k=null,I=function(){function n(){var e=0":n="number"==typeof t[r]&&"number"==typeof a[i]?n&&t[r]>a[i]:"string"==typeof t[r]&&"string"==typeof a[i]&&(n&&0=":n="number"==typeof t[r]&&"number"==typeof a[i]?n&&t[r]>=a[i]:"string"==typeof t[r]&&"string"==typeof a[i]&&(n&&0<=t[r].localeCompare(a[i]));break;case"<":n="number"==typeof t[r]&&"number"==typeof a[i]?n&&t[r]=this.cachedBlockLimit)for(var r in n.sort(function(e,n){return t.blockCache[e].seq-t.blockCache[n].seq}),n)this._removeBlockFromCache(n[r])}},{key:"_removeBlockFromCache",value:function(e){this.blockCache.hasOwnProperty(e)&&delete this.blockCache[e]}},{key:"_getBlock",value:function(t,r){var a=this,e=this._getBlockFromCache(t);e?r(null,e):W.Storage.getItem(t).then(function(e){e?a.encryption.decrypt(e,function(e,n){e?r(e):(n=_.buildFromSerializedData(t,n),a._putBlockToCache(n),r(null,n))}):r(null)}).catch(function(e){return r(e)})}},{key:"_assignNewBlock",value:function(e){this.info.cursor++;var n=_.createKey(this.name,this.info.cursor),t=new _(n);this._putBlockToCache(t),this.currentBlock=t,e&&e.key&&(t.add(e.key,e.value),this.info.blockMap[e.key]=n,this.info.count++),this.batchQueue.addJob(N.Action.SET,t.blockKey,t.data),this.batchQueue.addJob(N.Action.SET,D+this.name,this.info)}},{key:"init",value:function(e){var r=this,a=0n.getTime()?1:-1}}else if(E(n))return r?1:-1;return 0}(e[i],n[i],r);if(0!==s)return o*s}return 0}},{key:"init",value:function(e){var r=this,a=0":r="number"==typeof t[n]&&"number"==typeof a[i]?r&&t[n]>a[i]:"string"==typeof t[n]&&"string"==typeof a[i]&&(r&&0=":r="number"==typeof t[n]&&"number"==typeof a[i]?r&&t[n]>=a[i]:"string"==typeof t[n]&&"string"==typeof a[i]&&(r&&0<=t[n].localeCompare(a[i]));break;case"<":r="number"==typeof t[n]&&"number"==typeof a[i]?r&&t[n]":r="number"==typeof t[n]&&"number"==typeof a[i]?r&&t[n]>a[i]:"string"==typeof t[n]&&"string"==typeof a[i]&&(r&&0=":r="number"==typeof t[n]&&"number"==typeof a[i]?r&&t[n]>=a[i]:"string"==typeof t[n]&&"string"==typeof a[i]&&(r&&0<=t[n].localeCompare(a[i]));break;case"<":r="number"==typeof t[n]&&"number"==typeof a[i]?r&&t[n]n[t])return s.index[t];if(e[t]=s.limit?t.slice(i,s.limit+i):t.slice(i))}else e(new Error("Invalid type: 'query' should be Query type."))},e)}},{key:"count",value:function(i,e){var s=this;return this.queue.addTask(function(e){if(!i||i instanceof ve)if(i){var n,t=0,r=i.offset||0;for(n in s.store){if(t>=i.limit)break;var a=s.store[n];i.match(a)&&(r<=0?t+=1:r--)}e(null,t)}else e(null,Object.keys(s.store).length);else e(new Error("Invalid type: 'query' should be Query type."))},e)}},{key:"_insertSingle",value:function(t,e){var r=this;return fe(function(e){var n;t[r.pk]?(n="".concat(t[r.pk]),r.store.hasOwnProperty(n)?e(new Error("Duplicated item: item already exists.")):e(null,r.store[n]=t)):e(new Error("Invalid key: item should have key."))},e)}},{key:"insert",value:function(r,e){var a=this;return this.queue.addTask(function(t){if(Array.isArray(r)){for(var e=[],n=0;n=":2=":n},pendingResolveBottom:{"<=":t}});l.updateIf(t,{sendingStatus:"failed"},function(e,n){r(e,n?n.map(function(e){return h(e)}):null)})},this.pullPendingResolveTop=function(e,n,t){e=new Wn.LocalDB.Query({ownerUserId:Wn.getInstance().currentUserId,channelUrl:e,sendingStatus:"pending",pendingResolveTop:{"<":n}});l.updateIf(e,{pendingResolveTop:n},function(e,n){t(e,n?n.map(function(e){return h(e)}):null)})},this.pullPendingResolveBottom=function(e,n,t){e=new Wn.LocalDB.Query({ownerUserId:Wn.getInstance().currentUserId,channelUrl:e,sendingStatus:"pending",pendingResolveBottom:Number.MAX_SAFE_INTEGER});l.updateIf(e,{pendingResolveBottom:n},function(e,n){t(e,n?n.map(function(e){return h(e)}):null)})},this.shrinkMessageChunk=function(t,r,a){var e={top:Number.MAX_SAFE_INTEGER,bottom:0},n=j(r);try{for(n.s();!(i=n.n()).done;){var i=i.value;e.top=Math.min(e.top,i.createdAt),e.bottom=Math.max(e.bottom,i.createdAt)}}catch(e){n.e(e)}finally{n.f()}un.getInstance().chunkContainer.sliceRange(t,e.top,e.bottom,function(e){var n;e?a(e):(n=0,r.forEach(function(e){je(e),l.remove(e.messageId,function(e){e||(s.messageCount[t]--,s.messageCount.all--),++n>=r.length&&a(null)})}))})},this},Ge={},Qe=function(e){var n,t=[];for(n in e)t.push("".concat(n,"=").concat(e[n]));return t.join("&")},He=function(){function t(e,n){h(this,t),this.chunkId=Le(),this.channelUrl=e,this.filterKey=Qe(n),this.filter=n,this.startAt=(new Date).getTime(),this.endAt=0}return c(t,[{key:"hasDefaultFilter",value:function(){var e=t.getDefaultFilter();return Fe(this.filter,e)}},{key:"hasVolume",value:function(){return this.endAt>this.startAt}},{key:"isOverlap",value:function(e){return e.startAt<=this.startAt&&this.startAt<=e.endAt||e.startAt<=this.endAt&&this.endAt<=e.endAt}},{key:"isSame",value:function(e){return!!e&&(e.startAt===this.startAt&&this.endAt===e.endAt)}},{key:"hasSameFilter",value:function(e){return!!e&&(e.channelUrl===this.channelUrl&&e.filterKey===this.filterKey)}},{key:"contains",value:function(e){return this.startAt<=e&&e<=this.endAt}},{key:"containsMessage",value:function(e){return this.contains(e.createdAt)}},{key:"serialize",value:function(){var e=JSON.parse(JSON.stringify(this));return Object.freeze(e)}},{key:"extendForward",value:function(e){this.endAt=Math.max(this.endAt,e)}},{key:"extendBackward",value:function(e){this.startAt=Math.min(this.startAt,e)}},{key:"extendWithChunk",value:function(e){return this.extendForwardWithChunk(e),this.extendBackwardWithChunk(e),this}},{key:"extendForwardWithChunk",value:function(e){return this.extendForward(e.endAt),this}},{key:"extendBackwardWithChunk",value:function(e){return this.extendBackward(e.startAt),this}},{key:"extendWithMessage",value:function(e){return this.extendForwardWithMessage(e),this.extendBackwardWithMessage(e),this}},{key:"extendForwardWithMessage",value:function(e){return this.extendForward(e.createdAt),this}},{key:"extendBackwardWithMessage",value:function(e){return this.extendBackward(e.createdAt),this}}],[{key:"createFromJson",value:function(e){var n=new t(e.channelUrl,e.filter);return n.chunkId=e.chunkId,n.startAt=e.startAt,n.endAt=e.endAt,n}},{key:"getDefaultFilter",value:function(){return{messageTypeFilter:null,customTypeFilter:null,senderUserIdsFilter:[],includeMetaArray:!0}}},{key:"MessageTypeFilterRealValue",get:function(){return["","user","file","admin"]}}]),t}(),Ke=function(e){var c=this,l=e.collection("MessageChunk"),a=new T;return this.reload=function(e,n){return l.findById(e.chunkId,n)},this.upsert=function(e,t){var n,r;n=e,r=function(e,n){e?t(e):t(null,He.createFromJson(n))},a.lock(function(t){var e=Wn.getInstance();e.currentUserId?(n.ownerUserId=e.currentUserId,Ge[n.chunkId]=n,l.upsert(Ge[n.chunkId].serialize(),function(e,n){t(),e?r(e):r(null,n)})):(t(),r(Te.create(Te.Type.ERROR_SETUP_MISSING)))})},this.remove=function(n,t){var e,r;e=n,r=function(e){e?t(e):t(null,n)},a.lock(function(t){Wn.getInstance().currentUserId?(Ge[e]&&delete Ge[e],l.remove(e,function(e,n){t(),e?r(e):r(null,n)})):(t(),r(Te.create(Te.Type.ERROR_SETUP_MISSING)))})},this.clear=function(e){return t=e,void a.lock(function(n){Ge={},l.clear(function(e){n(),t(e)})});var t},this.getChunksByHistoryOffset=function(e,n,t){var r=Wn.getInstance(),a=He.getDefaultFilter();r.currentUserId&&((e=new Wn.LocalDB.Query({ownerUserId:r.currentUserId,channelUrl:n,filterKey:Qe(a),endAt:{"<=":e}})).limit=Number.MAX_SAFE_INTEGER,e.index={ownerUserId:Wn.LocalDB.Query.Order.ASC,channelUrl:Wn.LocalDB.Query.Order.ASC,filterKey:Wn.LocalDB.Query.Order.ASC,endAt:Wn.LocalDB.Query.Order.DESC},l.find(e,t))},this.clearChunkByHistoryOffset=function(a,n,t){var e,r,i=Wn.getInstance(),s=He.getDefaultFilter();i.currentUserId&&(e=new Promise(function(t,r){var e=new Wn.LocalDB.Query({ownerUserId:i.currentUserId,channelUrl:n,filterKey:Qe(s),endAt:{"<=":a}});e.limit=Number.MAX_SAFE_INTEGER,e.index={ownerUserId:Wn.LocalDB.Query.Order.ASC,channelUrl:Wn.LocalDB.Query.Order.ASC,filterKey:Wn.LocalDB.Query.Order.ASC,endAt:Wn.LocalDB.Query.Order.DESC},l.removeIf(e,function(e,n){return e?r(e):t(n)})}),r=new Promise(function(t,r){c.getChunkByTimestamp(n,s,a,function(e,n){return e?r(e):(n&&(n.extendBackward(a),c.upsert(n,function(e,n){return e?r(e):void t(n)})),void t(n))})}),Promise.all([e,r]).then(function(e){t(null)}).catch(function(e){t(e)}))},this.getChunkByTimestamp=function(r,e,a,i){var n=Wn.getInstance();n.currentUserId?((e=new Wn.LocalDB.Query({ownerUserId:n.currentUserId,channelUrl:r,filterKey:Qe(e),startAt:{"<=":a},endAt:{">=":a}})).limit=1,e.index={ownerUserId:Wn.LocalDB.Query.Order.ASC,channelUrl:Wn.LocalDB.Query.Order.ASC,filterKey:Wn.LocalDB.Query.Order.ASC,endAt:Wn.LocalDB.Query.Order.DESC},l.find(e,function(e,n){var t;e?i(e):(t=0=":r.startAt}})).limit=Number.MAX_SAFE_INTEGER,l.find(e,function(e,t){e?a(e):0=i.length&&u(null)})}()}catch(e){n.e(e)}finally{n.f()}}():u(null))})):u(Te.create(Te.Type.ERROR_SETUP_MISSING))},this};function We(e,n,t){return t?n.channelUrl===e.url&&((!t.messageType||t.messageType===n.messageType)&&((!t.customType||t.customType===n.customType)&&!(Array.isArray(t.senderUserIdsFilter)&&0t[s.url])&&(t[s.url]=s.messageOffsetTimestamp,t[s.url]&&(un.getInstance().chunkContainer.clearChunkByHistoryOffset(s.messageOffsetTimestamp,s.url,function(e){e&&_e.error("Error while clearing message chunk history",e)}),un.getInstance().messageContainer.loadMessagesByHistoryOffset(s.messageOffsetTimestamp,s.url,function(e,n){if(!e){un.getInstance().messageContainer.clearMessagesByHistoryOffset(s.messageOffsetTimestamp,s.url,function(e,n){e&&_e.error("Error while clearing chat history",e)});var t=n.filter(function(e){return e.hasOwnProperty("sendingStatus")&&"failed"===e.sendingStatus}).map(function(e){return e.reqId}),r=n.filter(function(e){return e.hasOwnProperty("sendingStatus")&&"succeeded"===e.sendingStatus}).map(function(e){return e.messageId});if(0t[e.channel.url])&&(t[e.channel.url]=e.channel.messageOffsetTimestamp)},this.removeCollection=function(e){e=u.map(function(e){return e.controller}).indexOf(e);0<=e&&(u[e].controller._pause(),u.splice(e,1))},this.clearCollection=function(){for(var e in u)u[e].controller._pause();u=[]},this.pause=function(){for(var e in u)u[e].controller._pause()},this.resume=function(n){var e,t=u.length,r=null;for(e in u)u[e].controller._resume(function(e){r=e||r,--t<=0&&n(r)})},this.upsert=function(e,n){if(0Wn.syncManagerOptions.automaticMessageResendRetryCount)return this._appendMessagesWithOrder(this.automaticMessages,{isAutomatic:!1}),this.automaticMessages=[],rn.getInstance().upsertMessages(this._channelUrl,this.manualMessages),void this._clear({noManualMessages:!0});this._resendingTimer=setTimeout(function(){var a,e,i,s=o.automaticMessages[0];s&&o._isRunning?(e=(a=un.getInstance()).sb,i=e.getErrorFirstCallback(),e.GroupChannel.getChannel(o._channelUrl,function(e,n){var t;i&&(t=n,n=e,e=t),n?(o._increaseDelayTime(),o._resendUserMessage()):e.resendUserMessage(s,function(e,n){var t,r;i&&(t=n,n=e,e=t),n?(800110===n.code?(r={reason:Ze.REMOVE_UNKNOWN},rn.getInstance().removeMessages(o._channelUrl,[s],r),o.removeMessages([s])):o._increaseDelayTime(),o._resendUserMessage()):(o.removeMessages([s]),o._retryCount=0,o._delayTime=0,r={reason:Ze.REMOVE_RESEND_SUCCEEDED},rn.getInstance().removeMessages(o._channelUrl,[s],r),a.messageContainer.upsert(e,function(e,n){e||a.broadcast.upsert([n]),o._resendUserMessage()}))})})):(o._retryCount=0,o._delayTime=0)},this._delayTime)}},{key:"_increaseDelayTime",value:function(){this._delayTime=1e4===this._delayTime?this._delayTime:this._delayTime+2e3}},{key:"_toggleResendingInterval",value:function(){this._isRunning?this._resendUserMessage():(clearTimeout(this._resendingTimer),this._resendingTimer=null,this._retryCount=0,this._delayTime=0)}},{key:"resumeResending",value:function(){_e.call("FailedMessageQueue resumeResending()"),this._retryCount=0,this._delayTime=0,this._isRunning=!0}},{key:"pauseResending",value:function(){_e.call("FailedMessageQueue pauseResending()"),this._isRunning=!1}},{key:"increaseCount",value:function(){++this.collectionReferenceCount}},{key:"decreaseCount",value:function(){--this.collectionReferenceCount,0===this.collectionReferenceCount&&this._clear()}}]),r}(),nn=function(){function r(e){var n=e.msec,t=void 0===n?0:n,n=e.isEternal,n=void 0===n||n,e=e.timeoutFn,e=void 0===e?function(){}:e;h(this,r),this.time=t,this.isEternal=n,this.timeoutFn=e,this.checker=null}return c(r,[{key:"reset",value:function(){this.stop(),this.time=0,this.timeoutFn=function(){}}},{key:"start",value:function(){var e,n=this;null===this.checker&&(e=(new Date).getTime(),this.checker=setTimeout(function(){(new Date).getTime()-e>=n.time&&(n.isEternal?n.start():n.stop(),n.timeoutFn&&"function"==typeof n.timeoutFn&&n.timeoutFn())},432e5))}},{key:"stop",value:function(){clearTimeout(this.checker),this.checker=null}}]),r}(),tn=null,rn=function(){function e(){if(h(this,e),tn)return tn;this.queueMap={},this.expirationTimer=new nn({msec:864e5*Wn.syncManagerOptions.failedMessageRetentionDays,isEternal:!0,timeoutFn:this.removeExpiredMessages}),this.oldestFailedMessageTs=0,tn=this}return c(e,[{key:"getMessages",value:function(e){return this.queueMap[e]?this.queueMap[e].messages:[]}},{key:"loadFailedMessages",value:function(a,i,s){var o=this;un.getInstance().messageContainer.loadFailedMessages(a,{},{},function(e,n){var t,r=n;e||(_e.cache("fetch failed message",n.map(function(e){return e.reqId})),(t=o.queueMap[a])&&(t.appendMessages(n),t.resumeResending()),r=n.filter(function(e){var n=!0,t=!0,r=!0;if(i.messageTypeFilter&&(n=e.messageType===He.MessageTypeFilterRealValue[i.messageTypeFilter]),i.customTypeFilter&&(t=e.customType===i.customTypeFilter),i.senderUserIdsFilter&&Array.isArray(i.senderUserIdsFilter)&&0r){_e.cache("messages exceeds messageStoreCapacity.");var e,t,n=[];for(e in c.cacheManager.messageCount)"all"!==e&&c.cacheManager.messageCount[e]>a&&n.push({channelUrl:e,count:c.cacheManager.messageCount[e]});0=s.length&&(o(),u(null,!e))})})}}))}else o(),u(null,!1)})}},{key:"applyTrimmedChunk",value:function(e,n){this.broadcast.applyTrimmedChunk(e,n)}},{key:"syncChangeLog",value:function(r,e){var a,i=this,s=1n&&dn.broadcast.upsert([a])});break;case"onUserMuted":case"onUserUnmuted":case"onUserUnbanned":case"onChannelFrozen":case"onChannelUnfrozen":case"onMetaDataCreated":case"onMetaDataUpdated":case"onMetaDataDeleted":case"onMetaCountersCreated":case"onMetaCountersUpdated":case"onMetaCountersDeleted":_e.event(u,t[0].url),dn.channelContainer.upsert(t[0],function(e,n){e?Te.throw(e):dn.broadcast.update([n])});break;case"onUserReceivedInvitation":case"onUserJoined":_e.event(u,t[0].url),dn.channelContainer.upsert(t[0],function(e,n){e?Te.throw(e):t[1].userId===l.currentUserId?dn.broadcast.upsert([n]):dn.broadcast.update([n])});break;case"onReadReceiptUpdated":dn.channelContainer.upsert(t[0],function(e){e&&Te.throw(e)});break;case"onChannelHidden":_e.event(u,t[0].url);var i=t[0];dn.channelContainer.upsert(i,function(e){e?Te.throw(e):dn.broadcast.hide([i])});break;case"onUserLeft":case"onUserBanned":_e.event(u,t[0].url);var s=t[0];t[1].userId===l.currentUserId?dn.channelContainer.remove(s,function(e){e?Te.throw(e):dn.broadcast.remove([s])}):dn.channelContainer.upsert(s,function(e,n){e?Te.throw(e):dn.broadcast.update([n])});break;case"onUserDeclinedInvitation":_e.event(u,t[0].url);var o=t[0];t[2].userId===l.currentUserId?dn.channelContainer.remove(o,function(e){e?Te.throw(e):dn.broadcast.remove([o])}):dn.channelContainer.upsert(o,function(e,n){e?Te.throw(e):dn.broadcast.update([n])});break;case"onChannelDeleted":_e.event(u,t[0]),dn.channelContainer.getItem(t[0],function(e,n){e?Te.throw(e):n&&dn.channelContainer.remove(n,function(e){e?Te.throw(e):dn.broadcast.remove([n])})})}}}),c.addChannelHandler(fn,n)),dn}return c(a,[{key:"syncChangeLog",value:function(o,u){var c,l=this;this.isFetchingChangeLog?u(Te.create(Te.Type.ERROR_DUPLICATED_CHANGELOG_SYNC)):(this.isFetchingChangeLog=!0,_e.call("channel syncChangeLog()"),c="".concat(hn),Ee.get(c).then(function(e){var n="getMyGroupChannelChangeLogsByToken",t=[];t.push([]),t.push(!0),e?(n="getMyGroupChannelChangeLogsByToken",t.unshift(e)):(n="getMyGroupChannelChangeLogsByTimestamp",t.unshift((new Date).getTime()-100)),_e.call(n),(e=l.sb)[n].apply(e,t.concat([function(s,e){var n,t;l.sb.getErrorFirstCallback()&&(n=s,s=e,e=n),e?l.isFetchingChangeLog=!1:(_e.sync("updated",s.updatedChannels&&0":0}),"all"!=h.query.hiddenChannelFilter)switch(h.query.hiddenChannelFilter){case e.GroupChannel.HiddenChannelFilter.UNHIDDEN:s.hiddenState=e.GroupChannel.HiddenState.UNHIDDEN;break;case e.GroupChannel.HiddenChannelFilter.HIDDEN:s.hiddenState={"/in":[e.GroupChannel.HiddenState.HIDDEN_ALLOW_AUTO_UNHIDE,e.GroupChannel.HiddenState.HIDDEN_PREVENT_AUTO_UNHIDE]};break;case e.GroupChannel.HiddenChannelFilter.HIDDEN_ALLOW_AUTO_UNHIDE:s.hiddenState=e.GroupChannel.HiddenState.HIDDEN_ALLOW_AUTO_UNHIDE;break;case e.GroupChannel.HiddenChannelFilter.HIDDEN_PREVENT_AUTO_UNHIDE:s.hiddenState=e.GroupChannel.HiddenState.HIDDEN_PREVENT_AUTO_UNHIDE}var o=null,u=!0;switch(h.query.order){case"latest_last_message":!h.query.hasNext&&h.query.savepoint&&(s.lastMessageUpdatedAt={">=":parseInt(h.query.savepoint)}),o={ownerUserId:1,lastMessageUpdatedAt:-1};break;case"chronological":!h.query.hasNext&&h.query.savepoint&&(s.createdAt={">=":parseInt(h.query.savepoint)}),o={ownerUserId:1,createdAt:-1};break;case"channel_name_alphabetical":!h.query.hasNext&&h.query.savepoint&&(s.name={"<=":h.query.savepoint}),u=!(o={ownerUserId:1,name:1});break;default:!h.query.hasNext&&h.query.savepoint&&(s.lastMessageUpdatedAt={">=":parseInt(h.query.savepoint)}),o={ownerUserId:1,lastMessageUpdatedAt:-1}}function r(t,r){i.channelContainer.query(s,{offset:a.channels.length,limit:t,index:o,desc:u},function(e,n){e?(h._isLoading=!1,r(e)):(h._isLoading=!1,(n=n.map(function(e){return h.sendBird.GroupChannel.cachedChannels[e.url]||(h.sendBird.GroupChannel.cachedChannels[e.url]=e),h.sendBird.GroupChannel.cachedChannels[e.url]})).sort(function(e,n){return 0Wn.syncManagerOptions.messageCollectionCapacity&&(o="next"===S.direction?(c=a-Wn.syncManagerOptions.messageCollectionCapacity,A.messages.splice(0,c)):A.messages.splice(Wn.syncManagerOptions.messageCollectionCapacity),N.push.apply(N,B(o)))}else{var a=!t.isUserMessage()||"pending"===t.sendingStatus,c=xe(t,A.unsentMessages);c<0?xe(t,A.messages)<0&&((a?x:P).push(t),A.unsentMessages.push(t)):(o=A.unsentMessages[c]).isUserMessage()?"pending"===o.sendingStatus?a||(F.push(o),P.push(t),A.unsentMessages[c]=t):(L.push(t),A.unsentMessages[c]=t):A.unsentMessages[c]=t}}if(0=v;_e.sync("message synchronize() end",f,"ts=".concat(d),"hasMore=".concat(i),h.map(function(e){return"".concat(e.message," ").concat(e.messageId," ").concat(e.createdAt)}));var s,o=[],n=j(h);try{for(n.s();!(s=n.n()).done;)!function(){var e=s.value;e.isVisible=!0;var n=j(y.unsentMessages);try{for(n.s();!(t=n.n()).done;){var t=t.value;if("pending"===t.sendingStatus&&t.reqId===e.reqId){o.push(e);break}}}catch(e){n.e(e)}finally{n.f()}r.push(new Promise(function(n,t){m.messageContainer.upsert(e,function(e){return e?t(e):n()})})),a.startAt=Math.min(a.startAt,e.createdAt),a.endAt=Math.max(a.endAt,e.createdAt)}()}catch(e){n.e(e)}finally{n.f()}if(0===h.length&&(a.startAt=y.viewpoint,a.endAt=y.viewpoint),p.currentChunk&&p.currentChunk.isOverlap(a)||(p.currentChunk=new He(y.channel.url,y.filter),_e.message("chunk is created",p.currentChunk.startAt,p.currentChunk.endAt)),p.currentChunk.extendWithChunk(a),0=(_e.isValidLevel(_e.level)?200:0)&&e<=Number.MAX_SAFE_INTEGER&&(a=e)}});var i=Wn.Options.MessageResendPolicy.NONE;Object.defineProperty(this,"messageResendPolicy",{get:function(){return i},set:function(e){-1(_e.isValidLevel(_e.level)?0:-2)&&e<=Number.MAX_SAFE_INTEGER||e===Wn.Options.INFINITY)&&(u=e)}})}}(),Wn.Options.MessageResendPolicy={NONE:"none",MANUAL:"manual",AUTOMATIC:"automatic"},Wn.Options.INFINITY=Number.MAX_SAFE_INTEGER,Wn}); \ No newline at end of file +!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e=e||self).SendBirdSyncManager=n()}(this,function(){"use strict";function f(e){return(f="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function h(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}function r(e,n){for(var t=0;te.length)&&(n=e.length);for(var t=0,r=new Array(n);t=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:a}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,s=!0,o=!1;return{s:function(){t=e[Symbol.iterator]()},n:function(){var e=t.next();return s=e.done,e},e:function(e){o=!0,i=e},f:function(){try{s||null==t.return||t.return()}finally{if(o)throw i}}}}var v=null,y=function(){function n(){var e=0n.getTime()?1:-1}}else if(w(n))return r?1:-1;return 0}function E(e,t,a){if(!t)return new Promise(function(t,r){e(function(e,n){a&&"function"==typeof a&&a(),e?r(e):t(n)})});e(function(e,n){a&&"function"==typeof a&&a(),t(e,n)})}var M=function(){function r(e){h(this,r),this.condition=e,this.offset=0,this.limit=1/0,this.index=null,this.desc=!1}return c(r,null,[{key:"and",value:function(){for(var e=arguments.length,n=new Array(e),t=0;t":n="number"==typeof r[a]&&"number"==typeof i[s]?n&&r[a]>i[s]:"string"==typeof r[a]&&"string"==typeof i[s]&&(n&&0=":n="number"==typeof r[a]&&"number"==typeof i[s]?n&&r[a]>=i[s]:"string"==typeof r[a]&&"string"==typeof i[s]&&(n&&0<=r[a].localeCompare(i[s]));break;case"<":n="number"==typeof r[a]&&"number"==typeof i[s]?n&&r[a]=this.cachedBlockLimit)for(var r in n.sort(function(e,n){return t.blockCache[e].seq-t.blockCache[n].seq}),n)this._removeBlockFromCache(n[r])}},{key:"_removeBlockFromCache",value:function(e){this.blockCache.hasOwnProperty(e)&&delete this.blockCache[e]}},{key:"_getBlock",value:function(r,a){var i=this,e=this._getBlockFromCache(r);e?a(null,e):V.Storage.getItem(r).then(function(e){e?i.encryption.decrypt(e,function(e,n){if(e)a(e);else{var t=A.buildFromSerializedData(r,n);i._putBlockToCache(t),a(null,t)}}):a(null)}).catch(function(e){return a(e)})}},{key:"_assignNewBlock",value:function(e){this.info.cursor++;var n=A.createKey(this.name,this.info.cursor),t=new A(n);this._putBlockToCache(t),this.currentBlock=t,e&&e.key&&(t.add(e.key,e.value),this.info.blockMap[e.key]=n,this.info.count++),this.batchQueue.addJob(T.Action.SET,t.blockKey,t.data),this.batchQueue.addJob(T.Action.SET,R+this.name,this.info)}},{key:"init",value:function(e){var r=this,a=0":n="number"==typeof r[a]&&"number"==typeof i[s]?n&&r[a]>i[s]:"string"==typeof r[a]&&"string"==typeof i[s]&&(n&&0=":n="number"==typeof r[a]&&"number"==typeof i[s]?n&&r[a]>=i[s]:"string"==typeof r[a]&&"string"==typeof i[s]&&(n&&0<=r[a].localeCompare(i[s]));break;case"<":n="number"==typeof r[a]&&"number"==typeof i[s]?n&&r[a]":n="number"==typeof r[a]&&"number"==typeof i[s]?n&&r[a]>i[s]:"string"==typeof r[a]&&"string"==typeof i[s]&&(n&&0=":n="number"==typeof r[a]&&"number"==typeof i[s]?n&&r[a]>=i[s]:"string"==typeof r[a]&&"string"==typeof i[s]&&(n&&0<=r[a].localeCompare(i[s]));break;case"<":n="number"==typeof r[a]&&"number"==typeof i[s]?n&&r[a]n[t])return s.index[t];if(e[t]=s.limit?n.slice(i,s.limit+i):n.slice(i))}else e(new Error("Invalid type: 'query' should be Query type."))},e)}},{key:"count",value:function(i,e){var s=this;return this.queue.addTask(function(e){if(!i||i instanceof ce)if(i){var n=0,t=i.offset||0;for(var r in s.store){if(n>=i.limit)break;var a=s.store[r];i.match(a)&&(t<=0?n+=1:t--)}e(null,n)}else e(null,Object.keys(s.store).length);else e(new Error("Invalid type: 'query' should be Query type."))},e)}},{key:"_insertSingle",value:function(t,e){var r=this;return ue(function(e){if(t[r.pk]){var n="".concat(t[r.pk]);r.store.hasOwnProperty(n)?e(new Error("Duplicated item: item already exists.")):e(null,r.store[n]=t)}else e(new Error("Invalid key: item should have key."))},e)}},{key:"insert",value:function(r,e){var a=this;return this.queue.addTask(function(t){if(Array.isArray(r)){for(var e=[],n=0;n=e.createdAt){r=a;break}return r}"undefined"==typeof Promise&&(Promise=e);function Ue(){var t=(new Date).getTime();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var n=(t+16*Math.random())%16|0;return t=Math.floor(t/16),("x"===e?n:3&n|8).toString(16)})}function Ne(e,n){if(!n)return new Promise(function(n,t){e(function(e){return e?t(e):n()})});e(n)}var xe="unsent";function De(e){return"".concat(xe,"-").concat(e)}function Fe(e){if(e)if(e.sendingStatus&&"succeeded"!==e.sendingStatus){if(!e.reqId)throw Ae.throw(Ae.create(Ae.Type.ERROR_INVALID_PARAMETER));e.messageId=De(e.reqId)}else e.messageId="".concat(e.messageId)}function Pe(e,r,o){function u(n,a){i.lock(function(t){var e=Pn.getInstance(),r=n.isDeleted?n:h(n.serialize());Fe(r),r.messageId?e.currentUserId?(r.hasOwnProperty("isVisible")||(r.isVisible=!0),r.hasOwnProperty("isDeleted")||(r.isDeleted=!1),r.ownerUserId=e.currentUserId,Me.cache("upsert message","owner="+r.ownerUserId,"visible="+r.isVisible,"deleted="+r.isDeleted,r),l.findById(r.messageId,function(e,n){e?(t(),a(e)):n?n.isDeleted?(t(),a(null,n)):"pending"!==r.sendingStatus||"pending"===n.sendingStatus?(r.isVisible=r.isVisible||n.isVisible,l.upsert(r.serialize(),function(e,n){t(),e?a(e):a(null,n)})):(t(),a(null,n)):l.upsert(r.serialize(),function(e,n){e?(t(),a(e)):(o.messageCount[r.channelUrl]||(o.messageCount[r.channelUrl]=0),o.messageCount.all++,o.messageCount[r.channelUrl]++,t(),a(null,n))})})):(t(),a(Ae.create(Ae.Type.ERROR_SETUP_MISSING))):(t(),a(null,n))})}function s(e,n){return n.messageType&&(e.messageType=n.messageType),n.customType&&(e.customType=n.customType),n.senderUserIdsFilter&&0=":2=":n},pendingResolveBottom:{"<=":t}});l.updateIf(a,{sendingStatus:"failed"},function(e,n){r(e,n?n.map(function(e){return h(e)}):null)})},this.pullPendingResolveTop=function(e,n,t){var r=new Pn.LocalDB.Query({ownerUserId:Pn.getInstance().currentUserId,channelUrl:e,sendingStatus:"pending",pendingResolveTop:{"<":n}});l.updateIf(r,{pendingResolveTop:n},function(e,n){t(e,n?n.map(function(e){return h(e)}):null)})},this.pullPendingResolveBottom=function(e,n,t){var r=new Pn.LocalDB.Query({ownerUserId:Pn.getInstance().currentUserId,channelUrl:e,sendingStatus:"pending",pendingResolveBottom:Number.MAX_SAFE_INTEGER});l.updateIf(r,{pendingResolveBottom:n},function(e,n){t(e,n?n.map(function(e){return h(e)}):null)})},this.shrinkMessageChunk=function(t,r,a){var e,n={top:Number.MAX_SAFE_INTEGER,bottom:0},i=Y(r);try{for(i.s();!(e=i.n()).done;){var s=e.value;n.top=Math.min(n.top,s.createdAt),n.bottom=Math.max(n.bottom,s.createdAt)}}catch(e){i.e(e)}finally{i.f()}tn.getInstance().chunkContainer.sliceRange(t,n.top,n.bottom,function(e){if(e)a(e);else{var n=0;r.forEach(function(e){Fe(e),l.remove(e.messageId,function(e){e||(o.messageCount[t]--,o.messageCount.all--),++n>=r.length&&a(null)})})}})},this}function qe(e){var n=[];for(var t in e)n.push("".concat(t,"=").concat(e[t]));return n.join("&")}function Le(e){var c=this,l=e.collection("MessageChunk"),a=new S;return this.reload=function(e,n){return l.findById(e.chunkId,n)},this.upsert=function(e,t){var n,r;n=e,r=function(e,n){e?t(e):t(null,je.createFromJson(n))},a.lock(function(t){var e=Pn.getInstance();e.currentUserId?(n.ownerUserId=e.currentUserId,Be[n.chunkId]=n,l.upsert(Be[n.chunkId].serialize(),function(e,n){t(),e?r(e):r(null,n)})):(t(),r(Ae.create(Ae.Type.ERROR_SETUP_MISSING)))})},this.remove=function(n,t){var e,r;e=n,r=function(e){e?t(e):t(null,n)},a.lock(function(t){Pn.getInstance().currentUserId?(Be[e]&&delete Be[e],l.remove(e,function(e,n){t(),e?r(e):r(null,n)})):(t(),r(Ae.create(Ae.Type.ERROR_SETUP_MISSING)))})},this.clear=function(e){return t=e,void a.lock(function(n){Be={},l.clear(function(e){n(),t(e)})});var t},this.getChunksByHistoryOffset=function(e,n,t){var r=Pn.getInstance(),a=je.getDefaultFilter();if(r.currentUserId){var i=new Pn.LocalDB.Query({ownerUserId:r.currentUserId,channelUrl:n,filterKey:qe(a),endAt:{"<=":e}});i.limit=Number.MAX_SAFE_INTEGER,i.index={ownerUserId:Pn.LocalDB.Query.Order.ASC,channelUrl:Pn.LocalDB.Query.Order.ASC,filterKey:Pn.LocalDB.Query.Order.ASC,endAt:Pn.LocalDB.Query.Order.DESC},l.find(i,t)}},this.clearChunkByHistoryOffset=function(a,n,t){var i=Pn.getInstance(),s=je.getDefaultFilter();if(i.currentUserId){var e=new Promise(function(t,r){var e=new Pn.LocalDB.Query({ownerUserId:i.currentUserId,channelUrl:n,filterKey:qe(s),endAt:{"<=":a}});e.limit=Number.MAX_SAFE_INTEGER,e.index={ownerUserId:Pn.LocalDB.Query.Order.ASC,channelUrl:Pn.LocalDB.Query.Order.ASC,filterKey:Pn.LocalDB.Query.Order.ASC,endAt:Pn.LocalDB.Query.Order.DESC},l.removeIf(e,function(e,n){return e?r(e):t(n)})}),r=new Promise(function(t,r){c.getChunkByTimestamp(n,s,a,function(e,n){if(e)return r(e);n&&(n.extendBackward(a),c.upsert(n,function(e,n){if(e)return r(e);t(n)})),t(n)})});Promise.all([e,r]).then(function(e){t(null)}).catch(function(e){t(e)})}},this.getChunkByTimestamp=function(r,e,i,s){var n=Pn.getInstance();if(n.currentUserId){var t=new Pn.LocalDB.Query({ownerUserId:n.currentUserId,channelUrl:r,filterKey:qe(e),startAt:{"<=":i},endAt:{">=":i}});t.limit=1,t.index={ownerUserId:Pn.LocalDB.Query.Order.ASC,channelUrl:Pn.LocalDB.Query.Order.ASC,filterKey:Pn.LocalDB.Query.Order.ASC,endAt:Pn.LocalDB.Query.Order.DESC},l.find(t,function(e,n){if(e)s(e);else{var a=0=":r.startAt}});n.limit=Number.MAX_SAFE_INTEGER,l.find(n,function(e,t){if(e)a(e);else if(0=i.length&&u(null)})};for(n.s();!(e=n.n()).done;)t()}catch(e){n.e(e)}finally{n.f()}}():u(null))})}else u(Ae.create(Ae.Type.ERROR_SETUP_MISSING))},this}var Be={},je=function(){function t(e,n){h(this,t),this.chunkId=Ue(),this.channelUrl=e,this.filterKey=qe(n),this.filter=n,this.startAt=(new Date).getTime(),this.endAt=0}return c(t,[{key:"hasDefaultFilter",value:function(){var e=t.getDefaultFilter();return function n(t,r){var e=f(t),a=f(r);return!t||!r||"object"!==e||e!==a||t instanceof Date?t instanceof Date?t.getTime()===r.getTime():"function"===e&&"function"===a||t===r:Object.keys(t).length===Object.keys(r).length&&Object.keys(t).every(function(e){return n(t[e],r[e])})}(this.filter,e)}},{key:"hasVolume",value:function(){return this.endAt>this.startAt}},{key:"isOverlap",value:function(e){return e.startAt<=this.startAt&&this.startAt<=e.endAt||e.startAt<=this.endAt&&this.endAt<=e.endAt}},{key:"isSame",value:function(e){return!!e&&(e.startAt===this.startAt&&this.endAt===e.endAt)}},{key:"hasSameFilter",value:function(e){return!!e&&(e.channelUrl===this.channelUrl&&e.filterKey===this.filterKey)}},{key:"contains",value:function(e){return this.startAt<=e&&e<=this.endAt}},{key:"containsMessage",value:function(e){return this.contains(e.createdAt)}},{key:"serialize",value:function(){var e=JSON.parse(JSON.stringify(this));return Object.freeze(e)}},{key:"extendForward",value:function(e){this.endAt=Math.max(this.endAt,e)}},{key:"extendBackward",value:function(e){this.startAt=Math.min(this.startAt,e)}},{key:"extendWithChunk",value:function(e){return this.extendForwardWithChunk(e),this.extendBackwardWithChunk(e),this}},{key:"extendForwardWithChunk",value:function(e){return this.extendForward(e.endAt),this}},{key:"extendBackwardWithChunk",value:function(e){return this.extendBackward(e.startAt),this}},{key:"extendWithMessage",value:function(e){return this.extendForwardWithMessage(e),this.extendBackwardWithMessage(e),this}},{key:"extendForwardWithMessage",value:function(e){return this.extendForward(e.createdAt),this}},{key:"extendBackwardWithMessage",value:function(e){return this.extendBackward(e.createdAt),this}}],[{key:"createFromJson",value:function(e){var n=new t(e.channelUrl,e.filter);return n.chunkId=e.chunkId,n.startAt=e.startAt,n.endAt=e.endAt,n}},{key:"getDefaultFilter",value:function(){return{messageTypeFilter:null,customTypeFilter:null,senderUserIdsFilter:[],includeMetaArray:!0}}},{key:"MessageTypeFilterRealValue",get:function(){return["","user","file","admin"]}}]),t}();function Ve(e,n,t){return t?n.channelUrl===e.url&&((!t.messageType||t.messageType===n.messageType)&&((!t.customType||t.customType===n.customType)&&!(Array.isArray(t.senderUserIdsFilter)&&0t[s.url])&&(t[s.url]=s.messageOffsetTimestamp,t[s.url]&&(tn.getInstance().chunkContainer.clearChunkByHistoryOffset(s.messageOffsetTimestamp,s.url,function(e){e&&Me.error("Error while clearing message chunk history",e)}),tn.getInstance().messageContainer.loadMessagesByHistoryOffset(s.messageOffsetTimestamp,s.url,function(e,n){if(!e){tn.getInstance().messageContainer.clearMessagesByHistoryOffset(s.messageOffsetTimestamp,s.url,function(e,n){e&&Me.error("Error while clearing chat history",e)});var t=n.filter(function(e){return e.hasOwnProperty("sendingStatus")&&"failed"===e.sendingStatus}).map(function(e){return e.reqId}),r=n.filter(function(e){return e.hasOwnProperty("sendingStatus")&&"succeeded"===e.sendingStatus}).map(function(e){return e.messageId});if(0t[e.channel.url])&&(t[e.channel.url]=e.channel.messageOffsetTimestamp)},this.removeCollection=function(e){var n=u.map(function(e){return e.controller}).indexOf(e);0<=n&&(u[n].controller._pause(),u.splice(n,1))},this.clearCollection=function(){for(var e in u)u[e].controller._pause();u=[]},this.pause=function(){for(var e in u)u[e].controller._pause()},this.resume=function(n){var t=u.length,r=null;for(var e in u)u[e].controller._resume(function(e){r=e||r,--t<=0&&n(r)})},this.upsert=function(e,n){if(0Pn.syncManagerOptions.automaticMessageResendRetryCount)return this._appendMessagesWithOrder(this.automaticMessages,{isAutomatic:!1}),this.automaticMessages=[],$e.getInstance().upsertMessages(this._channelUrl,this.manualMessages),void this._clear({noManualMessages:!0});this._resendingTimer=setTimeout(function(){var i=u.automaticMessages[0];if(i&&u._isRunning){var s=tn.getInstance(),e=s.sb,o=e.getErrorFirstCallback();e.GroupChannel.getChannel(u._channelUrl,function(e,n){if(o){var t=n;n=e,e=t}n?(u._increaseDelayTime(),u._resendUserMessage()):e.resendUserMessage(i,function(e,n){if(o){var t=n;n=e,e=t}if(n){if(800110===n.code){var r={reason:ze.REMOVE_UNKNOWN};$e.getInstance().removeMessages(u._channelUrl,[i],r),u.removeMessages([i])}else u._increaseDelayTime();u._resendUserMessage()}else{u.removeMessages([i]),u._retryCount=0,u._delayTime=0;var a={reason:ze.REMOVE_RESEND_SUCCEEDED};$e.getInstance().removeMessages(u._channelUrl,[i],a),s.messageContainer.upsert(e,function(e,n){e||s.broadcast.upsert([n]),u._resendUserMessage()})}})})}else u._retryCount=0,u._delayTime=0},this._delayTime)}},{key:"_increaseDelayTime",value:function(){this._delayTime=1e4===this._delayTime?this._delayTime:this._delayTime+2e3}},{key:"_toggleResendingInterval",value:function(){this._isRunning?this._resendUserMessage():(clearTimeout(this._resendingTimer),this._resendingTimer=null,this._retryCount=0,this._delayTime=0)}},{key:"resumeResending",value:function(){Me.call("FailedMessageQueue resumeResending()"),this._retryCount=0,this._delayTime=0,this._isRunning=!0}},{key:"pauseResending",value:function(){Me.call("FailedMessageQueue pauseResending()"),this._isRunning=!1}},{key:"increaseCount",value:function(){++this.collectionReferenceCount}},{key:"decreaseCount",value:function(){--this.collectionReferenceCount,0===this.collectionReferenceCount&&this._clear()}}]),a}(),Xe=function(){function o(e){var n=e.msec,t=void 0===n?0:n,r=e.isEternal,a=void 0===r||r,i=e.timeoutFn,s=void 0===i?function(){}:i;h(this,o),this.time=t,this.isEternal=a,this.timeoutFn=s,this.checker=null}return c(o,[{key:"reset",value:function(){this.stop(),this.time=0,this.timeoutFn=function(){}}},{key:"start",value:function(){var e=this;if(null===this.checker){var n=(new Date).getTime();this.checker=setTimeout(function(){(new Date).getTime()-n>=e.time&&(e.isEternal?e.start():e.stop(),e.timeoutFn&&"function"==typeof e.timeoutFn&&e.timeoutFn())},432e5)}}},{key:"stop",value:function(){clearTimeout(this.checker),this.checker=null}}]),o}(),Ye=null,$e=function(){function e(){if(h(this,e),Ye)return Ye;this.queueMap={},this.expirationTimer=new Xe({msec:864e5*Pn.syncManagerOptions.failedMessageRetentionDays,isEternal:!0,timeoutFn:this.removeExpiredMessages}),this.oldestFailedMessageTs=0,Ye=this}return c(e,[{key:"getMessages",value:function(e){return this.queueMap[e]?this.queueMap[e].messages:[]}},{key:"loadFailedMessages",value:function(a,i,s){var o=this;tn.getInstance().messageContainer.loadFailedMessages(a,{},{},function(e,n){var t=n;if(!e){Me.cache("fetch failed message",n.map(function(e){return e.reqId}));var r=o.queueMap[a];r&&(r.appendMessages(n),r.resumeResending()),t=n.filter(function(e){var n=!0,t=!0,r=!0;if(i.messageTypeFilter&&(n=e.messageType===je.MessageTypeFilterRealValue[i.messageTypeFilter]),i.customTypeFilter&&(t=e.customType===i.customTypeFilter),i.senderUserIdsFilter&&Array.isArray(i.senderUserIdsFilter)&&0r){Me.cache("messages exceeds messageStoreCapacity.");var e=[];for(var n in l.cacheManager.messageCount)"all"!==n&&l.cacheManager.messageCount[n]>a&&e.push({channelUrl:n,count:l.cacheManager.messageCount[n]});if(0=o.length&&(u(),c(null,!e))})})}})}else u(),c(null,!1)})}},{key:"applyTrimmedChunk",value:function(e,n){this.broadcast.applyTrimmedChunk(e,n)}},{key:"syncChangeLog",value:function(r,e){var a=this,i=1t&&ln.broadcast.upsert([a])}});break;case"onUserMuted":case"onUserUnmuted":case"onUserUnbanned":case"onChannelFrozen":case"onChannelUnfrozen":case"onMetaDataCreated":case"onMetaDataUpdated":case"onMetaDataDeleted":case"onMetaCountersCreated":case"onMetaCountersUpdated":case"onMetaCountersDeleted":Me.event(u,t[0].url),ln.channelContainer.upsert(t[0],function(e,n){e?Ae.throw(e):ln.broadcast.update([n])});break;case"onUserReceivedInvitation":case"onUserJoined":Me.event(u,t[0].url),ln.channelContainer.upsert(t[0],function(e,n){e?Ae.throw(e):t[1].userId===l.currentUserId?ln.broadcast.upsert([n]):ln.broadcast.update([n])});break;case"onReadReceiptUpdated":ln.channelContainer.upsert(t[0],function(e){e&&Ae.throw(e)});break;case"onChannelHidden":Me.event(u,t[0].url);var i=t[0];ln.channelContainer.upsert(i,function(e){e?Ae.throw(e):ln.broadcast.hide([i])});break;case"onUserLeft":case"onUserBanned":Me.event(u,t[0].url);var s=t[0];t[1].userId===l.currentUserId?ln.channelContainer.remove(s,function(e){e?Ae.throw(e):ln.broadcast.remove([s])}):ln.channelContainer.upsert(s,function(e,n){e?Ae.throw(e):ln.broadcast.update([n])});break;case"onUserDeclinedInvitation":Me.event(u,t[0].url);var o=t[0];t[2].userId===l.currentUserId?ln.channelContainer.remove(o,function(e){e?Ae.throw(e):ln.broadcast.remove([o])}):ln.channelContainer.upsert(o,function(e,n){e?Ae.throw(e):ln.broadcast.update([n])});break;case"onChannelDeleted":Me.event(u,t[0]),ln.channelContainer.getItem(t[0],function(e,n){e?Ae.throw(e):n&&ln.channelContainer.remove(n,function(e){e?Ae.throw(e):ln.broadcast.remove([n])})})}}}),c.addChannelHandler(cn,a)}return ln}return c(i,[{key:"syncChangeLog",value:function(o,u){var c=this;if(this.isFetchingChangeLog)u(Ae.create(Ae.Type.ERROR_DUPLICATED_CHANGELOG_SYNC));else{this.isFetchingChangeLog=!0,Me.call("channel syncChangeLog()");var l="".concat(un);Ie.get(l).then(function(e){var n,t="getMyGroupChannelChangeLogsByToken",r=[];r.push([]),r.push(!0),e?(t="getMyGroupChannelChangeLogsByToken",r.unshift(e)):(t="getMyGroupChannelChangeLogsByTimestamp",r.unshift((new Date).getTime()-100)),Me.call(t),(n=c.sb)[t].apply(n,r.concat([function(s,e){if(c.sb.getErrorFirstCallback()){var n=s;s=e,e=n}if(e)c.isFetchingChangeLog=!1;else{Me.sync("updated",s.updatedChannels&&0":0}}if("all"!=h.query.hiddenChannelFilter)switch(h.query.hiddenChannelFilter){case e.GroupChannel.HiddenChannelFilter.UNHIDDEN:s.hiddenState=e.GroupChannel.HiddenState.UNHIDDEN;break;case e.GroupChannel.HiddenChannelFilter.HIDDEN:s.hiddenState={"/in":[e.GroupChannel.HiddenState.HIDDEN_ALLOW_AUTO_UNHIDE,e.GroupChannel.HiddenState.HIDDEN_PREVENT_AUTO_UNHIDE]};break;case e.GroupChannel.HiddenChannelFilter.HIDDEN_ALLOW_AUTO_UNHIDE:s.hiddenState=e.GroupChannel.HiddenState.HIDDEN_ALLOW_AUTO_UNHIDE;break;case e.GroupChannel.HiddenChannelFilter.HIDDEN_PREVENT_AUTO_UNHIDE:s.hiddenState=e.GroupChannel.HiddenState.HIDDEN_PREVENT_AUTO_UNHIDE}var o=null,u=!0;switch(h.query.order){case"latest_last_message":!h.query.hasNext&&h.query.savepoint&&(s.lastMessageUpdatedAt={">=":parseInt(h.query.savepoint)}),o={ownerUserId:1,lastMessageUpdatedAt:-1};break;case"chronological":!h.query.hasNext&&h.query.savepoint&&(s.createdAt={">=":parseInt(h.query.savepoint)}),o={ownerUserId:1,createdAt:-1};break;case"channel_name_alphabetical":!h.query.hasNext&&h.query.savepoint&&(s.name={"<=":h.query.savepoint}),u=!(o={ownerUserId:1,name:1});break;default:!h.query.hasNext&&h.query.savepoint&&(s.lastMessageUpdatedAt={">=":parseInt(h.query.savepoint)}),o={ownerUserId:1,lastMessageUpdatedAt:-1}}function r(t,r){i.channelContainer.query(s,{offset:a.channels.length,limit:t,index:o,desc:u},function(e,n){e?(h._isLoading=!1,r(e)):(h._isLoading=!1,(n=n.map(function(e){return h.sendBird.GroupChannel.cachedChannels[e.url]||(h.sendBird.GroupChannel.cachedChannels[e.url]=e),h.sendBird.GroupChannel.cachedChannels[e.url]})).sort(function(e,n){return 0Pn.syncManagerOptions.messageCollectionCapacity){if("next"===P.direction){var y=g-Pn.syncManagerOptions.messageCollectionCapacity;v=F.messages.splice(0,y)}else v=F.messages.splice(Pn.syncManagerOptions.messageCollectionCapacity);G.push.apply(G,X(v))}}else{var m=!t.isUserMessage()||"pending"===t.sendingStatus,p=Te(t,F.unsentMessages);if(p<0){Te(t,F.messages)<0&&(m?H.push(t):W.push(t),F.unsentMessages.push(t))}else{var k=F.unsentMessages[p];k.isUserMessage()?"pending"===k.sendingStatus?m||(K.push(k),W.push(t),F.unsentMessages[p]=t):(z.push(t),F.unsentMessages[p]=t):F.unsentMessages[p]=t}}}if(0=y;Me.sync("message synchronize() end",d,"ts=".concat(g),"hasMore=".concat(r),f.map(function(e){return"".concat(e.message," ").concat(e.messageId," ").concat(e.createdAt)}));var s,o=[],n=Y(f);try{var e=function(){var e=s.value;e.isVisible=!0;var n,t=Y(m.unsentMessages);try{for(t.s();!(n=t.n()).done;){var r=n.value;if("pending"===r.sendingStatus&&r.reqId===e.reqId){o.push(e);break}}}catch(e){t.e(e)}finally{t.f()}a.push(new Promise(function(n,t){p.messageContainer.upsert(e,function(e){return e?t(e):n()})})),i.startAt=Math.min(i.startAt,e.createdAt),i.endAt=Math.max(i.endAt,e.createdAt)};for(n.s();!(s=n.n()).done;)e()}catch(e){n.e(e)}finally{n.f()}if(0===f.length&&(i.startAt=m.viewpoint,i.endAt=m.viewpoint),k.currentChunk&&k.currentChunk.isOverlap(i)||(k.currentChunk=new je(m.channel.url,m.filter),Me.message("chunk is created",k.currentChunk.startAt,k.currentChunk.endAt)),k.currentChunk.extendWithChunk(i),0=(Me.isValidLevel(Me.level)?200:0)&&e<=Number.MAX_SAFE_INTEGER&&(a=e)}});var i=Pn.Options.MessageResendPolicy.NONE;Object.defineProperty(this,"messageResendPolicy",{get:function(){return i},set:function(e){-1(Me.isValidLevel(Me.level)?0:-2)&&e<=Number.MAX_SAFE_INTEGER||e===Pn.Options.INFINITY)&&(u=e)}})}}(),Pn.Options.MessageResendPolicy={NONE:"none",MANUAL:"manual",AUTOMATIC:"automatic"},Pn.Options.INFINITY=Number.MAX_SAFE_INTEGER,Pn}); \ No newline at end of file diff --git a/package.json b/package.json index d36025e..c93d0e1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sendbird-syncmanager", - "version": "1.1.26", + "version": "1.1.27", "description": "SendBird data sync manager for JavaScript", "main": "SendBirdSyncManager.min.js", "scripts": {