Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
fc7f5088
Commit
fc7f5088
authored
Mar 22, 2016
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored MUC plugin to not have to override ChatBoxes collection.
Instead we use event handlers.
parent
1f284003
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
64 deletions
+66
-64
spec/chatroom.js
spec/chatroom.js
+1
-1
src/converse-muc.js
src/converse-muc.js
+65
-63
No files found.
spec/chatroom.js
View file @
fc7f5088
...
...
@@ -163,7 +163,7 @@
)[
0
];
expect
(
converse
.
chatboxes
.
models
.
length
).
toBe
(
1
);
expect
(
converse
.
chatboxes
.
models
[
0
].
id
).
toBe
(
"
controlbox
"
);
converse
.
chatboxes
.
onInvite
(
message
);
converse
.
onDirectMUCInvitation
(
message
);
expect
(
window
.
confirm
).
toHaveBeenCalledWith
(
name
+
'
has invited you to join a chat room:
'
+
room_jid
+
'
, and left the following reason: "
'
+
reason
+
'
"
'
);
...
...
src/converse-muc.js
View file @
fc7f5088
...
...
@@ -97,6 +97,8 @@
},
onConnected
:
function
()
{
// TODO: This can probably be refactored to be an event
// handler (and therefore removed from overrides)
var
converse
=
this
.
_super
.
converse
;
this
.
_super
.
onConnected
.
apply
(
this
,
arguments
);
...
...
@@ -126,65 +128,6 @@
}
},
ChatBoxes
:
{
registerMessageHandler
:
function
()
{
/* Override so that we can register a handler
* for chat room invites.
*/
this
.
_super
.
registerMessageHandler
.
apply
(
this
,
arguments
);
// First call the original
this
.
_super
.
converse
.
connection
.
addHandler
(
function
(
message
)
{
this
.
onInvite
(
message
);
return
true
;
}.
bind
(
this
),
'
jabber:x:conference
'
,
'
message
'
);
},
onInvite
:
function
(
message
)
{
/* An invitation to join a chat room has been received */
var
converse
=
this
.
_super
.
converse
,
$message
=
$
(
message
),
$x
=
$message
.
children
(
'
x[xmlns="jabber:x:conference"]
'
),
from
=
Strophe
.
getBareJidFromJid
(
$message
.
attr
(
'
from
'
)),
room_jid
=
$x
.
attr
(
'
jid
'
),
reason
=
$x
.
attr
(
'
reason
'
),
contact
=
converse
.
roster
.
get
(
from
),
result
;
if
(
converse
.
auto_join_on_invite
)
{
result
=
true
;
}
else
{
contact
=
contact
?
contact
.
get
(
'
fullname
'
):
Strophe
.
getNodeFromJid
(
from
);
// Invite request might come from someone not your roster list
if
(
!
reason
)
{
result
=
confirm
(
__
(
___
(
"
%1$s has invited you to join a chat room: %2$s
"
),
contact
,
room_jid
)
);
}
else
{
result
=
confirm
(
__
(
___
(
'
%1$s has invited you to join a chat room: %2$s, and left the following reason: "%3$s"
'
),
contact
,
room_jid
,
reason
)
);
}
}
if
(
result
===
true
)
{
var
chatroom
=
converse
.
chatboxviews
.
showChat
({
'
id
'
:
room_jid
,
'
jid
'
:
room_jid
,
'
name
'
:
Strophe
.
unescapeNode
(
Strophe
.
getNodeFromJid
(
room_jid
)),
'
nick
'
:
Strophe
.
unescapeNode
(
Strophe
.
getNodeFromJid
(
converse
.
connection
.
jid
)),
'
type
'
:
'
chatroom
'
,
'
box_id
'
:
b64_sha1
(
room_jid
),
'
password
'
:
$x
.
attr
(
'
password
'
)
});
if
(
!
_
.
contains
(
[
Strophe
.
Status
.
CONNECTING
,
Strophe
.
Status
.
CONNECTED
],
chatroom
.
get
(
'
connection_status
'
))
)
{
converse
.
chatboxviews
.
get
(
room_jid
).
join
(
null
);
}
}
}
},
ChatBoxViews
:
{
onChatBoxAdded
:
function
(
item
)
{
var
view
=
this
.
get
(
item
.
get
(
'
id
'
));
...
...
@@ -207,6 +150,7 @@
this
.
updateSettings
({
allow_muc
:
true
,
auto_join_on_invite
:
false
,
// Auto-join chatroom on invite
auto_join_rooms
:
[],
// List of JIDs of rooms to be joined upon login
auto_list_rooms
:
false
,
hide_muc_server
:
false
,
muc_history_max_stanzas
:
undefined
,
// Takes an integer, limits the amount of messages to fetch from chat room's history
...
...
@@ -1336,10 +1280,69 @@
}
});
/* Support for XEP-0249: Direct MUC invitations */
/* ------------------------------------------------------------ */
converse
.
onDirectMUCInvitation
=
function
(
message
)
{
/* A direct MUC invitation to join a room has been received */
var
$message
=
$
(
message
),
$x
=
$message
.
children
(
'
x[xmlns="jabber:x:conference"]
'
),
from
=
Strophe
.
getBareJidFromJid
(
$message
.
attr
(
'
from
'
)),
room_jid
=
$x
.
attr
(
'
jid
'
),
reason
=
$x
.
attr
(
'
reason
'
),
contact
=
converse
.
roster
.
get
(
from
),
result
;
if
(
converse
.
auto_join_on_invite
)
{
result
=
true
;
}
else
{
// Invite request might come from someone not your roster list
contact
=
contact
?
contact
.
get
(
'
fullname
'
):
Strophe
.
getNodeFromJid
(
from
);
if
(
!
reason
)
{
result
=
confirm
(
__
(
___
(
"
%1$s has invited you to join a chat room: %2$s
"
),
contact
,
room_jid
)
);
}
else
{
result
=
confirm
(
__
(
___
(
'
%1$s has invited you to join a chat room: %2$s, and left the following reason: "%3$s"
'
),
contact
,
room_jid
,
reason
)
);
}
}
if
(
result
===
true
)
{
var
chatroom
=
converse
.
chatboxviews
.
showChat
({
'
id
'
:
room_jid
,
'
jid
'
:
room_jid
,
'
name
'
:
Strophe
.
unescapeNode
(
Strophe
.
getNodeFromJid
(
room_jid
)),
'
nick
'
:
Strophe
.
unescapeNode
(
Strophe
.
getNodeFromJid
(
converse
.
connection
.
jid
)),
'
type
'
:
'
chatroom
'
,
'
box_id
'
:
b64_sha1
(
room_jid
),
'
password
'
:
$x
.
attr
(
'
password
'
)
});
if
(
!
_
.
contains
(
[
Strophe
.
Status
.
CONNECTING
,
Strophe
.
Status
.
CONNECTED
],
chatroom
.
get
(
'
connection_status
'
))
)
{
converse
.
chatboxviews
.
get
(
room_jid
).
join
(
null
);
}
}
};
var
registerInviteHandler
=
function
()
{
converse
.
connection
.
addHandler
(
function
(
message
)
{
converse
.
onDirectMUCInvitation
(
message
);
return
true
;
},
'
jabber:x:conference
'
,
'
message
'
);
};
converse
.
on
(
'
connected
'
,
registerInviteHandler
);
converse
.
on
(
'
reconnected
'
,
registerInviteHandler
);
/* ------------------------------------------------------------ */
/* We extend the default converse.js API to add methods specific to MUC
* chat rooms.
*/
_
.
extend
(
converse_api
,
{
/* We extend the default converse.js API to add methods specific to MUC
* chat rooms.
*/
'
rooms
'
:
{
'
open
'
:
function
(
jids
,
nick
)
{
if
(
!
nick
)
{
...
...
@@ -1378,7 +1381,6 @@
return
converse
.
wrappedChatBox
(
converse
.
chatboxes
.
getChatBox
(
jids
,
true
));
}
return
_
.
map
(
jids
,
_
.
partial
(
converse
.
wrappedChatBox
,
_
.
bind
(
converse
.
chatboxes
.
getChatBox
,
converse
.
chatboxes
,
_
,
true
)));
}
}
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment