20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#import "XMPPPresence.h"
#import "namespaces.h"
@implementation XMPPPresence
+ presence
{
return [[[self alloc] init] autorelease];
}
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
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
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <assert.h>
#import "XMPPPresence.h"
#import "namespaces.h"
// This provides us with sortable values for show values
static int show_to_int(OFString *show)
{
if ([show isEqual: @"chat"]) return 0;
if (show == nil) return 1; // available
if ([show isEqual: @"away"]) return 2;
if ([show isEqual: @"dnd"]) return 3;
if ([show isEqual: @"xa"]) return 4;
assert(0);
}
@implementation XMPPPresence
+ presence
{
return [[[self alloc] init] autorelease];
}
|
160
161
162
163
164
165
166
167
|
OF_SETTER(priority, priority_, YES, 1);
}
- (OFString*)priority
{
return [[priority copy] autorelease];
}
@end
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
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
|
OF_SETTER(priority, priority_, YES, 1);
}
- (OFString*)priority
{
return [[priority copy] autorelease];
}
- (of_comparison_result_t)compare: (id <OFComparing>)object
{
XMPPPresence *otherPresence;
OFString *otherShow;
of_comparison_result_t priorityOrder;
if (object == self)
return OF_ORDERED_SAME;
if (![object isKindOfClass: [XMPPPresence class]])
@throw [OFInvalidArgumentException
exceptionWithClass: [self class]
selector: _cmd];
otherPresence = (XMPPPresence*)object;
priorityOrder = [priority compare: [otherPresence priority]];
if (priorityOrder != OF_ORDERED_SAME)
return priorityOrder;
otherShow = [otherPresence show];
if ([show isEqual: otherShow])
return OF_ORDERED_SAME;
if (show_to_int(show) < show_to_int(otherShow))
return OF_ORDERED_ASCENDING;
return OF_ORDERED_DESCENDING;
}
@end
|