]> cgit.babelmonkeys.de Git - jubjub.git/blobdiff - src/core/JubChatClient.m
Move away from BOOL
[jubjub.git] / src / core / JubChatClient.m
index 77a4791541806bff07e079e3ecf01b7f4f26a1ae..fa4bd9e0aa2309957810b6e85f711c7296a9f0ef 100644 (file)
@@ -1,9 +1,16 @@
 #import "JubChatClient.h"
+#import "ObjXMPP/namespaces.h"
+
+#import "JubAvatarManager.h"
+
+#define JUB_CLIENT_URI @"http://babelmonkeys.de/jubjub"
 
 @implementation JubChatClient
 @synthesize connection = _connection;
 @synthesize roster = _roster;
+@synthesize avatarManager = _avatarManager;
 @synthesize contactManager = _contactManager;
+@synthesize discoEntity = _discoEntity;
 @synthesize presence = _presence;
 @synthesize ui = _ui;
 
                _roster = [[XMPPRoster alloc] initWithConnection: _connection];
                [_roster addDelegate: self];
 
+               _discoEntity =
+                   [[XMPPDiscoEntity alloc] initWithConnection: _connection
+                                                      capsNode: JUB_CLIENT_URI];
+
+               XMPPDiscoIdentity *identity =
+                   [XMPPDiscoIdentity identityWithCategory: @"client"
+                                                      type: @"pc"
+                                                      name: @"JubJub"];
+               [_discoEntity addIdentity: identity];
+               [_discoEntity addFeature: XMPP_NS_CAPS];
+
+               _avatarManager =
+                   [[JubAvatarManager alloc] initWithClient: self];
+
                _contactManager = [[XMPPContactManager alloc]
                    initWithConnection: _connection
                                roster: _roster];
@@ -31,8 +52,6 @@
 
                _streamManagement = [[XMPPStreamManagement alloc]
                    initWithConnection: _connection];
-
-               [_connection asyncConnectAndHandle];
        } @catch (id e) {
                [self release];
                @throw e;
@@ -49,7 +68,9 @@
 
        [_roster release];
        [_contactManager release];
+       [_discoEntity release];
        [_streamManagement release];
+       [_avatarManager release];
        [_connection release];
        [_presence release];
        [_chatMap release];
        return chat;
 }
 
+- (void)sendPresenceWithStatus: (OFString*)status
+{
+       [self sendPresenceWithStatus: status
+                               text: nil];
+}
+
+- (void)sendPresenceWithStatus: (OFString*)status
+                         text: (OFString*)text
+{
+       XMPPPresence *presence;
+
+       if ([status isEqual: @"unavailable"])
+               presence = [XMPPPresence presenceWithType: @"unavailable"];
+       else
+               presence = [XMPPPresence presence];
+
+       if (!([status isEqual: @"available"] ||
+             [status isEqual: @"unavailable"]))
+               presence.show = status;
+
+       if (text != nil)
+               presence.status = text;
+
+       OFXMLElement *caps = [OFXMLElement elementWithName: @"c"
+                                                namespace: XMPP_NS_CAPS];
+       [caps addAttributeWithName: @"hash"
+                      stringValue: @"sha-1"];
+       [caps addAttributeWithName: @"ver"
+                      stringValue: [_discoEntity capsHash]];
+       [caps addAttributeWithName: @"node"
+                      stringValue: JUB_CLIENT_URI];
+
+       [presence addChild: caps];
+
+       [_connection sendStanza: presence];
+}
+
 - (void)connection: (XMPPConnection*)connection
      wasBoundToJID: (XMPPJID*)jid
 {
-       of_log(@"Bound to JID: %@", [jid fullJID]);
-
        [_roster requestRoster];
 }
 
        if ([presence.from isEqual: connection.JID]) {
                [_ui         client: self
                  didChangePresence: presence];
-               OF_SETTER(_presence, presence, YES, 0);
+               OF_SETTER(_presence, presence, true, 0);
        }
 }
 
 
 - (void)rosterWasReceived: (XMPPRoster*)roster
 {
-       XMPPPresence *pres = [XMPPPresence presence];
-       [pres setStatus: @"Hello from JubJub"];
-       [_connection sendStanza: pres];
+       [self sendPresenceWithStatus: @"available"
+                               text: @"Hello from JubJub"];
 }
 @end