XMPPContactManager: Support for handling subscription requests
This commit is contained in:
parent
702a18636d
commit
bd0440b3ee
2 changed files with 49 additions and 4 deletions
|
@ -57,6 +57,15 @@
|
|||
- (void)contactManager: (XMPPContactManager*)manager
|
||||
didRemoveContact: (XMPPContact*)contact;
|
||||
|
||||
/**
|
||||
* \brief This callback is called when a subscription request is received
|
||||
*
|
||||
* \param manager The contact manager that received the request
|
||||
* \param presence The type=subscribe presence
|
||||
*/
|
||||
- (void)contactManager: (XMPPContactManager*)manager
|
||||
didReceiveSubscriptionRequest: (XMPPPresence*)presence;
|
||||
|
||||
/**
|
||||
* \brief This callback is called whenever a contact is about to change its
|
||||
* roster item
|
||||
|
@ -118,6 +127,9 @@
|
|||
- initWithConnection: (XMPPConnection*)connection
|
||||
roster: (XMPPRoster*)roster;
|
||||
|
||||
- (void)sendSubscribedToJID: (XMPPJID*)subscriber;
|
||||
- (void)sendUnsubscribedToJID: (XMPPJID*)subscriber;
|
||||
|
||||
/**
|
||||
* \brief Adds the specified delegate.
|
||||
*
|
||||
|
|
|
@ -58,6 +58,22 @@
|
|||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
- (void)sendSubscribedToJID: (XMPPJID*)subscriber
|
||||
{
|
||||
XMPPPresence *presence = [XMPPPresence presenceWithType: @"subscribed"];
|
||||
[presence setTo: subscriber];
|
||||
[_connection sendStanza: presence];
|
||||
}
|
||||
|
||||
- (void)sendUnsubscribedToJID: (XMPPJID*)subscriber
|
||||
{
|
||||
XMPPPresence *presence =
|
||||
[XMPPPresence presenceWithType: @"unsubscribed"];
|
||||
[presence setTo: subscriber];
|
||||
[_connection sendStanza: presence];
|
||||
}
|
||||
|
||||
- (void)addDelegate: (id <XMPPContactManagerDelegate>)delegate
|
||||
{
|
||||
[_delegates addDelegate: delegate];
|
||||
|
@ -145,26 +161,43 @@
|
|||
- (void)connection: (XMPPConnection*)connection
|
||||
didReceivePresence: (XMPPPresence*)presence
|
||||
{
|
||||
XMPPContact *contact;
|
||||
XMPPJID *JID = [presence from];
|
||||
XMPPContact *contact = [_contacts objectForKey: [JID bareJID]];
|
||||
OFString *type = [presence type];
|
||||
|
||||
/* Subscription request */
|
||||
if ([type isEqual: @"subscribe"]) {
|
||||
of_log(@"ObjXMPP: received subscription request");
|
||||
[_delegates broadcastSelector: @selector(contactManager:
|
||||
didReceiveSubscriptionRequest:)
|
||||
withObject: self
|
||||
withObject: presence];
|
||||
return;
|
||||
}
|
||||
|
||||
contact = [_contacts objectForKey: [JID bareJID]];
|
||||
if (contact == nil)
|
||||
return;
|
||||
|
||||
// We only care for available and unavailable here, not subscriptions
|
||||
if ([[presence type] isEqual: @"available"]) {
|
||||
/* Available presence */
|
||||
if ([type isEqual: @"available"]) {
|
||||
[contact XMPP_setPresence: presence
|
||||
resource: [JID resource]];
|
||||
[_delegates broadcastSelector: @selector(contact:
|
||||
didSendPresence:)
|
||||
withObject: contact
|
||||
withObject: presence];
|
||||
} else if ([[presence type] isEqual: @"unavailable"]) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Unavailable presence */
|
||||
if ([type isEqual: @"unavailable"]) {
|
||||
[contact XMPP_removePresenceForResource: [JID resource]];
|
||||
[_delegates broadcastSelector: @selector(contact:
|
||||
didSendPresence:)
|
||||
withObject: contact
|
||||
withObject: presence];
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue