summaryrefslogtreecommitdiff
path: root/Juick/ViewControllers
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-03-04 11:50:14 +0300
committerGravatar Vitaly Takmazov2018-03-04 11:50:22 +0300
commita04f0db29cb280eb45888d3a56967cf9adc6214d (patch)
treeb1625107b75a906b7b402296b3a93ca11a578633 /Juick/ViewControllers
parent782219f3cdc8cac644cc33657813a5f8319dbae7 (diff)
ChatViewController
Diffstat (limited to 'Juick/ViewControllers')
-rw-r--r--Juick/ViewControllers/ChatViewController.h15
-rw-r--r--Juick/ViewControllers/ChatViewController.m65
-rw-r--r--Juick/ViewControllers/DialogsViewController.m13
3 files changed, 93 insertions, 0 deletions
diff --git a/Juick/ViewControllers/ChatViewController.h b/Juick/ViewControllers/ChatViewController.h
new file mode 100644
index 0000000..7ea8030
--- /dev/null
+++ b/Juick/ViewControllers/ChatViewController.h
@@ -0,0 +1,15 @@
+//
+// ChatViewController.h
+// Juick
+//
+// Created by Vitaly Takmazov on 04/03/2018.
+// Copyright © 2018 com.juick. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+#import "User.h"
+
+@interface ChatViewController : UITableViewController
+@property(nonatomic, strong) NSMutableArray *messages;
+@property(nonatomic, strong) NSString *uname;
+@end
diff --git a/Juick/ViewControllers/ChatViewController.m b/Juick/ViewControllers/ChatViewController.m
new file mode 100644
index 0000000..f88bfa5
--- /dev/null
+++ b/Juick/ViewControllers/ChatViewController.m
@@ -0,0 +1,65 @@
+//
+// ChatViewController.m
+// Juick
+//
+// Created by Vitaly Takmazov on 04/03/2018.
+// Copyright © 2018 com.juick. All rights reserved.
+//
+
+#import "ChatViewController.h"
+#import "BubbleMessageCell.h"
+#import "APIClient.h"
+
+@interface ChatViewController ()
+
+@end
+
+@implementation ChatViewController
+
+- (void)viewDidLoad {
+ [super viewDidLoad];
+
+ [self.tableView registerNib:[UINib nibWithNibName:@"BubbleMessageCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"bubbleMessageCell"];
+ self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
+ self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeInteractive;
+ self.tableView.allowsSelection = NO;
+ self.messages = [NSMutableArray array];
+ [[APIClient sharedClient] fetchChatWithUser:self.uname callback:^(NSArray *messages, NSError *err) {
+ if (err == nil) {
+ [self.messages addObjectsFromArray:[[messages reverseObjectEnumerator] allObjects]];
+ NSMutableArray *indexPaths = [NSMutableArray new];
+ for (NSUInteger index = 0; index < [messages count]; index++) {
+ [indexPaths addObject:[NSIndexPath indexPathForRow:index inSection: 0]];
+ }
+ [self.tableView beginUpdates];
+ [self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:YES];
+ [self.tableView endUpdates];
+ [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:[self.messages count]-1 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:NO];
+ }
+ }];
+}
+
+- (void)didReceiveMemoryWarning {
+ [super didReceiveMemoryWarning];
+ // Dispose of any resources that can be recreated.
+}
+
+#pragma mark - Table view data source
+
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
+ return 1;
+}
+
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
+ return [self.messages count];
+}
+
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
+ BubbleMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"bubbleMessageCell" forIndexPath:indexPath];
+
+ [cell configureWithMessage:[self.messages objectAtIndex:indexPath.row]];
+
+ return cell;
+}
+
+@end
diff --git a/Juick/ViewControllers/DialogsViewController.m b/Juick/ViewControllers/DialogsViewController.m
index 8eea017..878e912 100644
--- a/Juick/ViewControllers/DialogsViewController.m
+++ b/Juick/ViewControllers/DialogsViewController.m
@@ -7,6 +7,7 @@
//
#import "DialogsViewController.h"
+#import "ChatViewController.h"
#import "ColorScheme.h"
#import "ConversationCell.h"
#import "APIClient.h"
@@ -53,5 +54,17 @@
return cell;
}
+-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
+ [self performSegueWithIdentifier:@"chatSegue" sender:self];
+}
+
+-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
+ if ([segue.identifier isEqualToString:@"chatSegue"]) {
+ Chat *chat = [self.chats objectAtIndex:[self.tableView indexPathForSelectedRow].row];
+ ChatViewController *vc = (ChatViewController *)segue.destinationViewController;
+ [vc setUname:chat.uname];
+ }
+}
+
@end