Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avatar Bug Fixes #46

Closed
wants to merge 11 commits into from
2 changes: 1 addition & 1 deletion Core/XMPPStream.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

// Log levels: off, error, warn, info, verbose
#if DEBUG
static const int xmppLogLevel = XMPP_LOG_LEVEL_INFO | XMPP_LOG_FLAG_SEND_RECV; // | XMPP_LOG_FLAG_TRACE;
static const int xmppLogLevel = XMPP_LOG_LEVEL_INFO | XMPP_LOG_FLAG_SEND_RECV; // | XMPP_LOG_FLAG_TRACE;
#else
static const int xmppLogLevel = XMPP_LOG_LEVEL_WARN;
#endif
Expand Down
2 changes: 2 additions & 0 deletions Extensions/CoreDataStorage/XMPPCoreDataStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,6 @@
**/
@property (strong, readonly) NSManagedObjectContext *mainThreadManagedObjectContext;

- (void)resetManagedObjectContext;

@end
9 changes: 9 additions & 0 deletions Extensions/CoreDataStorage/XMPPCoreDataStorage.m
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,15 @@ - (void)scheduleBlock:(dispatch_block_t)block
}});
}

- (void)resetManagedObjectContext
{
XMPPLogTrace();

[self executeBlock:^{
[[self managedObjectContext] reset];
}];
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark Memory Management
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
32 changes: 32 additions & 0 deletions Extensions/Roster/XMPPRoster.m
Original file line number Diff line number Diff line change
Expand Up @@ -804,4 +804,36 @@ - (void)xmppvCardAvatarModule:(XMPPvCardAvatarModule *)vCardTempModule

#endif

- (void)refetchRoster
{
// This is a public method, so it may be invoked on any thread/queue.

dispatch_block_t block = ^{ @autoreleasepool {

[self setRequestedRoster:NO];
[self setHasRoster:NO];

[earlyPresenceElements removeAllObjects];

// <iq type="get">
// <query xmlns="jabber:iq:roster"/>
// </iq>

NSXMLElement *query = [NSXMLElement elementWithName:@"query" xmlns:@"jabber:iq:roster"];

NSXMLElement *iq = [NSXMLElement elementWithName:@"iq"];
[iq addAttributeWithName:@"type" stringValue:@"get"];
[iq addChild:query];

[xmppStream sendElement:iq];

[self setRequestedRoster:YES];
}};

if (dispatch_get_current_queue() == moduleQueue)
block();
else
dispatch_async(moduleQueue, block);
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ - (NSData *)photoData {

- (void)setPhotoData:(NSData *)photoData
{
if (photoData == nil)
if ([photoData length] == 0)
{
if (self.vCardAvatarRel != nil)
{
Expand Down
10 changes: 9 additions & 1 deletion Extensions/XEP-0054/XMPPvCardTempModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

#import <Foundation/Foundation.h>
#import "XMPP.h"
#import "XMPPvCardTemp.h"

@class XMPPvCardTemp;
@class XMPPIDTracker;

#define _XMPP_VCARD_TEMP_MODULE_H

Expand All @@ -19,6 +21,7 @@
@interface XMPPvCardTempModule : XMPPModule
{
id <XMPPvCardTempModuleStorage> __strong _moduleStorage;
XMPPIDTracker *myvCardTracker;
}


Expand Down Expand Up @@ -48,6 +51,11 @@
didReceivevCardTemp:(XMPPvCardTemp *)vCardTemp
forJID:(XMPPJID *)jid;

- (void)xmppvCardTempModuleDidUpdateMyvCard:(XMPPvCardTempModule *)vCardTempModule;

- (void)xmppvCardTempModule:(XMPPvCardTempModule *)vCardTempModule failedToUpdateMyvCard:(NSXMLElement *)error;


@end

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
68 changes: 63 additions & 5 deletions Extensions/XEP-0054/XMPPvCardTempModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#import "XMPP.h"
#import "XMPPLogging.h"
#import "XMPPvCardTempModule.h"
#import "XMPPvCardTemp.h"
#import "XMPPIDTracker.h"

#if ! __has_feature(objc_arc)
#warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
Expand Down Expand Up @@ -81,6 +83,8 @@ - (BOOL)activate:(XMPPStream *)aXmppStream
{
// Custom code goes here (if needed)

myvCardTracker = [[XMPPIDTracker alloc] initWithDispatchQueue:moduleQueue];

return YES;
}

Expand All @@ -90,6 +94,18 @@ - (BOOL)activate:(XMPPStream *)aXmppStream
- (void)deactivate
{
// Custom code goes here (if needed)

dispatch_block_t block = ^{ @autoreleasepool {

[myvCardTracker removeAllIDs];
myvCardTracker = nil;

}};

if (dispatch_get_current_queue() == moduleQueue)
block();
else
dispatch_sync(moduleQueue, block);

[super deactivate];
}
Expand Down Expand Up @@ -145,13 +161,29 @@ - (XMPPvCardTemp *)myvCardTemp

- (void)updateMyvCardTemp:(XMPPvCardTemp *)vCardTemp
{
XMPPvCardTemp *newvCardTemp = [vCardTemp copy];

dispatch_block_t block = ^{ @autoreleasepool {

NSString *elemId = [xmppStream generateUUID];
XMPPIQ *iq = [XMPPIQ iqWithType:@"set" to:nil elementID:elemId child:newvCardTemp];
[xmppStream sendElement:iq];
XMPPvCardTemp *newvCardTemp = [vCardTemp copy];

[self _updatevCardTemp:newvCardTemp forJID:[xmppStream myJID]];
NSString *myvCardElementID = [xmppStream generateUUID];

XMPPIQ *iq = [XMPPIQ iqWithType:@"set" to:nil elementID:myvCardElementID child:newvCardTemp];
[xmppStream sendElement:iq];

[myvCardTracker addID:myvCardElementID
target:self
selector:@selector(handleMyvcard:withInfo:)
timeout:60];

[self _updatevCardTemp:newvCardTemp forJID:[xmppStream myJID]];

}};

if (dispatch_get_current_queue() == moduleQueue)
block();
else
dispatch_sync(moduleQueue, block);

}

Expand All @@ -161,6 +193,10 @@ - (void)updateMyvCardTemp:(XMPPvCardTemp *)vCardTemp

- (void)_updatevCardTemp:(XMPPvCardTemp *)vCardTemp forJID:(XMPPJID *)jid
{
if(jid == nil){
return;
}

// this method could be called from anywhere
dispatch_block_t block = ^{ @autoreleasepool {

Expand All @@ -179,6 +215,20 @@ - (void)_updatevCardTemp:(XMPPvCardTemp *)vCardTemp forJID:(XMPPJID *)jid
dispatch_async(moduleQueue, block);
}

- (void)handleMyvcard:(XMPPIQ *)iq withInfo:(XMPPBasicTrackingInfo *)trackerInfo{

if([iq isResultIQ])
{
[(id <XMPPvCardTempModuleDelegate>)multicastDelegate xmppvCardTempModuleDidUpdateMyvCard:self];
}
else if([iq isErrorIQ])
{
NSXMLElement *errorElement = [iq elementForName:@"error"];
[(id <XMPPvCardTempModuleDelegate>)multicastDelegate xmppvCardTempModule:self failedToUpdateMyvCard:errorElement];
}

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark XMPPStreamDelegate methods
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -187,11 +237,14 @@ - (BOOL)xmppStream:(XMPPStream *)sender didReceiveIQ:(XMPPIQ *)iq
{
// This method is invoked on the moduleQueue.

[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.
//
// Therefore we use vCardTempCopyFromIQ instead of vCardTempSubElementFromIQ.


XMPPvCardTemp *vCardTemp = [XMPPvCardTemp vCardTempCopyFromIQ:iq];
if (vCardTemp != nil)
{
Expand All @@ -203,4 +256,9 @@ - (BOOL)xmppStream:(XMPPStream *)sender didReceiveIQ:(XMPPIQ *)iq
return NO;
}

- (void)xmppStreamDidDisconnect:(XMPPStream *)sender withError:(NSError *)error
{
[myvCardTracker removeAllIDs];
}

@end
43 changes: 30 additions & 13 deletions Extensions/XEP-0115/XMPPCapabilities.m
Original file line number Diff line number Diff line change
Expand Up @@ -1532,19 +1532,36 @@ - (XMPPPresence *)xmppStream:(XMPPStream *)sender willSendPresence:(XMPPPresence
}
else if ([type isEqualToString:@"available"])
{
if (myCapabilitiesQuery == nil)
{
// It appears we haven't collected our list of capabilites yet.
// This will need to be done before we can add the hash to the outgoing presence element.

[self collectMyCapabilities];
}
else if (myCapabilitiesC)
{
NSXMLElement *c = [myCapabilitiesC copy];

[presence addChild:c];
}

NSXMLElement *cElement = [presence elementForName:@"c" xmlns:XMLNS_CAPS];

//Remove the existing C Element
if(cElement)
{
NSUInteger currentCElementIndex = [[presence children] indexOfObject:cElement];

if(currentCElementIndex != NSNotFound)
{
[presence removeChildAtIndex:currentCElementIndex];
}
}

// The capabilities have already been set (maybe the existing presence is being resent?)
// So don't add them again

if (myCapabilitiesQuery == nil)
{
// It appears we haven't collected our list of capabilites yet.
// This will need to be done before we can add the hash to the outgoing presence element.

[self collectMyCapabilities];
}
else if (myCapabilitiesC)
{
NSXMLElement *c = [myCapabilitiesC copy];

[presence addChild:c];
}
}

return presence;
Expand Down
Loading