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.xcodeproj/project.pbxproj | 26 +++++++++ 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 +++++++++++++++++++++++++++ 12 files changed, 381 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 diff --git a/Juick.xcodeproj/project.pbxproj b/Juick.xcodeproj/project.pbxproj index a1cc004..e8c6344 100644 --- a/Juick.xcodeproj/project.pbxproj +++ b/Juick.xcodeproj/project.pbxproj @@ -21,6 +21,11 @@ 77317BD0181BBE8500D60005 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 77317BAF181BBE8500D60005 /* UIKit.framework */; }; 77317BD8181BBE8500D60005 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 77317BD6181BBE8500D60005 /* InfoPlist.strings */; }; 77317BDA181BBE8500D60005 /* JuickTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 77317BD9181BBE8500D60005 /* JuickTests.m */; }; + 773E6393204BCAD6008B8F8D /* BubbleMessageCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 773E6391204BCAD6008B8F8D /* BubbleMessageCell.xib */; }; + 773E6394204BCAD6008B8F8D /* ConversationCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 773E6392204BCAD6008B8F8D /* ConversationCell.xib */; }; + 773E6397204BCB64008B8F8D /* ConversationCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 773E6396204BCB64008B8F8D /* ConversationCell.m */; }; + 773E639A204BCE6D008B8F8D /* DialogsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 773E6399204BCE6D008B8F8D /* DialogsViewController.m */; }; + 773E639D204BD0F2008B8F8D /* Chat.m in Sources */ = {isa = PBXBuildFile; fileRef = 773E639C204BD0F2008B8F8D /* Chat.m */; }; 773F231C1F76DD0B00B5B0DF /* SerpentineBoldItalic.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 773F231B1F76DD0B00B5B0DF /* SerpentineBoldItalic.ttf */; }; 773F23331F76ECAC00B5B0DF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 773F23321F76ECAC00B5B0DF /* LaunchScreen.storyboard */; }; 773F23371F76ED5E00B5B0DF /* Splash.png in Resources */ = {isa = PBXBuildFile; fileRef = 773F23341F76ED5D00B5B0DF /* Splash.png */; }; @@ -81,6 +86,14 @@ 77317BD5181BBE8500D60005 /* JuickTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "JuickTests-Info.plist"; sourceTree = ""; }; 77317BD7181BBE8500D60005 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 77317BD9181BBE8500D60005 /* JuickTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = JuickTests.m; sourceTree = ""; }; + 773E6391204BCAD6008B8F8D /* BubbleMessageCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = BubbleMessageCell.xib; sourceTree = ""; }; + 773E6392204BCAD6008B8F8D /* ConversationCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ConversationCell.xib; sourceTree = ""; }; + 773E6395204BCB64008B8F8D /* ConversationCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ConversationCell.h; sourceTree = ""; }; + 773E6396204BCB64008B8F8D /* ConversationCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ConversationCell.m; sourceTree = ""; }; + 773E6398204BCE6D008B8F8D /* DialogsViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DialogsViewController.h; sourceTree = ""; }; + 773E6399204BCE6D008B8F8D /* DialogsViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DialogsViewController.m; sourceTree = ""; }; + 773E639B204BD0F2008B8F8D /* Chat.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Chat.h; sourceTree = ""; }; + 773E639C204BD0F2008B8F8D /* Chat.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Chat.m; sourceTree = ""; }; 773F231B1F76DD0B00B5B0DF /* SerpentineBoldItalic.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = SerpentineBoldItalic.ttf; sourceTree = ""; }; 773F23321F76ECAC00B5B0DF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = ""; }; 773F23341F76ED5D00B5B0DF /* Splash.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Splash.png; sourceTree = ""; }; @@ -268,6 +281,8 @@ 770A428F1E8881CB000B206A /* DeviceRegistration.h */, 774528C01F930C06004D110B /* Attachment.h */, 774528C11F930C06004D110B /* Attachment.m */, + 773E639B204BD0F2008B8F8D /* Chat.h */, + 773E639C204BD0F2008B8F8D /* Chat.m */, ); path = Model; sourceTree = ""; @@ -285,6 +300,8 @@ 77C6ADE31F7717BC000AEA8C /* ThreadViewController.m */, 776C41BF1FD3FF6E0063B82E /* DiscoverViewController.h */, 776C41C01FD3FF6E0063B82E /* DiscoverViewController.m */, + 773E6398204BCE6D008B8F8D /* DialogsViewController.h */, + 773E6399204BCE6D008B8F8D /* DialogsViewController.m */, ); path = ViewControllers; sourceTree = ""; @@ -305,12 +322,16 @@ 77FFC0151D5FD13C003BD81A /* Views */ = { isa = PBXGroup; children = ( + 773E6391204BCAD6008B8F8D /* BubbleMessageCell.xib */, + 773E6392204BCAD6008B8F8D /* ConversationCell.xib */, 776C41BA1FD3EF180063B82E /* MessageCell.h */, 776C41BB1FD3EF180063B82E /* MessageCell.m */, 776C41BC1FD3EF180063B82E /* MessageCell.xib */, 77E61A5A1FD467FC00B4E304 /* MessageInputView.xib */, 77E61A5C1FD4682B00B4E304 /* MessageInputView.h */, 77E61A5D1FD4682B00B4E304 /* MessageInputView.m */, + 773E6395204BCB64008B8F8D /* ConversationCell.h */, + 773E6396204BCB64008B8F8D /* ConversationCell.m */, ); path = Views; sourceTree = ""; @@ -423,6 +444,8 @@ 77317BB6181BBE8500D60005 /* InfoPlist.strings in Resources */, 773F23331F76ECAC00B5B0DF /* LaunchScreen.storyboard in Resources */, 77E61A5B1FD467FC00B4E304 /* MessageInputView.xib in Resources */, + 773E6394204BCAD6008B8F8D /* ConversationCell.xib in Resources */, + 773E6393204BCAD6008B8F8D /* BubbleMessageCell.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -524,6 +547,8 @@ 776C41C11FD3FF6E0063B82E /* DiscoverViewController.m in Sources */, 77FCADDF1D6A50DA00CBA649 /* APIClient.m in Sources */, 77A0954A181F1F25002BDECD /* Message.m in Sources */, + 773E639D204BD0F2008B8F8D /* Chat.m in Sources */, + 773E639A204BCE6D008B8F8D /* DialogsViewController.m in Sources */, 774528C51F93AC0F004D110B /* CoreDataStack.m in Sources */, 77B09994189D0B9900A84F59 /* UIImage+Utils.m in Sources */, 77317BC2181BBE8500D60005 /* MessagesViewController.m in Sources */, @@ -533,6 +558,7 @@ 77C67EE81828379700427098 /* ColorScheme.m in Sources */, 77C67EE51828342000427098 /* NSURL+PathParameters.m in Sources */, 77E35A82189A5B5A00B2D216 /* LoginViewController.m in Sources */, + 773E6397204BCB64008B8F8D /* ConversationCell.m in Sources */, 776C41BD1FD3EF180063B82E /* MessageCell.m in Sources */, 77317BB8181BBE8500D60005 /* main.m in Sources */, 774528C21F930C06004D110B /* Attachment.m in Sources */, 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