Skip to content

Commit 3a80f53

Browse files
committed
Added MUC join room functionality
1 parent 41c2733 commit 3a80f53

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

src/app.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,42 @@ const createApplication = (core, proc) => {
113113
id,
114114
self: connection.jid,
115115
title: username,
116-
user: from
116+
target: from
117117
});
118118
}
119119

120120
return chatWindow;
121121
};
122122

123+
const findOrCreateMucWindow = name => {
124+
let chatWindow = findChatWindow(name);
125+
if (!chatWindow) {
126+
const id = 'StropheJSChatWindow_' + name;
127+
128+
chatWindow = createChatWindow(core, proc, win, bus, {
129+
id,
130+
self: connection.jid,
131+
title: name,
132+
target: name,
133+
muc: true
134+
});
135+
}
136+
};
137+
138+
const createJoinRoomDialog = () => {
139+
core.make('osjs/dialog', 'prompt', {
140+
title: 'Room name',
141+
message: 'Enter room name',
142+
parent: win,
143+
value: `conference@${proc.settings.username.split('@')[1]}`
144+
}, (btn, value) => {
145+
if (btn === 'ok' && value) {
146+
connection.muc.join(value);
147+
findOrCreateMucWindow(value);
148+
}
149+
});
150+
};
151+
123152
const onReceiveMessage = msg => {
124153
const from = msg.getAttribute('from');
125154
const isTyping = msg.getElementsByTagName('cha:composing').length > 0;
@@ -166,6 +195,7 @@ const createApplication = (core, proc) => {
166195
}
167196
};
168197

198+
bus.on('open-room-join-dialog', () => createJoinRoomDialog());
169199
bus.on('open-connection-window', () => createConnectionWindow(core, proc, win, bus));
170200
bus.on('open-chat-window', from => findOrCreateChatWindow(from).focus());
171201
bus.on('send-message', msg => connection.send(msg));

src/chat-window.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export const createChatWindow = (core, proc, parent, bus, options) => {
126126
return;
127127
}
128128

129-
const msg = createMessage(options.self, options.user, value);
129+
const msg = createMessage(options.self, options.target, value);
130130

131131
actions.sendMessage(msg);
132132
actions.addMessage({date: new Date(), msg});

src/main-window.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const createFileMenu = (state, actions) => ([
5151
{label: 'Connection Options', onclick: () => actions.menuOptions()},
5252
{label: 'Connect', disabled: state.connected, onclick: () => actions.menuConnect()},
5353
{label: 'Disconnect', disabled: !state.connected, onclick: () => actions.menuDisconnect()},
54+
{label: 'Join Room', disabled: !state.connected, onclick: () => actions.menuJoinRoom()},
5455
{label: 'Quit', onclick: () => actions.menuQuit()}
5556
]);
5657

@@ -107,6 +108,7 @@ export const createMainWindow = (core, proc, bus) => {
107108
menuOptions: () => () => bus.emit('open-connection-window'),
108109
menuConnect: () => () => bus.emit('connect'),
109110
menuDisconnect: () => () => bus.emit('disconnect'),
111+
menuJoinRoom: () => () => bus.emit('open-room-join-dialog'),
110112
menuQuit: () => () => proc.destroy(),
111113
menuFile: ev => (state, actions) => {
112114
core.make('osjs/contextmenu').show({

src/utils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export const getMessageText = msg => {
6767
.join('\n');
6868
}
6969

70+
console.warn(msg);
7071
return '';
7172
};
7273

0 commit comments

Comments
 (0)