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

Add _Nullable to XMPPRoster #1160

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alessioarsuffi
Copy link

Add _Nullable to method of XMPPRoster:

(NSArray *)jidsForXMPPStream:(XMPPStream * _Nullable)stream

to be able to call this from swift with a nil stream reference.

This is especially useful when user wants to retrieve roster from swift code and stream is not yet connected.

Add _Nullable to method of XMPPRoster:

`(NSArray *)jidsForXMPPStream:(XMPPStream * _Nullable)stream`

to be able to call this from swift with a nil stream reference.

This is especially useful when user wants to retrieve roster from swift code and stream is not yet connected.
@alessioarsuffi
Copy link
Author

Hi @chrisballinger :)

This is a small change to better support swift.
Please let me know if this is ok for you, i'm available to add more _Nullable flags to the framework in future.

Thanks

@chrisballinger
Copy link
Collaborator

I'm not sure if we really want to change this API contract. You can always construct an XMPPStream that is not connected and pass that in.

@alessioarsuffi
Copy link
Author

- (NSArray *)jidsForXMPPStream:(XMPPStream * _Nullable)stream {
    
    XMPPLogTrace();
    
    __block NSMutableArray *results = [NSMutableArray array];
	
	[self executeBlock:^{
		
		NSManagedObjectContext *moc = [self managedObjectContext];
		
		NSEntityDescription *entity = [NSEntityDescription entityForName:@"XMPPUserCoreDataStorageObject"
												  inManagedObjectContext:moc];
		
		NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
		[fetchRequest setEntity:entity];
		[fetchRequest setFetchBatchSize:self->saveThreshold];
		
		if (stream)
		{
			NSPredicate *predicate;
			predicate = [NSPredicate predicateWithFormat:@"streamBareJidStr == %@",
                         [[self myJIDForXMPPStream:stream] bare]];
			
			[fetchRequest setPredicate:predicate];
		}
		
		NSArray *allUsers = [moc executeFetchRequest:fetchRequest error:nil];
        
        for(XMPPUserCoreDataStorageObject *user in allUsers){
            [results addObject:[user.jid bareJID]];
        }
		
	}];
    
    return results;
}

The problem is inside this method, if we use a not connected stream, will be applied to predicate a nil streamBareJidStr value, resulting in 0 fetched jabbers from database, if we pass a stream which is nil and not connected we will fetch jabbers from roster even if we are still not connected.
Without _Nullable in that signature is not possible to fetch jabbers from database without a valid stream connection. Because query will exclude all jabbers in roster.

Also, if stream cannot be nil, why we check if stream exist to create a predicate?

@chrisballinger
Copy link
Collaborator

@alessioarsuffi Sorry for the delay on this! An XMPPStream can be instantiated without being connected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants