}
ENDCLICOMMAND
+BEGINCLICOMMAND(JubCLISubsCommand, @":subs",
+ @"[list | ack <who> | nak <who>]",
+ @"Lists, acknowledges or denies subscription requests")
+{
+ if ([parameters count] < 1) {
+ [of_stdout writeLine: @"Syntax: ':subs "
+ @"[list | ack <who> | nak <who>]'"];
+ return;
+ }
+
+ OFString *action = parameters[0];
+ if (![action isEqual: @"list"] && ([parameters count] != 2)) {
+ [of_stdout writeLine: @"Syntax: ':subs "
+ @"[list | ack <who> | nak <who>]'"];
+ return;
+ }
+
+ if ([action isEqual: @"list"]) {
+ for (OFString *request in _ui.subRequests)
+ [of_stdout writeLine: request];
+ return;
+ }
+
+ XMPPJID *JID = [XMPPJID JIDWithString: parameters[1]];
+
+ if ([action isEqual: @"ack"])
+ [_ui.client.contactManager sendSubscribedToJID: JID];
+ else if ([action isEqual: @"nak"])
+ [_ui.client.contactManager sendUnsubscribedToJID: JID];
+
+ [_ui.subRequests removeObject: parameters[1]];
+}
+ENDCLICOMMAND
+
@implementation JubCLIUI
@synthesize client = _client;
@synthesize lastIn = _lastIn;
@synthesize sink = _sink;
+@synthesize subRequests = _subRequests;
- initWithClient: (JubChatClient*)client
{
@try {
_commands = [OFMutableDictionary new];
+ _subRequests = [OFMutableSet new];
_client = [client retain];
_contactManager = client.contactManager;
[_contactManager addDelegate: self];
[self addCommand: [[[JubCLIRosterCommand alloc]
initWithCLIUI: self] autorelease]];
+ [self addCommand: [[[JubCLISubsCommand alloc]
+ initWithCLIUI: self] autorelease]];
} @catch (id e) {
[self release];
@throw e;
{
[_contactManager removeDelegate: self];
[_client release];
+ [_subRequests release];
[_commands release];
[super dealloc];
}
return YES;
}
+- (void)contactManager: (XMPPContactManager*)manager
+ didAddContact: (XMPPContact*)contact
+{
+ XMPPRosterItem *rosterItem = contact.rosterItem;
+ OFString *subscription = rosterItem.subscription;
+ OFString *bareJID = [rosterItem.JID bareJID];
+
+ if ([subscription isEqual: @"from"] || [subscription isEqual: @"both"])
+ [_subRequests removeObject: bareJID];
+}
+
+- (void)contactManager: (XMPPContactManager*)manager
+ didReceiveSubscriptionRequest: (XMPPPresence*)presence
+{
+ OFString *bareJID = [presence.from bareJID];
+ [_subRequests addObject: bareJID];
+ [of_stdout writeFormat: @"\r" BOLD("%@") @" send a request to "
+ @"subscribe to your presence\r\n"
+ @"Use the :subs command to answer it\n",
+ bareJID];
+ [[Linenoise sharedLinenoise] refreshLine];
+}
+
+- (void)contact: (XMPPContact*)contact
+ willUpdateWithRosterItem: (XMPPRosterItem*)rosterItem
+{
+ OFString *subscription = rosterItem.subscription;
+ OFString *bareJID = [rosterItem.JID bareJID];
+
+ if ([subscription isEqual: @"from"] || [subscription isEqual: @"both"])
+ [_subRequests removeObject: bareJID];
+}
+
- (void)contact: (XMPPContact*)contact
didSendMessage: (XMPPMessage*)message
{