ObjXMPP  Diff

Differences From Artifact [47e770589e]:

To Artifact [a2a1eacbe7]:


1
2

3
4
5
6
7
8
9
/*
 * Copyright (c) 2011, 2012, 2013, 2016, 2019, Jonathan Schleifer <js@heap.zone>

 * Copyright (c) 2011, 2012, 2013, Florian Zeitz <florob@babelmonkeys.de>
 *
 * 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) 2011, 2012, 2013, 2016, 2019, 2021,
 *   Jonathan Schleifer <js@nil.im>
 * Copyright (c) 2011, 2012, 2013, Florian Zeitz <florob@babelmonkeys.de>
 *
 * 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.
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
	if ([show isEqual: @"away"])
		return 2;
	if ([show isEqual: @"dnd"])
		return 3;
	if ([show isEqual: @"xa"])
		return 4;

	OF_ENSURE(0);
}

@implementation XMPPPresence
@synthesize status = _status, show = _show, priority = _priority;

+ (instancetype)presence
{







|







40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
	if ([show isEqual: @"away"])
		return 2;
	if ([show isEqual: @"dnd"])
		return 3;
	if ([show isEqual: @"xa"])
		return 4;

	OFEnsure(0);
}

@implementation XMPPPresence
@synthesize status = _status, show = _show, priority = _priority;

+ (instancetype)presence
{
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125

		if ((subElement = [element elementForName: @"status"
						namespace: XMPP_NS_CLIENT]))
			self.status = subElement.stringValue;

		if ((subElement = [element elementForName: @"priority"
						namespace: XMPP_NS_CLIENT]))
			self.priority = [OFNumber
			    numberWithIntMax: subElement.decimalValue];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}







|
|







111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126

		if ((subElement = [element elementForName: @"status"
						namespace: XMPP_NS_CLIENT]))
			self.status = subElement.stringValue;

		if ((subElement = [element elementForName: @"priority"
						namespace: XMPP_NS_CLIENT]))
			self.priority = [OFNumber numberWithLongLong:
			    [subElement longLongValueWithBase: 10]];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
	old = _status;
	_status = [status copy];
	[old release];
}

- (void)setPriority: (OFNumber *)priority
{
	intmax_t prio = priority.intMaxValue;
	OFNumber *old;

	if ((prio < -128) || (prio > 127))
		@throw [OFInvalidArgumentException exception];

	OFXMLElement *oldPriority = [self elementForName: @"priority"
					       namespace: XMPP_NS_CLIENT];

	if (oldPriority != nil)
		[self removeChild: oldPriority];

	OFString *priority_s =
	    [OFString stringWithFormat: @"%" @PRId8, priority.int8Value];
	[self addChild: [OFXMLElement elementWithName: @"priority"
					    namespace: XMPP_NS_CLIENT
					  stringValue: priority_s]];

	old = _priority;
	_priority = [priority copy];
	[old release];
}

- (of_comparison_result_t)compare: (id <OFComparing>)object
{
	XMPPPresence *otherPresence;
	OFNumber *otherPriority;
	OFString *otherShow;
	of_comparison_result_t priorityOrder;

	if (object == self)
		return OF_ORDERED_SAME;

	if (![(id)object isKindOfClass: [XMPPPresence class]])
		@throw [OFInvalidArgumentException exception];

	otherPresence = (XMPPPresence *)object;
	otherPriority = otherPresence.priority;
	if (otherPriority == nil)
		otherPriority = [OFNumber numberWithInt8: 0];

	if (_priority != nil)
		priorityOrder = [_priority compare: otherPriority];
	else
		priorityOrder =
		    [[OFNumber numberWithInt8: 0] compare: otherPriority];

	if (priorityOrder != OF_ORDERED_SAME)
		return priorityOrder;

	otherShow = otherPresence.show;
	if ([_show isEqual: otherShow])
		return OF_ORDERED_SAME;

	if (showToInt(_show) < showToInt(otherShow))
		return OF_ORDERED_ASCENDING;

	return OF_ORDERED_DESCENDING;
}
@end







|












|









|




|


|







|





|

|




|


|

|


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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
	old = _status;
	_status = [status copy];
	[old release];
}

- (void)setPriority: (OFNumber *)priority
{
	long long prio = priority.longLongValue;
	OFNumber *old;

	if ((prio < -128) || (prio > 127))
		@throw [OFInvalidArgumentException exception];

	OFXMLElement *oldPriority = [self elementForName: @"priority"
					       namespace: XMPP_NS_CLIENT];

	if (oldPriority != nil)
		[self removeChild: oldPriority];

	OFString *priority_s =
	    [OFString stringWithFormat: @"%hhd", priority.charValue];
	[self addChild: [OFXMLElement elementWithName: @"priority"
					    namespace: XMPP_NS_CLIENT
					  stringValue: priority_s]];

	old = _priority;
	_priority = [priority copy];
	[old release];
}

- (OFComparisonResult)compare: (id <OFComparing>)object
{
	XMPPPresence *otherPresence;
	OFNumber *otherPriority;
	OFString *otherShow;
	OFComparisonResult priorityOrder;

	if (object == self)
		return OFOrderedSame;

	if (![(id)object isKindOfClass: [XMPPPresence class]])
		@throw [OFInvalidArgumentException exception];

	otherPresence = (XMPPPresence *)object;
	otherPriority = otherPresence.priority;
	if (otherPriority == nil)
		otherPriority = [OFNumber numberWithChar: 0];

	if (_priority != nil)
		priorityOrder = [_priority compare: otherPriority];
	else
		priorityOrder =
		    [[OFNumber numberWithChar: 0] compare: otherPriority];

	if (priorityOrder != OFOrderedSame)
		return priorityOrder;

	otherShow = otherPresence.show;
	if ([_show isEqual: otherShow])
		return OFOrderedSame;

	if (showToInt(_show) < showToInt(otherShow))
		return OFOrderedAscending;

	return OFOrderedDescending;
}
@end