Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Xep 0012(Last Activity) implemented #99

Closed
wants to merge 1 commit into from

4 participants

tolgatanriverdi rexshi João Nunes Spencer MacDonald
tolgatanriverdi

I've implemented xep 012 if you like you can add this to master branch
If you want any changes you can let me know and I can make the changes

rexshi

great work

João Nunes

good stuff!

João Nunes

It might be also useful to return only the seconds in a method similar to: (NSDate*)lastActivityTime
returning a NSInteger.

Spencer MacDonald
Collaborator

This is superseded by #153

If you feel anything is missing let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 13, 2012
  1. tolgatanriverdi
This page is out of date. Refresh to see the latest.
18 Extensions/XEP-0012/XMPPIQ+LastActivity.h
View
@@ -0,0 +1,18 @@
+//
+// XMPPIQ+LastActivity.h
+// ArgelaIMPS
+//
+// Created by Tolga Tanriverdi on 8/8/12.
+// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
+//
+
+#import "XMPPIQ.h"
+
+@interface XMPPIQ (LastActivity)
++(XMPPIQ *) queryLastActivityOf:(XMPPJID*)jid;
+-(BOOL) hasLastActivity;
+-(NSDate*) lastActivityTime;
+-(NSString*) lastActivityFrom;
+-(BOOL) hasStatusMessage;
+-(NSString*)statusMessage;
+@end
76 Extensions/XEP-0012/XMPPIQ+LastActivity.m
View
@@ -0,0 +1,76 @@
+//
+// XMPPIQ+LastActivity.m
+// ArgelaIMPS
+//
+// Created by Tolga Tanriverdi on 8/8/12.
+// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
+//
+
+#import "XMPPIQ+LastActivity.h"
+#import "NSXMLElement+XMPP.h"
+#import "XMPPJID.h"
+#import "XMPPStream.h"
+
+@implementation XMPPIQ (LastActivity)
+
++(XMPPIQ*) queryLastActivityOf:(XMPPJID *)jid
+{
+ XMPPIQ *iq = [XMPPIQ iqWithType:@"get" to:jid elementID:[XMPPStream generateUUID]];
+ [iq addChild:[self elementLastActivity]];
+ return iq;
+}
+
++(NSXMLElement *)elementLastActivity {
+ return [NSXMLElement elementWithName:@"query" xmlns:@"jabber:iq:last"];
+}
+
+-(BOOL) hasLastActivity
+{
+ if (![[self type] isEqualToString:@"result"]) {
+ return NO;
+ }
+
+ if ([self elementForName:@"error"]) {
+ return NO;
+ }
+
+ return ([self elementForName:@"query" xmlns:@"jabber:iq:last"] != nil);
+}
+
+
+-(NSDate*)lastActivityTime
+{
+ NSXMLElement *activityElement = [self elementForName:@"query"];
+ int lastLogoutTime = [activityElement attributeIntValueForName:@"seconds"];
+ NSLog(@"Last Logout Time: %d Seconds Left",lastLogoutTime);
+
+
+ NSDate *result = [NSDate date];
+
+ result = [result dateByAddingTimeInterval:(lastLogoutTime*-1)];
+
+ return result;
+}
+
+-(NSString*) lastActivityFrom
+{
+ return [[self from] bare];
+}
+
+-(BOOL) hasStatusMessage
+{
+ NSXMLElement *activityElement = [self elementForName:@"query"];
+ NSLog(@"Activity Message: %@",[self description]);
+ if ([[activityElement stringValue] length]) {
+ return YES;
+ }
+
+ return NO;
+}
+
+-(NSString*) statusMessage
+{
+ return [[self elementForName:@"query"] stringValue];
+}
+
+@end
16 Xcode/iPhoneXMPP/iPhoneXMPP.xcodeproj/project.pbxproj
View
@@ -42,6 +42,7 @@
28AD73600D9D9599002E5188 /* MainWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 28AD735F0D9D9599002E5188 /* MainWindow.xib */; };
28C286E10D94DF7D0034E888 /* RootViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 28C286E00D94DF7D0034E888 /* RootViewController.m */; };
28F335F11007B36200424DE2 /* RootViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 28F335F01007B36200424DE2 /* RootViewController.xib */; };
+ 8895EC7B15D931F9003A154F /* XMPPIQ+LastActivity.m in Sources */ = {isa = PBXBuildFile; fileRef = 8895EC7A15D931F9003A154F /* XMPPIQ+LastActivity.m */; };
DC1CF89B1361F28000E71363 /* NSString+DDXML.m in Sources */ = {isa = PBXBuildFile; fileRef = DC1CF8901361F28000E71363 /* NSString+DDXML.m */; };
DC1CF89D1361F28000E71363 /* DDXMLDocument.m in Sources */ = {isa = PBXBuildFile; fileRef = DC1CF8941361F28000E71363 /* DDXMLDocument.m */; };
DC1CF89E1361F28000E71363 /* DDXMLElement.m in Sources */ = {isa = PBXBuildFile; fileRef = DC1CF8961361F28000E71363 /* DDXMLElement.m */; };
@@ -164,6 +165,8 @@
28C286E00D94DF7D0034E888 /* RootViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = RootViewController.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
28F335F01007B36200424DE2 /* RootViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = RootViewController.xib; sourceTree = "<group>"; };
29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
+ 8895EC7915D931F9003A154F /* XMPPIQ+LastActivity.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "XMPPIQ+LastActivity.h"; sourceTree = "<group>"; };
+ 8895EC7A15D931F9003A154F /* XMPPIQ+LastActivity.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "XMPPIQ+LastActivity.m"; sourceTree = "<group>"; };
8D1107310486CEB800E47090 /* iPhoneXMPP-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "iPhoneXMPP-Info.plist"; plistStructureDefinitionIdentifier = "com.apple.xcode.plist.structure-definition.iphone.info-plist"; sourceTree = "<group>"; };
DC1CF88F1361F28000E71363 /* NSString+DDXML.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+DDXML.h"; sourceTree = "<group>"; };
DC1CF8901361F28000E71363 /* NSString+DDXML.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+DDXML.m"; sourceTree = "<group>"; };
@@ -311,9 +314,10 @@
070400471347CB510092A737 /* Extensions */ = {
isa = PBXGroup;
children = (
- DC37309B139E9FD100A8407D /* Reconnect */,
DC488440134AEB06000F79C5 /* CoreDataStorage */,
+ DC37309B139E9FD100A8407D /* Reconnect */,
DC37309F139E9FDA00A8407D /* Roster */,
+ 8895EC7815D931F9003A154F /* XEP-0012 */,
DCC2211F149A61F000736DC1 /* XEP-0045 */,
070400591347CB510092A737 /* XEP-0054 */,
0704007B1347CB520092A737 /* XEP-0082 */,
@@ -491,6 +495,15 @@
name = Frameworks;
sourceTree = "<group>";
};
+ 8895EC7815D931F9003A154F /* XEP-0012 */ = {
+ isa = PBXGroup;
+ children = (
+ 8895EC7915D931F9003A154F /* XMPPIQ+LastActivity.h */,
+ 8895EC7A15D931F9003A154F /* XMPPIQ+LastActivity.m */,
+ );
+ path = "XEP-0012";
+ sourceTree = "<group>";
+ };
DC1CF88D1361F28000E71363 /* KissXML */ = {
isa = PBXGroup;
children = (
@@ -965,6 +978,7 @@
DC30E6CF153E09D2001B9E6D /* XMPPDigestMD5Authentication.m in Sources */,
DC30E6D0153E09D2001B9E6D /* XMPPPlainAuthentication.m in Sources */,
DC30E6D1153E09D2001B9E6D /* XMPPXFacebookPlatformAuthentication.m in Sources */,
+ 8895EC7B15D931F9003A154F /* XMPPIQ+LastActivity.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Something went wrong with that request. Please try again.