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
7bf39a09
Commit
7bf39a09
authored
Dec 06, 2019
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
muc: move message handler into own method
parent
890db342
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
53 deletions
+43
-53
.eslintrc.json
.eslintrc.json
+1
-1
spec/muc.js
spec/muc.js
+5
-5
src/headless/converse-muc.js
src/headless/converse-muc.js
+37
-47
No files found.
.eslintrc.json
View file @
7bf39a09
...
@@ -210,7 +210,7 @@
...
@@ -210,7 +210,7 @@
"object-curly-newline"
:
"off"
,
"object-curly-newline"
:
"off"
,
"object-curly-spacing"
:
"off"
,
"object-curly-spacing"
:
"off"
,
"object-property-newline"
:
[
"object-property-newline"
:
[
"
error
"
,
"
off
"
,
{
{
"allowMultiplePropertiesPerLine"
:
true
"allowMultiplePropertiesPerLine"
:
true
}
}
...
...
spec/muc.js
View file @
7bf39a09
...
@@ -2907,7 +2907,7 @@
...
@@ -2907,7 +2907,7 @@
done
();
done
();
}));
}));
it
(
"
notifies user
of role and affiliation changes for members not
in the groupchat
"
,
it
(
"
notifies user
s of role and affiliation changes for members not currently
in the groupchat
"
,
mock
.
initConverse
(
mock
.
initConverse
(
[
'
rosterGroupsFetched
'
],
{},
[
'
rosterGroupsFetched
'
],
{},
async
function
(
done
,
_converse
)
{
async
function
(
done
,
_converse
)
{
...
@@ -2923,14 +2923,14 @@
...
@@ -2923,14 +2923,14 @@
})
})
.
c
(
'
x
'
,
{
'
xmlns
'
:
'
http://jabber.org/protocol/muc#user
'
})
.
c
(
'
x
'
,
{
'
xmlns
'
:
'
http://jabber.org/protocol/muc#user
'
})
.
c
(
'
item
'
,
{
.
c
(
'
item
'
,
{
'
jid
'
:
'
a
nnoying
guy@montague.lit
'
,
'
jid
'
:
'
a
bsent
guy@montague.lit
'
,
'
affiliation
'
:
'
member
'
,
'
affiliation
'
:
'
member
'
,
'
role
'
:
'
none
'
'
role
'
:
'
none
'
});
});
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
message
));
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
message
));
await
u
.
waitUntil
(()
=>
view
.
model
.
occupants
.
length
>
1
);
await
u
.
waitUntil
(()
=>
view
.
model
.
occupants
.
length
>
1
);
expect
(
view
.
model
.
occupants
.
length
).
toBe
(
2
);
expect
(
view
.
model
.
occupants
.
length
).
toBe
(
2
);
expect
(
view
.
model
.
occupants
.
findWhere
({
'
jid
'
:
'
a
nnoying
guy@montague.lit
'
}).
get
(
'
affiliation
'
)).
toBe
(
'
member
'
);
expect
(
view
.
model
.
occupants
.
findWhere
({
'
jid
'
:
'
a
bsent
guy@montague.lit
'
}).
get
(
'
affiliation
'
)).
toBe
(
'
member
'
);
message
=
$msg
({
message
=
$msg
({
from
:
'
lounge@montague.lit
'
,
from
:
'
lounge@montague.lit
'
,
...
@@ -2939,13 +2939,13 @@
...
@@ -2939,13 +2939,13 @@
})
})
.
c
(
'
x
'
,
{
'
xmlns
'
:
'
http://jabber.org/protocol/muc#user
'
})
.
c
(
'
x
'
,
{
'
xmlns
'
:
'
http://jabber.org/protocol/muc#user
'
})
.
c
(
'
item
'
,
{
.
c
(
'
item
'
,
{
'
jid
'
:
'
a
nnoying
guy@montague.lit
'
,
'
jid
'
:
'
a
bsent
guy@montague.lit
'
,
'
affiliation
'
:
'
none
'
,
'
affiliation
'
:
'
none
'
,
'
role
'
:
'
none
'
'
role
'
:
'
none
'
});
});
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
message
));
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
message
));
expect
(
view
.
model
.
occupants
.
length
).
toBe
(
2
);
expect
(
view
.
model
.
occupants
.
length
).
toBe
(
2
);
expect
(
view
.
model
.
occupants
.
findWhere
({
'
jid
'
:
'
a
nnoying
guy@montague.lit
'
}).
get
(
'
affiliation
'
)).
toBe
(
'
none
'
);
expect
(
view
.
model
.
occupants
.
findWhere
({
'
jid
'
:
'
a
bsent
guy@montague.lit
'
}).
get
(
'
affiliation
'
)).
toBe
(
'
none
'
);
done
();
done
();
}));
}));
...
...
src/headless/converse-muc.js
View file @
7bf39a09
...
@@ -480,17 +480,41 @@ converse.plugins.add('converse-muc', {
...
@@ -480,17 +480,41 @@ converse.plugins.add('converse-muc', {
return
this
.
occupants
.
fetched
;
return
this
.
occupants
.
fetched
;
},
},
handleAffiliationChangedMessage
(
stanza
)
{
const
item
=
sizzle
(
`x[xmlns="
${
Strophe
.
NS
.
MUC_USER
}
"] item`
,
stanza
).
pop
();
if
(
item
)
{
const
from
=
stanza
.
getAttribute
(
"
from
"
);
const
type
=
stanza
.
getAttribute
(
"
type
"
);
const
affiliation
=
item
.
getAttribute
(
'
affiliation
'
);
const
jid
=
item
.
getAttribute
(
'
jid
'
);
const
data
=
{
from
,
type
,
affiliation
,
'
nick
'
:
Strophe
.
getNodeFromJid
(
jid
),
'
states
'
:
[],
'
show
'
:
type
==
'
unavailable
'
?
'
offline
'
:
'
online
'
,
'
role
'
:
item
.
getAttribute
(
'
role
'
),
'
jid
'
:
Strophe
.
getBareJidFromJid
(
jid
),
'
resource
'
:
Strophe
.
getResourceFromJid
(
jid
)
}
const
occupant
=
this
.
occupants
.
findOccupant
({
'
jid
'
:
data
.
jid
});
if
(
occupant
)
{
occupant
.
save
(
data
);
}
else
{
this
.
occupants
.
create
(
data
);
}
}
},
registerHandlers
()
{
registerHandlers
()
{
// Register presence and message handlers for this groupchat
// Register presence and message handlers for this groupchat
const
room_jid
=
this
.
get
(
'
jid
'
);
const
room_jid
=
this
.
get
(
'
jid
'
);
this
.
removeHandlers
();
this
.
removeHandlers
();
this
.
presence_handler
=
_converse
.
connection
.
addHandler
(
stanza
=>
{
this
.
presence_handler
=
_converse
.
connection
.
addHandler
(
this
.
onPresence
(
stanza
);
stanza
=>
(
this
.
onPresence
(
stanza
)
||
true
),
return
true
;
},
null
,
'
presence
'
,
null
,
null
,
room_jid
,
null
,
'
presence
'
,
null
,
null
,
room_jid
,
{
'
ignoreNamespaceFragment
'
:
true
,
'
matchBareFromJid
'
:
true
}
{
'
ignoreNamespaceFragment
'
:
true
,
'
matchBareFromJid
'
:
true
}
);
);
this
.
message_handler
=
_converse
.
connection
.
addHandler
(
stanza
=>
{
this
.
message_handler
=
_converse
.
connection
.
addHandler
(
stanza
=>
{
if
(
sizzle
(
`message > result[xmlns="
${
Strophe
.
NS
.
MAM
}
"]`
,
stanza
).
pop
())
{
if
(
sizzle
(
`message > result[xmlns="
${
Strophe
.
NS
.
MAM
}
"]`
,
stanza
).
pop
())
{
// MAM messages are handled in converse-mam.
// MAM messages are handled in converse-mam.
...
@@ -504,61 +528,27 @@ converse.plugins.add('converse-muc', {
...
@@ -504,61 +528,27 @@ converse.plugins.add('converse-muc', {
},
null
,
'
message
'
,
'
groupchat
'
,
null
,
room_jid
,
},
null
,
'
message
'
,
'
groupchat
'
,
null
,
room_jid
,
{
'
matchBareFromJid
'
:
true
}
{
'
matchBareFromJid
'
:
true
}
);
);
this
.
muc_notifications_handler
=
_converse
.
connection
.
addHandler
(
stanza
=>
{
const
item
=
sizzle
(
`x[xmlns="
${
Strophe
.
NS
.
MUC_USER
}
"] item`
,
stanza
).
pop
();
if
(
item
)
{
const
from
=
stanza
.
getAttribute
(
"
from
"
);
const
type
=
stanza
.
getAttribute
(
"
type
"
);
const
affiliation
=
item
.
getAttribute
(
'
affiliation
'
);
const
jid
=
item
.
getAttribute
(
'
jid
'
);
const
data
=
{
'
from
'
:
from
,
'
nick
'
:
Strophe
.
getNodeFromJid
(
jid
),
'
type
'
:
type
,
'
states
'
:
[],
'
show
'
:
type
==
'
unavailable
'
?
'
offline
'
:
'
online
'
,
'
affiliation
'
:
affiliation
,
'
role
'
:
item
.
getAttribute
(
'
role
'
),
'
jid
'
:
Strophe
.
getBareJidFromJid
(
jid
),
'
resource
'
:
Strophe
.
getResourceFromJid
(
jid
)
}
const
occupant
=
this
.
occupants
.
findOccupant
({
'
jid
'
:
data
.
jid
});
this
.
affiliation_message_handler
=
_converse
.
connection
.
addHandler
(
stanza
=>
(
this
.
handleAffiliationChangedMessage
(
stanza
)
||
true
),
if
(
occupant
)
{
Strophe
.
NS
.
MUC_USER
,
'
message
'
,
null
,
null
,
room_jid
occupant
.
save
(
data
);
);
}
else
{
this
.
occupants
.
create
(
data
);
}
}
return
true
;
},
Strophe
.
NS
.
MUC_USER
,
'
message
'
,
null
,
null
,
room_jid
);
},
},
removeHandlers
()
{
removeHandlers
()
{
// Remove the presence and message handlers that were
// Remove the presence and message handlers that were
// registered for this groupchat.
// registered for this groupchat.
if
(
this
.
message_handler
)
{
if
(
this
.
message_handler
)
{
if
(
_converse
.
connection
)
{
_converse
.
connection
&&
_converse
.
connection
.
deleteHandler
(
this
.
message_handler
);
_converse
.
connection
.
deleteHandler
(
this
.
message_handler
);
}
delete
this
.
message_handler
;
delete
this
.
message_handler
;
}
}
if
(
this
.
presence_handler
)
{
if
(
this
.
presence_handler
)
{
if
(
_converse
.
connection
)
{
_converse
.
connection
&&
_converse
.
connection
.
deleteHandler
(
this
.
presence_handler
);
_converse
.
connection
.
deleteHandler
(
this
.
presence_handler
);
}
delete
this
.
presence_handler
;
delete
this
.
presence_handler
;
}
}
if
(
this
.
affiliation_message_handler
)
{
if
(
this
.
muc_notifications_handler
)
{
_converse
.
connection
&&
_converse
.
connection
.
deleteHandler
(
this
.
affiliation_message_handler
);
if
(
_converse
.
connection
)
{
delete
this
.
affiliation_message_handler
;
_converse
.
connection
.
deleteHandler
(
this
.
muc_notifications_handler
);
}
delete
this
.
muc_notifications_handler
;
}
}
return
this
;
return
this
;
},
},
...
...
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