From 782219f3cdc8cac644cc33657813a5f8319dbae7 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sun, 4 Mar 2018 10:22:28 +0300 Subject: groups_pms --- Juick/APIClient.h | 1 + Juick/APIClient.m | 21 +++++++ Juick/Main.storyboard | 35 ++++++++--- Juick/Model/Chat.h | 17 ++++++ Juick/Model/Chat.m | 13 +++++ Juick/ViewControllers/DialogsViewController.h | 15 +++++ Juick/ViewControllers/DialogsViewController.m | 57 ++++++++++++++++++ Juick/Views/BubbleMessageCell.xib | 74 ++++++++++++++++++++++++ Juick/Views/ConversationCell.h | 20 +++++++ Juick/Views/ConversationCell.m | 26 +++++++++ Juick/Views/ConversationCell.xib | 83 +++++++++++++++++++++++++++ 11 files changed, 355 insertions(+), 7 deletions(-) create mode 100644 Juick/Model/Chat.h create mode 100644 Juick/Model/Chat.m create mode 100644 Juick/ViewControllers/DialogsViewController.h create mode 100644 Juick/ViewControllers/DialogsViewController.m create mode 100644 Juick/Views/BubbleMessageCell.xib create mode 100644 Juick/Views/ConversationCell.h create mode 100644 Juick/Views/ConversationCell.m create mode 100644 Juick/Views/ConversationCell.xib (limited to 'Juick') diff --git a/Juick/APIClient.h b/Juick/APIClient.h index b336c8c..668a0a9 100644 --- a/Juick/APIClient.h +++ b/Juick/APIClient.h @@ -19,6 +19,7 @@ -(void) pullNextFromPath:(NSString *)path params:(NSDictionary *)params callback:(void(^)(NSArray *, NSError *))callback; -(void) postMessage:(NSString *)text result:(void(^)(Message *, NSError *))callback; -(void) postReplyToThread:(NSNumber *)mid inReplyTo:(NSNumber *)rid text:(NSString *)text result:(void(^)(Message *, NSError *))callback; +-(void) fetchChats:(void(^)(NSArray *, NSError *))callback; +(NSString *) messagesUrl; +(NSString *) threadUrl; diff --git a/Juick/APIClient.m b/Juick/APIClient.m index 3190659..5352320 100644 --- a/Juick/APIClient.m +++ b/Juick/APIClient.m @@ -8,6 +8,7 @@ #import "APIClient.h" #import "PDKeychainBindings.h" #import "Message.h" +#import "Chat.h" @interface APIClient() @property(nonatomic, strong) NSOperationQueue *backgroundQueue; @@ -101,6 +102,26 @@ }]; }]; } +-(void) fetchChats:(void (^)(NSArray *, NSError *))callback { + AFHTTPSessionManager *manager = [APIClient sharedClient].manager; + [self.backgroundQueue addOperationWithBlock:^{ + [manager GET:@"/groups_pms" parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { + NSMutableArray *groups = [NSMutableArray new]; + NSArray *pms = [(NSDictionary *)responseObject objectForKey:@"pms"]; + [pms enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { + [groups addObject:[Chat yy_modelWithJSON:obj]]; + }]; + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + callback(groups, nil); + }]; + } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { + NSLog(@"Error: %@", [error localizedDescription]); + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + callback(nil, error); + }]; + }]; + }]; +} +(NSString *) messagesUrl { diff --git a/Juick/Main.storyboard b/Juick/Main.storyboard index 5c8cc68..3383f18 100644 --- a/Juick/Main.storyboard +++ b/Juick/Main.storyboard @@ -1,5 +1,5 @@ - + @@ -10,17 +10,18 @@ - + + - + @@ -89,6 +90,7 @@ + @@ -123,7 +125,7 @@ - + @@ -223,13 +225,13 @@ - + - + @@ -243,6 +245,7 @@ + @@ -258,7 +261,7 @@ - + @@ -293,6 +296,24 @@ + + + + + + + + + + + + + + + + + + diff --git a/Juick/Model/Chat.h b/Juick/Model/Chat.h new file mode 100644 index 0000000..42647b0 --- /dev/null +++ b/Juick/Model/Chat.h @@ -0,0 +1,17 @@ +// +// Chat.h +// Juick +// +// Created by Vitaly Takmazov on 04/03/2018. +// Copyright © 2018 com.juick. All rights reserved. +// + +#import +#import "User.h" + +@interface Chat : NSObject + +@property NSNumber *uid; +@property NSString *uname; +@property NSNumber *unreadCount; +@end diff --git a/Juick/Model/Chat.m b/Juick/Model/Chat.m new file mode 100644 index 0000000..ff5fb83 --- /dev/null +++ b/Juick/Model/Chat.m @@ -0,0 +1,13 @@ +// +// Chat.m +// Juick +// +// Created by Vitaly Takmazov on 04/03/2018. +// Copyright © 2018 com.juick. All rights reserved. +// + +#import "Chat.h" + +@implementation Chat + +@end diff --git a/Juick/ViewControllers/DialogsViewController.h b/Juick/ViewControllers/DialogsViewController.h new file mode 100644 index 0000000..c37f6a6 --- /dev/null +++ b/Juick/ViewControllers/DialogsViewController.h @@ -0,0 +1,15 @@ +// +// DialogsViewController.h +// Juick +// +// Created by Vitaly Takmazov on 04/03/2018. +// Copyright © 2018 com.juick. All rights reserved. +// + +#import "MessagesViewController.h" + +@interface DialogsViewController : UITableViewController + +@property(nonatomic, strong) NSMutableArray *chats; + +@end diff --git a/Juick/ViewControllers/DialogsViewController.m b/Juick/ViewControllers/DialogsViewController.m new file mode 100644 index 0000000..8eea017 --- /dev/null +++ b/Juick/ViewControllers/DialogsViewController.m @@ -0,0 +1,57 @@ +// +// DialogsViewController.m +// Juick +// +// Created by Vitaly Takmazov on 04/03/2018. +// Copyright © 2018 com.juick. All rights reserved. +// + +#import "DialogsViewController.h" +#import "ColorScheme.h" +#import "ConversationCell.h" +#import "APIClient.h" + +@interface DialogsViewController () + +@end + +@implementation DialogsViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + + [self.view setBackgroundColor:[ColorScheme mainBackground]]; + [self.tableView registerNib:[UINib nibWithNibName:@"ConversationCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"notificationCell"]; + self.chats = [NSMutableArray array]; + [[APIClient sharedClient] fetchChats:^(NSArray *groups, NSError *err) { + if (err == nil) { + [self.chats addObjectsFromArray:groups]; + NSMutableArray *indexPaths = [NSMutableArray new]; + for (NSUInteger index = 0; index < [groups count]; index++) { + [indexPaths addObject:[NSIndexPath indexPathForRow:index inSection: 0]]; + } + [self.tableView beginUpdates]; + [self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:YES]; + [self.tableView endUpdates]; + } + }]; +} + +#pragma mark - Table view data source + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { + return 1; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + return self.chats.count; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + ConversationCell *cell = [tableView dequeueReusableCellWithIdentifier:@"notificationCell" forIndexPath:indexPath]; + [cell configureWithChat:[self.chats objectAtIndex:indexPath.row]]; + return cell; +} + + +@end diff --git a/Juick/Views/BubbleMessageCell.xib b/Juick/Views/BubbleMessageCell.xib new file mode 100644 index 0000000..a2b6bc3 --- /dev/null +++ b/Juick/Views/BubbleMessageCell.xib @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Juick/Views/ConversationCell.h b/Juick/Views/ConversationCell.h new file mode 100644 index 0000000..f31057b --- /dev/null +++ b/Juick/Views/ConversationCell.h @@ -0,0 +1,20 @@ +// +// ConversationCell.h +// Juick +// +// Created by Vitaly Takmazov on 04/03/2018. +// Copyright © 2018 com.juick. All rights reserved. +// + +#import +#import "Chat.h" + +@interface ConversationCell : UITableViewCell +@property (strong, nonatomic) IBOutlet UILabel *chatName; +@property (strong, nonatomic) IBOutlet UIImageView *avatar; +@property (strong, nonatomic) IBOutlet UILabel *lastMessage; +@property (strong, nonatomic) IBOutlet UILabel *unreadMarker; + +-(void) configureWithChat:(Chat *)chat; + +@end diff --git a/Juick/Views/ConversationCell.m b/Juick/Views/ConversationCell.m new file mode 100644 index 0000000..750ab45 --- /dev/null +++ b/Juick/Views/ConversationCell.m @@ -0,0 +1,26 @@ +// +// ConversationCell.m +// Juick +// +// Created by Vitaly Takmazov on 04/03/2018. +// Copyright © 2018 com.juick. All rights reserved. +// + +#import "ConversationCell.h" +@import YYWebImage; + +@implementation ConversationCell + +- (void)awakeFromNib { + [super awakeFromNib]; + // Initialization code +} + +-(void) configureWithChat:(Chat *)chat { + self.chatName.text = chat.uname; + self.lastMessage.text = @""; + self.unreadMarker.text = @""; + [self.avatar yy_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://i.juick.com/a/%d.png", [chat.uid intValue]]] options:YYWebImageOptionProgressiveBlur|YYWebImageOptionSetImageWithFadeAnimation]; +} + +@end diff --git a/Juick/Views/ConversationCell.xib b/Juick/Views/ConversationCell.xib new file mode 100644 index 0000000..504f7a4 --- /dev/null +++ b/Juick/Views/ConversationCell.xib @@ -0,0 +1,83 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3