Commit 1b18f233 authored by Mauro E. Bender's avatar Mauro E. Bender

Close #32 - Show conversations and unread count in example app

parent 09ae262b
......@@ -6,7 +6,7 @@ build_code:
script:
- bundle install
- cp Example/Config/ChatSetup.plist.example Example/Config/ChatSetup.plist
- cd Example && fastlane test
- cd Example && bundle exec fastlane test
tags:
- ios
artifacts:
......
......@@ -28,6 +28,11 @@
9871B3221C6D2E690028BB1B /* AMLChatExampleMessagesTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = 9871B3211C6D2E690028BB1B /* AMLChatExampleMessagesTableView.m */; };
9871B3251C6D318F0028BB1B /* ChatSetup.plist in Resources */ = {isa = PBXBuildFile; fileRef = 9871B3241C6D318F0028BB1B /* ChatSetup.plist */; };
987E20931C720C4F004C1D86 /* AMLChatConversationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 987E20921C720C4F004C1D86 /* AMLChatConversationTests.m */; };
98AB2E661C74A99D008DB153 /* AMLChatExampleConversationsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 98AB2E651C74A99D008DB153 /* AMLChatExampleConversationsViewController.m */; };
98AB2E6A1C74AAC3008DB153 /* AMLChatExampleConversationsTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = 98AB2E691C74AAC3008DB153 /* AMLChatExampleConversationsTableView.m */; };
98AB2E6E1C74AB82008DB153 /* AMLChatExampleConversationTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 98AB2E6C1C74AB82008DB153 /* AMLChatExampleConversationTableViewCell.m */; };
98AB2E6F1C74AB82008DB153 /* AMLChatExampleConversationTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 98AB2E6D1C74AB82008DB153 /* AMLChatExampleConversationTableViewCell.xib */; };
98AB2E731C74B424008DB153 /* AMLChatExampleConversationsInitializer.m in Sources */ = {isa = PBXBuildFile; fileRef = 98AB2E721C74B424008DB153 /* AMLChatExampleConversationsInitializer.m */; };
98F9FF7E1C6CDC9400B6FD51 /* AMLChatConversationHistoryLoaderTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 98F9FF761C6CDC9400B6FD51 /* AMLChatConversationHistoryLoaderTests.m */; };
98F9FF7F1C6CDC9400B6FD51 /* AMLChatMessageDecoderTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 98F9FF771C6CDC9400B6FD51 /* AMLChatMessageDecoderTests.m */; };
98F9FF801C6CDC9400B6FD51 /* AMLChatMessageEncoderTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 98F9FF781C6CDC9400B6FD51 /* AMLChatMessageEncoderTests.m */; };
......@@ -81,6 +86,15 @@
9871B3211C6D2E690028BB1B /* AMLChatExampleMessagesTableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AMLChatExampleMessagesTableView.m; path = Views/Messages/AMLChatExampleMessagesTableView.m; sourceTree = "<group>"; };
9871B3241C6D318F0028BB1B /* ChatSetup.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = ChatSetup.plist; path = Config/ChatSetup.plist; sourceTree = SOURCE_ROOT; };
987E20921C720C4F004C1D86 /* AMLChatConversationTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AMLChatConversationTests.m; sourceTree = "<group>"; };
98AB2E641C74A99D008DB153 /* AMLChatExampleConversationsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AMLChatExampleConversationsViewController.h; sourceTree = "<group>"; };
98AB2E651C74A99D008DB153 /* AMLChatExampleConversationsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AMLChatExampleConversationsViewController.m; sourceTree = "<group>"; };
98AB2E681C74AAC3008DB153 /* AMLChatExampleConversationsTableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AMLChatExampleConversationsTableView.h; path = Views/Conversations/AMLChatExampleConversationsTableView.h; sourceTree = "<group>"; };
98AB2E691C74AAC3008DB153 /* AMLChatExampleConversationsTableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AMLChatExampleConversationsTableView.m; path = Views/Conversations/AMLChatExampleConversationsTableView.m; sourceTree = "<group>"; };
98AB2E6B1C74AB82008DB153 /* AMLChatExampleConversationTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AMLChatExampleConversationTableViewCell.h; path = Views/Conversations/AMLChatExampleConversationTableViewCell.h; sourceTree = "<group>"; };
98AB2E6C1C74AB82008DB153 /* AMLChatExampleConversationTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AMLChatExampleConversationTableViewCell.m; path = Views/Conversations/AMLChatExampleConversationTableViewCell.m; sourceTree = "<group>"; };
98AB2E6D1C74AB82008DB153 /* AMLChatExampleConversationTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = AMLChatExampleConversationTableViewCell.xib; path = Views/Conversations/AMLChatExampleConversationTableViewCell.xib; sourceTree = "<group>"; };
98AB2E711C74B424008DB153 /* AMLChatExampleConversationsInitializer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AMLChatExampleConversationsInitializer.h; path = Managers/AMLChatExampleConversationsInitializer.h; sourceTree = "<group>"; };
98AB2E721C74B424008DB153 /* AMLChatExampleConversationsInitializer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AMLChatExampleConversationsInitializer.m; path = Managers/AMLChatExampleConversationsInitializer.m; sourceTree = "<group>"; };
98F9FF761C6CDC9400B6FD51 /* AMLChatConversationHistoryLoaderTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AMLChatConversationHistoryLoaderTests.m; sourceTree = "<group>"; };
98F9FF771C6CDC9400B6FD51 /* AMLChatMessageDecoderTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AMLChatMessageDecoderTests.m; sourceTree = "<group>"; };
98F9FF781C6CDC9400B6FD51 /* AMLChatMessageEncoderTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AMLChatMessageEncoderTests.m; sourceTree = "<group>"; };
......@@ -172,8 +186,11 @@
6003F59C195388D20070C39A /* AMLAppDelegate.h */,
6003F59D195388D20070C39A /* AMLAppDelegate.m */,
873B8AEA1B1F5CCA007FD442 /* Main.storyboard */,
98AB2E641C74A99D008DB153 /* AMLChatExampleConversationsViewController.h */,
98AB2E651C74A99D008DB153 /* AMLChatExampleConversationsViewController.m */,
6003F5A5195388D20070C39A /* AMLChatExampleConversationViewController.h */,
6003F5A6195388D20070C39A /* AMLChatExampleConversationViewController.m */,
98AB2E701C74B401008DB153 /* Managers */,
98F9FF861C6CFC8000B6FD51 /* Views */,
9871B3231C6D30FE0028BB1B /* Config */,
6003F594195388D20070C39A /* Supporting Files */,
......@@ -240,9 +257,31 @@
name = Config;
sourceTree = "<group>";
};
98AB2E671C74AA8F008DB153 /* Conversations */ = {
isa = PBXGroup;
children = (
98AB2E681C74AAC3008DB153 /* AMLChatExampleConversationsTableView.h */,
98AB2E691C74AAC3008DB153 /* AMLChatExampleConversationsTableView.m */,
98AB2E6B1C74AB82008DB153 /* AMLChatExampleConversationTableViewCell.h */,
98AB2E6C1C74AB82008DB153 /* AMLChatExampleConversationTableViewCell.m */,
98AB2E6D1C74AB82008DB153 /* AMLChatExampleConversationTableViewCell.xib */,
);
name = Conversations;
sourceTree = "<group>";
};
98AB2E701C74B401008DB153 /* Managers */ = {
isa = PBXGroup;
children = (
98AB2E711C74B424008DB153 /* AMLChatExampleConversationsInitializer.h */,
98AB2E721C74B424008DB153 /* AMLChatExampleConversationsInitializer.m */,
);
name = Managers;
sourceTree = "<group>";
};
98F9FF861C6CFC8000B6FD51 /* Views */ = {
isa = PBXGroup;
children = (
98AB2E671C74AA8F008DB153 /* Conversations */,
98F9FF871C6CFC8700B6FD51 /* Messages */,
);
name = Views;
......@@ -350,6 +389,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
98AB2E6F1C74AB82008DB153 /* AMLChatExampleConversationTableViewCell.xib in Resources */,
9871B31F1C6D2D740028BB1B /* AMLChatExampleMessageTableViewCell.xib in Resources */,
873B8AEB1B1F5CCA007FD442 /* Main.storyboard in Resources */,
9871B3251C6D318F0028BB1B /* ChatSetup.plist in Resources */,
......@@ -466,7 +506,11 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
98AB2E6E1C74AB82008DB153 /* AMLChatExampleConversationTableViewCell.m in Sources */,
98AB2E731C74B424008DB153 /* AMLChatExampleConversationsInitializer.m in Sources */,
98AB2E6A1C74AAC3008DB153 /* AMLChatExampleConversationsTableView.m in Sources */,
6003F59E195388D20070C39A /* AMLAppDelegate.m in Sources */,
98AB2E661C74A99D008DB153 /* AMLChatExampleConversationsViewController.m in Sources */,
6003F5A7195388D20070C39A /* AMLChatExampleConversationViewController.m in Sources */,
9871B31E1C6D2D740028BB1B /* AMLChatExampleMessageTableViewCell.m in Sources */,
9871B3221C6D2E690028BB1B /* AMLChatExampleMessagesTableView.m in Sources */,
......
......@@ -28,7 +28,7 @@
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "4CF7E418FC99BEEA800D569F631378B3"
BlueprintIdentifier = "41B776A0C0527E7EC80BD59A1330502A"
BuildableName = "AMLChat.framework"
BlueprintName = "AMLChat"
ReferencedContainer = "container:Pods/Pods.xcodeproj">
......
......@@ -8,6 +8,8 @@
#import "AMLAppDelegate.h"
#define kAMLChatPubNubClientUUIDUserDefaultsKey @"com.theamalgama.AMLChat.pubNubUUID"
@implementation AMLAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
......@@ -17,22 +19,35 @@
}
- (void)initChat {
NSString *identifier = [[self class] getUniquePersistedUUID];
NSString *name = [identifier substringToIndex:5];
_currentChatUser = [AMLChatUser userWithIdentifier:identifier
name:name];
AMLChatPushNotificationsConfiguration *pushConfig =
[[AMLChatPushNotificationsConfiguration alloc] initWithAlertMessage:@"[USER]: [MESSAGE]"
alertSound:@""
alertType:nil];
[[AMLChatPushNotificationsConfiguration alloc] initWithAlertMessage:@"[USER]: [MESSAGE]"
alertSound:@""
alertType:nil];
NSString *pubNubConfigPath = [[NSBundle mainBundle] pathForResource:@"ChatSetup" ofType:@"plist"];
_chatClient = [AMLChat chatManagerWithPubNubConfigurationFromPlistFileWithPath:pubNubConfigPath
pushNotificationsConfiguration:pushConfig];
_chatClient = [AMLChat chatManagerWithPubNubUUID:_currentChatUser.identifier
pubNubConfigurationFromPlistFileWithPath:pubNubConfigPath
pushNotificationsConfiguration:pushConfig];
[PNLog enabled:YES];
}
NSString *identifier = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
NSString *name = [identifier substringToIndex:5];
+ (NSString *)getUniquePersistedUUID {
NSString *pubNubUUID = [[NSUserDefaults standardUserDefaults] objectForKey:kAMLChatPubNubClientUUIDUserDefaultsKey];
_currentChatUser = [AMLChatUser userWithIdentifier:identifier
name:name];
if(!pubNubUUID) {
pubNubUUID = [[NSUUID UUID] UUIDString];
[[NSUserDefaults standardUserDefaults] setObject:pubNubUUID forKey:kAMLChatPubNubClientUUIDUserDefaultsKey];
}
return pubNubUUID;
}
- (void)applicationWillResignActive:(UIApplication *)application
......
......@@ -13,6 +13,6 @@
- (instancetype)initWithConversation:(AMLChatConversation *)conversation;
@property (nonatomic) AMLChatConversation *conversation;
@property AMLChatConversation *conversation;
@end
......@@ -12,13 +12,12 @@
#import "AMLAppDelegate.h"
@interface AMLChatExampleConversationViewController () {
AMLChatUser *_user;
}
@interface AMLChatExampleConversationViewController ()
@property (weak, nonatomic) IBOutlet AMLChatExampleMessagesTableView *messagesTableView;
@property (weak, nonatomic) IBOutlet UITextField *messageTextField;
@property (weak, nonatomic) IBOutlet UIButton *sendMessageButton;
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *loadingSpinner;
@end
......@@ -37,30 +36,9 @@
- (void)viewDidLoad {
[super viewDidLoad];
[self createTestConversation];
[self startObservingMessageReceivedNotification];
self.automaticallyAdjustsScrollViewInsets = NO;
[self updateViews];
}
- (void)createTestConversation {
AMLChatConversation *conversation = [AMLChatConversation conversationWithIdentifier:@"test_conv"];
[CHAT_CLIENT registerConversation:conversation];
_conversation = conversation;
_user = [AMLChatUser userWithIdentifier:@"user" name:@"Test"];
[CHAT_CLIENT.conversationHistoryLoader getHistoryForConversation:_conversation
sinceMessage:nil
limit:10].then(^(NSArray *messages)
{
[_conversation addMessages:messages];
[_messagesTableView addMessages:messages];
[_messagesTableView scrollToLastMessage];
});
}
- (void)startObservingMessageReceivedNotification {
......@@ -82,18 +60,11 @@
AMLChatMessage *receivedMessage = [notification.userInfo objectForKey:AMLChatNotificationMessageKey];
[_messagesTableView addMessage:receivedMessage];
[_messagesTableView scrollToLastMessage];
[_messagesTableView scrollToLastMessageAnimated:YES];
}
- (void)setConversation:(AMLChatConversation *)conversation {
_conversation = conversation;
[self updateViews];
}
- (void)updateViews {
- (void)reloadMessagesForConversation {
[_messagesTableView replaceMessagesWithMessages:_conversation.messages];
[_messagesTableView reloadData];
}
- (IBAction)sendMessageButtonTapped:(id)sender {
......@@ -104,13 +75,12 @@
sender:CURRENT_USER];
[_messagesTableView addMessage:message];
[_messagesTableView scrollToLastMessage];
[_messagesTableView scrollToLastMessageAnimated:YES];
_messageTextField.text = @"";
[CHAT_CLIENT.messageSender sendMessage:message
toConversation:_conversation].then(^(NSNumber *status) {
NSLog(@"status: %@", status.unsignedIntegerValue == AMLChatMessageStatusSent ? @"Sent" : @"Unkwon");
});
}
......@@ -118,6 +88,17 @@
[super viewWillAppear:animated];
[_messageTextField becomeFirstResponder];
[self reloadMessagesForConversation];
[_messagesTableView scrollToLastMessageAnimated:NO];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
_conversation.unreadMessagesCount = 0;
[CHAT_CLIENT.conversationHistoryLoader resetUnreadMessagesCountForConversation:_conversation];
}
- (void)dealloc {
......
//
// AMLChatExampleConversationsViewController.h
// AMLChat
//
// Created by Mauro Bender on 17/2/16.
// Copyright © 2016 Mauro Bender. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface AMLChatExampleConversationsViewController : UIViewController
@end
//
// AMLChatExampleConversationsViewController.m
// AMLChat
//
// Created by Mauro Bender on 17/2/16.
// Copyright © 2016 Mauro Bender. All rights reserved.
//
#import "AMLChatExampleConversationsViewController.h"
#import "AMLChatExampleConversationsInitializer.h"
#import "AMLChatExampleConversationsTableView.h"
#import "AMLChatExampleConversationViewController.h"
#import "AMLAppDelegate.h"
@interface AMLChatExampleConversationsViewController () <AMLChatExampleConversationsTableViewDelegate> {
NSArray *_conversations;
BOOL _conversationsInitialized;
AMLChatConversation *_selectedConversation;
AMLChatExampleConversationsInitializer *_conversationsInitializer;
}
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *refreshingSpinner;
@property (weak, nonatomic) IBOutlet AMLChatExampleConversationsTableView *conversationsTableView;
@end
@implementation AMLChatExampleConversationsViewController
- (void)viewDidLoad {
[super viewDidLoad];
_conversationsTableView.converstionsTableViewDelegate = self;
self.automaticallyAdjustsScrollViewInsets = NO;
[self createTestConversations];
[self initTestConversations];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self startObservingMessageReceivedNotification];
[_conversationsTableView reloadData];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self stopObservingNotifications];
}
- (void)startObservingMessageReceivedNotification {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didReceiveMessageReceivedNotification:)
name:AMLChatConversationDidReceiveMessage
object:nil];
}
- (void)stopObservingNotifications {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)didReceiveMessageReceivedNotification:(NSNotification *)notification {
[_conversationsTableView reloadData];
}
- (void)initTestConversations {
[_refreshingSpinner startAnimating];
[self initTestConversationsWithCompletion:^{
[_refreshingSpinner stopAnimating];
_conversationsTableView.conversations = _conversations;
}];
}
- (void)createTestConversations {
AMLChatConversation *conversation1 = [AMLChatConversation conversationWithIdentifier:@"conversation_1"];
AMLChatConversation *conversation2 = [AMLChatConversation conversationWithIdentifier:@"conversation_2"];
AMLChatConversation *conversation3 = [AMLChatConversation conversationWithIdentifier:@"conversation_3"];
_conversations = @[conversation1, conversation2, conversation3];
}
- (void)initTestConversationsWithCompletion:(void(^)())completion {
_conversationsInitializer =
[[AMLChatExampleConversationsInitializer alloc] initWithChatClient:CHAT_CLIENT currentChatUser:CURRENT_USER];
[_conversationsInitializer initializeConversations:_conversations completion:completion];
}
- (void)conversationsTableView:(AMLChatExampleConversationsTableView *)tableView
didSelectConversation:(AMLChatConversation *)conversation
{
_selectedConversation = conversation;
[self performSegueWithIdentifier:@"ConversationsToConversationDetailsSegue" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"ConversationsToConversationDetailsSegue"]) {
AMLChatExampleConversationViewController *destVC = (AMLChatExampleConversationViewController *) segue.destinationViewController;
destVC.conversation = _selectedConversation;
}
}
- (void)dealloc {
[self stopObservingNotifications];
}
@end
......@@ -5,6 +5,47 @@
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
</dependencies>
<scenes>
<!--Conversations-->
<scene sceneID="WSc-HH-bpo">
<objects>
<viewController id="uFG-zR-Yo8" customClass="AMLChatExampleConversationsViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="C31-cF-yyO"/>
<viewControllerLayoutGuide type="bottom" id="IbK-lu-jGY"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="tff-UH-UUF">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="00z-kG-oS5" customClass="AMLChatExampleConversationsTableView">
<rect key="frame" x="0.0" y="64" width="600" height="536"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</tableView>
<activityIndicatorView hidden="YES" opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" hidesWhenStopped="YES" style="gray" translatesAutoresizingMaskIntoConstraints="NO" id="Pge-Jx-Vc8">
<rect key="frame" x="290" y="72" width="20" height="20"/>
</activityIndicatorView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="00z-kG-oS5" firstAttribute="top" secondItem="C31-cF-yyO" secondAttribute="bottom" id="HtN-ef-AOm"/>
<constraint firstItem="IbK-lu-jGY" firstAttribute="top" secondItem="00z-kG-oS5" secondAttribute="bottom" id="OPk-oI-Udy"/>
<constraint firstItem="Pge-Jx-Vc8" firstAttribute="centerX" secondItem="tff-UH-UUF" secondAttribute="centerX" id="bek-cX-ycK"/>
<constraint firstItem="00z-kG-oS5" firstAttribute="leading" secondItem="tff-UH-UUF" secondAttribute="leading" id="dnd-It-HjR"/>
<constraint firstAttribute="trailing" secondItem="00z-kG-oS5" secondAttribute="trailing" id="klF-tQ-bIQ"/>
<constraint firstItem="Pge-Jx-Vc8" firstAttribute="top" secondItem="C31-cF-yyO" secondAttribute="bottom" constant="8" id="zqf-Jf-pxU"/>
</constraints>
</view>
<navigationItem key="navigationItem" title="Conversations" id="gOO-bn-Tqq"/>
<connections>
<outlet property="conversationsTableView" destination="00z-kG-oS5" id="GSG-JQ-bJI"/>
<outlet property="refreshingSpinner" destination="Pge-Jx-Vc8" id="VxM-hf-Wem"/>
<segue destination="whP-gf-Uak" kind="show" identifier="ConversationsToConversationDetailsSegue" id="YZu-Wr-lsi"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="amI-Du-eKw" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="749" y="473"/>
</scene>
<!--Messages-->
<scene sceneID="wQg-tq-qST">
<objects>
......@@ -53,22 +94,28 @@
<constraint firstItem="c9V-ab-E6a" firstAttribute="leading" secondItem="q4m-YQ-Urj" secondAttribute="trailing" constant="8" id="i0k-bU-Qsg"/>
</constraints>
</view>
<activityIndicatorView hidden="YES" opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" hidesWhenStopped="YES" style="gray" translatesAutoresizingMaskIntoConstraints="NO" id="3qR-GW-AF0">
<rect key="frame" x="290" y="72" width="20" height="20"/>
</activityIndicatorView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="CzF-H5-2sX" firstAttribute="leading" secondItem="TpU-gO-2f1" secondAttribute="leading" id="4QZ-Fo-MWL"/>
<constraint firstAttribute="trailing" secondItem="CzF-H5-2sX" secondAttribute="trailing" id="G8Y-8Y-umJ"/>
<constraint firstItem="3qR-GW-AF0" firstAttribute="top" secondItem="uEw-UM-LJ8" secondAttribute="bottom" constant="8" id="JaU-wJ-NlU"/>
<constraint firstItem="cKQ-E6-QSe" firstAttribute="top" secondItem="CzF-H5-2sX" secondAttribute="bottom" constant="1" id="JsF-dK-Pzq"/>
<constraint firstItem="cKQ-E6-QSe" firstAttribute="leading" secondItem="TpU-gO-2f1" secondAttribute="leading" id="MTx-3w-WAi"/>
<constraint firstItem="Mvr-aV-6Um" firstAttribute="top" secondItem="cKQ-E6-QSe" secondAttribute="bottom" constant="220" id="SER-G0-ljp"/>
<constraint firstItem="CzF-H5-2sX" firstAttribute="top" secondItem="uEw-UM-LJ8" secondAttribute="bottom" id="ZBt-Df-K9J"/>
<constraint firstAttribute="trailing" secondItem="cKQ-E6-QSe" secondAttribute="trailing" id="bYF-bw-GDr"/>
<constraint firstItem="3qR-GW-AF0" firstAttribute="centerX" secondItem="TpU-gO-2f1" secondAttribute="centerX" id="ucc-E8-08p"/>
</constraints>
</view>
<toolbarItems/>
<navigationItem key="navigationItem" title="Messages" id="hXK-XK-fHZ"/>
<simulatedToolbarMetrics key="simulatedBottomBarMetrics"/>
<connections>
<outlet property="loadingSpinner" destination="3qR-GW-AF0" id="GPf-fr-rls"/>
<outlet property="messageTextField" destination="q4m-YQ-Urj" id="Tuj-y1-5W9"/>
<outlet property="messagesTableView" destination="CzF-H5-2sX" id="AQV-4p-uRA"/>
<outlet property="sendMessageButton" destination="c9V-ab-E6a" id="j5P-Hk-2YE"/>
......@@ -76,7 +123,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="tc2-Qw-aMS" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1117" y="433"/>
<point key="canvasLocation" x="1492" y="473"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="uWI-PZ-9uF">
......@@ -89,12 +136,12 @@
</navigationBar>
<nil name="viewControllers"/>
<connections>
<segue destination="whP-gf-Uak" kind="relationship" relationship="rootViewController" id="M2A-2f-daA"/>
<segue destination="uFG-zR-Yo8" kind="relationship" relationship="rootViewController" id="ha6-5l-q3f"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Hs8-Yr-uxw" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="305" y="433"/>
<point key="canvasLocation" x="25" y="473"/>
</scene>
</scenes>
</document>
//
// AMLChatExampleConversationsInitializer.h
// AMLChat
//
// Created by Mauro Bender on 17/2/16.
// Copyright © 2016 Mauro Bender. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <PromiseKit/PromiseKit.h>
@import AMLChat;
typedef void(^ChatConversationsInitializationCompletionHandler)();
@interface AMLChatExampleConversationsInitializer : NSObject
- (instancetype)initWithChatClient:(AMLChat *)chatClient
currentChatUser:(AMLChatUser *)currentChatUser;
@property AMLChat *chatClient;
@property AMLChatUser *currentChatUser;
- (void)initializeConversations:(NSArray *)conversations
completion:(ChatConversationsInitializationCompletionHandler)completion;
@end
//
// AMLChatExampleConversationsInitializer.m
// AMLChat
//
// Created by Mauro Bender on 17/2/16.
// Copyright © 2016 Mauro Bender. All rights reserved.
//
#import "AMLChatExampleConversationsInitializer.h"
@implementation AMLChatExampleConversationsInitializer
- (instancetype)initWithChatClient:(AMLChat *)chatClient
currentChatUser:(AMLChatUser *)currentChatUser
{
self = [super init];
if(self) {
_chatClient = chatClient;
_currentChatUser = currentChatUser;
}
return self;
}
- (void)initializeConversations:(NSArray *)conversations
completion:(ChatConversationsInitializationCompletionHandler)completion
{
[_chatClient registerConversations:conversations];
NSMutableArray *promises = [NSMutableArray new];
for(AMLChatConversation *conversation in conversations) {
[promises addObject:[self updateUnreadMessagesCountForConversation:conversation]];
[promises addObject:[self updateConversationHistoryForConversation:conversation]];
}
PMKJoin(promises).finally(^{
completion();
});
}
- (AnyPromise *)updateConversationHistoryForConversation:(AMLChatConversation *)conversation {
return [_chatClient.conversationHistoryLoader getHistoryForConversation:conversation
sinceDate:nil
limit:10]
.then(^(NSArray *messages) {
if(messages)
[conversation addMessages:messages];
});
}
- (AnyPromise *)updateUnreadMessagesCountForConversation:(AMLChatConversation *)conversation {
return [_chatClient.conversationHistoryLoader getUnreadMessagesCountForConversation:conversation
user:_currentChatUser]
.then(^(NSNumber *unreadCount) {
conversation.unreadMessagesCount = [unreadCount unsignedIntegerValue];
});
}
@end
//
// AMLChatExampleConversationTableViewCell.h
// AMLChat
//
// Created by Mauro Bender on 17/2/16.
// Copyright © 2016 Mauro Bender. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface AMLChatExampleConversationTableViewCell : UITableViewCell
@property (nonatomic) AMLChatConversation *conversation;
@end
//
// AMLChatExampleConversationTableViewCell.m
// AMLChat
//
// Created by Mauro Bender on 17/2/16.
// Copyright © 2016 Mauro Bender. All rights reserved.
//
#import "AMLChatExampleConversationTableViewCell.h"
@interface AMLChatExampleConversationTableViewCell ()
@property (weak, nonatomic) IBOutlet UILabel *conversationNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *conversationLastMessageLabel;
@property (weak, nonatomic) IBOutlet UILabel *conversationUnreadMessagesCountLabel;
@end
@implementation AMLChatExampleConversationTableViewCell
- (void)awakeFromNib {
self.selectionStyle = UITableViewCellSelectionStyleNone;
}
- (void)setConversation:(AMLChatConversation *)conversation {
_conversation = conversation;
[self updateViews];
}