summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2017-03-27 01:22:24 +0300
committerGravatar Vitaly Takmazov2017-06-28 21:26:00 +0300
commit9f4b7a156a40769a0383911ab38e9ed09f986507 (patch)
treeafc00e6222941f8bd09d9fc483e3ca181c425d8c
parent92451d2a01f928ebeaa5a6ec4634b7a7ed9a0edf (diff)
fix reply updates
-rw-r--r--Juick/ViewControllers/MessagesViewController.m81
-rw-r--r--Juick/ViewControllers/RevealPanelViewController.m2
-rw-r--r--Juick/Views/MessageCell.m4
-rw-r--r--Juick/Views/MessageCell.xib21
4 files changed, 76 insertions, 32 deletions
diff --git a/Juick/ViewControllers/MessagesViewController.m b/Juick/ViewControllers/MessagesViewController.m
index e8857a7..3e6b7c5 100644
--- a/Juick/ViewControllers/MessagesViewController.m
+++ b/Juick/ViewControllers/MessagesViewController.m
@@ -26,36 +26,52 @@ static NSString *CellIdentifier = @"MessageCell";
@property(nonatomic, assign) Boolean dataLoading;
@property(nonatomic, strong) NSString *path;
@property(nonatomic, strong) NSMutableDictionary *params;
+@property(nonatomic, strong) dispatch_queue_t concurrent_queue;
@end
@implementation MessagesViewController
+- (id)init {
+ if (self = [super init]) {
+ self.concurrent_queue = dispatch_queue_create("Queue", DISPATCH_QUEUE_SERIAL);
+ };
+ return self;
+}
+
- (void)loadFromPath:(NSString *)messagesPath withParams:(NSDictionary *)params withTitle:(NSString *)title
{
[self setPath:messagesPath];
[self setParams:[[NSMutableDictionary alloc] initWithDictionary:params]];
self.title = title;
__weak MessagesViewController * weakSelf = self;
- [self.messages removeAllObjects];
- [weakSelf refreshData];
+ dispatch_sync(self.concurrent_queue, ^{
+ [self.messages removeAllObjects];
+ [weakSelf refreshData];
+ });
}
- (void) refreshData {
- if ([self.path isEqualToString:[Message threadUrl]]) {
- [self.messages removeAllObjects];
- }
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- self.dataLoading = YES;
- [Message pullNextFromPath:self.path params:self.params callback:^(NSArray *next) {
- [[NSOperationQueue mainQueue] addOperationWithBlock:^{
- [self.messages addObjectsFromArray:next];
- [self.tableView reloadData];
- [self.refreshControl endRefreshing];
- self.dataLoading = NO;
- }];
- }];
- });
+ self.dataLoading = YES;
+ [Message pullNextFromPath:self.path params:self.params callback:^(NSArray *next) {
+ NSArray *newMsgs = next;
+ if ([self.path isEqualToString:[Message threadUrl]]) {
+ NSUInteger lastRid = [((Message *)[self.messages lastObject]).rid unsignedIntegerValue];
+ NSUInteger count = [next count] - 1;
+ NSUInteger oldCount = [self.messages count];
+ if (oldCount > 0) {
+ if (lastRid && lastRid < count) {
+ newMsgs = [next subarrayWithRange:NSMakeRange(lastRid, count - lastRid)];
+ } else {
+ return;
+ }
+ }
+ }
+ [self.messages addObjectsFromArray:newMsgs];
+ [self.tableView reloadData];
+ [self.refreshControl endRefreshing];
+ self.dataLoading = NO;
+ }];
}
- (UIStatusBarStyle)preferredStatusBarStyle
@@ -119,12 +135,21 @@ static NSString *CellIdentifier = @"MessageCell";
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return _messages.count;
+ __block NSInteger count;
+ dispatch_sync(self.concurrent_queue, ^{
+ count = self.messages.count;
+ });
+ return count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
MessageCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- Message *msg = [_messages objectAtIndex:indexPath.row];
+ __block Message *msg;
+ dispatch_sync(self.concurrent_queue, ^{
+ msg = [self.messages objectAtIndex:indexPath.row];
+ });
+ cell.layer.borderWidth = 6;
+ cell.layer.borderColor = [ColorScheme mainBackground].CGColor;
[cell setMessage:msg];
if ([msg.attach length] > 0) {
[cell.attach yy_setImageWithURL:[NSURL URLWithString:msg.attach] placeholder:[UIImage imageNamed:@"AttachPlaceholder"] options:YYWebImageOptionProgressiveBlur | YYWebImageOptionSetImageWithFadeAnimation completion:^(UIImage * _Nullable image, NSURL * _Nonnull url, YYWebImageFromType from, YYWebImageStage stage, NSError * _Nullable error) {
@@ -146,7 +171,10 @@ static NSString *CellIdentifier = @"MessageCell";
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if ([self.path isEqualToString:[Message threadUrl]])
return;
- Message *msg = [_messages objectAtIndex:indexPath.row];
+ __block Message *msg;
+ dispatch_sync(self.concurrent_queue, ^{
+ msg = [self.messages objectAtIndex:indexPath.row];
+ });
MessagesViewController *threadViewController = [[MessagesViewController alloc] init];
[threadViewController loadFromPath:[Message threadUrl] withParams:[NSDictionary dictionaryWithObjectsAndKeys:msg.mid, @"mid", nil] withTitle:@"Thread"];
[self.navigationController pushViewController:threadViewController animated:NO];
@@ -156,13 +184,16 @@ static NSString *CellIdentifier = @"MessageCell";
CGFloat actualPosition = scrollView_.contentOffset.y;
CGFloat contentHeight = scrollView_.contentSize.height - scrollView_.contentSize.height / 2;
if (actualPosition >= contentHeight && !self.dataLoading) {
- NSNumber *lastMid = ((Message *)[self.messages lastObject]).mid;
- if (![self.path isEqualToString:[Message threadUrl]]) {
- [self.params setValue:lastMid forKey:@"before_mid"];
- }
- [self refreshData];
+ __block Message *lastMsg;
+ dispatch_sync(self.concurrent_queue, ^{
+ lastMsg = [self.messages lastObject];
+ NSNumber *lastMid = lastMsg.mid;
+ if (![self.path isEqualToString:[Message threadUrl]]) {
+ [self.params setValue:lastMid forKey:@"before_mid"];
+ }
+ [self refreshData];
+ });
}
}
-
@end
diff --git a/Juick/ViewControllers/RevealPanelViewController.m b/Juick/ViewControllers/RevealPanelViewController.m
index b74d556..c327ca6 100644
--- a/Juick/ViewControllers/RevealPanelViewController.m
+++ b/Juick/ViewControllers/RevealPanelViewController.m
@@ -46,7 +46,7 @@ static NSString *CellIdentifier = @"NavCell";
self.tableView.dataSource = self;
[self.tableView setSeparatorInset:UIEdgeInsetsZero];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
- self.tableView.separatorColor =[UIColor darkGrayColor];
+ self.tableView.separatorColor =[UIColor whiteColor];
[self.tableView registerNib:[UINib nibWithNibName:@"NavCell" bundle:nil] forCellReuseIdentifier:CellIdentifier];
[self.view addSubview:self.tableView];
self.signButton = [[UIButton alloc] init];
diff --git a/Juick/Views/MessageCell.m b/Juick/Views/MessageCell.m
index 963707c..13f33a5 100644
--- a/Juick/Views/MessageCell.m
+++ b/Juick/Views/MessageCell.m
@@ -35,7 +35,9 @@
if ([msg.repliesBy length] > 0) {
self.summary.text = [NSString stringWithFormat:@"%@ replies by %@", msg.repliesCount, msg.repliesBy];
} else {
- self.summary.text = [NSString stringWithFormat:@"%@ replies", msg.repliesCount];
+ if (msg.repliesCount > 0) {
+ self.summary.text = [NSString stringWithFormat:@"%@ replies", msg.repliesCount];
+ }
}
} else {
self.summary.text = nil;
diff --git a/Juick/Views/MessageCell.xib b/Juick/Views/MessageCell.xib
index c83b579..e555b60 100644
--- a/Juick/Views/MessageCell.xib
+++ b/Juick/Views/MessageCell.xib
@@ -1,5 +1,8 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11201" systemVersion="15G1004" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
+<?xml version="1.0" encoding="UTF-8"?>
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
+ <device id="ipad12_9" orientation="portrait">
+ <adaptation id="fullscreen"/>
+ </device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
@@ -12,12 +15,14 @@
<rect key="frame" x="0.0" y="0.0" width="592" height="343"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
- <frame key="frameInset" width="592" height="342"/>
+ <rect key="frame" x="0.0" y="0.0" width="592" height="342"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
- <stackView opaque="NO" contentMode="scaleToFill" axis="vertical" alignment="top" spacing="6" translatesAutoresizingMaskIntoConstraints="NO" id="rE3-Mc-Kov">
+ <stackView opaque="NO" contentMode="scaleToFill" axis="vertical" alignment="top" spacing="12" translatesAutoresizingMaskIntoConstraints="NO" id="rE3-Mc-Kov">
+ <rect key="frame" x="12" y="12" width="568" height="318"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" spacing="12" translatesAutoresizingMaskIntoConstraints="NO" id="lkI-Na-bF2">
+ <rect key="frame" x="0.0" y="0.0" width="103.5" height="48"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="kHx-jc-jaD">
<constraints>
@@ -26,13 +31,16 @@
</constraints>
</imageView>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="6" translatesAutoresizingMaskIntoConstraints="NO" id="ttr-pF-8Zm">
+ <rect key="frame" x="60" y="0.0" width="43.5" height="48"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="zVa-uf-1Mb">
+ <rect key="frame" x="0.0" y="0.0" width="43.5" height="26"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleHeadline"/>
<color key="textColor" red="0.0" green="0.40000000000000002" blue="0.59999999999999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="252" verticalHuggingPriority="252" horizontalCompressionResistancePriority="751" verticalCompressionResistancePriority="751" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="5IY-8Y-0W9">
+ <rect key="frame" x="0.0" y="32" width="43.5" height="16"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleFootnote"/>
<color key="textColor" red="0.59999999999999998" green="0.59999999999999998" blue="0.59999999999999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
@@ -42,11 +50,14 @@
</subviews>
</stackView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="0Q9-qY-nj2" customClass="TTTAttributedLabel">
+ <rect key="frame" x="0.0" y="60" width="42" height="0.0"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
- <imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="53j-SC-IXj"/>
+ <imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="53j-SC-IXj">
+ <rect key="frame" x="0.0" y="72" width="568" height="234"/>
+ </imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="zDd-8E-ic8">
<fontDescription key="fontDescription" style="UICTFontTextStyleFootnote"/>
<color key="textColor" red="0.59999999999999998" green="0.59999999999999998" blue="0.59999999999999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>