Reset the unread indicator state if possible while app is in the background.

* Clean up timer usage.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent 95c17afe7e
commit 76df8431a8

@ -585,6 +585,7 @@ typedef enum : NSUInteger {
} }
}]; }];
[self.voiceMemoUpdateTimer invalidate];
self.voiceMemoUpdateTimer = [NSTimer weakScheduledTimerWithTimeInterval:0.1f self.voiceMemoUpdateTimer = [NSTimer weakScheduledTimerWithTimeInterval:0.1f
target:self target:self
selector:@selector(updateVoiceMemo) selector:@selector(updateVoiceMemo)
@ -971,6 +972,10 @@ typedef enum : NSUInteger {
selector:@selector(applicationWillEnterForeground:) selector:@selector(applicationWillEnterForeground:)
name:UIApplicationWillEnterForegroundNotification name:UIApplicationWillEnterForegroundNotification
object:nil]; object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidEnterBackground:)
name:UIApplicationDidEnterBackgroundNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationWillResignActive:) selector:@selector(applicationWillResignActive:)
name:UIApplicationWillResignActiveNotification name:UIApplicationWillResignActiveNotification
@ -1006,6 +1011,16 @@ typedef enum : NSUInteger {
[self ensureThreadOffersAndIndicators]; [self ensureThreadOffersAndIndicators];
} }
- (void)applicationDidEnterBackground:(NSNotification *)notification
{
// self.hasEnteredBackground = YES;
if (self.hasClearedUnreadMessagesIndicator) {
self.hasClearedUnreadMessagesIndicator = NO;
self.offersAndIndicators = nil;
}
}
- (void)applicationWillResignActive:(NSNotification *)notification - (void)applicationWillResignActive:(NSNotification *)notification
{ {
[self cancelVoiceMemo]; [self cancelVoiceMemo];
@ -1279,7 +1294,8 @@ typedef enum : NSUInteger {
} }
- (void)startReadTimer { - (void)startReadTimer {
self.readTimer = [NSTimer scheduledTimerWithTimeInterval:1 [self.readTimer invalidate];
self.readTimer = [NSTimer weakScheduledTimerWithTimeInterval:2
target:self target:self
selector:@selector(readTimerDidFire) selector:@selector(readTimerDidFire)
userInfo:nil userInfo:nil
@ -2972,8 +2988,12 @@ typedef enum : NSUInteger {
// make sure we don't show it again. // make sure we don't show it again.
self.hasClearedUnreadMessagesIndicator = YES; self.hasClearedUnreadMessagesIndicator = YES;
if (self.offersAndIndicators.unreadIndicatorPosition) {
// If we've just cleared the "unread messages" indicator,
// update the dynamic interactions.
[self ensureThreadOffersAndIndicators]; [self ensureThreadOffersAndIndicators];
} }
}
#pragma mark - Attachment Picking: Documents #pragma mark - Attachment Picking: Documents

@ -127,6 +127,7 @@ NS_ASSUME_NONNULL_BEGIN
[self.audioPlayer prepareToPlay]; [self.audioPlayer prepareToPlay];
[self.audioPlayer play]; [self.audioPlayer play];
[self.audioPlayerPoller invalidate];
self.audioPlayerPoller = [NSTimer weakScheduledTimerWithTimeInterval:.05f self.audioPlayerPoller = [NSTimer weakScheduledTimerWithTimeInterval:.05f
target:self target:self
selector:@selector(audioPlayerUpdated:) selector:@selector(audioPlayerUpdated:)

@ -6,6 +6,7 @@
#import "OWSDeviceTableViewCell.h" #import "OWSDeviceTableViewCell.h"
#import "OWSLinkDeviceViewController.h" #import "OWSLinkDeviceViewController.h"
#import "UIViewController+CameraPermissions.h" #import "UIViewController+CameraPermissions.h"
#import <SignalServiceKit/NSTimer+OWS.h>
#import <SignalServiceKit/OWSDevice.h> #import <SignalServiceKit/OWSDevice.h>
#import <SignalServiceKit/OWSDevicesService.h> #import <SignalServiceKit/OWSDevicesService.h>
#import <SignalServiceKit/TSDatabaseView.h> #import <SignalServiceKit/TSDatabaseView.h>
@ -100,8 +101,8 @@ int const OWSLinkedDevicesTableViewControllerSectionAddDevice = 1;
self.editing = NO; self.editing = NO;
__weak typeof(self) wself = self; __weak typeof(self) wself = self;
self.pollingRefreshTimer = [NSTimer scheduledTimerWithTimeInterval:(10.0) [self.pollingRefreshTimer invalidate];
target:wself self.pollingRefreshTimer = [NSTimer weakScheduledTimerWithTimeInterval:(10.0)target:wself
selector:@selector(refreshDevices) selector:@selector(refreshDevices)
userInfo:nil userInfo:nil
repeats:YES]; repeats:YES];

@ -4,6 +4,7 @@
#import "SignalsNavigationController.h" #import "SignalsNavigationController.h"
#import "UIUtil.h" #import "UIUtil.h"
#import <SignalServiceKit/NSTimer+OWS.h>
#import <SignalServiceKit/OWSSignalService.h> #import <SignalServiceKit/OWSSignalService.h>
#import <SignalServiceKit/TSSocketManager.h> #import <SignalServiceKit/TSSocketManager.h>
@ -87,7 +88,8 @@ static double const STALLED_PROGRESS = 0.9;
case SocketManagerStateClosed: case SocketManagerStateClosed:
if (_socketStatusView == nil) { if (_socketStatusView == nil) {
[self initializeSocketStatusBar]; [self initializeSocketStatusBar];
_updateStatusTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 [_updateStatusTimer invalidate];
_updateStatusTimer = [NSTimer weakScheduledTimerWithTimeInterval:0.5
target:self target:self
selector:@selector(updateProgress) selector:@selector(updateProgress)
userInfo:nil userInfo:nil

@ -155,7 +155,7 @@ NS_ASSUME_NONNULL_BEGIN
// have been marked as read. // have been marked as read.
// //
// IFF this variable is non-null, there are unseen messages in the thread. // IFF this variable is non-null, there are unseen messages in the thread.
__block NSNumber *firstUnseenInteractionTimestamp = nil; NSNumber *firstUnseenInteractionTimestamp = nil;
if (firstUnseenInteractionTimestampParameter) { if (firstUnseenInteractionTimestampParameter) {
firstUnseenInteractionTimestamp = firstUnseenInteractionTimestampParameter; firstUnseenInteractionTimestamp = firstUnseenInteractionTimestampParameter;
} else { } else {

Loading…
Cancel
Save