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
e2a7045e
Commit
e2a7045e
authored
Apr 13, 2020
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move MUC presence parsing code to src/headless/utils/stanza.js
parent
a1d55639
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
44 deletions
+41
-44
src/headless/converse-muc.js
src/headless/converse-muc.js
+1
-44
src/headless/utils/stanza.js
src/headless/utils/stanza.js
+40
-0
No files found.
src/headless/converse-muc.js
View file @
e2a7045e
...
...
@@ -1566,7 +1566,7 @@ converse.plugins.add('converse-muc', {
* @param { XMLElement } pres - The presence stanza
*/
updateOccupantsOnPresence
(
pres
)
{
const
data
=
st
.
parseMUCPresence
Stanza
(
pres
);
const
data
=
st
.
parseMUCPresence
(
pres
);
if
(
data
.
type
===
'
error
'
||
(
!
data
.
jid
&&
!
data
.
nick
))
{
return
true
;
}
...
...
@@ -1594,49 +1594,6 @@ converse.plugins.add('converse-muc', {
}
},
parsePresence
(
pres
)
{
const
from
=
pres
.
getAttribute
(
"
from
"
),
type
=
pres
.
getAttribute
(
"
type
"
),
data
=
{
'
from
'
:
from
,
'
nick
'
:
Strophe
.
getResourceFromJid
(
from
),
'
type
'
:
type
,
'
states
'
:
[],
'
show
'
:
type
!==
'
unavailable
'
?
'
online
'
:
'
offline
'
};
pres
.
childNodes
.
forEach
(
child
=>
{
switch
(
child
.
nodeName
)
{
case
"
status
"
:
data
.
status
=
child
.
textContent
||
null
;
break
;
case
"
show
"
:
data
.
show
=
child
.
textContent
||
'
online
'
;
break
;
case
"
x
"
:
if
(
child
.
getAttribute
(
"
xmlns
"
)
===
Strophe
.
NS
.
MUC_USER
)
{
child
.
childNodes
.
forEach
(
item
=>
{
switch
(
item
.
nodeName
)
{
case
"
item
"
:
data
.
affiliation
=
item
.
getAttribute
(
"
affiliation
"
);
data
.
role
=
item
.
getAttribute
(
"
role
"
);
data
.
jid
=
item
.
getAttribute
(
"
jid
"
);
data
.
nick
=
item
.
getAttribute
(
"
nick
"
)
||
data
.
nick
;
break
;
case
"
status
"
:
if
(
item
.
getAttribute
(
"
code
"
))
{
data
.
states
.
push
(
item
.
getAttribute
(
"
code
"
));
}
}
});
}
else
if
(
child
.
getAttribute
(
"
xmlns
"
)
===
Strophe
.
NS
.
VCARDUPDATE
)
{
data
.
image_hash
=
child
.
querySelector
(
'
photo
'
)?.
textContent
;
}
}
});
return
data
;
},
fetchFeaturesIfConfigurationChanged
(
stanza
)
{
// 104: configuration change
// 170: logging enabled
...
...
src/headless/utils/stanza.js
View file @
e2a7045e
...
...
@@ -350,6 +350,46 @@ const stanza_utils = {
// as the Model id, to avoid duplicates.
attrs
[
'
id
'
]
=
attrs
[
'
origin_id
'
]
||
attrs
[
`stanza_id
${(
attrs
.
from_muc
||
attrs
.
from
)}
`
]
||
u
.
getUniqueId
();
return
attrs
;
},
/**
* Parses a passed in MUC presence stanza and returns an object of attributes.
* @private
* @method stanza_utils#parseMUCPresence
* @param { XMLElement } stanza - The presence stanza
* @returns { Object }
*/
parseMUCPresence
(
stanza
)
{
const
from
=
stanza
.
getAttribute
(
"
from
"
);
const
type
=
stanza
.
getAttribute
(
"
type
"
);
const
data
=
{
'
from
'
:
from
,
'
nick
'
:
Strophe
.
getResourceFromJid
(
from
),
'
type
'
:
type
,
'
states
'
:
[],
'
show
'
:
type
!==
'
unavailable
'
?
'
online
'
:
'
offline
'
};
Array
.
from
(
stanza
.
children
).
forEach
(
child
=>
{
if
(
child
.
matches
(
'
status
'
))
{
data
.
status
=
child
.
textContent
||
null
;
}
else
if
(
child
.
matches
(
'
show
'
))
{
data
.
show
=
child
.
textContent
||
'
online
'
;
}
else
if
(
child
.
matches
(
'
x
'
)
&&
child
.
getAttribute
(
'
xmlns
'
)
===
Strophe
.
NS
.
MUC_USER
)
{
Array
.
from
(
child
.
children
).
forEach
(
item
=>
{
if
(
item
.
nodeName
===
"
item
"
)
{
data
.
affiliation
=
item
.
getAttribute
(
"
affiliation
"
);
data
.
role
=
item
.
getAttribute
(
"
role
"
);
data
.
jid
=
item
.
getAttribute
(
"
jid
"
);
data
.
nick
=
item
.
getAttribute
(
"
nick
"
)
||
data
.
nick
;
}
else
if
(
item
.
nodeName
==
'
status
'
&&
item
.
getAttribute
(
"
code
"
))
{
data
.
states
.
push
(
item
.
getAttribute
(
"
code
"
));
}
});
}
else
if
(
child
.
matches
(
'
x
'
)
&&
child
.
getAttribute
(
'
xmlns
'
)
===
Strophe
.
NS
.
VCARDUPDATE
)
{
data
.
image_hash
=
child
.
querySelector
(
'
photo
'
)?.
textContent
;
}
});
return
data
;
}
}
...
...
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