Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

XMPPvCardAvatarModule APIs Updated for Consistency

Fixes #95
  • Loading branch information...
commit 2a4ed5f20546e8e85afcb06954ce8bf4ec9efc65 1 parent 9a2b64d
@ObjColumnist ObjColumnist authored
View
3  Extensions/CoreDataStorage/XMPPCoreDataStorage.h
@@ -49,12 +49,13 @@
NSManagedObjectContext *managedObjectContext;
NSManagedObjectContext *mainThreadManagedObjectContext;
- BOOL autoAllowExternalBinaryDataStorage;
@protected
NSString *databaseFileName;
NSUInteger saveThreshold;
NSUInteger saveCount;
+
+ BOOL autoAllowExternalBinaryDataStorage;
dispatch_queue_t storageQueue;
void *storageQueueTag;
View
12 Extensions/XEP-0054/CoreDataStorage/XMPPvCardCoreDataStorage.m
@@ -61,6 +61,11 @@ - (BOOL)configureWithParent:(XMPPvCardTempModule *)aParent queue:(dispatch_queue
#pragma mark Overrides
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+- (void)commonInit
+{
+ autoAllowExternalBinaryDataStorage = YES;
+ [super commonInit];
+}
- (BOOL)addPersistentStoreWithPath:(NSString *)storePath error:(NSError **)errorPtr
{
BOOL result = [super addPersistentStoreWithPath:storePath error:errorPtr];
@@ -195,6 +200,13 @@ - (void)setvCardTemp:(XMPPvCardTemp *)vCardTemp forJID:(XMPPJID *)jid xmppStream
}];
}
+- (XMPPvCardTemp *)myvCardTempForXMPPStream:(XMPPStream *)stream
+{
+ if(!stream) return nil;
+
+ return [self vCardTempForJID:[[stream myJID] bareJID] xmppStream:stream];
+}
+
- (BOOL)shouldFetchvCardTempForJID:(XMPPJID *)jid xmppStream:(XMPPStream *)stream
{
// This is a public method.
View
36 Extensions/XEP-0054/XMPPvCardTempModule.h
@@ -20,22 +20,36 @@
@interface XMPPvCardTempModule : XMPPModule
{
- id <XMPPvCardTempModuleStorage> __strong _moduleStorage;
- XMPPIDTracker *myvCardTracker;
+ id <XMPPvCardTempModuleStorage> __strong _xmppvCardTempModuleStorage;
+ XMPPIDTracker *_myvCardTracker;
}
-@property(nonatomic, strong, readonly) id <XMPPvCardTempModuleStorage> moduleStorage;
+@property(nonatomic, strong, readonly) id <XMPPvCardTempModuleStorage> xmppvCardTempModuleStorage;
@property(nonatomic, strong, readonly) XMPPvCardTemp *myvCardTemp;
- (id)initWithvCardStorage:(id <XMPPvCardTempModuleStorage>)storage;
- (id)initWithvCardStorage:(id <XMPPvCardTempModuleStorage>)storage dispatchQueue:(dispatch_queue_t)queue;
-/*
- * Return the cached vCard for the user or fetch it, if we don't have it.
- */
-- (XMPPvCardTemp *)fetchvCardTempForJID:(XMPPJID *)jid;
-- (XMPPvCardTemp *)fetchvCardTempForJID:(XMPPJID *)jid useCache:(BOOL)useCache;
+/**
+ * Fetches the vCardTemp for the given JID if it is not in the storage
+**/
+- (void)fetchvCardTempForJID:(XMPPJID *)jid;
+
+/**
+ * Fetches the vCardTemp for the given JID, optionally ignoring the storage
+**/
+- (void)fetchvCardTempForJID:(XMPPJID *)jid ignoreStorage:(BOOL)ignoreStorage;
+
+/**
+ * Returns the vCardTemp for the given JID, this is the equivalent of calling the vCardTempForJID:xmppStream: on the moduleStorage
+ * If there is no vCardTemp in the storage for the given jid and shouldFetch is YES, it will automatically fetch it from the network
+**/
+- (XMPPvCardTemp *)vCardTempForJID:(XMPPJID *)jid shouldFetch:(BOOL)shouldFetch;
+
+/**
+ * Updates myvCard in storage and sends it to the server
+**/
- (void)updateMyvCardTemp:(XMPPvCardTemp *)vCardTemp;
@end
@@ -55,7 +69,6 @@
- (void)xmppvCardTempModule:(XMPPvCardTempModule *)vCardTempModule failedToUpdateMyvCard:(NSXMLElement *)error;
-
@end
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -91,6 +104,11 @@
- (void)setvCardTemp:(XMPPvCardTemp *)vCardTemp forJID:(XMPPJID *)jid xmppStream:(XMPPStream *)stream;
/**
+ * Returns My vCardTemp object or nil
+**/
+- (XMPPvCardTemp *)myvCardTempForXMPPStream:(XMPPStream *)stream;
+
+/**
* Asks the backend if we should fetch the vCardTemp from the network.
* This is used so that we don't request the vCardTemp multiple times.
**/
View
76 Extensions/XEP-0054/XMPPvCardTempModule.m
@@ -27,6 +27,7 @@
@interface XMPPvCardTempModule()
- (void)_updatevCardTemp:(XMPPvCardTemp *)vCardTemp forJID:(XMPPJID *)jid;
+- (void)_fetchvCardTempForJID:(XMPPJID *)jid;
@end
@@ -36,7 +37,7 @@ - (void)_updatevCardTemp:(XMPPvCardTemp *)vCardTemp forJID:(XMPPJID *)jid;
@implementation XMPPvCardTempModule
-@synthesize moduleStorage = _moduleStorage;
+@synthesize xmppvCardTempModuleStorage = _xmppvCardTempModuleStorage;
- (id)init
{
@@ -67,7 +68,7 @@ - (id)initWithvCardStorage:(id <XMPPvCardTempModuleStorage>)storage dispatchQueu
{
if ([storage configureWithParent:self queue:moduleQueue])
{
- _moduleStorage = storage;
+ _xmppvCardTempModuleStorage = storage;
}
else
{
@@ -83,7 +84,7 @@ - (BOOL)activate:(XMPPStream *)aXmppStream
{
// Custom code goes here (if needed)
- myvCardTracker = [[XMPPIDTracker alloc] initWithDispatchQueue:moduleQueue];
+ _myvCardTracker = [[XMPPIDTracker alloc] initWithDispatchQueue:moduleQueue];
return YES;
}
@@ -97,8 +98,8 @@ - (void)deactivate
dispatch_block_t block = ^{ @autoreleasepool {
- [myvCardTracker removeAllIDs];
- myvCardTracker = nil;
+ [_myvCardTracker removeAllIDs];
+ _myvCardTracker = nil;
}};
@@ -112,35 +113,54 @@ - (void)deactivate
- (void)dealloc
{
- _moduleStorage = nil;
+ _xmppvCardTempModuleStorage = nil;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark Fetch vCardTemp methods
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-- (XMPPvCardTemp *)fetchvCardTempForJID:(XMPPJID *)jid
+- (void)fetchvCardTempForJID:(XMPPJID *)jid
{
- return [self fetchvCardTempForJID:jid useCache:YES];
+ return [self fetchvCardTempForJID:jid ignoreStorage:NO];
}
-- (XMPPvCardTemp *)fetchvCardTempForJID:(XMPPJID *)jid useCache:(BOOL)useCache
-{
- __block XMPPvCardTemp *result;
-
+- (void)fetchvCardTempForJID:(XMPPJID *)jid ignoreStorage:(BOOL)ignoreStorage
+{
dispatch_block_t block = ^{ @autoreleasepool {
XMPPvCardTemp *vCardTemp = nil;
- if (useCache)
+ if (!ignoreStorage)
+ {
+ // Try loading from storage
+ vCardTemp = [_xmppvCardTempModuleStorage vCardTempForJID:jid xmppStream:xmppStream];
+ }
+
+ if (vCardTemp == nil && [_xmppvCardTempModuleStorage shouldFetchvCardTempForJID:jid xmppStream:xmppStream])
{
- // Try loading from the cache
- vCardTemp = [_moduleStorage vCardTempForJID:jid xmppStream:xmppStream];
+ [self _fetchvCardTempForJID:jid];
}
- if (vCardTemp == nil && [_moduleStorage shouldFetchvCardTempForJID:jid xmppStream:xmppStream])
+ }};
+
+ if (dispatch_get_specific(moduleQueueTag))
+ block();
+ else
+ dispatch_sync(moduleQueue, block);
+}
+
+- (XMPPvCardTemp *)vCardTempForJID:(XMPPJID *)jid shouldFetch:(BOOL)shouldFetch{
+
+ __block XMPPvCardTemp *result;
+
+ dispatch_block_t block = ^{ @autoreleasepool {
+
+ XMPPvCardTemp *vCardTemp = [_xmppvCardTempModuleStorage vCardTempForJID:jid xmppStream:xmppStream];
+
+ if (vCardTemp == nil && shouldFetch && [_xmppvCardTempModuleStorage shouldFetchvCardTempForJID:jid xmppStream:xmppStream])
{
- [xmppStream sendElement:[XMPPvCardTemp iqvCardRequestForJID:jid]];
+ [self _fetchvCardTempForJID:jid];
}
result = vCardTemp;
@@ -156,7 +176,7 @@ - (XMPPvCardTemp *)fetchvCardTempForJID:(XMPPJID *)jid useCache:(BOOL)useCache
- (XMPPvCardTemp *)myvCardTemp
{
- return [self fetchvCardTempForJID:[xmppStream myJID]];
+ return [self vCardTempForJID:[xmppStream myJID] shouldFetch:YES];
}
- (void)updateMyvCardTemp:(XMPPvCardTemp *)vCardTemp
@@ -171,10 +191,10 @@ - (void)updateMyvCardTemp:(XMPPvCardTemp *)vCardTemp
XMPPIQ *iq = [XMPPIQ iqWithType:@"set" to:nil elementID:myvCardElementID child:newvCardTemp];
[xmppStream sendElement:iq];
- [myvCardTracker addID:myvCardElementID
+ [_myvCardTracker addID:myvCardElementID
target:self
selector:@selector(handleMyvcard:withInfo:)
- timeout:60];
+ timeout:600];
[self _updatevCardTemp:newvCardTemp forJID:[xmppStream myJID]];
@@ -193,16 +213,14 @@ - (void)updateMyvCardTemp:(XMPPvCardTemp *)vCardTemp
- (void)_updatevCardTemp:(XMPPvCardTemp *)vCardTemp forJID:(XMPPJID *)jid
{
- if(jid == nil){
- return;
- }
+ if(!jid) return;
// this method could be called from anywhere
dispatch_block_t block = ^{ @autoreleasepool {
XMPPLogVerbose(@"%@: %s %@", THIS_FILE, __PRETTY_FUNCTION__, [jid bare]);
- [_moduleStorage setvCardTemp:vCardTemp forJID:jid xmppStream:xmppStream];
+ [_xmppvCardTempModuleStorage setvCardTemp:vCardTemp forJID:jid xmppStream:xmppStream];
[(id <XMPPvCardTempModuleDelegate>)multicastDelegate xmppvCardTempModule:self
didReceivevCardTemp:vCardTemp
@@ -215,6 +233,12 @@ - (void)_updatevCardTemp:(XMPPvCardTemp *)vCardTemp forJID:(XMPPJID *)jid
dispatch_async(moduleQueue, block);
}
+- (void)_fetchvCardTempForJID:(XMPPJID *)jid{
+ if(!jid) return;
+
+ [xmppStream sendElement:[XMPPvCardTemp iqvCardRequestForJID:jid]];
+}
+
- (void)handleMyvcard:(XMPPIQ *)iq withInfo:(XMPPBasicTrackingInfo *)trackerInfo{
if([iq isResultIQ])
@@ -237,7 +261,7 @@ - (BOOL)xmppStream:(XMPPStream *)sender didReceiveIQ:(XMPPIQ *)iq
{
// This method is invoked on the moduleQueue.
- [myvCardTracker invokeForID:[iq elementID] withObject:iq];
+ [_myvCardTracker invokeForID:[iq elementID] withObject:iq];
// Remember XML heirarchy memory management rules.
// The passed parameter is a subnode of the IQ, and we need to pass it to an asynchronous operation.
@@ -258,7 +282,7 @@ - (BOOL)xmppStream:(XMPPStream *)sender didReceiveIQ:(XMPPIQ *)iq
- (void)xmppStreamDidDisconnect:(XMPPStream *)sender withError:(NSError *)error
{
- [myvCardTracker removeAllIDs];
+ [_myvCardTracker removeAllIDs];
}
@end
View
12 Extensions/XEP-0153/XMPPvCardAvatarModule.m
@@ -68,7 +68,7 @@ - (id)initWithvCardTempModule:(XMPPvCardTempModule *)xmppvCardTempModule dispatc
// we don't need to call the storage configureWithParent:queue: method,
// because the vCardTempModule already did that.
- _moduleStorage = (id <XMPPvCardAvatarStorage>)xmppvCardTempModule.moduleStorage;
+ _moduleStorage = (id <XMPPvCardAvatarStorage>)xmppvCardTempModule.xmppvCardTempModuleStorage;
[_xmppvCardTempModule addDelegate:self delegateQueue:moduleQueue];
@@ -136,7 +136,7 @@ - (NSData *)photoDataForJID:(XMPPJID *)jid
if (photoData == nil)
{
- [_xmppvCardTempModule fetchvCardTempForJID:jid useCache:YES];
+ [_xmppvCardTempModule vCardTempForJID:jid shouldFetch:YES];
}
}};
@@ -171,7 +171,7 @@ - (void)xmppStreamDidConnect:(XMPPStream *)sender {
- (void)xmppStreamDidAuthenticate:(XMPPStream *)sender {
XMPPLogTrace();
- [_xmppvCardTempModule fetchvCardTempForJID:[sender myJID] useCache:NO];
+ [_xmppvCardTempModule fetchvCardTempForJID:[sender myJID] ignoreStorage:YES];
}
@@ -236,7 +236,7 @@ - (void)xmppStream:(XMPPStream *)sender didReceivePresence:(XMPPPresence *)prese
// check the hash
if (![photoHash isEqualToString:[_moduleStorage photoHashForJID:jid xmppStream:xmppStream]]
&& !([photoHash length] == 0 && [savedPhotoHash length] == 0)) {
- [_xmppvCardTempModule fetchvCardTempForJID:jid useCache:NO];
+ [_xmppvCardTempModule fetchvCardTempForJID:jid ignoreStorage:YES];
}
}
@@ -287,12 +287,12 @@ - (void)xmppvCardTempModule:(XMPPvCardTempModule *)vCardTempModule
- (void)xmppvCardTempModuleDidUpdateMyvCard:(XMPPvCardTempModule *)vCardTempModule{
//The vCard has been updated on the server so we need to cache it
- [_xmppvCardTempModule fetchvCardTempForJID:[xmppStream myJID] useCache:NO];
+ [_xmppvCardTempModule fetchvCardTempForJID:[xmppStream myJID] ignoreStorage:YES];
}
- (void)xmppvCardTempModule:(XMPPvCardTempModule *)vCardTempModule failedToUpdateMyvCard:(NSXMLElement *)error{
//The vCard failed to update so we fetch the current one from the server
- [_xmppvCardTempModule fetchvCardTempForJID:[xmppStream myJID] useCache:NO];
+ [_xmppvCardTempModule fetchvCardTempForJID:[xmppStream myJID] ignoreStorage:YES];
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Please sign in to comment.
Something went wrong with that request. Please try again.