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
1ea770c7
Commit
1ea770c7
authored
Apr 06, 2015
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add the ability to reject presence subscriptions.
Still part of the refactoring of strophe.roster.
parent
f380e118
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
35 deletions
+45
-35
converse.js
converse.js
+37
-24
spec/controlbox.js
spec/controlbox.js
+8
-11
No files found.
converse.js
View file @
1ea770c7
...
...
@@ -30,21 +30,7 @@
}
);
}
else
{
root
.
converse
=
factory
(
templates
,
jQuery
,
$iq
,
$msg
,
$pres
,
$build
,
DSA
,
OTR
,
Strophe
,
_
,
moment
,
utils
,
b64_sha1
);
root
.
converse
=
factory
(
templates
,
jQuery
,
$iq
,
$msg
,
$pres
,
$build
,
DSA
,
OTR
,
Strophe
,
_
,
moment
,
utils
,
b64_sha1
);
}
}(
this
,
function
(
templates
,
$
,
$iq
,
$msg
,
$pres
,
$build
,
DSA
,
OTR
,
Strophe
,
_
,
moment
,
utils
,
b64_sha1
)
{
// "use strict";
...
...
@@ -397,8 +383,27 @@
}
}
};
this
.
rejectPresenceSubscription
=
function
(
jid
,
message
)
{
/* Reject or cancel another user's subscription to our presence updates.
* Parameters:
* (String) jid - The Jabber ID of the user whose subscription
* is being canceled.
* (String) message - An optional message to the user
*/
var
pres
=
$pres
({
to
:
jid
,
type
:
"
unsubscribed
"
});
if
(
message
&&
message
!==
""
)
{
pres
.
c
(
"
status
"
).
t
(
message
);
}
converse
.
connection
.
send
(
pres
);
};
this
.
getVCard
=
function
(
jid
,
callback
,
errback
)
{
/* Request the VCard of another user.
* Parameters:
* (String) jid - The Jabber ID of the user whose VCard is being requested.
* (Function) callback - A function to call once the VCard is returned
* (Function) errback - A function to call if an error occured
* while trying to fetch the VCard.
*/
if
(
!
this
.
use_vcards
)
{
if
(
callback
)
{
callback
(
jid
,
jid
);
...
...
@@ -3511,14 +3516,24 @@
unauthorize
:
function
(
message
)
{
/* Unauthorize this contact's presence subscription
* Parameters:
* (String) message -
An optional message to send to the person being unauthorized.
* (String) message -
Optional message to send to the person being unauthorized
*/
var
pres
=
$pres
({
to
:
this
.
get
(
'
jid
'
),
type
:
"
unsubscribed
"
});
if
(
message
&&
message
!==
""
)
{
pres
.
c
(
"
status
"
).
t
(
message
);
}
converse
.
connection
.
send
(
pres
);
converse
.
rejectPresenceSubscription
(
this
.
get
(
'
jid
'
),
message
);
return
this
;
},
authorize
:
function
(
message
)
{
/* Authorize presence subscription
* Parameters:
* (String) message - Optional message to send to the person being authorized
*/
var
pres
=
$pres
({
to
:
jid
,
type
:
"
subscribed
"
});
if
(
message
&&
message
!==
""
)
{
pres
.
c
(
"
status
"
).
t
(
message
);
}
converse
.
connection
.
send
(
pres
);
},
removeFromRoster
:
function
(
callback
)
{
/* Instruct the XMPP server to remove this contact from our roster
* Parameters:
...
...
@@ -3657,7 +3672,7 @@
acceptRequest
:
function
(
ev
)
{
if
(
ev
&&
ev
.
preventDefault
)
{
ev
.
preventDefault
();
}
var
jid
=
this
.
model
.
get
(
'
jid
'
);
converse
.
connection
.
roster
.
authorize
(
jid
);
this
.
model
.
authorize
(
);
converse
.
connection
.
roster
.
add
(
jid
,
this
.
model
.
get
(
'
fullname
'
),
[],
function
(
iq
)
{
converse
.
roster
.
subscribe
(
jid
,
null
,
converse
.
xmppstatus
.
get
(
'
fullname
'
));
});
...
...
@@ -3667,8 +3682,7 @@
if
(
ev
&&
ev
.
preventDefault
)
{
ev
.
preventDefault
();
}
var
result
=
confirm
(
__
(
"
Are you sure you want to decline this contact request?
"
));
if
(
result
===
true
)
{
converse
.
connection
.
roster
.
unauthorize
(
this
.
model
.
get
(
'
jid
'
));
this
.
model
.
destroy
();
this
.
model
.
unauthorize
().
destroy
();
}
return
this
;
}
...
...
@@ -3902,9 +3916,8 @@
handleIncomingSubscription
:
function
(
jid
)
{
var
bare_jid
=
Strophe
.
getBareJidFromJid
(
jid
);
var
item
=
this
.
get
(
bare_jid
);
if
(
!
converse
.
allow_contact_requests
)
{
converse
.
connection
.
roster
.
unauthorize
(
bare_jid
);
converse
.
rejectPresenceSubscription
(
jid
,
__
(
"
This client does not allow presence subscriptions
"
)
);
return
true
;
}
if
(
converse
.
auto_subscribe
)
{
...
...
spec/controlbox.js
View file @
1ea770c7
...
...
@@ -889,35 +889,32 @@
// mock_connection.
var
name
=
mock
.
req_names
.
sort
()[
0
];
var
jid
=
name
.
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
spyOn
(
this
.
connection
.
roster
,
'
authorize
'
);
var
contact
=
this
.
roster
.
get
(
jid
);
spyOn
(
contact
,
'
authorize
'
);
converse
.
rosterview
.
$el
.
find
(
"
.req-contact-name:contains('
"
+
name
+
"
')
"
)
.
siblings
(
'
.request-actions
'
)
.
find
(
'
.accept-xmpp-request
'
).
click
();
expect
(
this
.
connection
.
roster
.
authorize
).
toHaveBeenCalled
();
expect
(
contact
.
authorize
).
toHaveBeenCalled
();
},
converse
));
it
(
"
can have their requests denied by the user
"
,
$
.
proxy
(
function
()
{
this
.
rosterview
.
model
.
reset
();
runs
(
$
.
proxy
(
function
()
{
spyOn
(
converse
,
'
emit
'
);
spyOn
(
this
.
connection
.
roster
,
'
unauthorize
'
);
spyOn
(
window
,
'
confirm
'
).
andReturn
(
true
);
utils
.
createContacts
(
'
requesting
'
).
openControlBox
();
converse
.
rosterview
.
update
();
// XXX: Hack to make sure $roster element is attaced.
},
this
));
waits
(
50
);
runs
(
$
.
proxy
(
function
()
{
var
name
=
mock
.
req_names
.
sort
()[
1
];
var
jid
=
name
.
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
var
contact
=
this
.
roster
.
get
(
jid
);
spyOn
(
window
,
'
confirm
'
).
andReturn
(
true
);
spyOn
(
contact
,
'
unauthorize
'
).
andCallFake
(
function
()
{
return
contact
;
});
converse
.
rosterview
.
$el
.
find
(
"
.req-contact-name:contains('
"
+
name
+
"
')
"
)
.
siblings
(
'
.request-actions
'
)
.
find
(
'
.decline-xmpp-request
'
).
click
();
},
this
));
waits
(
50
);
runs
(
$
.
proxy
(
function
()
{
expect
(
window
.
confirm
).
toHaveBeenCalled
();
expect
(
this
.
connection
.
roster
.
unauthorize
).
toHaveBeenCalled
();
expect
(
contact
.
unauthorize
).
toHaveBeenCalled
();
// There should now be one less contact
expect
(
this
.
roster
.
length
).
toEqual
(
mock
.
req_names
.
length
-
1
);
},
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