UNPKG

@sendbird/chat

Version:
1 lines 220 kB
var e,t=require("./__bundle-846135d7.cjs");class s{constructor(e,t,s){var i,n;this.width=0,this.height=0,this.realWidth=0,this.realHeight=0,this._requireAuth=!1,this._iid=e,this.plainUrl=t.url,this.width=t.width,this.height=t.height,this.realWidth=null!==(i=t.real_width)&&void 0!==i?i:t.width,this.realHeight=null!==(n=t.real_height)&&void 0!==n?n:t.height,this._requireAuth=s}static payloadify(e){return e instanceof s?t.deundefined(t.undefineNullProps({url:e.plainUrl,width:e.width,height:e.height,real_width:e.realWidth,real_height:e.realHeight})):t.deundefined(t.undefineNullProps({url:"",width:e.maxWidth,height:e.maxHeight,real_width:0,real_height:0}))}get url(){const{sessionManager:e}=t.Vault.of(this._iid);return this._requireAuth&&e.ekey?`${this.plainUrl}?auth=${e.ekey}`:this.plainUrl}}class i extends t.APIRequestCommand{constructor(e){if(super(),this.method=t.APIRequestMethod.POST,this.path=`${t.API_PATH_UPLOAD}`,this.params=t.deundefined({file:e.file,channel_url:e.channelUrl}),e.thumbnailSizes)for(let t=0;t<e.thumbnailSizes.length;t++){const{maxWidth:s,maxHeight:i}=e.thumbnailSizes[t];this.params[`thumbnail${t+1}`]=`${s},${i}`}this.requestId=e.requestId}}class n extends t.APIResponseCommand{constructor(e,t){var i,n,a,r;super(e,t),this.url=t.url,this.fileSize=null!==(i=t.file_size)&&void 0!==i?i:0,this.thumbnails=null!==(a=null===(n=t.thumbnails)||void 0===n?void 0:n.map((t=>new s(e,t,!1))))&&void 0!==a?a:[],this.requireAuth=null!==(r=t.require_auth)&&void 0!==r&&r}}class a extends t.InstancedObject{constructor(e,s){var i,n,a,r,o;super(e),this.replyCount=0,this.memberCount=0,this.lastRepliedAt=0,this.updatedAt=0,this.replyCount=null!==(i=s.reply_count)&&void 0!==i?i:0,this.memberCount=null!==(n=s.member_count)&&void 0!==n?n:0,this.mostRepliedUsers=s.most_replies&&t.isArrayOf("object",s.most_replies)?s.most_replies.map((e=>new t.User(this._iid,e))):[],this.unreadReplyCount=null!==(a=s.unread_message_count)&&void 0!==a?a:0,this.isPushNotificationEnabled="number"==typeof s.push_enabled?s.push_enabled>0:void 0,this.lastRepliedAt=null!==(r=s.last_replied_at)&&void 0!==r?r:0,this.updatedAt=null!==(o=s.updated_at)&&void 0!==o?o:0}static payloadify(e){return t.deundefined(t.undefineNullProps(Object.assign(Object.assign({},super.payloadify(e)),{reply_count:e.replyCount,unread_message_count:e.unreadReplyCount,member_count:e.memberCount,most_replies:Array.isArray(e.mostRepliedUsers)?e.mostRepliedUsers.map((e=>t.User.payloadify(e))):[],push_enabled:"boolean"==typeof e.isPushNotificationEnabled?e.isPushNotificationEnabled?1:0:void 0,last_replied_at:e.lastRepliedAt,updated_at:e.updatedAt})))}get _isUpdateRequired(){return void 0===this.unreadReplyCount||void 0===this.isPushNotificationEnabled}_updateFrom(e){var t,s;this.unreadReplyCount=null!==(t=e.unreadReplyCount)&&void 0!==t?t:this.unreadReplyCount,this.isPushNotificationEnabled=null!==(s=e.isPushNotificationEnabled)&&void 0!==s?s:this.isPushNotificationEnabled}}exports.ReactionEventOperation=void 0,(e=exports.ReactionEventOperation||(exports.ReactionEventOperation={})).ADD="add",e.DELETE="delete";class r{constructor(e){var s;this.messageId=0,this.operation=null,this.updatedAt=0;const i=t.isTypeOf("string",e.msg_id)?parseInt(e.msg_id):e.msg_id,n=e.user_id,a=e.operation?e.operation.toLowerCase():null,r=e.reaction,o=e.updated_at,l=e.count,d=e.sampled_user_ids,u=null!==(s=e.sampled_user_info)&&void 0!==s?s:{};i&&t.isTypeOf("string",n)&&t.isTypeOf("string",a)&&t.isEnumOf(exports.ReactionEventOperation,a)&&t.isTypeOf("string",r)&&r&&t.isTypeOf("number",o)&&(this.messageId=i,this.userId=n,this.key=r,this.operation=a,this.updatedAt=o,this._count=l,this._sampledUserIds=d,this._sampledUserInfoList=u)}}class o extends t.InstancedObject{constructor(e,t,s){var i;super(e),this.userId=t,this.nickname=s.nickname,this.plainProfileUrl=s.profile_url,this.requireAuth=null!==(i=s.require_auth_for_profile_image)&&void 0!==i&&i}get profileUrl(){const{sessionManager:e}=t.Vault.of(this._iid);return this.requireAuth&&e.ekey?`${this.plainProfileUrl}?auth=${e.ekey}`:this.plainProfileUrl}static payloadify(e){return{nickname:e.nickname,profile_url:e.plainProfileUrl,require_auth_for_profile_image:e.requireAuth}}}class l extends t.InstancedObject{constructor(e,s){var i,n,a,r,l,d,u;super(e),this._sampledUserInfoList=[],this._count=0,this._hasCurrentUserReacted=!1;const c=s.key,h=[...null!==(n=null!==(i=s.sampled_user_ids)&&void 0!==i?i:s.user_ids)&&void 0!==n?n:[]],p=null!==(r=null!==(a=s.last_ts)&&void 0!==a?a:s.updated_at)&&void 0!==r?r:0,m=null!==(l=s.is_self_included)&&void 0!==l?l:h.includes(t.Vault.of(e).sdkState.userId),_=null!==(d=s.sampled_user_info)&&void 0!==d?d:{};t.isTypeOf("string",c)&&c&&t.isArrayOf("string",h)&&h.length>0&&t.isTypeOf("number",p)&&(this.key=c,this._sampledUserIds=h,this._updatedAt=p,this._count=null!==(u=s.count)&&void 0!==u?u:h.length,this._hasCurrentUserReacted=m,Object.keys(_).forEach((t=>{this._sampledUserInfoList.push(new o(e,t,_[t]))})));const g={};for(const e of this.sampledUserIds)g[e]=this.updatedAt;this._version=g}get isEmpty(){return 0===this._count}get userIds(){return this._sampledUserIds}get sampledUserIds(){return this._sampledUserIds}get sampledUserInfoList(){return this._sampledUserInfoList}get count(){return this._count}get updatedAt(){return this._updatedAt}get hasCurrentUserReacted(){return this._hasCurrentUserReacted}static payloadify(e){const s={};return e._sampledUserInfoList.forEach((e=>{s[e.userId]=o.payloadify(e)})),t.deundefined(t.undefineNullProps({key:e.key,sampled_user_ids:e._sampledUserIds,sampled_user_info:s,count:e._count,is_self_included:e._hasCurrentUserReacted,last_ts:e._updatedAt}))}applyEvent(e){if(e.key===this.key&&this.updatedAt<=e.updatedAt)if(e._sampledUserIds)this._sampledUserIds=e._sampledUserIds,this._sampledUserInfoList=[],Object.keys(e._sampledUserInfoList).forEach((t=>{this._sampledUserInfoList.push(new o(this._iid,t,e._sampledUserInfoList[t]))})),this._count=e._count,void 0!==e._hasCurrentUserReacted&&(this._hasCurrentUserReacted=e._hasCurrentUserReacted),this._updatedAt=e.updatedAt;else{if(!this._version[e.userId]||this._version[e.userId]<=e.updatedAt){const t=this._sampledUserIds.indexOf(e.userId);switch(e.operation){case exports.ReactionEventOperation.ADD:t<0&&this._sampledUserIds.push(e.userId);break;case exports.ReactionEventOperation.DELETE:t>=0&&this._sampledUserIds.splice(t,1)}this._count=this._sampledUserIds.length,this._version[e.userId]=e.updatedAt}this._updatedAt=Math.max(this.updatedAt,e.updatedAt)}}}class d{constructor(e){this.secureUrl=null,this.type=null,this.width=0,this.height=0,this.alt=null,this.url=e.url,e.secure_url&&(this.secureUrl=e.secure_url),e.type&&(this.type=e.type),e.width&&(this.width=e.width),e.height&&(this.height=e.height),e.alt&&(this.alt=e.alt)}static payloadify(e){var s,i;return t.deundefined(t.undefineNullProps({url:e.url,secure_url:e.secureUrl,type:e.type,width:null!==(s=e.width)&&void 0!==s?s:0,height:null!==(i=e.height)&&void 0!==i?i:0,alt:e.alt}))}}class u{constructor(e){this.title=null,this.url=null,this.description=null,this.defaultImage=null,e["og:title"]&&(this.title=e["og:title"]),e["og:url"]&&(this.url=e["og:url"]),e["og:description"]&&(this.description=e["og:description"]),e["og:image"]&&(this.defaultImage=new d(e["og:image"]))}static payloadify(e){return t.deundefined(t.undefineNullProps({"og:title":e.title,"og:url":e.url,"og:description":e.description,"og:image":e.defaultImage?d.payloadify(e.defaultImage):null}))}}class c{constructor(e){var t,s;this.volume=0,this.name=null!==(t=e.name)&&void 0!==t?t:"default",this.volume=null!==(s=e.volume)&&void 0!==s?s:1}serialize(){return{name:this.name,volume:this.volume}}static payloadify(e){return t.deundefined(t.undefineNullProps({name:e.name,volume:e.volume}))}}var h;exports.FeedbackRating=void 0,(h=exports.FeedbackRating||(exports.FeedbackRating={})).GOOD="good",h.BAD="bad";class p{constructor(e){this.id=e.id,this.rating=e.rating,this.comment=e.comment}static _getStatus(e){return e?"id"in e?"SUBMITTED":"NO_FEEDBACK":"NOT_APPLICABLE"}static _isSubmitted(e){return"SUBMITTED"===p._getStatus(e)}static _getPayloadByStatus(e){return"NO_FEEDBACK"===e?{}:null}static payloadify(e){return t.deundefined(t.undefineNullProps({id:e.id,rating:e.rating,comment:e.comment}))}}class m extends t.User{constructor(e,s){var i;super(e,s),this.isBlockedByMe=!1,this.role=t.isEnumOf(t.Role,s.role)?s.role:t.Role.NONE,this.isBlockedByMe=null!==(i=s.is_blocked_by_me)&&void 0!==i&&i}static payloadify(e){return t.deundefined(t.undefineNullProps(Object.assign(Object.assign({},super.payloadify(e)),{role:e.role,is_blocked_by_me:e.isBlockedByMe})))}}class _{constructor(e){this.key=e.key,this.value=t.isArrayOf("string",e.value)?[...e.value]:[]}static payloadify(e){var s;return t.deundefined(t.undefineNullProps({key:e.key,value:null!==(s=e.value)&&void 0!==s?s:[]}))}}const g=e=>{switch(e){case t.MessageType.BASE:return"";case t.MessageType.USER:return"MESG";case t.MessageType.FILE:return"FILE";case t.MessageType.ADMIN:return"ADMM"}};class y extends t.InstancedObject{constructor(e,s){var i,n,a,r,o,l,d,u,c;super(e),this.channelType=t.ChannelType.BASE,this.messageType=t.MessageType.BASE,this.mentionType=null,this.mentionedUsers=null,this.mentionedUserIds=null,this.metaArrays=[],this.extendedMessage={},this.createdAt=0,this.updatedAt=0,this.channelUrl=s.channel_url,this.channelType=t.isEnumOf(t.ChannelType,s.channel_type)?s.channel_type:t.ChannelType.GROUP,s.channel&&(s.channel.channel_url&&(this.channelUrl=s.channel.channel_url),s.channel.channel_type&&(this.channelType=s.channel.channel_type)),this.data=null!==(i=s.data)&&void 0!==i?i:"",this.customType=null!==(n=s.custom_type)&&void 0!==n?n:"",this.mentionType=t.isEnumOf(t.MentionType,s.mention_type)?s.mention_type:null,this.mentionedUsers=s.mentioned_users?s.mentioned_users.map((e=>new t.User(this._iid,e))):null,this.mentionedUserIds=null!==(a=s.mentioned_user_ids)&&void 0!==a?a:null,this.mentionedUsers&&!this.mentionedUserIds&&(this.mentionedUserIds=this.mentionedUsers.map((e=>e.userId)));const h=null!==(r=s.metaarray)&&void 0!==r?r:{},p=null!==(o=s.metaarray_key_order)&&void 0!==o?o:Object.keys(h).sort(((e,t)=>e.localeCompare(t)));this.metaArrays=[];for(let e=0;e<p.length;e++){const t=p[e];this.metaArrays.push(new _({key:t,value:h[t]||[]}))}s.sorted_metaarray&&(this.metaArrays=s.sorted_metaarray.map((e=>new _(e)))),this.extendedMessage=null!==(l=s.extended_message)&&void 0!==l?l:{},this.extendedMessagePayload=s.extended_message_payload,this.createdAt=null!==(u=null!==(d=s.created_at)&&void 0!==d?d:s.ts)&&void 0!==u?u:0,this.updatedAt=null!==(c=s.updated_at)&&void 0!==c?c:0}static payloadify(e){var s,i;return t.deundefined(t.undefineNullProps(Object.assign(Object.assign({},super.payloadify(e)),{channel_url:e.channelUrl,channel_type:e.channelType,type:g(e.messageType),data:e.data,custom_type:e.customType,mention_type:e.mentionType,mentioned_user_ids:e.mentionedUserIds,mentioned_users:null===(s=e.mentionedUsers)||void 0===s?void 0:s.map((e=>t.User.payloadify(e))),sorted_metaarray:null===(i=e.metaArrays)||void 0===i?void 0:i.map((e=>_.payloadify(e))),extended_message:e.extendedMessage,extended_message_payload:e.extendedMessagePayload,created_at:e.createdAt,updated_at:e.updatedAt})))}isIdentical(e){return!0}isEqual(e){return t.deepEqual(this,e)}isUserMessage(){return this.messageType===t.MessageType.USER}isFileMessage(){return this.messageType===t.MessageType.FILE&&!Object.prototype.hasOwnProperty.call(this,"fileInfoList")}isMultipleFilesMessage(){return this.messageType===t.MessageType.FILE&&Object.prototype.hasOwnProperty.call(this,"fileInfoList")}isAdminMessage(){return this.messageType===t.MessageType.ADMIN}serialize(){return t.serialize(this)}getMetaArraysByKeys(e){return this.metaArrays.filter((t=>e.includes(t.key)))}}class f extends t.InstancedObject{constructor(e,s){var i,n;super(e),this.channelUrl=null!==(i=s.channel_url)&&void 0!==i?i:"",this.channelType=null!==(n=s.channel_type)&&void 0!==n?n:t.ChannelType.GROUP,this.reader=new t.User(this._iid,s.user),this.readAt=s.ts}}class v extends t.WebSocketRequestCommand{constructor({channelUrl:e}){super({code:"READ",ackRequired:!0,payload:{channel_url:e}})}}class I extends t.APIRequestCommand{constructor(e){super();const{channelUrl:s,channelType:i,userId:n,notificationIds:a}=e;this.method=t.APIRequestMethod.PUT,this.path=`${t.getChannelApiPathByType(i)}/${encodeURIComponent(s)}/messages/mark_as_read`,this.params=t.deundefined(t.undefineNullProps({user_id:n,message_ids:a}))}}class E extends t.WebSocketEventCommand{constructor(e,t,s){super(e,"READ",s),this.readStatus=new f(e,s)}}class T extends t.APIResponseCommand{constructor(e,t){super(e,t),this.readAt=t.ts,this.unreadMessageCount=t.unread_message_count}}class b extends t.WebSocketRequestCommand{constructor({channelUrl:e,messageId:t}){super({code:"READ",ackRequired:!0,payload:{channel_url:e,parent_message_id:t}})}}class S extends t.APIRequestCommand{constructor({channelType:e,channelUrl:s,messageId:i,pushEnabled:n}){super(),this.method=t.APIRequestMethod.PUT,this.path=`${t.getChannelApiPathByType(e)}/${encodeURIComponent(s)}/messages/${i}/thread_push`,this.params={push_enabled:n}}}class M extends t.APIRequestCommand{constructor({channelType:e,channelUrl:s,messageId:i,rating:n,comment:a}){super(),this.method=t.APIRequestMethod.POST,this.path=`${t.getChannelApiPathByType(e)}/${encodeURIComponent(s)}/messages/${i}/feedbacks`,this.params={rating:n,comment:a}}}class O extends t.APIResponseCommand{constructor(e,t){super(e,t),this.feedback=new p(t)}}class A extends t.APIRequestCommand{constructor({channelType:e,channelUrl:s,messageId:i,feedbackId:n,rating:a,comment:r}){super(),this.method=t.APIRequestMethod.PUT,this.path=`${t.getChannelApiPathByType(e)}/${encodeURIComponent(s)}/messages/${i}/feedbacks/${n}`,this.params={rating:a,comment:r}}}class C extends t.APIResponseCommand{constructor(e,t){super(e,t),this.feedback=new p(t)}}class w extends t.APIRequestCommand{constructor({channelType:e,channelUrl:s,messageId:i,feedbackId:n}){super(),this.method=t.APIRequestMethod.DELETE,this.path=`${t.getChannelApiPathByType(e)}/${encodeURIComponent(s)}/messages/${i}/feedbacks/${n}`}}class N extends t.InstancedObject{constructor(e,t){var i,n,a,r,o;super(e),this.plainUrl="",this.fileName=null,this.mimeType=null,this.fileSize=0,this.thumbnails=[],this._requireAuth=!1,this.plainUrl=null!==(i=t.url)&&void 0!==i?i:"",this.fileName=null!==(n=t.file_name)&&void 0!==n?n:null,this.mimeType=null!==(a=t.file_type)&&void 0!==a?a:null,this.fileSize=null!==(r=t.file_size)&&void 0!==r?r:0,this._requireAuth=null!==(o=t.require_auth)&&void 0!==o&&o,this.thumbnails=t.thumbnails?t.thumbnails.map((e=>{var t;return new s(this._iid,"string"==typeof e?{url:e,width:0,height:0}:Object.assign(Object.assign({},e),{url:(null!==(t=e.url)&&void 0!==t?t:"").split("auth=")[0]}),this._requireAuth)})):[]}static payloadify(e){var s;return t.deundefined(t.undefineNullProps({url:e.plainUrl,file_name:e.fileName,file_type:e.mimeType,file_size:e.fileSize,thumbnails:null===(s=e.thumbnails)||void 0===s?void 0:s.map((e=>{var t;return{url:(null!==(t=e.plainUrl)&&void 0!==t?t:"").split("auth=")[0],width:e.width,height:e.height,real_width:e.realWidth,real_height:e.realHeight}})),require_auth:e._requireAuth}))}get url(){const{sessionManager:e}=t.Vault.of(this._iid);return this._requireAuth&&e.ekey?`${this.plainUrl}?auth=${e.ekey}`:this.plainUrl}}class P{constructor({channelUrl:e,channelType:t,parentMessage:s}){this.channelUrl=e,this.channelType=t,this.parentMessage=s}}var U,R,x,k;!function(e){e.NUMBER="number",e.ENUM="enum",e.TEXT="text",e.REGEX="regex",e.DECIMAL_PLACE="decimal_place"}(U||(U={})),exports.MessageFormItemLayout=void 0,(R=exports.MessageFormItemLayout||(exports.MessageFormItemLayout={})).TEXT="text",R.TEXTAREA="textarea",R.NUMBER="number",R.PHONE="phone",R.EMAIL="email",R.CHIP="chip";class L{constructor(e,t){const{id:s,name:i,items:n,version:a,is_submitted:r}=t;this.messageId=e,this.id=s,this.name=i,this.items=n.map((e=>new D(e))).sort(((e,t)=>e.sortOrder-t.sortOrder)),this.version=null!=a?a:1,this._isSubmitted=r}get isSubmitted(){var e;return null!==(e=this._isSubmitted)&&void 0!==e?e:this.items.some((e=>Array.isArray(e.submittedValues)))}get isSubmittable(){return this.items.every((e=>e.required?!!(Array.isArray(e.draftValues)&&e.draftValues.length>0)&&e.isValid(e.draftValues):!(Array.isArray(e.draftValues)&&e.draftValues.length>0)||e.isValid(e.draftValues)))}static payloadify(e){return t.deundefined(t.undefineNullProps({id:e.id,name:e.name,items:e.items.map((e=>D.payloadify(e))),version:e.version,is_submitted:e._isSubmitted}))}static isMessageFormPayload(e){return Boolean(null==e?void 0:e.message_form)}}class D{constructor(e){const{id:s,name:i,required:n,sort_order:a,placeholder:r,style:o,item_type:l,validators:d,value:u,values:c}=e;this.id=s,this.name=i,this.required=n,this.sortOrder=a,this.placeholder=r,0===Object.keys(o).length?this.style={layout:l}:this.style=t.deundefined({layout:o.layout,options:o.options,defaultOptions:o.default_options,resultCount:o.result_count}),c?this.submittedValues=c:u&&(this.submittedValues=[u]),this._validators=d}isValid(e){return e.every((e=>{const t=function(e,t){return t.every((t=>{switch(t.key){case U.NUMBER:{const s=Number(e);return!(isNaN(s)||t.min&&"number"!=typeof t.min||t.max&&"number"!=typeof t.max||"number"==typeof t.min&&s<t.min||"number"==typeof t.max&&s>t.max)}case U.ENUM:return"string"==typeof e&&(!(t.enums&&Array.isArray(t.enums)&&t.enums.length>0&&!t.enums.includes(e))||t.allow_other);case U.TEXT:return!("string"!=typeof e||"number"==typeof t.min_length&&e.length<t.min_length||"number"==typeof t.max_length&&e.length>t.max_length);case U.REGEX:if("string"!=typeof e)return!1;if(t.regex){if("string"!=typeof t.regex)return!1;if(!new RegExp(t.regex).test(e))return!1}return!0;case U.DECIMAL_PLACE:{if(0===e.length)return!1;const s=Number(e);return!(isNaN(s)||(!t.max_decimal_place||"number"==typeof t.max_decimal_place)&&t.max_decimal_place&&!function(e,t){const s=e.toString(),i=s.indexOf(".");return-1===i||s.slice(i+1).length<=t}(s,t.max_decimal_place))}default:return!0}}))}(e,this._validators);return t}))}static payloadify(e){return t.deundefined(t.undefineNullProps({id:e.id,name:e.name,required:e.required,sort_order:e.sortOrder,placeholder:e.placeholder,style:t.deundefined({layout:e.style.layout,options:e.style.options,default_options:e.style.defaultOptions,result_count:e.style.resultCount}),item_type:e.style.layout,validators:e._validators,values:e.submittedValues}))}}class q extends t.APIRequestCommand{constructor(e){super(),this.method=t.APIRequestMethod.POST,this.path=`${t.API_PATH_FORMS}/${e.formId}/submit`,this.params=t.deundefined({message_id:e.messageId,items:e.items})}}exports.ScheduledStatus=void 0,(x=exports.ScheduledStatus||(exports.ScheduledStatus={})).PENDING="pending",x.SENT="sent",x.FAILED="failed",x.CANCELED="canceled",exports.InternalScheduledStatus=void 0,(k=exports.InternalScheduledStatus||(exports.InternalScheduledStatus={})).PENDING="pending",k.IN_QUEUE="in_queue",k.SENT="sent",k.FAILED="failed",k.CANCELED="canceled",k.REMOVED="removed";class F extends y{constructor(e,s){var i,n,r,o,d,h,m,_,g;super(e,s),this.parentMessage=null,this.silent=!1,this.isOperatorMessage=!1,this.threadInfo=null,this.reactions=[],this.appleCriticalAlertOptions=null,this.scheduledInfo=null,this.suggestedReplies=null,this.myFeedback=null,this.myFeedbackStatus="NOT_APPLICABLE",this.messageForm=null,this._isContinuousMessages=!1,this._scheduledStatus=null,this._poll=null,this.messageId=null!==(n=null!==(i=s.msg_id)&&void 0!==i?i:s.message_id)&&void 0!==n?n:0,this.parentMessageId=null!==(r="string"==typeof s.parent_message_id?parseInt(s.parent_message_id):s.parent_message_id)&&void 0!==r?r:0,this.threadInfo=s.thread_info?new a(this._iid,s.thread_info):null,s.reactions_summary?this.reactions=s.reactions_summary.map((t=>new l(e,t))):s.reactions?this.reactions=s.reactions.map((t=>new l(e,t))):this.reactions=[],this.ogMetaData=s.og_tag?new u(s.og_tag):null,this.silent=null!==(o=s.silent)&&void 0!==o&&o,this.isOperatorMessage=null!==(d=s.is_op_msg)&&void 0!==d&&d,this.appleCriticalAlertOptions=s.apple_critical_alert_options?new c(s.apple_critical_alert_options):null,"number"==typeof s.scheduled_message_id&&"number"==typeof s.scheduled_at&&s.scheduled_status&&(this.scheduledInfo={scheduledMessageId:s.scheduled_message_id,scheduledAt:s.scheduled_at},this._scheduledStatus=s.scheduled_status),this._isContinuousMessages=null!==(h=s.is_continuous_messages)&&void 0!==h&&h,this.myFeedback=p._isSubmitted(s.feedback)?new p(s.feedback):null,this.myFeedbackStatus=p._getStatus(s.feedback),this.suggestedReplies=null!==(_=null===(m=s.extended_message_payload)||void 0===m?void 0:m.suggested_replies)&&void 0!==_?_:null,this.messageForm=L.isMessageFormPayload(s.extended_message_payload)?new L(this.messageId,s.extended_message_payload.message_form):null,this.message=null!==(g=s.message)&&void 0!==g?g:"",this._poll=s.poll?new t.Poll(this._iid,s.poll):null}static payloadify(e){var s,i;return t.deundefined(t.undefineNullProps(Object.assign(Object.assign({},super.payloadify(e)),{message_id:e.messageId,parent_message_id:e.parentMessageId,thread_info:e.threadInfo?a.payloadify(e.threadInfo):null,reactions_summary:e.reactions.map((e=>l.payloadify(e))),og_tag:e.ogMetaData?u.payloadify(e.ogMetaData):null,silent:e.silent,is_op_msg:e.isOperatorMessage,apple_critical_alert_options:e.appleCriticalAlertOptions?c.payloadify(e.appleCriticalAlertOptions):null,scheduled_message_id:null===(s=e.scheduledInfo)||void 0===s?void 0:s.scheduledMessageId,scheduled_at:null===(i=e.scheduledInfo)||void 0===i?void 0:i.scheduledAt,scheduled_status:e._scheduledStatus,feedback:e.myFeedback?p.payloadify(e.myFeedback):p._getPayloadByStatus(e.myFeedbackStatus),message:e.message,poll:e._poll?t.Poll.payloadify(e._poll):null})))}static _getParentMessageInfoPayload(e){return t.deundefined(t.undefineNullProps({type:g(e.messageType),ts:e.createdAt,user:e.sender?m.payloadify(e.sender):null,message:e.message,file:{url:e.plainUrl,name:e.name,type:e.type,require_auth:e.requireAuth},files:Array.isArray(e.fileInfoList)?e.fileInfoList.map((e=>N.payloadify(e))):null}))}isIdentical(e){return this.messageId===e.messageId}applyThreadInfoUpdateEvent(e){return this.messageId===e.targetMessageId&&(e.threadInfo._isUpdateRequired&&this.threadInfo&&e.threadInfo._updateFrom(this.threadInfo),this.threadInfo=e.threadInfo,!0)}_findReactionIndex(e){for(let t=0;t<this.reactions.length;t++)if(this.reactions[t].key===e)return t;return-1}applyReactionEvent(e){const{sdkState:s}=t.Vault.of(this._iid);if(this.messageId===e.messageId)switch(e.operation){case exports.ReactionEventOperation.ADD:{e.userId===s.userId&&(e._hasCurrentUserReacted=!0);const t=this._findReactionIndex(e.key);-1!==t?this.reactions[t].applyEvent(e):e._sampledUserIds?this.reactions.push(new l(this._iid,{key:e.key,sampled_user_ids:e._sampledUserIds,sampled_user_info:e._sampledUserInfoList,count:e._count,is_self_included:e._hasCurrentUserReacted,last_ts:e.updatedAt})):this.reactions.push(new l(this._iid,{key:e.key,user_ids:[e.userId],updated_at:e.updatedAt}));break}case exports.ReactionEventOperation.DELETE:{const t=this._findReactionIndex(e.key);-1!==t&&(e._sampledUserIds?0===e._count?this.reactions.splice(t,1):(e.userId===s.userId&&(e._hasCurrentUserReacted=!1),this.reactions[t].applyEvent(e)):(this.reactions[t].applyEvent(e),this.reactions[t].isEmpty&&this.reactions.splice(t,1)));break}}}applyParentMessage(e){if(!this.parentMessage)return this.parentMessage=e,!0;if(this.parentMessageId===e.messageId){const t=this.parentMessage.updatedAt;if(e.updatedAt>=t)return this.parentMessage=e,!0}return!1}applyPoll(e){return!(this._poll&&this._poll.id===e.id&&this._poll.updatedAt>e.updatedAt)&&(this._poll=e,!0)}get poll(){return this._poll}_triggerThreadInfoUpdatedEvent(){return t.__awaiter(this,void 0,void 0,(function*(){const{dispatcher:e}=t.Vault.of(this._iid);e.dispatch(new P({channelType:t.ChannelType.GROUP,channelUrl:this.channelUrl,parentMessage:this})),e.dispatch(new t.MessageUpdateEventCommand({messages:[this],source:t.CollectionEventSource.EVENT_MESSAGE_THREADINFO_UPDATED}))}))}markThreadAsRead(){return t.__awaiter(this,void 0,void 0,(function*(){const{requestQueue:e}=t.Vault.of(this._iid),s=new b({channelUrl:this.channelUrl,messageId:this.messageId});yield e.send(s),this.threadInfo&&0!==this.threadInfo.unreadReplyCount&&(this.threadInfo.unreadReplyCount=0,yield this._triggerThreadInfoUpdatedEvent())}))}setPushNotificationEnabled(e){return t.__awaiter(this,void 0,void 0,(function*(){const{requestQueue:s}=t.Vault.of(this._iid),i=new S({channelUrl:this.channelUrl,channelType:this.channelType,messageId:this.messageId,pushEnabled:e});yield s.send(i),this.threadInfo&&this.threadInfo.isPushNotificationEnabled!==e&&(this.threadInfo.isPushNotificationEnabled=e)}))}submitMessageForm(e){return t.__awaiter(this,void 0,void 0,(function*(){const{requestQueue:s}=t.Vault.of(this._iid);let i=null,n=null;const a=this.messageForm;if(!e&&a){if(!a.isSubmittable)throw new t.SendbirdError({code:t.SendbirdErrorCode.INVALID_PARAMETER,message:"The form is not submittable. Please check all form items are valid before submitting."});if(a.isSubmitted)throw new t.SendbirdError({code:t.SendbirdErrorCode.INVALID_PARAMETER,message:"The form has already been submitted."});i=a.id,n=a.items.reduce(((e,t)=>(e.push({form_item_id:t.id,values:Array.isArray(t.draftValues)?t.draftValues:[]}),e)),[])}else e&&(i=e.formId,n=Object.entries(e.answers).reduce(((e,[s,i])=>{const n=Number(s);if(Number.isNaN(n))throw new t.SendbirdError({code:t.SendbirdErrorCode.INVALID_PARAMETER,message:"Keys in answers must be numeric string."});return e.push({form_item_id:n,value:i}),e}),[]));if(!i||!n)throw new t.SendbirdError({code:t.SendbirdErrorCode.INVALID_PARAMETER,message:"Missing one or more required inputs: formId, answers."});const r=new q({messageId:this.messageId,formId:i,items:n});yield s.send(r)}))}submitFeedback(e){return t.__awaiter(this,void 0,void 0,(function*(){const{requestQueue:s,dispatcher:i}=t.Vault.of(this._iid),n=new M({channelUrl:this.channelUrl,channelType:this.channelType,messageId:this.messageId,rating:e.rating,comment:e.comment}),a=(yield s.send(n)).as(O);this.myFeedback=a.feedback,this.myFeedbackStatus="SUBMITTED",i.dispatch(new t.MessageUpdateEventCommand({messages:[this],source:t.CollectionEventSource.EVENT_MESSAGE_FEEDBACK_ADDED}))}))}updateFeedback(e){return t.__awaiter(this,void 0,void 0,(function*(){const{requestQueue:s,dispatcher:i}=t.Vault.of(this._iid),n=new A({channelUrl:this.channelUrl,channelType:this.channelType,messageId:this.messageId,feedbackId:e.id,rating:e.rating,comment:e.comment}),a=(yield s.send(n)).as(C);this.myFeedback=a.feedback,this.myFeedbackStatus="SUBMITTED",i.dispatch(new t.MessageUpdateEventCommand({messages:[this],source:t.CollectionEventSource.EVENT_MESSAGE_FEEDBACK_UPDATED}))}))}deleteFeedback(e){return t.__awaiter(this,void 0,void 0,(function*(){const{requestQueue:s,dispatcher:i}=t.Vault.of(this._iid),n=new w({channelUrl:this.channelUrl,channelType:this.channelType,messageId:this.messageId,feedbackId:e});yield s.send(n),this.myFeedback=null,this.myFeedbackStatus="NO_FEEDBACK",i.dispatch(new t.MessageUpdateEventCommand({messages:[this],source:t.CollectionEventSource.EVENT_MESSAGE_FEEDBACK_DELETED}))}))}}class B extends F{constructor(e,s){var i,n,a,r;if(super(e,s),this.reqId="",this.replyToChannel=!1,this.errorCode=0,this.sender=s.user?new m(this._iid,s.user):s.sender_id,this.reqId=null!==(n=null!==(i=s.req_id)&&void 0!==i?i:s.request_id)&&void 0!==n?n:"",this.replyToChannel=null!==(a=s.is_reply_to_channel)&&void 0!==a&&a,s.request_state&&t.isEnumOf(t.SendingStatus,s.request_state)&&(this.sendingStatus=s.request_state),!this.sendingStatus)if(this.messageId>0)this.sendingStatus=t.SendingStatus.SUCCEEDED;else if(this.scheduledInfo)switch(s.scheduled_status&&(this._scheduledStatus=s.scheduled_status),s.scheduled_status){case exports.InternalScheduledStatus.SENT:case exports.InternalScheduledStatus.IN_QUEUE:this.sendingStatus=t.SendingStatus.SUCCEEDED;break;case exports.InternalScheduledStatus.PENDING:this.sendingStatus=t.SendingStatus.SCHEDULED;break;case exports.InternalScheduledStatus.FAILED:case exports.InternalScheduledStatus.REMOVED:this.sendingStatus=t.SendingStatus.FAILED;break;case exports.InternalScheduledStatus.CANCELED:this.sendingStatus=t.SendingStatus.CANCELED}else this.sendingStatus=t.SendingStatus.PENDING;this.errorCode=null!==(r=s.error_code)&&void 0!==r?r:0,this._messageToken=s.mesg_token}static payloadify(e){return t.deundefined(t.undefineNullProps(Object.assign(Object.assign({},super.payloadify(e)),{user:m.payloadify(e.sender),req_id:e.reqId,is_reply_to_channel:e.replyToChannel,request_state:e.sendingStatus,error_code:e.errorCode,mesg_token:e._messageToken})))}get isResendable(){return(this.sendingStatus===t.SendingStatus.FAILED||this.sendingStatus===t.SendingStatus.CANCELED)&&t.isResendableError(this.errorCode)}isIdentical(e){return this.messageId>0&&e.messageId>0?this.messageId===e.messageId:this.reqId===e.reqId}}const j={prevResultSize:0,nextResultSize:0,isInclusive:!1,reverse:!1,messageTypeFilter:t.MessageTypeFilter.ALL,customTypesFilter:void 0,senderUserIdsFilter:void 0,includeReactions:!1,includeMetaArray:!1,includeParentMessageInfo:!1},V=e=>t.isTypeOf("number",e.prevResultSize)&&t.isTypeOf("number",e.nextResultSize)&&t.isTypeOf("boolean",e.isInclusive)&&t.isTypeOf("boolean",e.reverse)&&t.isTypeOf("string",e.messageTypeFilter)&&t.isEnumOf(t.MessageTypeFilter,e.messageTypeFilter)&&t.isArrayOf("string",e.customTypesFilter,!0)&&t.isArrayOf("string",e.senderUserIdsFilter,!0)&&t.isTypeOf("boolean",e.includeMetaArray)&&t.isTypeOf("boolean",e.includeReactions)&&t.isTypeOf("boolean",e.includeParentMessageInfo);class z extends F{constructor(e,s){var i,n,a;if(super(e,s),this.translations={},this.messageType=t.MessageType.ADMIN,this.translations=null!==(i=s.translations)&&void 0!==i?i:{},s.parent_message_info){const i=s.parent_message_info;this.parentMessage=Y(e,t.deundefined(t.undefineNullProps(Object.assign(Object.assign({},i),{message_id:this.parentMessageId,channel_url:this.channelUrl,channel_type:this.channelType,file:i.file,url:null===(n=i.file)||void 0===n?void 0:n.url,require_auth:null===(a=i.file)||void 0===a?void 0:a.require_auth}))))}}static payloadify(e){return t.deundefined(t.undefineNullProps(Object.assign(Object.assign({},super.payloadify(e)),{translations:e.translations,parent_message_info:e.parentMessage?super._getParentMessageInfoPayload(e.parentMessage):null})))}getThreadedMessagesByTimestamp(e,s){return t.__awaiter(this,void 0,void 0,(function*(){const i=Object.assign(Object.assign({},j),s);t.unless(this.messageId>0&&t.isTypeOf("number",e)&&V(i)).throw(t.SendbirdError.invalidParameters);const n=Xi.of(this._iid);return yield n.getThreadedMessagesByTimestamp(this,e,i)}))}}class ${constructor(e){var s,i;this.detail={},this.type=null!==(s=e.type)&&void 0!==s?s:"",this.vendor=null!==(i=e.vendor)&&void 0!==i?i:"",e.detail&&t.isTypeOf("object",e.detail)&&!Array.isArray(e.detail)&&(this.detail=e.detail)}static payloadify(e){return t.deundefined(t.undefineNullProps({type:e.type,vendor:e.vendor,detail:e.detail}))}}class Q{constructor(e){this.status=e.status,e.original_message_info&&(this.originalMessageInfo={createdAt:e.original_message_info.ts,messageId:e.original_message_info.id})}static payloadify(e){return t.deundefined({status:e.status,original_message_info:e.originalMessageInfo?{id:e.originalMessageInfo.messageId,ts:e.originalMessageInfo.createdAt}:void 0})}}class G extends B{constructor(e,s){var i,n,a,r,o;if(super(e,s),this.messageParams=null,this.mentionedMessageTemplate=void 0,this.translations={},this.translationTargetLanguages=[],this.messageSurvivalSeconds=-1,this.plugins=[],this.messageType=t.MessageType.USER,this.translations=null!==(i=s.translations)&&void 0!==i?i:{},this.translationTargetLanguages=null!==(n=s.target_langs)&&void 0!==n?n:[],0===Object.keys(this.translations).length&&this.translationTargetLanguages.length>0)for(const e of this.translationTargetLanguages)this.translations[e]="";if(this.mentionedMessageTemplate=s.mentioned_message_template,this.messageSurvivalSeconds=null!==(a=s.message_survival_seconds)&&void 0!==a?a:-1,this.plugins=s.plugins?s.plugins.map((e=>new $(e))):[],s.parent_message_info){const i=s.parent_message_info;this.parentMessage=Y(e,t.deundefined(t.undefineNullProps(Object.assign(Object.assign({},i),{created_at:i.ts,message_id:this.parentMessageId,channel_url:this.channelUrl,channel_type:this.channelType,file:i.file,url:null===(r=i.file)||void 0===r?void 0:r.url,require_auth:null===(o=i.file)||void 0===o?void 0:o.require_auth}))))}s.review_info&&(this.messageReviewInfo=new Q(s.review_info))}static payloadify(e){return t.deundefined(t.undefineNullProps(Object.assign(Object.assign({},super.payloadify(e)),{translations:e.translations,message_survival_seconds:e.messageSurvivalSeconds,mentioned_message_template:e.mentionedMessageTemplate,plugins:e.plugins.map((e=>$.payloadify(e))),parent_message_info:e.parentMessage?super._getParentMessageInfoPayload(e.parentMessage):null,review_info:e.messageReviewInfo?Q.payloadify(e.messageReviewInfo):void 0})))}getThreadedMessagesByTimestamp(e,s){return t.__awaiter(this,void 0,void 0,(function*(){const i=Object.assign(Object.assign({},j),s);t.unless(this.messageId>0&&t.isTypeOf("number",e)&&V(i)).throw(t.SendbirdError.invalidParameters);const n=Xi.of(this._iid);return yield n.getThreadedMessagesByTimestamp(this,e,i)}))}}class K extends B{constructor(e,s){var i,n,a,r,o,l,d,u;if(super(e,s),this.messageParams=null,this.fileInfoList=[],this.messageSurvivalSeconds=-1,this.messageType=t.MessageType.FILE,this.data=null!==(a=null!==(n=null===(i=s.file)||void 0===i?void 0:i.data)&&void 0!==n?n:s.custom)&&void 0!==a?a:"",this.fileInfoList=null!==(o=null===(r=s.files)||void 0===r?void 0:r.map((t=>new N(e,t))))&&void 0!==o?o:[],this.messageSurvivalSeconds=null!==(l=s.message_survival_seconds)&&void 0!==l?l:-1,s.parent_message_info){const i=s.parent_message_info;this.parentMessage=Y(e,t.deundefined(t.undefineNullProps(Object.assign(Object.assign({},i),{created_at:i.ts,message_id:this.parentMessageId,channel_url:this.channelUrl,channel_type:this.channelType,file:i.file,url:null===(d=i.file)||void 0===d?void 0:d.url,require_auth:null===(u=i.file)||void 0===u?void 0:u.require_auth}))))}}getThreadedMessagesByTimestamp(e,s){return t.__awaiter(this,void 0,void 0,(function*(){const i=Object.assign(Object.assign({},j),s);t.unless(this.messageId>0&&t.isTypeOf("number",e)&&V(i)).throw(t.SendbirdError.invalidParameters);const n=Xi.of(this._iid);return yield n.getThreadedMessagesByTimestamp(this,e,i)}))}static payloadify(e){var s,i,n,a,r,o;return t.deundefined(t.undefineNullProps(Object.assign(Object.assign({},super.payloadify(e)),{file:{name:null!==(i=null===(s=e.fileInfoList[0])||void 0===s?void 0:s.fileName)&&void 0!==i?i:"",size:null!==(a=null===(n=e.fileInfoList[0])||void 0===n?void 0:n.fileSize)&&void 0!==a?a:0,type:null!==(o=null===(r=e.fileInfoList[0])||void 0===r?void 0:r.mimeType)&&void 0!==o?o:"",data:e.data},files:Array.isArray(e.fileInfoList)?e.fileInfoList.map((e=>N.payloadify(e))):null,message_survival_seconds:e.messageSurvivalSeconds,parent_message_info:e.parentMessage?super._getParentMessageInfoPayload(e.parentMessage):null})))}static _isMultipleFilesMessagePayload(e){const t=e.files;return Array.isArray(t)&&t.length>=2}static _isMultipleFilesMessageSerializedData(e){const t=e.fileInfoList;return Array.isArray(t)}}var H;exports.NotificationMessageStatus=void 0,(H=exports.NotificationMessageStatus||(exports.NotificationMessageStatus={})).SENT="SENT",H.READ="READ";class W extends y{constructor(e,s){var i,n;if(super(e,s),this.notificationData=null,this.notificationId=s.notification_message_id,this.messageType=t.MessageType.ADMIN,this.messageStatus=null!==(i=s.message_status)&&void 0!==i?i:exports.NotificationMessageStatus.SENT,this.priority=null!==(n=s.priority)&&void 0!==n?n:t.NotificationPriority.NORMAL,this.notificationEventDeadline=s.notification_event_deadline,0===this.extendedMessage.sub_type)try{const{label:e,tags:t=[],template_key:s,template_variables:i}=JSON.parse(this.extendedMessage.sub_data);this.notificationData={label:e,tags:t,templateKey:s,templateVariables:i}}catch(e){}}static payloadify(e){return t.deundefined(t.undefineNullProps(Object.assign(Object.assign({},super.payloadify(e)),{notification_message_id:e.notificationId,message_status:e.messageStatus,priority:e.priority,notification_event_deadline:e.notificationEventDeadline})))}isIdentical(e){return this.notificationId===e.notificationId}}const Y=(e,t)=>{if(t.notification_message_id)return new W(e,t);switch(t.type){case"MESG":return new G(e,t);case"FILE":return K._isMultipleFilesMessagePayload(t)?new K(e,t):new X(e,t);case"ADMM":case"BRDM":return new z(e,t);default:return null}};class X extends B{constructor(e,i){var n,a,r,o,l,d,u,c,h,p,m,_,g,y;super(e,i),this.messageParams=null,this.plainUrl="",this.requireAuth=!1,this.thumbnails=[],this.messageSurvivalSeconds=-1,this.messageType=t.MessageType.FILE;const f=i.file;if(this.plainUrl=(null!==(a=null!==(n=null==f?void 0:f.url)&&void 0!==n?n:i.url)&&void 0!==a?a:"").split("?auth=")[0],this.name=null!==(o=null!==(r=null==f?void 0:f.name)&&void 0!==r?r:i.name)&&void 0!==o?o:"File",this.size=null!==(d=null!==(l=null==f?void 0:f.size)&&void 0!==l?l:i.size)&&void 0!==d?d:0,this.data=null!==(c=null!==(u=null==f?void 0:f.data)&&void 0!==u?u:i.custom)&&void 0!==c?c:"",this.type=f?null!==(h=f.type)&&void 0!==h?h:"":null!==(p=i.type)&&void 0!==p?p:"",this.requireAuth=null!==(m=i.require_auth)&&void 0!==m&&m,this.thumbnails=i.thumbnails?i.thumbnails.map((e=>{var t;return new s(this._iid,"string"==typeof e?{url:e,width:0,height:0}:Object.assign(Object.assign({},e),{url:(null!==(t=e.url)&&void 0!==t?t:"").split("auth=")[0]}),this.requireAuth)})):[],this.messageSurvivalSeconds=null!==(_=i.message_survival_seconds)&&void 0!==_?_:-1,i.parent_message_info){const s=i.parent_message_info;this.parentMessage=Y(e,t.deundefined(t.undefineNullProps(Object.assign(Object.assign({},s),{created_at:s.ts,message_id:this.parentMessageId,channel_url:this.channelUrl,channel_type:this.channelType,file:s.file,url:null===(g=s.file)||void 0===g?void 0:g.url,require_auth:null===(y=s.file)||void 0===y?void 0:y.require_auth}))))}}static payloadify(e){var s;return t.deundefined(t.undefineNullProps(Object.assign(Object.assign({},super.payloadify(e)),{url:e.plainUrl,require_auth:e.requireAuth,file:{name:e.name,size:e.size,type:e.type,data:e.data},thumbnails:null===(s=e.thumbnails)||void 0===s?void 0:s.map((e=>({url:e.plainUrl,width:e.width,height:e.height,real_width:e.realWidth,real_height:e.realHeight}))),message_survival_seconds:e.messageSurvivalSeconds,parent_message_info:e.parentMessage?super._getParentMessageInfoPayload(e.parentMessage):null})))}get url(){const{sessionManager:e}=t.Vault.of(this._iid);return this.requireAuth&&e.ekey?`${this.plainUrl}?auth=${e.ekey}`:this.plainUrl}getThreadedMessagesByTimestamp(e,s){return t.__awaiter(this,void 0,void 0,(function*(){const i=Object.assign(Object.assign({},j),s);t.unless(this.messageId>0&&t.isTypeOf("number",e)&&V(i)).throw(t.SendbirdError.invalidParameters);const n=Xi.of(this._iid);return yield n.getThreadedMessagesByTimestamp(this,e,i)}))}}class J extends t.InstancedObject{static getPlainUrl(e){return e instanceof J?e._plainUrl:e.fileUrl}constructor(e,{file:t,fileUrl:s,fileName:i,fileSize:n,mimeType:a,thumbnailSizes:r,_uploadedMetaData:o,_thumbnails:l}){super(e),this._plainUrl=s,this.file=t,this.fileName=i,this.fileSize=n,this.mimeType=a,this.thumbnailSizes=r,this._uploadedMetaData=o,this._thumbnails=l}get fileUrl(){var e;const{sessionManager:s}=t.Vault.of(this._iid);return this._plainUrl&&(null===(e=this._uploadedMetaData)||void 0===e?void 0:e.requireAuth)&&s.ekey?`${this._plainUrl}?auth=${s.ekey}`:this._plainUrl}set fileUrl(e){this._plainUrl=e}toJSON(){return{file:this.file,fileUrl:this._plainUrl,fileName:this.fileName,fileSize:this.fileSize,mimeType:this.mimeType,thumbnailSizes:this.thumbnailSizes,_thumbnails:this._thumbnails,_uploadedMetaData:this._uploadedMetaData}}}class Z extends t.WebSocketRequestCommand{constructor(e){var i,n,a,r;let o=[];e.mentionType===t.MentionType.USERS&&(e.mentionedUserIds?o=e.mentionedUserIds:e.mentionedUsers&&(o=e.mentionedUsers.map((e=>e.userId)))),super({code:"FILE",ackRequired:!0,payload:t.deundefined(t.undefineNullProps({channel_url:e.channelUrl,files:e.files?ie(e.files):null,url:e.url,name:null!==(i=e.fileName)&&void 0!==i?i:"",type:null!==(n=e.mimeType)&&void 0!==n?n:"",size:null!==(a=e.fileSize)&&void 0!==a?a:0,custom:e.data,custom_type:e.customType,thumbnails:null===(r=e._thumbnails)||void 0===r?void 0:r.map((e=>s.payloadify(e))),require_auth:e.requireAuth,metaarray:e.metaArrays,mention_type:e.mentionType,mentioned_user_ids:o,push_option:e.pushNotificationDeliveryOption&&e.pushNotificationDeliveryOption!==t.PushNotificationDeliveryOption.DEFAULT?e.pushNotificationDeliveryOption:void 0,apple_critical_alert_options:e.appleCriticalAlertOptions?c.payloadify(e.appleCriticalAlertOptions):null,silent:e.silent,reply_to_channel:e.isReplyToChannel,parent_message_id:e.parentMessageId?e.parentMessageId:null,req_id:e.reqId,poll_id:e.pollId,pin_message:e.isPinnedMessage,message:e.message}))})}}class ee extends t.APIRequestCommand{constructor(e){var i,n;super();let a=[];e.mentionType===t.MentionType.USERS&&(e.mentionedUserIds?a=e.mentionedUserIds:e.mentionedUsers&&(a=e.mentionedUsers.map((e=>e.userId)))),this.method=t.APIRequestMethod.POST,this.path=`${t.getChannelApiPathByType(e.channelType)}/${encodeURIComponent(e.channelUrl)}/messages`,this.params=t.deundefined(t.undefineNullProps({message_type:t.MessageType.FILE,user_id:e.userId,files:e.files?ie(e.files):null,url:e.fileUrl,mention_type:e.mentionType,mentioned_user_ids:a,file_name:e.fileName,file_size:e.fileSize,file_type:e.mimeType,data:e.data,custom_type:e.customType,thumbnails:null===(i=e._thumbnails)||void 0===i?void 0:i.map((e=>s.payloadify(e))),require_auth:e.requireAuth,sorted_metaarray:null===(n=e.metaArrays)||void 0===n?void 0:n.map((e=>_.payloadify(e))),push_option:e.pushNotificationDeliveryOption,parent_message_id:e.parentMessageId?e.parentMessageId:null,apple_critical_alert_options:e.appleCriticalAlertOptions?c.payloadify(e.appleCriticalAlertOptions):null,reply_to_channel:e.isReplyToChannel,req_id:e.reqId,poll_id:e.pollId,pin_message:e.isPinnedMessage}))}}class te extends t.WebSocketEventCommand{constructor(e,s,i){var n,a,r,o;super(e,"FILE",i),this.message=i.files&&i.files.length>=2?new K(e,i):new X(e,i);const{sdkState:l}=t.Vault.of(e);this.isMentioned=t.checkIfMentioned(this.message.mentionType,null!==(r=null!==(n=this.message.mentionedUserIds)&&void 0!==n?n:null===(a=this.message.mentionedUsers)||void 0===a?void 0:a.map((e=>e.userId)))&&void 0!==r?r:[],l.userId),this.forceUpdateLastMessage=null!==(o=i.force_update_last_message)&&void 0!==o&&o}}class se extends t.APIResponseCommand{constructor(e,s){var i,n,a,r;super(e,s),this.message=s.files&&s.files.length>=2?new K(e,s):new X(e,s);const{sdkState:o}=t.Vault.of(e);this.isMentioned=t.checkIfMentioned(this.message.mentionType,null!==(a=null!==(i=this.message.mentionedUserIds)&&void 0!==i?i:null===(n=this.message.mentionedUsers)||void 0===n?void 0:n.map((e=>e.userId)))&&void 0!==a?a:[],o.userId),this.forceUpdateLastMessage=null!==(r=s.force_update_last_message)&&void 0!==r&&r}}function ie(e){return e.map((e=>{var i,n;return t.deundefined(t.undefineNullProps({url:J.getPlainUrl(e),file_name:e.fileName,file_type:e.mimeType,file_size:e.fileSize,thumbnails:null===(i=e._thumbnails)||void 0===i?void 0:i.map((e=>s.payloadify(e))),require_auth:null===(n=e._uploadedMetaData)||void 0===n?void 0:n.requireAuth}))}))}var ne;!function(e){e[e.PENDING=0]="PENDING",e[e.UPLOADING=1]="UPLOADING",e[e.UPLOADED=2]="UPLOADED",e[e.SENDING=3]="SENDING",e[e.FAILED=4]="FAILED"}(ne||(ne={}));class ae{constructor(e,{sdkState:s,dispatcher:i,requestQueue:n,onlineDetector:a,cacheContext:r}){this._queueMap=new Map,this._iid=e,this._sdkState=s,this._requestQueue=n,this._cacheContext=r,this._dispatcher=i,this._dispatcher.on((e=>{e instanceof t.ConnectionStateChangeCommand&&(this._connectionState=e.stateType)})),this._onlineDetector=a}get _shouldSendThroughWebSocket(){return this._connectionState===t.ConnectionStateType.CONNECTED||this._connectionState===t.ConnectionStateType.CONNECTING||this._connectionState===t.ConnectionStateType.RECONNECTING}_sendFileMessage(e,s){return t.__awaiter(this,void 0,void 0,(function*(){const t=this._createSendFileMessageRequestParams(e,s);if(this._shouldSendThroughWebSocket){const e=new Z(t),s=yield this._requestQueue.send(e),{message:i}=s.as(te);return i}{const e=new ee(Object.assign(Object.assign({},t),{userId:this._sdkState.userId})),s=yield this._requestQueue.send(e),{message:i}=s.as(se);return i}}))}_createSendFileMessageRequestParams(e,t){const s=Object.assign(Object.assign({},t.params),{channelUrl:e.url,channelType:e.channelType,reqId:t.requestId,url:""});if(t.multipleFileUploadInfo){const e=t.params;s.files=e.fileInfoList}else{const e=t.params;s.url=e.fileUrl,s.requireAuth=e.requireAuth}return s}_resolveMessageQueue(e){var s;return t.__awaiter(this,void 0,void 0,(function*(){const i=this._queueMap.get(e.url);if(i)if(i.isResolving)i.isResolveRequestPending=!0;else{i.isResolving=!0;const n=[];let a=!0;for(const r of i.messageQueue)switch(r.state){case ne.PENDING:case ne.UPLOADING:a=!1,n.push(r);break;case ne.UPLOADED:if(a)try{r.state=ne.SENDING;const s=yield this._sendFileMessage(e,r);r.deferred.resolve(s),yield t.sleep(100)}catch(e){r.deferred.reject(e)}else n.push(r);break;case ne.FAILED:{const e=null!==(s=r.error)&&void 0!==s?s:t.SendbirdError.unknown;r.deferred.reject(e.code===t.SendbirdErrorCode.REQUEST_CANCELED?t.SendbirdError.fileUploadCanceled:e);break}}const r=i.isResolveRequestPending;i.messageQueue=n,i.isResolving=!1,i.isResolveRequestPending=!1,r&&(yield this._resolveMessageQueue(e))}}))}_uploadNextPendingItem(e){var s;return t.__awaiter(this,void 0,void 0,(function*(){const i=this._queueMap.get(e.url);if(i){const n=i.messageQueue.find((e=>e.state===ne.PENDING));if(n){if(n.multipleFileUploadInfo){const{uploadIndex:a,uploadCount:r,requestHandler:o}=n.multipleFileUploadInfo,l=n.params,d=l.fileInfoList[a];t.isFile(d.file)&&!(null===(s=d._uploadedMetaData)||void 0===s?void 0:s.isUploaded)?yield this._tryUploadNextItemAndUpdateItemState(e,i,n):n.state=a<r-1?ne.PENDING:ne.UPLOADED;const u=l.fileInfoList[a],c=n.multipleFileUploadInfo.uploadIndex++;n.multipleFileUploadInfo.isCopy||null==o||o._triggerOnFileUploaded(n.requestId,c,u,n.error)}else{const s=n.params;t.isFile(s.file)?yield this._tryUploadNextItemAndUpdateItemState(e,i,n):(s.thumbnailSizes=[],n.state=ne.UPLOADED)}this._uploadNextPendingItem(e),yield this._resolveMessageQueue(e)}}}))}_tryUploadNextItemAndUpdateItemState(e,s,i){return t.__awaiter(this,void 0,void 0,(function*(){const n=yield this._onlineDetector.isOnline(),{sessionManager:a}=t.Vault.of(this._iid);if(!a.currentUser||!n)return i.error=t.SendbirdError.connectionRequired,void(i.state=ne.FAILED);if(s.uploadQueue.length<6){i.state=ne.UPLOADING,s.uploadQueue.push(i);try{if(i.multipleFileUploadInfo){const{uploadIndex:t,uploadCount:s}=i.multipleFileUploadInfo,n=i.params;yield this._uploadNextFileForMultipleFilesItemAndUpdateParams(e,i,n),i.state=t<s-1?ne.PENDING:ne.UPLOADED}else{const t=i.params;yield this._uploadNextFileForSingleFileItemAndUpdateParams(e,i,t),i.state=ne.UPLOADED}}catch(e){switch(e.code){case t.SendbirdErrorCode.REQUEST_FAILED:i.error=new t.SendbirdError({code:t.SendbirdErrorCode.NETWORK_ERROR,message:"Failed to upload a file."});break;case t.SendbirdErrorCode.REQUEST_CANCELED:i.error=t.SendbirdError.fileUploadCanceled;break;default:i.error=e}i.state=ne.FAILED}this._dequeueUploadItem(s,i)}}))}_dequeueUploadItem(e,t){const s=e.uploadQueue.findIndex((e=>e.requestId===t.requestId));s>=0&&e.uploadQueue.splice(s,1)}_uploadNextFileForSingleFileItemAndUpdateParams(e,s,a){var r,o,l;return t.__awaiter(this,void 0,void 0,(function*(){const t=new i({file:a.file,channelUrl:e.url,thumbnailSizes:a.thumbnailSizes,requestId:s.requestId}),d=yield this._requestQueue.send(t),{url:u,fileSize:c=a.fileSize,thumbnails:h=[],requireAuth:p=!1}=d.as(n);a.fileName=null!==(r=a.fileName)&&void 0!==r?r:a.file.name,a.mimeType=null!==(o=a.mimeType)&&void 0!==o?o:a.file.type,a.fileSize=null!==(l=a.fileSize)&&void 0!==l?l:a.file.size,a.fileUrl=u,a.fileSize=c,a.requireAuth=p,a._thumbnails=h}))}_uploadNextFileForMultipleFilesItemAndUpdateParams(e,s,a){var r,o,l;return t.__awaiter(this,void 0,void 0,(function*(){const{uploadIndex:t}=s.multipleFileUploadInfo,d=a.fileInfoList[t],u=new i({file:d.file,channelUrl:e.url,thumbnailSizes:d.thumbnailSizes,requestId:s.requestId}),c=yield this._requestQueue.send(u),{url:h,fileSize:p=d.fileSize,thumbnails:m,requireAuth:_=!1}=c.as(n);d.fileName=null!==(r=d.fileName)&&void 0!==r?r:d.file.name,d.mimeType=null!==(o=d.mimeType)&&void 0!==o?o:d.file.type,d.fileSize=null!==(l=d.fileSize)&&void 0!==l?l:d.file.size,d.file=void 0,d.fileUrl=h,d.fileSize=p,d._thumbnails=m,d._uploadedMetaData=Object.assign(Object.assign({},d._uploadedMetaData),{requireAuth:_,isUploaded:!0}),d instanceof J||(a.fileInfoList[t]=new J(this._iid,d))}))}request(e,s,i,n={}){return t.__awaiter(this,void 0,void 0,(function*(){if(!this._queueMap.has(e.url)){const t={messageQueue:[],uploadQueue:[],isResolving:!1,isResolveRequestPending:!1};this._queueMap.set(e.url,t)}const a=this._queueMap.get(e.url),r=new t.Deferred,o={requestId:s,params:i,state:ne.PENDING,deferred:r};if(function(e){return"fileInfoList"in e}(i)){const e=i,t=Ob