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
53346ff5
Commit
53346ff5
authored
Jan 24, 2020
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
roster: refactor to use async/await
parent
c05e8110
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
17 deletions
+15
-17
src/headless/converse-roster.js
src/headless/converse-roster.js
+10
-14
src/headless/utils/core.js
src/headless/utils/core.js
+5
-3
No files found.
src/headless/converse-roster.js
View file @
53346ff5
...
...
@@ -476,13 +476,11 @@ converse.plugins.add('converse-roster', {
* @param { String } message - An optional message to explain the reason for the subscription request.
* @param { Object } attributes - Any additional attributes to be stored on the user's model.
*/
addAndSubscribe
(
jid
,
name
,
groups
,
message
,
attributes
)
{
const
handler
=
(
contact
)
=>
{
if
(
contact
instanceof
_converse
.
RosterContact
)
{
contact
.
subscribe
(
message
);
}
async
addAndSubscribe
(
jid
,
name
,
groups
,
message
,
attributes
)
{
const
contact
=
await
this
.
addContactToRoster
(
jid
,
name
,
groups
,
attributes
);
if
(
contact
instanceof
_converse
.
RosterContact
)
{
contact
.
subscribe
(
message
);
}
this
.
addContactToRoster
(
jid
,
name
,
groups
,
attributes
).
then
(
handler
,
handler
);
},
/**
...
...
@@ -535,19 +533,17 @@ converse.plugins.add('converse-roster', {
},
attributes
),
{
'
sort
'
:
false
});
},
subscribeBack
(
bare_jid
,
presence
)
{
async
subscribeBack
(
bare_jid
,
presence
)
{
const
contact
=
this
.
get
(
bare_jid
);
if
(
contact
instanceof
_converse
.
RosterContact
)
{
contact
.
authorize
().
subscribe
();
}
else
{
// Can happen when a subscription is retried or roster was deleted
const
handler
=
(
contact
)
=>
{
if
(
contact
instanceof
_converse
.
RosterContact
)
{
contact
.
authorize
().
subscribe
();
}
}
const
nickname
=
get
(
sizzle
(
`nick[xmlns="
${
Strophe
.
NS
.
NICK
}
"]`
,
presence
).
pop
(),
'
textContent
'
,
null
);
this
.
addContactToRoster
(
bare_jid
,
nickname
,
[],
{
'
subscription
'
:
'
from
'
}).
then
(
handler
,
handler
);
const
contact
=
await
this
.
addContactToRoster
(
bare_jid
,
nickname
,
[],
{
'
subscription
'
:
'
from
'
});
if
(
contact
instanceof
_converse
.
RosterContact
)
{
contact
.
authorize
().
subscribe
();
}
}
},
...
...
@@ -1087,7 +1083,7 @@ converse.plugins.add('converse-roster', {
if
(
!
isString
(
jid
)
||
!
jid
.
includes
(
'
@
'
))
{
throw
new
TypeError
(
'
contacts.add: invalid jid
'
);
}
_converse
.
roster
.
addAndSubscribe
(
jid
,
isEmpty
(
name
)?
jid
:
name
);
return
_converse
.
roster
.
addAndSubscribe
(
jid
,
isEmpty
(
name
)?
jid
:
name
);
}
}
});
...
...
src/headless/utils/core.js
View file @
53346ff5
...
...
@@ -371,10 +371,12 @@ u.isPersistableModel = function (model) {
return
model
.
collection
&&
model
.
collection
.
browserStorage
;
};
/**
* Returns a promise object on which `resolve` or `reject` can be called.
* @private
* @method u#getResolveablePromise
*/
u
.
getResolveablePromise
=
function
()
{
/* Returns a promise object on which `resolve` or `reject` can be
* called.
*/
const
wrapper
=
{
isResolved
:
false
,
isPending
:
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