diff --git a/src/app.js b/src/app.js index 6818a4c..6a68987 100644 --- a/src/app.js +++ b/src/app.js @@ -113,13 +113,42 @@ const createApplication = (core, proc) => { id, self: connection.jid, title: username, - user: from + target: from }); } return chatWindow; }; + const findOrCreateMucWindow = name => { + let chatWindow = findChatWindow(name); + if (!chatWindow) { + const id = 'StropheJSChatWindow_' + name; + + chatWindow = createChatWindow(core, proc, win, bus, { + id, + self: connection.jid, + title: name, + target: name, + muc: true + }); + } + }; + + const createJoinRoomDialog = () => { + core.make('osjs/dialog', 'prompt', { + title: 'Room name', + message: 'Enter room name', + parent: win, + value: `conference@${proc.settings.username.split('@')[1]}` + }, (btn, value) => { + if (btn === 'ok' && value) { + connection.muc.join(value); + findOrCreateMucWindow(value); + } + }); + }; + const onReceiveMessage = msg => { const from = msg.getAttribute('from'); const isTyping = msg.getElementsByTagName('cha:composing').length > 0; @@ -166,6 +195,7 @@ const createApplication = (core, proc) => { } }; + bus.on('open-room-join-dialog', () => createJoinRoomDialog()); bus.on('open-connection-window', () => createConnectionWindow(core, proc, win, bus)); bus.on('open-chat-window', from => findOrCreateChatWindow(from).focus()); bus.on('send-message', msg => connection.send(msg)); diff --git a/src/chat-window.js b/src/chat-window.js index de4b961..c6cda1e 100644 --- a/src/chat-window.js +++ b/src/chat-window.js @@ -126,7 +126,7 @@ export const createChatWindow = (core, proc, parent, bus, options) => { return; } - const msg = createMessage(options.self, options.user, value); + const msg = createMessage(options.self, options.target, value); actions.sendMessage(msg); actions.addMessage({date: new Date(), msg}); diff --git a/src/main-window.js b/src/main-window.js index bb2a34f..e5bcc8e 100644 --- a/src/main-window.js +++ b/src/main-window.js @@ -51,6 +51,7 @@ const createFileMenu = (state, actions) => ([ {label: 'Connection Options', onclick: () => actions.menuOptions()}, {label: 'Connect', disabled: state.connected, onclick: () => actions.menuConnect()}, {label: 'Disconnect', disabled: !state.connected, onclick: () => actions.menuDisconnect()}, + {label: 'Join Room', disabled: !state.connected, onclick: () => actions.menuJoinRoom()}, {label: 'Quit', onclick: () => actions.menuQuit()} ]); @@ -107,6 +108,7 @@ export const createMainWindow = (core, proc, bus) => { menuOptions: () => () => bus.emit('open-connection-window'), menuConnect: () => () => bus.emit('connect'), menuDisconnect: () => () => bus.emit('disconnect'), + menuJoinRoom: () => () => bus.emit('open-room-join-dialog'), menuQuit: () => () => proc.destroy(), menuFile: ev => (state, actions) => { core.make('osjs/contextmenu').show({ diff --git a/src/utils.js b/src/utils.js index a12a203..6e4a4b5 100644 --- a/src/utils.js +++ b/src/utils.js @@ -67,6 +67,7 @@ export const getMessageText = msg => { .join('\n'); } + console.warn(msg); return ''; };