]> cgit.babelmonkeys.de Git - jubjub.git/blobdiff - src/core/JubChatClient.m
Add a minimal JubChatClient class and refactor other code to use it
[jubjub.git] / src / core / JubChatClient.m
diff --git a/src/core/JubChatClient.m b/src/core/JubChatClient.m
new file mode 100644 (file)
index 0000000..a31bdb5
--- /dev/null
@@ -0,0 +1,57 @@
+#import "JubChatClient.h"
+
+@implementation JubChatClient
+@synthesize connection;
+@synthesize roster;
+@synthesize ui;
+
+- initWithConfig: (JubConfig*)config
+{
+       self = [super init];
+
+       @try {
+               connection = [XMPPConnection new];
+
+               connection.username = config.username;
+               connection.domain = config.domain;
+               connection.server = config.server;
+               connection.password = config.password;
+               [connection addDelegate: self];
+
+               roster = [[XMPPRoster alloc] initWithConnection: connection];
+               [roster addDelegate: self];
+
+               streamManagement = [[XMPPStreamManagement alloc]
+                   initWithConnection: connection];
+
+               [connection asyncConnectAndHandle];
+       } @catch (id e) {
+               [self release];
+               @throw e;
+       }
+
+       return self;
+}
+
+- (void)dealloc
+{
+       [roster release];
+       [streamManagement release];
+       [connection release];
+
+       [super dealloc];
+}
+
+- (void)connection: (XMPPConnection*)conn_
+     wasBoundToJID: (XMPPJID*)jid
+{
+       of_log(@"Bound to JID: %@", [jid fullJID]);
+
+       [roster requestRoster];
+}
+
+- (void)rosterWasReceived: (XMPPRoster*)roster
+{
+       [connection sendStanza: [XMPPPresence presence]];
+}
+@end