summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Juick/APIClient.m10
-rw-r--r--Juick/AppDelegate.m2
-rw-r--r--Juick/Model/Attachment.h2
-rw-r--r--Juick/Model/Attachment.m17
-rw-r--r--Juick/Model/Chat.h3
-rw-r--r--Juick/Model/Chat.m11
-rw-r--r--Juick/Model/DeviceRegistration.h8
-rw-r--r--Juick/Model/Entity.h2
-rw-r--r--Juick/Model/Entity.m10
-rw-r--r--Juick/Model/Message.h2
-rw-r--r--Juick/Model/Message.m24
-rw-r--r--Juick/Model/User.h2
-rw-r--r--Juick/Model/User.m10
-rw-r--r--Juick/Supporting Files/Juick-Prefix.pch1
-rw-r--r--Juick/Views/MessageCell.m20
-rw-r--r--Podfile1
-rw-r--r--Podfile.lock6
17 files changed, 102 insertions, 29 deletions
diff --git a/Juick/APIClient.m b/Juick/APIClient.m
index 6d9878d..6f69e9d 100644
--- a/Juick/APIClient.m
+++ b/Juick/APIClient.m
@@ -46,7 +46,7 @@
[manager GET:path parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSMutableArray *messages = [NSMutableArray new];
[((NSArray *)responseObject) enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- [messages addObject:[Message yy_modelWithJSON:obj]];
+ [messages addObject:[Message fromJSON:obj]];
}];
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
callback(messages, nil);
@@ -71,7 +71,7 @@
[formData appendPartWithFormData:[text dataUsingEncoding:NSUTF8StringEncoding] name:@"body"];
} progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSLog(@"Success!");
- Message *result = [Message yy_modelWithJSON:responseObject];
+ Message *result = [Message fromJSON:responseObject];
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
callback(result, nil);
}];
@@ -93,7 +93,7 @@
[formData appendPartWithFormData:[text dataUsingEncoding:NSUTF8StringEncoding] name:@"body"];
} progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSLog(@"Success!");
- Message *reply = [Message yy_modelWithJSON:responseObject];
+ Message *reply = [Message fromJSON:responseObject];
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
callback(reply, nil);
}];
@@ -131,7 +131,7 @@
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]];
+ [groups addObject:[Chat fromJSON:obj]];
}];
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
callback(groups, nil);
@@ -152,7 +152,7 @@
NSMutableArray *messages = [NSMutableArray new];
NSArray *messagesList = (NSArray *)responseObject;
[messagesList enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- [messages addObject:[Message yy_modelWithJSON:obj]];
+ [messages addObject:[Message fromJSON:obj]];
}];
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
callback(messages, nil);
diff --git a/Juick/AppDelegate.m b/Juick/AppDelegate.m
index 950f473..629c6ca 100644
--- a/Juick/AppDelegate.m
+++ b/Juick/AppDelegate.m
@@ -65,7 +65,7 @@
registration.type = @"apns";
registration.token = token;
AFHTTPSessionManager *manager = [APIClient sharedClient].manager;
- [manager PUT:@"/notifications" parameters:[@[registration] yy_modelToJSONObject] success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
+ [manager PUT:@"/notifications" parameters:@[[registration toJSON]] success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSLog(@"success %@", token);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"fail %@", [error localizedDescription]);
diff --git a/Juick/Model/Attachment.h b/Juick/Model/Attachment.h
index 26fc1c0..47c6c3a 100644
--- a/Juick/Model/Attachment.h
+++ b/Juick/Model/Attachment.h
@@ -15,4 +15,6 @@
@property(nonatomic, strong) Attachment *small;
@property(nonatomic, strong) Attachment *medium;
@property(nonatomic, strong) Attachment *thumbnail;
+
++(Attachment *) fromJSON:(NSDictionary *)jsonData;
@end
diff --git a/Juick/Model/Attachment.m b/Juick/Model/Attachment.m
index a54e462..006b72e 100644
--- a/Juick/Model/Attachment.m
+++ b/Juick/Model/Attachment.m
@@ -10,4 +10,21 @@
@implementation Attachment
++(Attachment *) fromJSON:(NSDictionary *)jsonData {
+ Attachment *attachment = [Attachment new];
+ attachment.url = jsonData[@"url"];
+ attachment.width = jsonData[@"width"];
+ attachment.height = jsonData[@"height"];
+ if (jsonData[@"small"]) {
+ attachment.small = [Attachment fromJSON:jsonData[@"small"]];
+ }
+ if (jsonData[@"medium"]) {
+ attachment.medium = [Attachment fromJSON:jsonData[@"medium"]];
+ }
+ if (jsonData[@"thumbnail"]) {
+ attachment.thumbnail = [Attachment fromJSON:jsonData[@"thumbnail"]];
+ }
+ return attachment;
+}
+
@end
diff --git a/Juick/Model/Chat.h b/Juick/Model/Chat.h
index 1e80bdf..4b7ec30 100644
--- a/Juick/Model/Chat.h
+++ b/Juick/Model/Chat.h
@@ -17,4 +17,7 @@
@property NSNumber *unreadCount;
@property NSDate *lastMessageTimestamp;
@property NSString *lastMessageText;
+
++ (Chat *) fromJSON:(NSDictionary *)jsonData;
+
@end
diff --git a/Juick/Model/Chat.m b/Juick/Model/Chat.m
index ff5fb83..66ed394 100644
--- a/Juick/Model/Chat.m
+++ b/Juick/Model/Chat.m
@@ -10,4 +10,15 @@
@implementation Chat
++(Chat *) fromJSON:(NSDictionary *)jsonData {
+ Chat *user = [Chat new];
+ user.uid = jsonData[@"uid"];
+ user.uname = jsonData[@"uname"];
+ user.avatar = jsonData[@"avatar"];
+ user.unreadCount = jsonData[@"unreadCount"];
+ user.lastMessageTimestamp = jsonData[@"lastMessageTimestamp"];
+ user.lastMessageText = jsonData[@"lastMessageText"];
+ return user;
+}
+
@end
diff --git a/Juick/Model/DeviceRegistration.h b/Juick/Model/DeviceRegistration.h
index e629637..d5b620c 100644
--- a/Juick/Model/DeviceRegistration.h
+++ b/Juick/Model/DeviceRegistration.h
@@ -11,7 +11,15 @@
@interface DeviceRegistration : NSObject
@property NSString *type;
@property NSString *token;
+
+-(NSDictionary *) toJSON;
@end
@implementation DeviceRegistration
+-(NSDictionary *) toJSON {
+ return @{
+ @"type": self.type,
+ @"token": self.token
+ };
+}
@end
diff --git a/Juick/Model/Entity.h b/Juick/Model/Entity.h
index 13142f1..4cdffc0 100644
--- a/Juick/Model/Entity.h
+++ b/Juick/Model/Entity.h
@@ -16,4 +16,6 @@
@property NSNumber *start;
@property NSNumber *end;
++(Entity *) fromJSON:(NSDictionary *)jsonData;
+
@end
diff --git a/Juick/Model/Entity.m b/Juick/Model/Entity.m
index ac53a1f..cf23a2a 100644
--- a/Juick/Model/Entity.m
+++ b/Juick/Model/Entity.m
@@ -10,4 +10,14 @@
@implementation Entity
++(Entity *) fromJSON:(NSDictionary *)jsonData {
+ Entity *entity = [Entity new];
+ entity.start = jsonData[@"start"];
+ entity.end = jsonData[@"end"];
+ entity.type = jsonData[@"type"];
+ entity.text = jsonData[@"text"];
+ entity.link = jsonData[@"url"];
+ return entity;
+}
+
@end
diff --git a/Juick/Model/Message.h b/Juick/Model/Message.h
index 8e1b01a..f822fdf 100644
--- a/Juick/Model/Message.h
+++ b/Juick/Model/Message.h
@@ -26,4 +26,6 @@
@property Attachment *attachment;
@property BOOL service;
++(Message *) fromJSON:(NSDictionary *)jsonData;
+
@end
diff --git a/Juick/Model/Message.m b/Juick/Model/Message.m
index d00f705..68cc7c9 100644
--- a/Juick/Model/Message.m
+++ b/Juick/Model/Message.m
@@ -11,10 +11,24 @@
@implementation Message
-+ (NSDictionary *)modelCustomPropertyMapper {
- return @{@"text" : @"body",
- @"attach" : @"photo.small",
- @"repliesCount": @"replies",
- @"repliesBy": @"repliesby"};
++ (Message *) fromJSON:(NSDictionary *)jsonData {
+ Message * message = [Message new];
+ message.mid = jsonData[@"mid"];
+ message.rid = jsonData[@"rid"];
+ message.text = jsonData[@"body"];
+ message.attach = jsonData[@"photo"][@"small"];
+ message.repliesCount = jsonData[@"replies"];
+ message.repliesBy = jsonData[@"repliesby"];
+ message.user = [User fromJSON:jsonData[@"user"]];
+ message.timestamp = jsonData[@"timestamp"];
+ message.service = jsonData[@"service"];
+ message.tags = jsonData[@"tags"];
+ NSMutableArray *entitiesArray = [NSMutableArray new];
+ for (NSDictionary *entityData in jsonData[@"entities"]) {
+ [entitiesArray addObject:[Entity fromJSON:entityData]];
+ }
+ message.entities = [entitiesArray copy];
+ message.attachment = [Attachment fromJSON:jsonData[@"attachment"]];
+ return message;
}
@end
diff --git a/Juick/Model/User.h b/Juick/Model/User.h
index 8120dec..59b010d 100644
--- a/Juick/Model/User.h
+++ b/Juick/Model/User.h
@@ -13,6 +13,8 @@
@property (nonatomic, strong) NSString *uid;
@property (nonatomic, strong) NSString *avatar;
++ (User *) fromJSON:(NSDictionary *)jsonData;
+
+ (void) get:(NSString *)name callback:(void(^)(User *))callback;
+ (BOOL) isAuthenticated;
diff --git a/Juick/Model/User.m b/Juick/Model/User.m
index 36a9b4c..a2f874c 100644
--- a/Juick/Model/User.m
+++ b/Juick/Model/User.m
@@ -11,6 +11,14 @@
@implementation User
++ (User *) fromJSON:(NSDictionary *)jsonData {
+ User *user = [User new];
+ user.uid = jsonData[@"uid"];
+ user.uname = jsonData[@"uname"];
+ user.avatar = jsonData[@"avatar"];
+ return user;
+}
+
+(BOOL) isAuthenticated {
return [[PDKeychainBindings sharedKeychainBindings] stringForKey:@"com.juick.username"] != nil;
}
@@ -46,7 +54,7 @@
AFHTTPSessionManager *manager = [APIClient sharedClient].manager;
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:name, @"uname", nil];
[manager GET:@"users" parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
- callback([User yy_modelWithJSON:[(NSArray *)responseObject firstObject]]);
+ callback([User fromJSON:[(NSArray *)responseObject firstObject]]);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
callback(nil);
}];
diff --git a/Juick/Supporting Files/Juick-Prefix.pch b/Juick/Supporting Files/Juick-Prefix.pch
index 4340a61..a4b3d0f 100644
--- a/Juick/Supporting Files/Juick-Prefix.pch
+++ b/Juick/Supporting Files/Juick-Prefix.pch
@@ -21,7 +21,6 @@
#import "UIImage+Utils.h"
#import <AFNetworking/AFNetworking.h>
#import <AFNetworking/UIImageView+AFNetworking.h>
- #import <YYModel/YYModel.h>
#import <DateTools/DateTools.h>
#import <TagListView-ObjC/TagListView.h>
#import <PHFComposeBarView/PHFComposeBarView.h>
diff --git a/Juick/Views/MessageCell.m b/Juick/Views/MessageCell.m
index faf3492..2686adf 100644
--- a/Juick/Views/MessageCell.m
+++ b/Juick/Views/MessageCell.m
@@ -77,16 +77,16 @@
initWithString:msg.text
attributes:@{NSFontAttributeName:[UIFont preferredFontForTextStyle:UIFontTextStyleBody]}];
[txt beginEditing];
- for (NSDictionary *entity in msg.entities) {
- NSUInteger start = [entity[@"start"] unsignedIntegerValue];
- NSUInteger end = [entity[@"end"] unsignedIntegerValue];
- NSString *text = entity[@"text"] ? entity[@"text"] : @"";
+ for (Entity *entity in msg.entities) {
+ NSUInteger start = entity.start ? [entity.start unsignedIntegerValue] : 0;
+ NSUInteger end = entity.end ? [entity.end unsignedIntegerValue] : 0;
+ NSString *text = entity.text ? entity.text : @"";
NSRange currentRange = NSMakeRange(start, end - start);
[txt addAttribute:@"displayText" value:text range:currentRange];
- if ([entity[@"type"] isEqualToString:@"a"]) {
- [txt addAttribute:NSLinkAttributeName value:entity[@"url"] range:currentRange];
+ if ([entity.type isEqualToString:@"a"]) {
+ [txt addAttribute:NSLinkAttributeName value:entity.link range:currentRange];
}
- if ([entity[@"type"] isEqualToString:@"q"]) {
+ if ([entity.type isEqualToString:@"q"]) {
[txt addAttribute:NSForegroundColorAttributeName value:[UIColor darkGrayColor] range:currentRange];
NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
paragraphStyle.firstLineHeadIndent = 12.0f;
@@ -94,18 +94,18 @@
paragraphStyle.paragraphSpacing = 12.0f;
[txt addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:currentRange];
}
- if ([entity[@"type"] isEqualToString:@"u"]) {
+ if ([entity.type isEqualToString:@"u"]) {
[txt addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:currentRange];
}
UIFontDescriptor* fontDescriptor = [UIFontDescriptor
preferredFontDescriptorWithTextStyle:UIFontTextStyleBody];
- if ([entity[@"type"] isEqualToString:@"b"]) {
+ if ([entity.type isEqualToString:@"b"]) {
UIFontDescriptor* boldFontDescriptor = [fontDescriptor
fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitBold];
UIFont* boldFont = [UIFont fontWithDescriptor:boldFontDescriptor size: 0.0];
[txt addAttribute:NSFontAttributeName value:boldFont range:currentRange];
}
- if ([entity[@"type"] isEqualToString:@"i"]) {
+ if ([entity.type isEqualToString:@"i"]) {
UIFontDescriptor* italicFontDescriptor = [fontDescriptor
fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitItalic];
UIFont* italicFont = [UIFont fontWithDescriptor:italicFontDescriptor size: 0.0];
diff --git a/Podfile b/Podfile
index 4c76e2d..fde7be9 100644
--- a/Podfile
+++ b/Podfile
@@ -4,7 +4,6 @@ platform :ios, "11.1"
target "Juick" do
pod 'AFNetworking'
pod 'PDKeychainBindingsController'
- pod 'YYModel'
pod 'DateTools'
pod 'TagListView-ObjC'
pod 'PHFComposeBarView'
diff --git a/Podfile.lock b/Podfile.lock
index 4c868af..05ec9b0 100644
--- a/Podfile.lock
+++ b/Podfile.lock
@@ -21,7 +21,6 @@ PODS:
- PHFDelegateChain (1.0.1)
- TagListView-ObjC (0.1.1)
- "UIView+Shimmer (1.0.0)"
- - YYModel (1.0.4)
DEPENDENCIES:
- AFNetworking
@@ -30,7 +29,6 @@ DEPENDENCIES:
- PHFComposeBarView
- TagListView-ObjC
- "UIView+Shimmer"
- - YYModel
SPEC REPOS:
https://github.com/cocoapods/specs.git:
@@ -41,7 +39,6 @@ SPEC REPOS:
- PHFDelegateChain
- TagListView-ObjC
- "UIView+Shimmer"
- - YYModel
SPEC CHECKSUMS:
AFNetworking: b6f891fdfaed196b46c7a83cf209e09697b94057
@@ -51,8 +48,7 @@ SPEC CHECKSUMS:
PHFDelegateChain: 491f9cd8a3fb8761f390ff05f74a0e168d48d285
TagListView-ObjC: 432991e24c5177eb4fa7d721de7084f09f39a0b8
"UIView+Shimmer": ed634f95e8f4bda666b28b47bd85a4336a4117d8
- YYModel: 2a7fdd96aaa4b86a824e26d0c517de8928c04b30
-PODFILE CHECKSUM: 36a9a80ef083ac6ad371a565479f28f75e93d8f8
+PODFILE CHECKSUM: acb9b85a84c58e82301075a1b96c09b73c238ce5
COCOAPODS: 1.5.3