Commit 7d16ffeb authored by Mauro E. Bender's avatar Mauro E. Bender

Close #48 - Replace conversations already registered in the message receiver

parent 66a2dcaa
......@@ -8,7 +8,7 @@
Pod::Spec.new do |s|
s.name = "AMLChat"
s.version = "0.1.0"
s.version = "0.1.1"
s.summary = "A chat implementation for iOS and OSX."
# This description is used to generate tags and improve search results.
......@@ -24,7 +24,7 @@ Pod::Spec.new do |s|
s.homepage = "https://git.theamalgama.com/ios/chat"
s.license = 'MIT'
s.author = { "Mauro Bender" => "mauro@theamalgama.com" }
s.source = { :git => "https://git.theamalgama.com/ios/chat.git", :tag => "v0.1.0" }
s.source = { :git => "https://git.theamalgama.com/ios/chat.git", :tag => "v0.1.1" }
s.ios.deployment_target = '8.1'
s.osx.deployment_target = '10.9'
......
......@@ -25,6 +25,8 @@
@property AMLChatMessageDecoder *messageDecoder;
@property (readonly) NSArray *subscribedConversations;
- (AMLChatConversation *)subscribedConversationWithIdentifier:(NSString *)indentifier;
@property NSNotificationCenter *notificationCenter;
- (void)subscribeConversation:(AMLChatConversation *)conversationToSubscribe;
......
......@@ -68,25 +68,16 @@
#pragma mark - Conversations subscription
- (void)subscribeConversation:(AMLChatConversation *)conversationToSubscribe {
if([self isConversationAlreadySubscribed:conversationToSubscribe])
return;
[_subscribedConversations setObject:conversationToSubscribe forKey:conversationToSubscribe.identifier];
[_pubNubClient subscribeToChannels:@[conversationToSubscribe.identifier] withPresence:NO];
}
- (void)subscribeConversations:(NSArray *)conversationsToSubscribe {
NSMutableArray *conversationsAdded = [NSMutableArray new];
for(AMLChatConversation *conversation in conversationsToSubscribe) {
if(![self isConversationAlreadySubscribed:conversation]) {
[_subscribedConversations setObject:conversation forKey:conversation.identifier];
[conversationsAdded addObject:conversation];
}
}
[_pubNubClient subscribeToChannels:[conversationsAdded valueForKey:@"identifier"] withPresence:NO];
[_pubNubClient subscribeToChannels:[conversationsToSubscribe valueForKey:@"identifier"] withPresence:NO];
}
- (void)unsubscribeConversation:(AMLChatConversation *)conversationToUnubscribe {
......@@ -113,6 +104,10 @@
return [self conversationWithIdentifier:conversation.identifier] != nil;
}
- (AMLChatConversation *)subscribedConversationWithIdentifier:(NSString *)indentifier {
return [_subscribedConversations objectForKey:indentifier];
}
#pragma mark - Message received
- (void)client:(PubNub *)client didReceiveMessage:(PNMessageResult *)messageResult {
AMLChatConversation *conversation = [self conversationWithIdentifier:messageResult.data.subscribedChannel];
......
......@@ -28,11 +28,17 @@ describe(@"ChatMessageReceiver", ^{
[[messageReceiver.subscribedConversations should] contain:conversation];
});
it(@"should not add a conversation to the list if it's already there", ^{
[messageReceiver subscribeConversation:conversation];
it(@"should replace a conversation if it's already there", ^{
AMLChatConversation *repeatedConversation = [[AMLChatConversation alloc] initWithIdentifier:conversation.identifier];
[messageReceiver subscribeConversation:conversation];
[messageReceiver subscribeConversation:repeatedConversation];
[[messageReceiver.subscribedConversations should] haveCountOf:1];
AMLChatConversation *registeredConversation = [messageReceiver subscribedConversationWithIdentifier:conversation.identifier];
[[theValue(registeredConversation == repeatedConversation) should] beTrue];
});
it(@"should subscribe the channel with PubNub", ^{
......@@ -60,12 +66,18 @@ describe(@"ChatMessageReceiver", ^{
containObjects:conversation, conversation2, nil];
});
it(@"should not add a conversation to the list if they're already there", ^{
it(@"should replace the conversation to the list if they're already there", ^{
AMLChatConversation *repeatedConversation = [[AMLChatConversation alloc] initWithIdentifier:conversation.identifier];
[messageReceiver subscribeConversation:conversation];
[messageReceiver subscribeConversations:@[conversation2, conversation, conversation2]];
[messageReceiver subscribeConversations:@[conversation2, repeatedConversation]];
AMLChatConversation *registeredConversation = [messageReceiver subscribedConversationWithIdentifier:conversation.identifier];
[[messageReceiver.subscribedConversations should] haveCountOf:2];
[[theValue(registeredConversation == repeatedConversation) should] beTrue];
});
it(@"should subscribe the channels with PubNub", ^{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment