ObjXMPP  Diff

Differences From Artifact [e40b256e89]:

To Artifact [5c8553fb32]:


28
29
30
31
32
33
34
35
36


37
38
39
40
41
42
43
28
29
30
31
32
33
34


35
36
37
38
39
40
41
42
43







-
-
+
+







#import "XMPPMulticastDelegate.h"
#import "XMPPPresence.h"
#import "XMPPRosterItem.h"

@implementation XMPPContactManager
@synthesize contacts = _contacts;

- initWithConnection: (XMPPConnection *)connection
	      roster: (XMPPRoster *)roster
- (instancetype)initWithConnection: (XMPPConnection *)connection
			    roster: (XMPPRoster *)roster
{
	self = [super init];

	@try {
		_connection = connection;
		[_connection addDelegate: self];
		_roster = roster;
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
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







-
-

-
-

-
+
-




-

+


+

-
+
-
-
-
+
+







- (void)removeDelegate: (id <XMPPContactManagerDelegate>)delegate
{
	[_delegates removeDelegate: delegate];
}

- (void)rosterWasReceived: (XMPPRoster *)roster
{
	OFEnumerator *contactEnumerator;
	XMPPContact *contact;
	OFDictionary *rosterItems;
	OFEnumerator *rosterItemEnumerator;
	OFString *bareJID;

	contactEnumerator = [_contacts objectEnumerator];
	for (XMPPContact *contact in _contacts)
	while ((contact = [contactEnumerator nextObject]) != nil) {
		[_delegates broadcastSelector: @selector(contactManager:
						   didRemoveContact:)
				   withObject: self
				   withObject: contact];
	}
	[_contacts release];
	_contacts = nil;

	_contacts = [[OFMutableDictionary alloc] init];

	rosterItems = [roster rosterItems];
	rosterItemEnumerator = [rosterItems keyEnumerator];
	for (OFString *bareJID in rosterItems) {
	while ((bareJID = [rosterItemEnumerator nextObject]) != nil) {
		contact = [[[XMPPContact alloc] init] autorelease];
		[contact XMPP_setRosterItem:
		XMPPContact *contact = [[[XMPPContact alloc] init] autorelease];
		[contact xmpp_setRosterItem:
		    [rosterItems objectForKey: bareJID]];
		[_contacts setObject: contact
			      forKey: bareJID];
		[_delegates broadcastSelector: @selector(contactManager:
						   didAddContact:)
				   withObject: self
				   withObject: contact];
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
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







-
+











-
+







					   withObject: contact];
		[_contacts removeObjectForKey: bareJID];
		return;
	}

	if (contact == nil) {
		contact = [[[XMPPContact alloc] init] autorelease];
		[contact XMPP_setRosterItem: rosterItem];
		[contact xmpp_setRosterItem: rosterItem];
		[_contacts setObject: contact
			     forKey: bareJID];
		[_delegates broadcastSelector: @selector(contactManager:
						   didAddContact:)
				   withObject: self
				   withObject: contact];
	} else {
		[_delegates broadcastSelector: @selector(contact:
						   willUpdateWithRosterItem:)
				   withObject: contact
				   withObject: rosterItem];
		[contact XMPP_setRosterItem: rosterItem];
		[contact xmpp_setRosterItem: rosterItem];
	}
}

-   (void)connection: (XMPPConnection *)connection
  didReceivePresence: (XMPPPresence *)presence
{
	XMPPContact *contact;
176
177
178
179
180
181
182
183

184
185
186
187
188
189
190
191
192
193
194

195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212

213
214
215
216
217
218
171
172
173
174
175
176
177

178
179
180
181
182
183
184
185
186
187
188

189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206

207
208
209
210
211
212
213







-
+










-
+

















-
+







	contact = [_contacts objectForKey: [JID bareJID]];
	if (contact == nil)
		return;

	/* Available presence */
	if ([type isEqual: @"available"]) {
		[contact XMPP_setPresence: presence
		[contact xmpp_setPresence: presence
				 resource: [JID resource]];
		[_delegates broadcastSelector: @selector(contact:
						   didSendPresence:)
				   withObject: contact
				   withObject: presence];
		return;
	}

	/* Unavailable presence */
	if ([type isEqual: @"unavailable"]) {
		[contact XMPP_removePresenceForResource: [JID resource]];
		[contact xmpp_removePresenceForResource: [JID resource]];
		[_delegates broadcastSelector: @selector(contact:
						   didSendPresence:)
				   withObject: contact
				   withObject: presence];
		return;
	}
}

-  (void)connection: (XMPPConnection *)connection
  didReceiveMessage: (XMPPMessage *)message
{
	XMPPJID *JID = [message from];
	XMPPContact *contact = [_contacts objectForKey: [JID bareJID]];

	if (contact == nil)
		return;

	[contact XMPP_setLockedOnJID: JID];
	[contact xmpp_setLockedOnJID: JID];

	[_delegates broadcastSelector: @selector(contact:didSendMessage:)
			   withObject: contact
			   withObject: message];
}
@end