Permalink
Browse files

Implement TNStropheVCard and use it. Cool for bindings

  • Loading branch information...
1 parent 66300b1 commit 38bfd2b6c17d6dee4e7efe8cde8cb69cd58ee844 @primalmotion primalmotion committed Mar 12, 2013
Showing with 220 additions and 75 deletions.
  1. +10 −8 StropheCappuccino.j
  2. +10 −25 TNStropheClient.j
  3. +19 −42 TNStropheContact.j
  4. +181 −0 TNStropheVCard.j
View
@@ -19,20 +19,22 @@
*/
-@import "Resources/Strophe/strophe.js"
+@import "MUC/TNStropheMUCRoom.j"
@import "Resources/Strophe/sha1.js"
-@import "TNStropheJID.j"
-@import "TNStropheStanza.j"
-@import "TNStropheGroup.j"
-@import "TNStropheIMClient.j"
+@import "Resources/Strophe/strophe.js"
+@import "TNPubSub.j"
@import "TNStropheClient.j"
@import "TNStropheConnection.j"
@import "TNStropheContact.j"
-@import "TNStropheRoster.j"
-@import "TNPubSub.j"
+@import "TNStropheGroup.j"
+@import "TNStropheIMClient.j"
+@import "TNStropheJID.j"
@import "TNStrophePrivateStorage.j"
+@import "TNStropheRoster.j"
@import "TNStropheServerAdministration.j"
-@import "MUC/TNStropheMUCRoom.j"
+@import "TNStropheStanza.j"
+@import "TNStropheVCard.j"
+
[TNStropheClient addNamespaceWithName:@"CAPS" value:@"http://jabber.org/protocol/caps"];
View
@@ -27,6 +27,7 @@
@import "TNStropheJID.j"
@import "TNStropheStanza.j"
@import "TNXMLNode.j"
+@import "TNStropheVCard.j"
@global TNStropheContactStatusOffline
@global TNStropheContactStatusOnline
@@ -48,7 +49,7 @@ TNStropheClientVCardReceivedNotification = @"TNStropheClientVCardReceived
id _delegate @accessors(property=delegate);
TNStropheConnection _connection @accessors(property=connection);
TNStropheJID _JID @accessors(property=JID);
- TNXMLNode _vCard @accessors(getter=vCard);
+ TNStropheVCard _vCard @accessors(getter=vCard);
CPImage _avatar @accessors(getter=avatar);
CPString _userPresenceShow;
@@ -373,17 +374,8 @@ TNStropheClientVCardReceivedNotification = @"TNStropheClientVCardReceived
{
if ([aStanza type] == @"result")
{
- _vCard = [aStanza firstChildWithName:@"vCard"];
-
- var photo = [_vCard firstChildWithName:@"PHOTO"];
-
- if (photo)
- {
- var type = [[photo firstChildWithName:@"TYPE"] text],
- binval = [[photo firstChildWithName:@"BINVAL"] text];
-
- _avatar = [[CPImage alloc] initWithData:[CPData dataWithBase64:binval]];
- }
+ _vCard = [[TNStropheVCard alloc] initWithXMLNode:[aStanza firstChildWithName:@"vCard"]];
+ _avatar = [_vCard photo];
}
[[CPNotificationCenter defaultCenter] postNotificationName:TNStropheClientVCardReceivedNotification object:self userInfo:aStanza];
@@ -401,18 +393,11 @@ TNStropheClientVCardReceivedNotification = @"TNStropheClientVCardReceived
{
var uid = [_connection getUniqueId],
stanza = [TNStropheStanza iqWithAttributes:{@"id": uid, @"type": @"set"}],
- params = [CPDictionary dictionaryWithObjectsAndKeys:uid, @"id"],
- photo = [aVCard firstChildWithName:@"PHOTO"];
-
- if (photo)
- {
- var binval = [[photo firstChildWithName:@"BINVAL"] text];
+ params = [CPDictionary dictionaryWithObjectsAndKeys:uid, @"id"];
- _avatar = [[CPImage alloc] initWithData:[CPData dataWithBase64:binval]];
- }
_vCard = aVCard;
- [stanza addNode:aVCard];
+ [stanza addNode:[_vCard XMLNode]];
[_connection registerSelector:@selector(notifyVCardUpdate:) ofObject:self withDict:params];
[_connection registerSelector:aSelector ofObject:anObject withDict:params userInfo:someUserInfo];
@@ -497,10 +482,10 @@ TNStropheClientVCardReceivedNotification = @"TNStropheClientVCardReceived
if (self)
{
- _JID = [aCoder decodeObjectForKey:@"_JID"];
- _password = [aCoder decodeObjectForKey:@"_password"];
- _delegate = [aCoder decodeObjectForKey:@"_delegate"];
- _connection = [aCoder decodeObjectForKey:@"_connection"];
+ _JID = [aCoder decodeObjectForKey:@"_JID"];
+ _password = [aCoder decodeObjectForKey:@"_password"];
+ _delegate = [aCoder decodeObjectForKey:@"_delegate"];
+ _connection = [aCoder decodeObjectForKey:@"_connection"];
}
return self;
View
@@ -24,7 +24,7 @@
@import "TNStropheConnection.j"
@import "TNStropheGroup.j"
@import "TNStropheJID.j"
-
+@import "TNStropheVCard.j"
TNStropheContactStatusAway = @"away";
TNStropheContactStatusBusy = @"xa";
@@ -66,19 +66,19 @@ TNStropheContactImageNewError = nil;
CPArray _groups @accessors(property=groups);
CPArray _messagesQueue @accessors(property=messagesQueue);
CPArray _resources @accessors(property=resources);
+ CPImage _avatar @accessors(property=avatar);
CPImage _statusIcon @accessors(property=statusIcon);
CPNumber _numberOfEvents @accessors(property=numberOfEvents);
CPString _nickname @accessors(property=nickname);
CPString _nodeName @accessors(property=nodeName);
CPString _subscription @accessors(property=subscription);
CPString _type @accessors(property=type);
- CPString _vCard @accessors(property=vCard);
CPString _XMPPShow @accessors(property=XMPPShow);
CPString _XMPPStatus @accessors(property=XMPPStatus);
id _delegate @accessors(getter=delegate);
- CPImage _avatar @accessors(property=avatar);
TNStropheConnection _connection @accessors(property=connection);
TNStropheJID _JID @accessors(property=JID);
+ TNStropheVCard _vCard @accessors(property=vCard);
BOOL _askingVCard;
BOOL _isComposing;
@@ -90,19 +90,6 @@ TNStropheContactImageNewError = nil;
#pragma mark -
#pragma mark Class methods
-+ (void)initialize
-{
- [self exposeBinding:@"statusIcon"];
- [self exposeBinding:@"nickname"];
- [self exposeBinding:@"subscription"];
- [self exposeBinding:@"vCard"];
- [self exposeBinding:@"XMPPShow"];
- [self exposeBinding:@"XMPPStatus"];
- [self exposeBinding:@"avatar"];
- [self exposeBinding:@"JID"];
- [self exposeBinding:@"resources"];
-}
-
/*! create a contact using a given connection, JID and group
@param aConnection TNStropheConnection to use
@param aJID the JID of the contact
@@ -167,7 +154,7 @@ TNStropheContactImageNewError = nil;
#pragma mark -
-#pragma mark Setters
+#pragma mark Setters and Getters
/*! Set the delegate
You should not use this yourself if you are
@@ -192,6 +179,11 @@ TNStropheContactImageNewError = nil;
_implementedDelegateMethods |= TNStropheContactDelegate_avatarForContact_;
}
+- (CPString)name
+{
+ return [_vCard fullName] || _nickname;
+}
+
#pragma mark -
#pragma mark Status
@@ -420,35 +412,20 @@ TNStropheContactImageNewError = nil;
if (aVCard)
{
- [self setVCard:aVCard];
+ var VCARD = [[TNStropheVCard alloc] initWithXMLNode:aVCard];
if (!_nickname || (_nickname == [_JID bare]) || (_nickname == [_JID node]))
- {
- if ([aVCard firstChildWithName:@"FN"])
- [self setNickname:[[aVCard firstChildWithName:@"FN"] text]];
- else
- [self setNickname:[_JID node]];
- }
-
- var photoNode,
- photoIDNode;
-
- if (photoNode = [aVCard firstChildWithName:@"PHOTO"])
- {
- var data = [[photoNode firstChildWithName:@"BINVAL"] text];
-
- // the delegate will send the TNStropheContactVCardReceivedNotification when image will be ready
- [self setAvatar:[[CPImage alloc] initWithData:[CPData dataWithBase64:data]]];
- [_avatar setDelegate:self];
+ [self setNickname:[VCARD fullName] || [_JID node]]
- }
- else
- {
- if (_implementedDelegateMethods & TNStropheContactDelegate_avatarForContact_)
- [self setAvatar:[_delegate avatarForContact:self]];
+ if ([VCARD photo])
+ [self setAvatar:[VCARD photo]];
+ else if (_implementedDelegateMethods & TNStropheContactDelegate_avatarForContact_)
+ [self setAvatar:[_delegate avatarForContact:self]];
- [[CPNotificationCenter defaultCenter] postNotificationName:TNStropheContactVCardReceivedNotification object:self];
- }
+ [self willChangeValueForKey:@"name"];
+ [self setVCard:VCARD];
+ [self didChangeValueForKey:@"name"];
+ [[CPNotificationCenter defaultCenter] postNotificationName:TNStropheContactVCardReceivedNotification object:self];
}
return NO;
Oops, something went wrong.

0 comments on commit 38bfd2b

Please sign in to comment.