Skip to content

Commit

Permalink
Added MUC join room functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
andersevenrud committed Jan 26, 2020
1 parent a24a576 commit 43088d4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
32 changes: 31 additions & 1 deletion src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/chat-window.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand Down
2 changes: 2 additions & 0 deletions src/main-window.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()}
]);

Expand Down Expand Up @@ -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({
Expand Down
1 change: 1 addition & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export const getMessageText = msg => {
.join('\n');
}

console.warn(msg);
return '';
};

Expand Down

0 comments on commit 43088d4

Please sign in to comment.