@@ -67,7 +67,7 @@ export const createChatWindow = (core, proc, parent, bus, options) => {
6767 const messages = ( state , actions ) => state . messages . map ( ( { date, msg} ) => {
6868 return h ( ChatMessage , {
6969 date : format ( date , 'longTime' ) ,
70- self : getUsername ( msg . getAttribute ( 'from' ) ) !== getUsername ( options . user ) ,
70+ self : getUsername ( msg . getAttribute ( 'from' ) ) !== getUsername ( options . target ) ,
7171 to : msg . getAttribute ( 'to' ) ,
7272 from : msg . getAttribute ( 'from' ) ,
7373 type : msg . getAttribute ( 'type' ) ,
@@ -127,20 +127,19 @@ export const createChatWindow = (core, proc, parent, bus, options) => {
127127 }
128128
129129 const msg = createMessage ( options . self , options . target , value ) ;
130-
131- actions . sendMessage ( msg ) ;
130+ actions . sendMessage ( options . muc ? value : msg ) ;
132131 actions . addMessage ( { date : new Date ( ) , msg} ) ;
133132
134133 setTimeout ( ( ) => ( textarea . value = '' ) , 1 ) ;
135134 } ,
136135 setTypeStatus : typing => ( ) => ( { typing} ) ,
137- sendMessage : msg => ( ) => bus . emit ( 'send-message' , msg ) ,
136+ sendMessage : msg => ( ) => bus . emit ( 'send-message' , msg , options . target , options . muc ) ,
138137 addMessage : obj => state => ( { messages : [ ...state . messages , obj ] } )
139138 } , view , $content ) ;
140139
141140 let typeStatusTimeout ;
142141
143- win . on ( 'strophejs/message' , msg => {
142+ const addMessage = msg => {
144143 a . addMessage ( { date : new Date ( ) , msg} ) ;
145144
146145 const container = $content . querySelector ( '.chat-messages' ) ;
@@ -149,7 +148,21 @@ export const createChatWindow = (core, proc, parent, bus, options) => {
149148 container . scrollTop = container . scrollHeight ;
150149 } , 1 ) ;
151150 }
151+ } ;
152+
153+ if ( options . muc ) {
154+ win . on ( 'destroy' , ( ) => bus . emit ( 'leave-room' , options . target ) ) ;
155+ }
156+
157+ win . on ( 'strophejs/room:message' , addMessage ) ;
158+ win . on ( 'strophejs/room:presence' , ( ...args ) => {
159+ console . warn ( 'TODO' , 'strophejs/room:presence' , args ) ;
152160 } ) ;
161+ win . on ( 'strophejs/room:roster' , ( ...args ) => {
162+ console . warn ( 'TODO' , 'strophejs/room:roster' , args ) ;
163+ } ) ;
164+
165+ win . on ( 'strophejs/message' , addMessage ) ;
153166
154167 win . on ( 'strophejs/started-typing' , ( ) => {
155168 clearTimeout ( typeStatusTimeout ) ;
0 commit comments