-
Notifications
You must be signed in to change notification settings - Fork 6
/
TNStropheIMClient.j
187 lines (148 loc) · 5.47 KB
/
TNStropheIMClient.j
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
* TNStropheIMClient.j
*
* Copyright (C) 2010 Ben Langfeld <ben@langfeld.me>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@import <Foundation/Foundation.j>
@import "TNStropheClient.j"
@import "TNStropheConnection.j"
@import "TNStropheJID.j"
@import "TNStropheRoster.j"
@import "TNStropheStanza.j"
@implementation TNStropheIMClient : TNStropheClient
{
TNStropheRoster _roster @accessors(getter=roster);
}
#pragma mark -
#pragma mark Class methods
/*! instantiate a TNStropheIMClient object
@param aService a url of a bosh service (MUST be complete url with http://)
@return a valid TNStropheIMClient
*/
+ (TNStropheIMClient)IMClientWithService:(CPString)aService
{
return [[TNStropheIMClient alloc] initWithService:aService];
}
/*! instantiate a TNStropheIMClient object
@param aService a url of a bosh service (MUST be complete url with http://)
@param aRosterClass the specific roster class to use (optional, defaults to TNStropheRoster)
@return a valid TNStropheIMClient
*/
+ (TNStropheIMClient)IMClientWithService:(CPString)aService rosterClass:(id)aRosterClass
{
return [[TNStropheIMClient alloc] initWithService:aService rosterClass:aRosterClass];
}
/*! instantiate a TNStropheIMClient object
@param aService a url of a bosh service (MUST be complete url with http://)
@param aJID a JID to connect to the XMPP server
@param aPassword the password associated to the JID
@return a valid TNStropheIMClient
*/
+ (TNStropheIMClient)IMClientWithService:(CPString)aService JID:(TNStropheJID)aJID password:(CPString)aPassword
{
return [[TNStropheIMClient alloc] initWithService:aService JID:aJID password:aPassword];
}
/*! instantiate a TNStropheIMClient object
@param aService a url of a bosh service (MUST be complete url with http://)
@param aJID a JID to connect to the XMPP server
@param aPassword the password associated to the JID
@param aRosterClass the specific roster class to use (optional, defaults to TNStropheRoster)
@return a valid TNStropheIMClient
*/
+ (TNStropheIMClient)IMClientWithService:(CPString)aService JID:(TNStropheJID)aJID password:(CPString)aPassword rosterClass:(id)aRosterClass
{
return [[TNStropheIMClient alloc] initWithService:aService JID:aJID password:aPassword rosterClass:aRosterClass];
}
#pragma mark -
#pragma mark Initialization
/*! initialize the TNStropheIMClient
@param aService a url of a bosh service (MUST be complete url with http://)
@param aRosterClass the specific roster class to use (optional, defaults to TNStropheRoster)
*/
- (id)initWithService:(CPString)aService rosterClass:(id)aRosterClass
{
if (self = [super initWithService:aService])
{
if (!aRosterClass)
aRosterClass = TNStropheRoster;
_roster = [aRosterClass rosterWithConnection:_connection];
}
return self;
}
/*! initialize the TNStropheIMClient
@param aService a url of a bosh service (MUST be complete url with http://)
@param aJID a JID to connect to the XMPP server
@param aPassword the password associated to the JID
@param aRosterClass the specific roster class to use (optional, defaults to TNStropheRoster)
*/
- (id)initWithService:(CPString)aService JID:(TNStropheJID)aJID password:(CPString)aPassword rosterClass:(id)aRosterClass
{
if (self = [self initWithService:aService rosterClass:aRosterClass])
{
_JID = aJID;
_password = aPassword;
[[CPNotificationCenter defaultCenter] addObserver:self selector:@selector(_didReceiveRoster:) name:TNStropheRosterRetrievedNotification object:nil];
}
return self;
}
#pragma mark -
#pragma mark Notification handler
/*! called when the roster has been retrieved and will send initial presence
and continue the connection delegate chain
@param aNotification the notification that triggers the message
*/
- (void)_didReceiveRoster:(CPNotification)aNotification
{
[self _sendInitialPresence];
[super onStropheConnected:_connection];
}
#pragma mark -
#pragma mark Connection
- (void)onStropheConnected:(TNStropheConnection)aConnection
{
[_roster getSubGroupDelimiter];
}
- (void)onStropheConnectFail:(TNStropheConnection)aConnection
{
[_roster clear];
[super onStropheConnectFail:aConnection];
}
- (void)onStropheDisconnected:(TNStropheConnection)aConnection
{
[_roster clear];
[super onStropheDisconnected:aConnection];
}
- (void)onStropheError:(TNStropheConnection)aConnection
{
[_roster clear];
[super onStropheError:aConnection];
}
- (id)initWithCoder:(CPCoder)aCoder
{
self = [super initWithCoder:aCoder];
if (self)
{
_roster = [aCoder decodeObjectForKey:@"_roster"];
}
return self;
}
- (void)encodeWithCoder:(CPCoder)aCoder
{
[super encodeWithCoder:aCoder];
[aCoder encodeObject:_roster forKey:@"_roster"];
}
@end