UNPKG

django-rest-messaging-js

Version:

Javascript consumer for django-rest-messaging and django-rest-messaging-centrifugo

2 lines 42.8 kB
var DjangoRestMessaging=function(e){function t(i){if(s[i])return s[i].exports;var n=s[i]={exports:{},id:i,loaded:!1};return e[i].call(n.exports,n,n.exports,t),n.loaded=!0,n.exports}var s={};return t.m=e,t.c=s,t.p="",t(0)}([function(e,t,s){var i={MessagesForm:s(21),MessagesFormDefaultInput:s(8),MessagesList:s(22),MessagesListRowDefaultLayout:s(9),MessagesLoadMore:s(23),MessagesManager:s(24),NotificationsCounter:s(25),ThreadsCreateLink:s(28),ThreadsForm:s(29),ThreadsFormDefaultRecipientRow:s(10),ThreadsFormDefaultRecipientSelectedBagde:s(11),ThreadsFormSelectableRecipients:s(12),ThreadsFormSelectedRecipients:s(13),ThreadsFormSelectedRecipientsSave:s(14),ThreadsList:s(30),ThreadsListRowDefaultLayout:s(15),ThreadsLoadMore:s(31),ThreadsQuit:s(32),ajaxRequest:s(7),MessageStore:s(2),MessageQueries:s(6),adapters:s(4),listeners:s(19),users:s(5),utils:s(20)};e.exports=i},function(e,t){e.exports=React},function(e,t,s){var i,n,r=s(18),a=s(38).EventEmitter,o=s(37),c=s(17),l=s(6),h=s(16),p=null,u={id:null,name:null,participants:[]},d=h.extend(!0,{},u),g={results:[],next:null,previous:null,count:0},f=h.extend(!0,{},g),m={results:[],next:null,previous:null,count:0},T=[],S=null,v=[],C=null,E=o({},a.prototype,{getLoggedInParticipantId:function(){return p},setLoggedInParticipantId:function(e){p=e,this.callbackDispatch(c.MESSAGES_SET_LOGIN_STATUS,e)},checkIfAuthenticated:function(){var e=this;l.checkIfAuthenticated().done(function(t){e.setLoggedInParticipantId(t.id)})},addLoginStatusChangeListener:function(e){this.on(c.MESSAGES_SET_LOGIN_STATUS,e)},removeLoginStatusChangeListener:function(e){this.removeListener(c.MESSAGES_SET_LOGIN_STATUS,e)},getCurrentThread:function(){return d},_updateCurrentThread:function(e){d=e,this.callbackDispatch(c.MESSAGES_THREAD_INFO_UPDATED,e)},setCurrentThread:function(e){var t=this;this.getCurrentThread().id!=e&&(d.id=e,f=h.extend(!0,{},g),l.retrieveThread(e).done(function(e){t._updateCurrentThread(e),t.queryMessagesInThread(e.id,null),l.markAsRead(e.id)}))},initializeNewThread:function(){d=h.extend(!0,{},u),d.id=0,f=h.extend(!0,{},g),this.callbackDispatch(c.MESSAGES_THREAD_INFO_UPDATED,d),this.callbackDispatch(c.MESSAGES_CURRENT_THREAD_UPDATED,f)},createThread:function(e,t){var s=this;return l.createThread(e,t).done(function(e){s.setCurrentThread(e.id)})},addThreadParticipants:function(e,t){var s=this;l.addParticipantsToThread(e,t).done(function(e){e.id==s.getCurrentThread().id&&s._updateCurrentThread(e)})},removeThreadParticipant:function(e,t){var s=this;l.removeParticipantFromThread(e,t).done(function(e){e.id==s.getCurrentThread().id&&s._updateCurrentThread(e)})},getCurrentThreadPaginatedMessages:function(){return f},queryMessagesInThread:function(e,t){var s=this;l.listMessagesInThread(e,t).done(function(e){s.setMessagesInThread(e)})},_handleMessagesResults:function(e,t,s){var i=e.map(function(e){return e.id});return e&&e.length>0?h.each(t,function(t,s){-1===h.inArray(s.id,i)&&e.push(s)}):e=t,"ascending"==s?e.sort(function(e,t){return e.id>t.id}):e.sort(function(e,t){return e.id<t.id})},setMessagesInThread:function(e){f.results=this._handleMessagesResults(f.results,e.results,"ascending"),f.next=e.next,f.previous=e.previous,f.count=e.count,this.callbackDispatch(c.MESSAGES_CURRENT_THREAD_UPDATED,e)},setSingleMessagesInThread:function(e){var t=f.results.map(function(e,t){return e.id});e.thread==this.getCurrentThread().id&&-1===h.inArray(e.id,t)&&(f.results.push(e),f.count=f.count+1),this.callbackDispatch(c.MESSAGES_CURRENT_THREAD_UPDATED,e)},addThreadInfoChangeListener:function(e){this.on(c.MESSAGES_THREAD_INFO_UPDATED,e)},removeThreadInfoChangeListener:function(e){this.removeListener(c.MESSAGES_THREAD_INFO_UPDATED,e)},addThreadChangeListener:function(e){this.on(c.MESSAGES_CURRENT_THREAD_UPDATED,e)},removeThreadChangeListener:function(e){this.removeListener(c.MESSAGES_CURRENT_THREAD_UPDATED,e)},getLastMessageOfAllThreads:function(){return m},queryLastMessageOfAllThreads:function(e){var t=this;l.listLastMessagesOfAllThreads(e).done(function(e){t.setLastMessageOfAllThreads(e)})},setLastMessageOfAllThreads:function(e){m.results=this._handleMessagesResults(m.results,e.results,"descending"),m.next=e.next,m.previous=e.previous,m.count=e.count,this.setNotificationsThreadsIds(m),this.callbackDispatch(c.MESSAGES_ALL_THREADS_UPDATED,e)},setSingleMessagesInLastThreads:function(e){for(var t=0;t<m.results.length;t++)m.results[t].thread==e.thread&&(e.readers=[],m.results[m.results.indexOf(m.results[t])]=e,m.results.sort(function(e,t){return e.id<t.id}));this.setNotificationsThreadsIds(m),this.callbackDispatch(c.MESSAGES_ALL_THREADS_UPDATED,e)},addLastMessageOfAllThreadsChangeListener:function(e){this.on(c.MESSAGES_ALL_THREADS_UPDATED,e)},removeLastMessageOfAllThreadsChangeListener:function(e){this.removeListener(c.MESSAGES_ALL_THREADS_UPDATED,e)},addSingleMessage:function(e){this.setSingleMessagesInThread(e),this.setSingleMessagesInLastThreads(e)},postMessage:function(e,t){return _this=this,l.postMessage(e,t).done(function(e){_this.addSingleMessage(e)})},getThreadForm:function(){return S},setThreadForm:function(e){S=e,this.callbackDispatch(c.MESSAGES_NEW_THREAD_FORM_UPDATED,e)},submitThreadForm:function(){return S.saveThreadWithRecipients()},addNewThreadFormChangeListener:function(e){this.on(c.MESSAGES_NEW_THREAD_FORM_UPDATED,e)},removeNewThreadFormChangeListener:function(e){this.removeListener(c.MESSAGES_NEW_THREAD_FORM_UPDATED,e)},getNotificationsCount:function(){return T.length},_pushToNotificationsThreadsIds:function(e){-1==T.indexOf(e.thread)&&e.sender!=this.getLoggedInParticipantId()&&T.push(e.thread)},setNotificationsThreadsIds:function(e){if(e.hasOwnProperty("results"))for(var t=0;t<e.results.length;t++)1==e.results[t].is_notification&&e.results[t].sender!=this.getLoggedInParticipantId()&&this._pushToNotificationsThreadsIds(e.results[t]);else e.hasOwnProperty("is_notification")&&1==e.is_notification&&e.sender!=this.getLoggedInParticipantId()&&this._pushToNotificationsThreadsIds(e)},_removeNotificationStatus:function(e){e.is_notification=!1},_iterateAllMessagesWithNotificationStatus:function(e){for(var t=!1,s=0;s<e.length;s++)1==e[s].is_notification&&(this._removeNotificationStatus(e[s]),t=!0);return t},notificationsChecked:function(){return _this=this,l.notificationsChecked().done(function(e){var t=_this._iterateAllMessagesWithNotificationStatus(f.results);1==t&&_this.callbackDispatch(c.MESSAGES_CURRENT_THREAD_UPDATED,f);var s=_this._iterateAllMessagesWithNotificationStatus(m.results);1==s&&_this.callbackDispatch(c.MESSAGES_ALL_THREADS_UPDATED,m),T=[]})},getRecipients:function(e){return v},setRecipients:function(e){v=e,this.callbackDispatch(c.MESSAGES_POTENTIAL_RECIPIENTS_UPDATED,e)},addRecipientsListener:function(e){this.on(c.MESSAGES_POTENTIAL_RECIPIENTS_UPDATED,e)},removeRecipientsListener:function(e){this.removeListener(c.MESSAGES_POTENTIAL_RECIPIENTS_UPDATED,e)},getlastQuitThreadId:function(){return C},quitCurrentThread:function(e){return e?(_this=this,l.removeParticipantFromThread(e,this.getLoggedInParticipantId()).done(function(t){d=h.extend(!0,{},u),f=h.extend(!0,{},g);for(var s=null,i=0;i<m.results.length;i++)if(m.results[i].thread==e){s=m.results.indexOf(m.results[i]);break}null!=s&&(m.results.splice(s,1),m.count=m.count-1),C=e,_this.callbackDispatch(c.MESSAGES_THREAD_INFO_UPDATED,d),_this.callbackDispatch(c.MESSAGES_CURRENT_THREAD_UPDATED,f),_this.callbackDispatch(c.MESSAGES_ALL_THREADS_UPDATED,m),_this.callbackDispatch(c.MESSAGES_THREAT_QUIT,e)})):void 0},addThreadQuitListener:function(e){this.on(c.MESSAGES_THREAT_QUIT,e)},removeThreadQuitListener:function(e){this.removeListener(c.MESSAGES_THREAT_QUIT,e)},emitChange:function(e){this.emit(e),this.setLastEmit(e)},getLastEmit:function(){return i},setLastEmit:function(e){i=e},getLastDispatchedAction:function(){return n},setLastDispatchedAction:function(e){n=e},callbackDispatch:function(e,t){r.dispatch({actionType:e,data:t}),this.setLastDispatchedAction(e),this.emitChange(e)}});E.dispatchToken=r.register(function(e){switch(e.actionType){case c.MESSAGES_SET_LOGIN_STATUS:break;default:return!0}return!0}),e.exports=E},function(e,t,s){var i=(s(1),s(2)),n={getInitialState:function(){return{loggedInParticipantId:i.getLoggedInParticipantId()}},componentDidMount:function(){i.addLoginStatusChangeListener(this.onChangeAuth)},componentWillUnmount:function(){i.removeLoginStatusChangeListener(this.onChangeAuth)},onChangeAuth:function(){this.setState({loggedInParticipantId:i.getLoggedInParticipantId()})}},r={getInitialState:function(){return{currentThread:i.getCurrentThread()}},componentDidMount:function(){i.addThreadInfoChangeListener(this.onChangeThread)},componentWillUnmount:function(){i.removeThreadInfoChangeListener(this.onChangeThread)},onChangeThread:function(){this.setState({currentThread:i.getCurrentThread()})}},a={getInitialState:function(){return{newthreadForm:i.getThreadForm()}},componentDidMount:function(){i.addNewThreadFormChangeListener(this.onChangeThreadForm)},componentWillUnmount:function(){i.removeNewThreadFormChangeListener(this.onChangeThreadForm)},onChangeThreadForm:function(){this.setState({newthreadForm:i.getThreadForm()})}},o={getInitialState:function(){return{messagesResultSet:i.getCurrentThreadPaginatedMessages()}},componentDidMount:function(){i.addThreadChangeListener(this.onChangeMessageList)},componentWillUnmount:function(){i.addThreadChangeListener(this.onChangeMessageList)},onChangeMessageList:function(){this.setState({messagesResultSet:i.getCurrentThreadPaginatedMessages()})}},c={getInitialState:function(){return{recipients:i.getRecipients()}},componentDidMount:function(){i.addRecipientsListener(this.onChangeRecipients)},componentWillUnmount:function(){i.removeRecipientsListener(this.onChangeRecipients)},onChangeRecipients:function(){this.setState({recipients:i.getRecipients()})}},l={getInitialState:function(){return{lastMessagesResultSet:i.getLastMessageOfAllThreads()}},componentDidMount:function(){i.addLastMessageOfAllThreadsChangeListener(this.onChangeLastMessageList)},componentWillUnmount:function(){i.removeLastMessageOfAllThreadsChangeListener(this.onChangeLastMessageList)},onChangeLastMessageList:function(){this.setState({lastMessagesResultSet:i.getLastMessageOfAllThreads()})}},h={LoginMixin:n,CurrentThreadMixin:r,NewThreadFormMixin:a,MessagesResultSetMixin:o,RecipientsMixin:c,LastMessageOfAllThreadsMixin:l};e.exports=h},function(e,t){var s={id:"id",image:"image",username:"username"},i={defaultParticipantAdapter:s};e.exports=i},function(e,t,s){var i=s(4),n=i.defaultParticipantAdapter,r=function(e,t,s){s||(s=n);var i={id:null,image:null,username:null};if(!e||e.length<1)return i;for(var r=0;r<e.length;r++)if(e[r][s.id]==t){for(var a in s)s.hasOwnProperty(a)&&(i[a]=e[r][s[a]]);break}return i},a={getUserInfo:r};e.exports=a},function(e,t,s){var i=s(7),n={listMessagesInThread:function(e,t){return t?i(t,"GET",null):i("/messaging/messages/"+e+"/list_messages_in_thread/","GET",null)},listLastMessagesOfAllThreads:function(e){return e?i(e,"GET",null):i("/messaging/messages/","GET",null)},postMessage:function(e,t){return i("/messaging/messages/"+e+"/post_message/","POST",{body:t})},retrieveThread:function(e){return i("/messaging/threads/"+e+"/","GET",null)},createThread:function(e,t){return i("/messaging/threads/","POST",{name:e,participants:JSON.stringify(t)})},updateThread:function(e,t){return i("/messaging/threads/"+e+"/","PUT",{name:t})},addParticipantsToThread:function(e,t){return i("/messaging/threads/"+e+"/add_participants/","POST",{participants:JSON.stringify(t)})},removeParticipantFromThread:function(e,t){return i("/messaging/threads/"+e+"/remove_participant/","POST",{participant:t})},markAsRead:function(e){return i("/messaging/threads/"+e+"/mark_thread_as_read/","POST",{})},notificationsChecked:function(){return i("/messaging/notifications/check/","POST",{})},getCentrifugeToken:function(){return i("/messaging/centrifugo/authentication/","POST",{})},checkIfAuthenticated:function(){return i("/messaging/authentication/","GET",null)}};e.exports=n},function(e,t,s){function i(e){var t=null;if(document.cookie&&""!=document.cookie)for(var s=document.cookie.split(";"),i=0;i<s.length;i++){var n=o.trim(s[i]);if(n.substring(0,e.length+1)==e+"="){t=decodeURIComponent(n.substring(e.length+1));break}}return t}function n(e){return/^(GET|HEAD|OPTIONS|TRACE)$/.test(e)}function r(e,t,s){return{url:e,type:t,dataType:"json",contentType:"application/json",data:JSON.stringify(s),beforeSend:function(e,t){var s=i("csrftoken");n(t.type)||this.crossDomain||e.setRequestHeader("X-CSRFToken",s)}}}function a(e,t,s,i){return o.ajax(r(e,t,s))}var o=s(16);e.exports=a},function(e,t,s){var i=s(1),n=i.createClass({displayName:"MessagesFormDefaultInput",getDefaultProps:function(){return{formSubmitClass:"btn btn-primary messageFormSubmit",formSubmitIClass:"glyphicon glyphicon-pencil",formSubmitText:"",formInputClass:"form-control messageFormInput",disabled:!1}},render:function(){return i.createElement("div",{className:"row"},i.createElement("div",{className:"col-md-10"},i.createElement("input",{type:"text",className:this.props.formInputClass,defaultValue:this.props.text,value:this.props.text,onChange:this.props.handleTextChange})),i.createElement("div",{className:"col-md-2"},i.createElement("button",{onClick:this.props.handleSubmit,className:this.props.formSubmitClass,disabled:this.props.disabled},i.createElement("i",{className:this.props.formSubmitIClass}))))}});e.exports=n},function(e,t,s){var i=s(1),n=s(5),r=n.getUserInfo,a=s(39),o=i.createClass({displayName:"MessagesListRowDefaultLayout",render:function(){if(this.props.sentByCurrentParticipant)var e="messageList messageSentByCurrentParticipant";else var e="messageList messageSentByOtherParticipant";var t=r(this.props.recipients,this.props.message.sender,this.props.participantAdapter);return i.createElement("div",{className:e},i.createElement("div",{className:"messageListCore"},i.createElement("img",{src:t.image,className:"messageListLayoutImage"}),i.createElement("span",{className:"messageListLayoutBody"},this.props.message.body)),i.createElement("div",{className:"messageListLayoutDate"},t.username,", ",a(this.props.message.sent_at).format("MMMM Do YYYY, h:mm:ss a")))}});e.exports=o},function(e,t,s){var i=s(1),n=i.createClass({displayName:"ThreadsFormDefaultRecipientRow",render:function(){return i.createElement("div",{onClick:this.props.addRecipient.bind(null,this.props.recipient),className:"selectableRecipient"},this.props.recipient.username)}});e.exports=n},function(e,t,s){var i=s(1),n=i.createClass({displayName:"ThreadsFormDefaultRecipientSelectedBagde",render:function(){return this.props.currentThread&&this.props.currentThread.participants&&-1!==this.props.currentThread.participants.indexOf(this.props.recipient.id)?i.createElement("span",{className:"recipientBadge"},this.props.recipient.username):i.createElement("span",{className:"recipientBadge"},this.props.recipient.username," ",i.createElement("i",{onClick:this.props.removeRecipient.bind(null,this.props.recipient),className:"removeRecipientBadge"},"x"))}});e.exports=n},function(e,t,s){var i=s(1),n=i.createClass({displayName:"ThreadsFormSelectableRecipients",render:function(){return this.props.currentThread&&null!=this.props.currentThread.id&&this.props.currentThread.id>=0?i.createElement("div",{className:this.props.recipientsSelectableClassName,style:this.props.recipientsSelectableStyle},i.createElement("input",{type:"text",className:this.props.recipientsFilterClass,onChange:this.props.filterRecipients,placeholder:this.props.recipientsPlaceholder}),this.props.recipientsSelectable&&this.props.recipientsSelectable.map(function(e,t){return i.createElement(this.props.recipientsRowLayout,{recipient:e,key:t,addRecipient:this.props.addRecipient,recipientsAdditionalInfo:this.props.recipientsAdditionalInfo,recipientsRowStyle:this.props.recipientsRowStyle})},this)):i.createElement("span",null)}});e.exports=n},function(e,t,s){var i=s(1),n=s(14),r=i.createClass({displayName:"ThreadsFormSelectedRecipients",render:function(){return i.createElement("div",{className:this.props.recipientsSelectedClassName,style:this.props.recipientsSelectedStyle},this.props.recipientsSelected&&this.props.recipientsSelected.map(function(e,t){return i.createElement(this.props.recipientsBadgeLayout,{recipient:e,key:t,removeRecipient:this.props.removeRecipient,currentThread:this.props.currentThread})},this),i.createElement(n,{recipientsSelected:this.props.recipientsSelected,currentThread:this.props.currentThread,saveRecipients:this.props.saveRecipients,saveRecipientsClassName:this.props.saveRecipientsClassName}))}});e.exports=r},function(e,t,s){var i=s(1),n=i.createClass({displayName:"ThreadsFormSelectedRecipientsSave",render:function(){return this.props.currentThread.id&&0!=this.props.currentThread.id&&this.props.recipientsSelected.length>this.props.currentThread.participants.length?i.createElement("button",{onClick:this.props.saveRecipients,className:this.props.saveRecipientsClassName},"Save"):i.createElement("span",null)}});e.exports=n},function(e,t,s){var i=s(1),n=s(5),r=n.getUserInfo,a=i.createClass({displayName:"ThreadsListRowDefaultLayout",render:function(){if(this.props.message&&this.props.message.body&&this.props.message.body.length>70)var e=this.props.message.body.substring(0,70)+" ...";else var e=this.props.message.body;var t=r(this.props.recipients,this.props.message.sender,this.props.participantAdapter),s="";1==this.props.message.is_notification&&(s="threadIsNotification");var n="";return this.props.message.readers&&-1==this.props.message.readers.indexOf(this.props.loggedInParticipantId)&&this.props.message.thread!=this.props.currentThread.id&&this.props.message.sender!=this.props.loggedInParticipantId&&(n="threadIsUnread"),this.props.loggedInParticipantId?i.createElement("div",{className:"threadListLayout "+s+" "+n,onClick:this.props.onClickThreadSelected},i.createElement("img",{src:t.image,className:"threadListLayoutImage"}),i.createElement("span",{className:"threadListLayoutBody"},e)):void 0}});e.exports=a},function(e,t){e.exports=$},function(e,t,s){var i=s(36);e.exports=i({MESSAGES_SET_LOGIN_STATUS:null,MESSAGES_CURRENT_THREAD_UPDATED:null,MESSAGES_ALL_THREADS_UPDATED:null,MESSAGES_ONE_THREAD_UPDATED:null,MESSAGES_NOTIFICATIONS_COUNT_UPDATED:null,MESSAGES_THREAD_INFO_UPDATED:null,MESSAGES_POTENTIAL_RECIPIENTS_UPDATED:null,MESSAGES_NEW_THREAD_FORM_UPDATED:null,MESSAGES_THREAT_QUIT:null})},function(e,t,s){var i=s(33).Dispatcher,n=new i;e.exports=n},function(e,t,s){var i=s(2),n=function(e){i.setLoggedInParticipantId(e)},r=function(){i.setLoggedInParticipantId(null)},a=function(e){i.setRecipients(e)},o={loginListener:n,logoutListener:r,recipientsListener:a};e.exports=o},function(e,t){var s=function(e){e=e||{};for(var t=1;t<arguments.length;t++){var i=arguments[t];if(i)for(var n in i)i.hasOwnProperty(n)&&("object"==typeof i[n]?e[n]=s(e[n],i[n]):e[n]=i[n])}return e},i={deepExtend:s};e.exports=i},function(e,t,s){var i=s(1),n=s(2),r=s(8),a=s(3),o=i.createClass({displayName:"MessagesForm",mixins:[a.LoginMixin,a.CurrentThreadMixin,a.NewThreadFormMixin],getDefaultProps:function(){return{disableWhenNoThread:!0,preSubmitCallback:null,wrappingTag:"div",wrappingClass:"messagesMessagesForm",wrappingStyle:{},formInput:r,formInputClass:"form-control messageFormInput",formSubmitClass:"btn btn-primary col-md-12 messageFormSubmit",formSubmitIClass:"glyphicon glyphicon-pencil",formSubmitText:""}},componentWillMount:function(){this.setState({text:""})},render:function(){if(this.state.currentThread&&0==this.state.currentThread.id&&1==this.props.disableWhenNoThread&&this.state.newthreadForm&&this.state.newthreadForm.state.recipientsSelected&&this.state.newthreadForm.state.recipientsSelected.length<1)var e=!0;else var e=!1;return null!=this.state.loggedInParticipantId&&null!=this.state.currentThread.id?i.createElement(this.props.wrappingTag,{className:this.props.wrappingClass,style:this.props.wrappingStyle},i.createElement(this.props.formInput,{formInputClass:this.props.formInputClass,formSubmitClass:this.props.formSubmitClass,formSubmitIClass:this.props.formSubmitIClass,text:this.state.text,handleTextChange:this.handleTextChange,handleSubmit:this.handleSubmit,disabled:e})):i.createElement("div",{className:"messagesMessagesFormUnactivated"})},handleTextChange:function(e){this.setState({text:e.target.value})},getText:function(){if(this.state.text)var e=this.state.text.trim();else var e="";return e},handleSubmit:function(e){e.preventDefault();var t=this.getText(),s=this;t.length<1||(this.state.currentThread&&this.state.currentThread.id>0?n.postMessage(this.state.currentThread.id,t).done(function(e){s.setState({text:""})}):this.state.currentThread&&0==this.state.currentThread.id&&n.submitThreadForm().done(function(e){n.postMessage(e.id,t).done(function(e){s.setState({text:""}),n.queryLastMessageOfAllThreads(null)})}))}});e.exports=o},function(e,t,s){var i=s(1),n=(s(2),s(9)),r=s(3),a=s(4),o=i.createClass({displayName:"MessagesList",mixins:[r.LoginMixin,r.MessagesResultSetMixin,r.RecipientsMixin],getDefaultProps:function(){return{wrappingTag:"div",wrappingClass:"messagesMessagesList",wrappingStyle:{},layoutForListRows:n,layoutAdditionnalInfo:{},layoutStyle:{},participantAdapter:a.defaultParticipantAdapter}},render:function(){return null!=this.state.loggedInParticipantId?i.createElement(this.props.wrappingTag,{className:this.props.wrappingClass,style:this.props.wrappingStyle},this.state.messagesResultSet&&this.state.messagesResultSet.results.map(function(e,t){return i.createElement(this.props.layoutForListRows,{sentByCurrentParticipant:e.sender==this.state.loggedInParticipantId,recipients:this.state.recipients,message:e,key:t,layoutAdditionnalInfo:this.props.layoutAdditionnalInfo,layoutStyle:this.props.layoutStyle})},this)):i.createElement(this.props.wrappingTag,{className:"messagesMessagesListUnauthenticated"})}});e.exports=o},function(e,t,s){function i(){return{currentThread:r.getCurrentThread()}}var n=s(1),r=s(2),a=s(3),o=n.createClass({displayName:"MessagesLoadMore",mixins:[a.LoginMixin,a.MessagesResultSetMixin],getDefaultProps:function(){return{wrappingTag:"button",wrappingClass:"messagesMessagesLoadMore btn btn-default btn-sm col-md-12",wrappingStyle:{},loadText:"Load more ..."}},getInitialState:function(){return i()},componentDidMount:function(){r.addThreadInfoChangeListener(this.onChangeThread)},componentWillUnmount:function(){r.removeThreadInfoChangeListener(this.onChangeThread)},render:function(){return this.state.currentThread&&this.state.currentThread.id&&this.state.messagesResultSet&&this.state.messagesResultSet.next?n.createElement(this.props.wrappingTag,{className:this.props.wrappingClass,style:this.props.wrappingStyle,onClick:this.queryNext},this.props.loadText):n.createElement("span",{className:"messagesLoadMoreUnactivated"})},onChangeThread:function(){this.setState({currentThread:r.getCurrentThread(),currentThreadPaginatedMessages:r.getCurrentThreadPaginatedMessages()})},queryNext:function(){r.queryMessagesInThread(this.state.currentThread.id,this.state.messagesResultSet.next)}});e.exports=o},function(e,t,s){var i,n,r=s(1),a=s(2),o=s(6),c=s(3),l=[],h=r.createClass({displayName:"MessagesManager",mixins:[c.LoginMixin,c.CurrentThreadMixin],getDefaultProps:function(){return{listInterval:6e4}},componentDidMount:function(){a.checkIfAuthenticated(),a.addThreadQuitListener(this.onThreadQuit)},componentWillUnmount:function(){a.removeThreadQuitListener(this.onThreadQuit)},componentWillUpdate:function(e,t){if(t.loggedInParticipantId&&t.loggedInParticipantId!=this.state.loggedInParticipantId){this.queryLastMessageOfAllThreads();var s=this.startTimer;this.connectToCentrifugo(s)}else this.state.timer&&this.stopTimer()},queryLastMessageOfAllThreads:function(){a.queryLastMessageOfAllThreads(null)},startTimer:function(){var e=this;n=setInterval(e.update,e.props.listInterval)},stopTimer:function(){clearInterval(n)},connectToCentrifugo:function(e,t){var s=this;o.getCentrifugeToken().done(function(e){var t=e.channels;s.initCentrifuge(e.connection_url,e.user,e.timestamp,e.token,e.debug,t),i.connect()}).fail(function(e){t(e)})},subscribeToChannelMessage:function(e){var t=i.subscribe(e,function(e){e.data&&a.addSingleMessage(e.data)});return l.push([e,t]),t},subscribeToChannelThread:function(e){var t=this,s=i.subscribe(e,function(e){e.data&&(t.subscribeToChannel(e.data.message_channel_to_connect_to),t.queryLastMessageOfAllThreads())});return s},subscribeToChannel:function(e){if(e.indexOf("message")>-1)var t=this.subscribeToChannelMessage(e);else if(e.indexOf("thread")>-1)var t=this.subscribeToChannelThread(e);t.on("ready",function(){t.presence(function(e){})}),t.on("join",function(e){}),t.on("leave",function(e){})},initCentrifuge:function(e,t,s,n,r,a){i=new Centrifuge({url:e,user:t,timestamp:s,token:n,debug:r}),a=a;var o=this;i.on("connect",function(){for(var e=0;e<a.length;e++)o.subscribeToChannel(a[e])}),i.on("error",function(e){}),i.on("disconnect",function(e){})},update:function(){this.queryLastMessageOfAllThreads(),this.state.currentThread&&this.state.currentThread.id&&a.queryMessagesInThread(this.state.currentThread.id)},onThreadQuit:function(){for(var e=a.getlastQuitThreadId(),t=0;t<l.length;t++)l[t][0].indexOf("messages:"+e)>-1},render:function(){return r.createElement("span",null)}});e.exports=h},function(e,t,s){function i(){return{notificationsCount:r.getNotificationsCount()}}var n=s(1),r=s(2),a=s(27),o=s(26),c=s(3),l=n.createClass({displayName:"NotificationsCounter",mixins:[c.LoginMixin,c.CurrentThreadMixin],getDefaultProps:function(){return{iconClass:"fa fa-envelope fa-lg",iconNullDefault:a,iconDefault:o}},getInitialState:function(){return i()},componentDidMount:function(){r.addLastMessageOfAllThreadsChangeListener(this.onChangeMessageList)},componentWillUnmount:function(){r.removeLastMessageOfAllThreadsChangeListener(this.onChangeMessageList)},render:function(){return null!=this.state.loggedInParticipantId?this.state.notificationsCount<1?n.createElement(this.props.iconNullDefault,{classNameNotification:"notificationCounter",iconClass:this.props.iconClass,notificationsCount:this.state.notificationsCount}):n.createElement(this.props.iconDefault,{classNameNotification:"notificationCounter",iconClass:this.props.iconClass,notificationsCount:this.state.notificationsCount,notificationsChecked:this.notificationsChecked}):n.createElement("span",{className:"notificationsUnactivated"})},onChangeMessageList:function(){this.setState({notificationsCount:r.getNotificationsCount()})},notificationsChecked:function(){var e=this;r.notificationsChecked().done(function(t){e.setState({notificationsCount:r.getNotificationsCount()})})}});e.exports=l},function(e,t,s){var i=s(1),n=i.createClass({displayName:"NotificationsCounterDefault",getDefaultProps:function(){return{iconClass:"fa fa-envelope fa-lg"}},render:function(){return i.createElement("span",{className:this.props.classNameNotification,onClick:this.props.notificationsChecked},i.createElement("i",{className:this.props.iconClass+" notificationCounterPositiveIcon"}),i.createElement("span",{className:"notificationCounterPositiveCount"},this.props.notificationsCount))}});e.exports=n},function(e,t,s){var i=s(1),n=i.createClass({displayName:"NotificationsCounterNullDefault",getDefaultProps:function(){return{iconClass:"fa fa-envelope fa-lg"}},render:function(){return i.createElement("span",{className:this.props.classNameNotification},i.createElement("i",{className:this.props.iconClass}))}});e.exports=n},function(e,t,s){var i=s(1),n=s(2),r=s(3),a=i.createClass({displayName:"ThreadsCreateLink",mixins:[r.LoginMixin],render:function(){return null!=this.state.loggedInParticipantId?i.createElement("a",{href:"#",className:"threadsCreate",onClick:this.initializeNewThread},"Create a new thread"):i.createElement("span",{className:"threadsCreateUnactivated"})},initializeNewThread:function(){n.initializeNewThread()}});e.exports=a},function(e,t,s){function i(){return{currentThread:r.getCurrentThread(),recipients:r.getRecipients()}}var n=s(1),r=s(2),a=s(11),o=s(10),c=s(12),l=s(13),h=s(3),p=s(4),u=s(5),d=u.getUserInfo,g=n.createClass({displayName:"ThreadsForm",mixins:[h.LoginMixin],getDefaultProps:function(){return{wrappingTag:"div",wrappingClass:"messagesThreadsForm",wrappingStyle:{},recipientsIterator:"username",recipientsRowLayout:o,recipientsAdditionalInfo:{},recipientsRowStyle:{},recipientsBadgeLayout:a,recipientsSelectableClassName:"recipientsSelectable",recipientsSelectedClassName:"recipientsSelected",recipientsSelectedStyle:{},recipientsSelectedBagde:a,recipientsPlaceholder:"Filter ...",recipientsFilterClass:"recipientsFilterClass form-control",recipientsEmptyAlertMessage:"Please select recipients",recipientsSelectMessage:"Select recipients:",saveRecipientsClassName:"btn btn-primary btn-sm saveNewRecipient",titleHeader:"Conversation with",recipientsAddToThreadIcon:"glyphicon glyphicon-user addUser",recipientsRemoveFromThreadIcon:"glyphicon glyphicon-remove removeUser",recipientAddToThreadLinkClass:"recipientAddToThreadLink pull-right",participantAdapter:p.defaultParticipantAdapter}},getInitialState:function(){var e=i();return e.currentThread&&0==e.currentThread.id&&this.registerInStore(),e},componentWillUpdate:function(e,t){t.currentThread&&0==t.currentThread.id&&(t.currentThread.id!=this.state.currentThread.id||t.recipientsSelected.length>=0)&&this.registerInStore()},componentWillMount:function(){this.chekSelectableSelected()},componentDidMount:function(){r.addThreadInfoChangeListener(this.onChangeThread),r.addRecipientsListener(this.onChangeRecipients)},componentWillUnmount:function(){r.removeThreadInfoChangeListener(this.onChangeThread),r.removeRecipientsListener(this.onChangeRecipients)},render:function(){var e=this;return null!=this.state.loggedInParticipantId?0==this.state.currentThread.id||1==this.state.showForm?n.createElement(this.props.wrappingTag,{className:this.props.wrappingClass,style:this.props.wrappingStyle},n.createElement("div",{className:"threadFormTitleHeader"},this.props.recipientsSelectMessage,n.createElement("a",{onClick:this.showForm.bind(null,!1),className:this.props.recipientAddToThreadLinkClass},n.createElement("i",{className:this.props.recipientsRemoveFromThreadIcon}))),n.createElement(l,{recipientsSelectedClassName:this.props.recipientsSelectedClassName,recipientsSelectedStyle:this.props.recipientsSelectedStyle,recipientsBadgeLayout:this.props.recipientsBadgeLayout,recipientsSelected:this.state.recipientsSelected,removeRecipient:this.removeRecipient,currentThread:this.state.currentThread,saveRecipients:this.saveRecipients,saveRecipientsClassName:this.props.saveRecipientsClassName}),n.createElement(c,{recipientsSelectableClassName:this.props.recipientsSelectableClassName,recipientsSelectableStyle:this.props.recipientsSelectableStyle,recipientsFilterClass:this.props.recipientsFilterClass,filterRecipients:this.filterRecipients,recipientsPlaceholder:this.props.recipientsPlaceholder,recipientsSelectable:this.state.recipientsSelectable,recipientsRowLayout:this.props.recipientsRowLayout,addRecipient:this.addRecipient,recipientsAdditionalInfo:this.props.recipientsAdditionalInfo,recipientsRowStyle:this.props.recipientsRowStyle,currentThread:this.state.currentThread})):this.state.recipientsSelected&&this.state.recipientsSelected.length>1?n.createElement("div",{className:"threadFormTitleHeader page-header"},this.props.titleHeader," ",this.state.recipientsSelected.map(function(t){var s=d(e.state.recipientsSelected,t.id,e.props.participantAdapter);return s.username}).join(", "),".  ",n.createElement("a",{onClick:this.showForm.bind(null,!0),className:this.props.recipientAddToThreadLinkClass},n.createElement("i",{className:this.props.recipientsAddToThreadIcon}))):n.createElement("span",null):n.createElement(this.props.wrappingTag,{className:"messagesThreadsFormUnauthenticated"})},onChangeThread:function(){var e=r.getCurrentThread();this.setState({ currentThread:e}),this.chekSelectableSelected(e)},onChangeRecipients:function(){this.setState({recipients:r.getRecipients()}),this.chekSelectableSelected(this.state.currentThread)},chekSelectableSelected:function(e){var t=[],s=[],i=this;this.state.recipients.map(function(n,r){e&&-1!==e.participants.indexOf(n.id)?t.push(n):i.state.loggedInParticipantId!=n.id&&s.push(n)}),this.setState({recipientsSelected:t,recipientsSelectable:s})},addRecipient:function(e){if(this.state.recipientsSelected){var t=this.state.recipientsSelected;-1===t.indexOf(e)&&(t.push(e),this.setState({recipientsSelected:t}))}else this.setState({recipientsSelected:[e]})},removeRecipient:function(e){if(this.state.recipientsSelected){for(var t=[],s=0;s<this.state.recipientsSelected.length;s++)e.id!=this.state.recipientsSelected[s].id&&t.push(this.state.recipientsSelected[s]);this.state.recipientsSelected.length!=t.length&&this.setState({recipientsSelected:t})}},filterRecipients:function(e){var t=e.target.value,s=this;if(!t||t.trim().length<1)this.setState({recipientsSelectable:this.state.recipients.map(function(e,t){return s.state.loggedInParticipantId!=recipients.id?e:void 0})});else{for(var i=[],n=0;n<this.state.recipients.length;n++)-1!==this.state.recipients[n][this.props.recipientsIterator].search(new RegExp(t,"i"))&&this.state.loggedInParticipantId!=this.state.recipients[n].id&&i.push(this.state.recipients[n]);this.setState({recipientsSelectable:i})}},saveRecipients:function(){if(this.state&&this.state.currentThread&&0!=this.state.currentThread.id){for(var e=[],t=0;t<this.state.recipientsSelected.length;t++)-1===this.state.currentThread.participants.indexOf(this.state.recipientsSelected[t].id)&&e.push(this.state.recipientsSelected[t].id);r.addThreadParticipants(this.state.currentThread.id,e)}},saveThreadWithRecipients:function(){var e=this.state.recipientsSelected.map(function(e,t){return e.id});return r.createThread(null,e)},registerInStore:function(){r.setThreadForm(this)},showForm:function(e){this.setState({showForm:e})}});e.exports=g},function(e,t,s){var i=s(1),n=s(2),r=s(15),a=s(3),o=i.createClass({displayName:"ThreadsList",mixins:[a.LoginMixin,a.CurrentThreadMixin,a.RecipientsMixin,a.LastMessageOfAllThreadsMixin],getDefaultProps:function(){return{wrappingTag:"div",wrappingClass:"messagesThreadsList",wrappingStyle:{},layoutForListRows:r,layoutAdditionnalInfo:{},layoutStyle:{}}},render:function(){return null!=this.state.loggedInParticipantId?i.createElement(this.props.wrappingTag,{className:this.props.wrappingClass,style:this.props.wrappingStyle},this.state.lastMessagesResultSet&&this.state.lastMessagesResultSet.results.map(function(e,t){return i.createElement(this.props.layoutForListRows,{message:e,key:t,onClickThreadSelected:this.onClickThreadSelected.bind(null,e.thread),layoutAdditionnalInfo:this.props.layoutAdditionnalInfo,layoutStyle:this.props.layoutStyle,recipients:this.state.recipients,loggedInParticipantId:this.state.loggedInParticipantId,currentThread:this.state.currentThread})},this)):i.createElement(this.props.wrappingTag,{className:"messagesThreadsListUnauthenticated"})},onClickThreadSelected:function(e){n.setCurrentThread(e)},notificationsChecked:function(){n.notificationsChecked()}});e.exports=o},function(e,t,s){var i=s(1),n=s(2),r=s(3),a=i.createClass({displayName:"ThreadsLoadMore",mixins:[r.LoginMixin,r.LastMessageOfAllThreadsMixin],getDefaultProps:function(){return{wrappingTag:"button",wrappingClass:"messagesThreadsLoadMore btn btn-default btn-sm col-md-12",wrappingStyle:{},loadText:"Load more ..."}},render:function(){return this.state.loggedInParticipantId&&this.state.lastMessagesResultSet&&this.state.lastMessagesResultSet.next?i.createElement(this.props.wrappingTag,{className:this.props.wrappingClass,style:this.props.wrappingStyle,onClick:this.queryNext},this.props.loadText):i.createElement("span",{className:"threadsLoadMoreUnactivated"})},queryNext:function(){n.queryLastMessageOfAllThreads(this.state.lastMessagesResultSet.next)}});e.exports=a},function(e,t,s){var i=s(1),n=s(2),r=s(3),a=i.createClass({displayName:"ThreadsQuit",mixins:[r.LoginMixin,r.CurrentThreadMixin],getDefaultProps:function(){return{wrappingTag:"a",wrappingClass:"messagesThreadsQuit",wrappingStyle:{},quitText:"Quit this thread"}},render:function(){return this.state.loggedInParticipantId&&this.state.currentThread&&this.state.currentThread.id?i.createElement(this.props.wrappingTag,{className:this.props.wrappingClass,style:this.props.wrappingStyle,onClick:this.queryQuit},this.props.quitText):i.createElement("span",{className:"threadsQuitUnactivated"})},queryQuit:function(){n.quitCurrentThread(this.state.currentThread.id)}});e.exports=a},function(e,t,s){e.exports.Dispatcher=s(34)},function(e,t,s){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}t.__esModule=!0;var n=s(35),r="ID_",a=function(){function e(){i(this,e),this._callbacks={},this._isDispatching=!1,this._isHandled={},this._isPending={},this._lastID=1}return e.prototype.register=function(e){var t=r+this._lastID++;return this._callbacks[t]=e,t},e.prototype.unregister=function(e){this._callbacks[e]?void 0:n(!1),delete this._callbacks[e]},e.prototype.waitFor=function(e){this._isDispatching?void 0:n(!1);for(var t=0;t<e.length;t++){var s=e[t];this._isPending[s]?this._isHandled[s]?void 0:n(!1):(this._callbacks[s]?void 0:n(!1),this._invokeCallback(s))}},e.prototype.dispatch=function(e){this._isDispatching?n(!1):void 0,this._startDispatching(e);try{for(var t in this._callbacks)this._isPending[t]||this._invokeCallback(t)}finally{this._stopDispatching()}},e.prototype.isDispatching=function(){return this._isDispatching},e.prototype._invokeCallback=function(e){this._isPending[e]=!0,this._callbacks[e](this._pendingPayload),this._isHandled[e]=!0},e.prototype._startDispatching=function(e){for(var t in this._callbacks)this._isPending[t]=!1,this._isHandled[t]=!1;this._pendingPayload=e,this._isDispatching=!0},e.prototype._stopDispatching=function(){delete this._pendingPayload,this._isDispatching=!1},e}();e.exports=a},function(e,t,s){"use strict";var i=function(e,t,s,i,n,r,a,o){if(!e){var c;if(void 0===t)c=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var l=[s,i,n,r,a,o],h=0;c=new Error("Invariant Violation: "+t.replace(/%s/g,function(){return l[h++]}))}throw c.framesToPop=1,c}};e.exports=i},function(e,t){"use strict";var s=function(e){var t,s={};if(!(e instanceof Object)||Array.isArray(e))throw new Error("keyMirror(...): Argument must be an object.");for(t in e)e.hasOwnProperty(t)&&(s[t]=t);return s};e.exports=s},function(e,t){"use strict";function s(e){if(null===e||void 0===e)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(e)}var i=Object.prototype.hasOwnProperty,n=Object.prototype.propertyIsEnumerable;e.exports=Object.assign||function(e,t){for(var r,a,o=s(e),c=1;c<arguments.length;c++){r=Object(arguments[c]);for(var l in r)i.call(r,l)&&(o[l]=r[l]);if(Object.getOwnPropertySymbols){a=Object.getOwnPropertySymbols(r);for(var h=0;h<a.length;h++)n.call(r,a[h])&&(o[a[h]]=r[a[h]])}}return o}},function(e,t){function s(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function i(e){return"function"==typeof e}function n(e){return"number"==typeof e}function r(e){return"object"==typeof e&&null!==e}function a(e){return void 0===e}e.exports=s,s.EventEmitter=s,s.prototype._events=void 0,s.prototype._maxListeners=void 0,s.defaultMaxListeners=10,s.prototype.setMaxListeners=function(e){if(!n(e)||0>e||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},s.prototype.emit=function(e){var t,s,n,o,c,l;if(this._events||(this._events={}),"error"===e&&(!this._events.error||r(this._events.error)&&!this._events.error.length)){if(t=arguments[1],t instanceof Error)throw t;throw TypeError('Uncaught, unspecified "error" event.')}if(s=this._events[e],a(s))return!1;if(i(s))switch(arguments.length){case 1:s.call(this);break;case 2:s.call(this,arguments[1]);break;case 3:s.call(this,arguments[1],arguments[2]);break;default:o=Array.prototype.slice.call(arguments,1),s.apply(this,o)}else if(r(s))for(o=Array.prototype.slice.call(arguments,1),l=s.slice(),n=l.length,c=0;n>c;c++)l[c].apply(this,o);return!0},s.prototype.addListener=function(e,t){var n;if(!i(t))throw TypeError("listener must be a function");return this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,i(t.listener)?t.listener:t),this._events[e]?r(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,r(this._events[e])&&!this._events[e].warned&&(n=a(this._maxListeners)?s.defaultMaxListeners:this._maxListeners,n&&n>0&&this._events[e].length>n&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace())),this},s.prototype.on=s.prototype.addListener,s.prototype.once=function(e,t){function s(){this.removeListener(e,s),n||(n=!0,t.apply(this,arguments))}if(!i(t))throw TypeError("listener must be a function");var n=!1;return s.listener=t,this.on(e,s),this},s.prototype.removeListener=function(e,t){var s,n,a,o;if(!i(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(s=this._events[e],a=s.length,n=-1,s===t||i(s.listener)&&s.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(r(s)){for(o=a;o-- >0;)if(s[o]===t||s[o].listener&&s[o].listener===t){n=o;break}if(0>n)return this;1===s.length?(s.length=0,delete this._events[e]):s.splice(n,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},s.prototype.removeAllListeners=function(e){var t,s;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(s=this._events[e],i(s))this.removeListener(e,s);else if(s)for(;s.length;)this.removeListener(e,s[s.length-1]);return delete this._events[e],this},s.prototype.listeners=function(e){var t;return t=this._events&&this._events[e]?i(this._events[e])?[this._events[e]]:this._events[e].slice():[]},s.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(i(t))return 1;if(t)return t.length}return 0},s.listenerCount=function(e,t){return e.listenerCount(t)}},function(e,t){e.exports=moment}]);