ObjXMPP  Diff

Differences From Artifact [44efae0635]:

To Artifact [f3f3c997c4]:


1
2
3
4
5
6
7
8
9
10
/*
 * Copyright (c) 2013, Florian Zeitz <florob@babelmonkeys.de>
 * Copyright (c) 2013, 2016, Jonathan Schleifer <js@heap.zone>
 *
 * https://heap.zone/objxmpp/
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice is present in all copies.
 *


|







1
2
3
4
5
6
7
8
9
10
/*
 * Copyright (c) 2013, Florian Zeitz <florob@babelmonkeys.de>
 * Copyright (c) 2013, 2016, 2019, Jonathan Schleifer <js@heap.zone>
 *
 * https://heap.zone/objxmpp/
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice is present in all copies.
 *
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
	[super dealloc];
}


- (void)sendSubscribedToJID: (XMPPJID *)subscriber
{
	XMPPPresence *presence = [XMPPPresence presenceWithType: @"subscribed"];
	[presence setTo: subscriber];
	[_connection sendStanza: presence];
}

- (void)sendUnsubscribedToJID: (XMPPJID *)subscriber
{
	XMPPPresence *presence =
	    [XMPPPresence presenceWithType: @"unsubscribed"];
	[presence setTo: subscriber];
	[_connection sendStanza: presence];
}

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







|







|







63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
	[super dealloc];
}


- (void)sendSubscribedToJID: (XMPPJID *)subscriber
{
	XMPPPresence *presence = [XMPPPresence presenceWithType: @"subscribed"];
	presence.to = subscriber;
	[_connection sendStanza: presence];
}

- (void)sendUnsubscribedToJID: (XMPPJID *)subscriber
{
	XMPPPresence *presence =
	    [XMPPPresence presenceWithType: @"unsubscribed"];
	presence.to = subscriber;
	[_connection sendStanza: presence];
}

- (void)addDelegate: (id <XMPPContactManagerDelegate>)delegate
{
	[_delegates addDelegate: delegate];
}
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
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
				   withObject: self
				   withObject: contact];
	[_contacts release];
	_contacts = nil;

	_contacts = [[OFMutableDictionary alloc] init];

	rosterItems = [roster rosterItems];
	for (OFString *bareJID in rosterItems) {
		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];
	}
}

-         (void)roster: (XMPPRoster *)roster
  didReceiveRosterItem: (XMPPRosterItem *)rosterItem
{
	XMPPContact *contact;
	OFString *bareJID = [[rosterItem JID] bareJID];

	contact = [_contacts objectForKey: bareJID];

	if ([[rosterItem subscription] isEqual: @"remove"]) {
		if (contact != nil)
			[_delegates broadcastSelector: @selector(contactManager:
							   didRemoveContact:)
					   withObject: self
					   withObject: contact];
		[_contacts removeObjectForKey: bareJID];
		return;
	}

	if (contact == nil) {
		contact = [[[XMPPContact alloc] init] autorelease];
		[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];
	}
}

-   (void)connection: (XMPPConnection *)connection
  didReceivePresence: (XMPPPresence *)presence
{
	XMPPContact *contact;
	XMPPJID *JID = [presence from];
	OFString *type = [presence type];

	/* Subscription request */
	if ([type isEqual: @"subscribe"]) {
		of_log(@"ObjXMPP: received subscription request");
		[_delegates broadcastSelector: @selector(contactManager:
						 didReceiveSubscriptionRequest:)
				   withObject: self
				   withObject: presence];
		return;
	}

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

	/* Available presence */
	if ([type isEqual: @"available"]) {
		[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]];
		[_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];

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







|


<
|













|



|











|











|







|
|











|






|









|











|
|




|






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
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
				   withObject: self
				   withObject: contact];
	[_contacts release];
	_contacts = nil;

	_contacts = [[OFMutableDictionary alloc] init];

	rosterItems = roster.rosterItems;
	for (OFString *bareJID in rosterItems) {
		XMPPContact *contact = [[[XMPPContact alloc] init] autorelease];

		contact.rosterItem = [rosterItems objectForKey: bareJID];
		[_contacts setObject: contact
			      forKey: bareJID];
		[_delegates broadcastSelector: @selector(contactManager:
						   didAddContact:)
				   withObject: self
				   withObject: contact];
	}
}

-         (void)roster: (XMPPRoster *)roster
  didReceiveRosterItem: (XMPPRosterItem *)rosterItem
{
	XMPPContact *contact;
	OFString *bareJID = rosterItem.JID.bareJID;

	contact = [_contacts objectForKey: bareJID];

	if ([rosterItem.subscription isEqual: @"remove"]) {
		if (contact != nil)
			[_delegates broadcastSelector: @selector(contactManager:
							   didRemoveContact:)
					   withObject: self
					   withObject: contact];
		[_contacts removeObjectForKey: bareJID];
		return;
	}

	if (contact == nil) {
		contact = [[[XMPPContact alloc] init] autorelease];
		contact.rosterItem = 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.rosterItem = rosterItem;
	}
}

-   (void)connection: (XMPPConnection *)connection
  didReceivePresence: (XMPPPresence *)presence
{
	XMPPContact *contact;
	XMPPJID *JID = presence.from;
	OFString *type = presence.type;

	/* Subscription request */
	if ([type isEqual: @"subscribe"]) {
		of_log(@"ObjXMPP: received subscription request");
		[_delegates broadcastSelector: @selector(contactManager:
						 didReceiveSubscriptionRequest:)
				   withObject: self
				   withObject: presence];
		return;
	}

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

	/* Available presence */
	if ([type isEqual: @"available"]) {
		[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];
		[_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_lockedOnJID = JID;

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