Skip to content

Commit 7c6e9e0

Browse files
committed
Read receipts remove lockscreen notifications
No need to have a notification for a message you've already read on desktop. // FREEBIE
1 parent f7198d5 commit 7c6e9e0

File tree

9 files changed

+147
-19
lines changed

9 files changed

+147
-19
lines changed

Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ source 'https://github.com/CocoaPods/Specs.git'
33

44
target 'Signal' do
55
pod 'SocketRocket', :git => 'https://github.com/facebook/SocketRocket.git'
6-
pod 'SignalServiceKit', git: 'https://github.com/WhisperSystems/SignalServiceKit.git', branch: 'desktop-integration'
6+
pod 'SignalServiceKit', git: 'https://github.com/WhisperSystems/SignalServiceKit.git'
77
#pod 'SignalServiceKit', path: '../SignalServiceKit'
88
pod 'OpenSSL', '~> 1.0.208'
99
pod 'PastelogKit', '~> 1.3'

Podfile.lock

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,18 @@ DEPENDENCIES:
119119
- OpenSSL (~> 1.0.208)
120120
- PastelogKit (~> 1.3)
121121
- SCWaveformView (~> 1.0)
122-
- SignalServiceKit (from `https://github.com/WhisperSystems/SignalServiceKit.git`, branch `desktop-integration`)
122+
- SignalServiceKit (from `https://github.com/WhisperSystems/SignalServiceKit.git`)
123123
- SocketRocket (from `https://github.com/facebook/SocketRocket.git`)
124124

125125
EXTERNAL SOURCES:
126126
SignalServiceKit:
127-
:branch: desktop-integration
128127
:git: https://github.com/WhisperSystems/SignalServiceKit.git
129128
SocketRocket:
130129
:git: https://github.com/facebook/SocketRocket.git
131130

132131
CHECKOUT OPTIONS:
133132
SignalServiceKit:
134-
:commit: 800e2a95412045f565e7559b77b05eff5567cb95
133+
:commit: 9821e0c0d03a01f556680a6ae869b70bf5b93681
135134
:git: https://github.com/WhisperSystems/SignalServiceKit.git
136135
SocketRocket:
137136
:commit: 8096fef47d582bff8ae3758c9ae7af1d55ea53d6
@@ -162,6 +161,6 @@ SPEC CHECKSUMS:
162161
UnionFind: c33be5adb12983981d6e827ea94fc7f9e370f52d
163162
YapDatabase: b1e43555a34a5298e23a045be96817a5ef0da58f
164163

165-
PODFILE CHECKSUM: 430c423130f22d8319fc2a420b55a4a3c7b39c9a
164+
PODFILE CHECKSUM: 5dccee4c1c1ba5d4bf9575a81eeede82d1e89e8b
166165

167166
COCOAPODS: 1.0.1

Signal.xcodeproj/project.pbxproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
458E383A1D6699FA0094BD24 /* OWSDeviceProvisioningURLParserTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 458E38391D6699FA0094BD24 /* OWSDeviceProvisioningURLParserTest.m */; };
2525
459311FC1D75C948008DD4F0 /* OWSDeviceTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 459311FB1D75C948008DD4F0 /* OWSDeviceTableViewCell.m */; };
2626
459C3F0D1C9B3A1B003ACF51 /* TSMessageAdapterTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 459C3F0C1C9B3A1B003ACF51 /* TSMessageAdapterTest.m */; };
27+
45BFFFA81D898AF0004A12A7 /* OWSStaleNotificationObserver.m in Sources */ = {isa = PBXBuildFile; fileRef = 45BFFFA71D898AF0004A12A7 /* OWSStaleNotificationObserver.m */; };
28+
45BFFFA91D898AF0004A12A7 /* OWSStaleNotificationObserver.m in Sources */ = {isa = PBXBuildFile; fileRef = 45BFFFA71D898AF0004A12A7 /* OWSStaleNotificationObserver.m */; };
2729
45C681B71D305A580050903A /* OWSCall.m in Sources */ = {isa = PBXBuildFile; fileRef = 45C681B61D305A580050903A /* OWSCall.m */; };
2830
45C681B81D305A580050903A /* OWSCall.m in Sources */ = {isa = PBXBuildFile; fileRef = 45C681B61D305A580050903A /* OWSCall.m */; };
2931
45C681BC1D305C080050903A /* OWSCallCollectionViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 45C681BA1D305C080050903A /* OWSCallCollectionViewCell.m */; };
@@ -537,6 +539,8 @@
537539
4597E94E1D8313C100040CDE /* sq */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = sq; path = translations/sq.lproj/Localizable.strings; sourceTree = "<group>"; };
538540
4597E94F1D8313CB00040CDE /* bg */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = bg; path = translations/bg.lproj/Localizable.strings; sourceTree = "<group>"; };
539541
459C3F0C1C9B3A1B003ACF51 /* TSMessageAdapterTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TSMessageAdapterTest.m; path = "view controllers/Signals/TSMessageAdapters/TSMessageAdapterTest.m"; sourceTree = "<group>"; };
542+
45BFFFA61D898AF0004A12A7 /* OWSStaleNotificationObserver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OWSStaleNotificationObserver.h; path = Observers/OWSStaleNotificationObserver.h; sourceTree = "<group>"; };
543+
45BFFFA71D898AF0004A12A7 /* OWSStaleNotificationObserver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OWSStaleNotificationObserver.m; path = Observers/OWSStaleNotificationObserver.m; sourceTree = "<group>"; };
540544
45C681B51D305A580050903A /* OWSCall.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSCall.h; sourceTree = "<group>"; };
541545
45C681B61D305A580050903A /* OWSCall.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSCall.m; sourceTree = "<group>"; };
542546
45C681B91D305C080050903A /* OWSCallCollectionViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSCallCollectionViewCell.h; sourceTree = "<group>"; };
@@ -1167,6 +1171,15 @@
11671171
name = TSMessageAdapters;
11681172
sourceTree = "<group>";
11691173
};
1174+
45BFFFA51D898AB8004A12A7 /* Observers */ = {
1175+
isa = PBXGroup;
1176+
children = (
1177+
45BFFFA61D898AF0004A12A7 /* OWSStaleNotificationObserver.h */,
1178+
45BFFFA71D898AF0004A12A7 /* OWSStaleNotificationObserver.m */,
1179+
);
1180+
name = Observers;
1181+
sourceTree = "<group>";
1182+
};
11701183
70B8009F190C529C0042E3F0 /* Products */ = {
11711184
isa = PBXGroup;
11721185
children = (
@@ -1218,6 +1231,7 @@
12181231
457F3AC01D14A0F700C51351 /* Models */,
12191232
76EB052B18170B33006006FC /* Views */,
12201233
76EB04FE18170B33006006FC /* View Controllers */,
1234+
45BFFFA51D898AB8004A12A7 /* Observers */,
12211235
);
12221236
path = src;
12231237
sourceTree = "<group>";
@@ -2689,6 +2703,7 @@
26892703
E197B61918BBEC1A00F073E5 /* RemoteIOBufferListWrapper.m in Sources */,
26902704
76EB05A618170B33006006FC /* RtpPacket.m in Sources */,
26912705
76EB064218170B33006006FC /* StringUtil.m in Sources */,
2706+
45BFFFA81D898AF0004A12A7 /* OWSStaleNotificationObserver.m in Sources */,
26922707
A547DD741A70A87800103EC7 /* DJWActionSheet+OWS.m in Sources */,
26932708
45C681B71D305A580050903A /* OWSCall.m in Sources */,
26942709
76EB062618170B33006006FC /* Queue.m in Sources */,
@@ -2883,6 +2898,7 @@
28832898
B660F7311C29988E00687D6E /* IpEndPoint.m in Sources */,
28842899
B660F7321C29988E00687D6E /* PacketHandler.m in Sources */,
28852900
B660F7331C29988E00687D6E /* RtpPacket.m in Sources */,
2901+
45BFFFA91D898AF0004A12A7 /* OWSStaleNotificationObserver.m in Sources */,
28862902
B660F7341C29988E00687D6E /* RtpSocket.m in Sources */,
28872903
B660F7351C29988E00687D6E /* SequenceCounter.m in Sources */,
28882904
B660F7361C29988E00687D6E /* SrtpSocket.m in Sources */,

Signal/Signal-Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
</dict>
3939
</array>
4040
<key>CFBundleVersion</key>
41-
<string>2.5.0.11</string>
41+
<string>2.5.0.12</string>
4242
<key>ITSAppUsesNonExemptEncryption</key>
4343
<false/>
4444
<key>LOGS_EMAIL</key>

Signal/src/AppDelegate.m

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#import "TSSocketManager.h"
1616
#import "TextSecureKitEnv.h"
1717
#import "VersionMigrations.h"
18+
#import "OWSStaleNotificationObserver.h"
1819
#import <SignalServiceKit/OWSReadReceiptObserver.h>
1920

2021
static NSString *const kStoryboardName = @"Storyboard";
@@ -26,6 +27,7 @@ @interface AppDelegate ()
2627

2728
@property (nonatomic, retain) UIWindow *screenProtectionWindow;
2829
@property (nonatomic) OWSReadReceiptObserver *readReceiptObserver;
30+
@property (nonatomic) OWSStaleNotificationObserver *staleNotificationObserver;
2931

3032
@end
3133

@@ -119,20 +121,25 @@ - (void)setupTSKitEnv {
119121
[TextSecureKitEnv sharedEnv].contactsManager = [Environment getCurrent].contactsManager;
120122
[[TSStorageManager sharedManager] setupDatabase];
121123
[TextSecureKitEnv sharedEnv].notificationsManager = [[NotificationsManager alloc] init];
122-
self.readReceiptObserver =
123-
[[OWSReadReceiptObserver alloc] initWithMessagesManager:[TSMessagesManager sharedManager]];
124+
self.readReceiptObserver = [OWSReadReceiptObserver new];
124125
[self.readReceiptObserver startObserving];
126+
127+
self.staleNotificationObserver = [OWSStaleNotificationObserver new];
128+
[self.staleNotificationObserver startObserving];
125129
}
126130

127-
- (void)application:(UIApplication *)application
128-
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
131+
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
132+
{
133+
DDLogDebug(@"%@ Successfully registered for remote notifications with token: %@", self.tag, deviceToken);
129134
[PushManager.sharedManager.pushNotificationFutureSource trySetResult:deviceToken];
130135
}
131136

132-
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
137+
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
138+
{
139+
DDLogError(@"%@ Failed to register for remote notifications with error %@", self.tag, error);
133140
#ifdef DEBUG
134-
DDLogWarn(@"We're in debug mode, and registered a fake push identifier");
135-
[PushManager.sharedManager.pushNotificationFutureSource trySetResult:@"aFakePushIdentifier"];
141+
DDLogWarn(@"%@ We're in debug mode. Faking success for remote registration with a fake push identifier", self.tag);
142+
[PushManager.sharedManager.pushNotificationFutureSource trySetResult:[NSData dataWithLength:32]];
136143
#else
137144
[PushManager.sharedManager.pushNotificationFutureSource trySetFailure:error];
138145
#endif
@@ -352,4 +359,14 @@ - (BOOL)applicationIsActive {
352359
return NO;
353360
}
354361

362+
+ (NSString *)tag
363+
{
364+
return [NSString stringWithFormat:@"[%@]", self.class];
365+
}
366+
367+
- (NSString *)tag
368+
{
369+
return self.class.tag;
370+
}
371+
355372
@end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Created by Michael Kirk on 9/14/16.
2+
// Copyright © 2016 Open Whisper Systems. All rights reserved.
3+
4+
NS_ASSUME_NONNULL_BEGIN
5+
6+
@class PushManager;
7+
8+
@interface OWSStaleNotificationObserver : NSObject
9+
10+
- (instancetype)initWithPushManager:(PushManager *)pushManager NS_DESIGNATED_INITIALIZER;
11+
- (void)startObserving;
12+
13+
@end
14+
15+
NS_ASSUME_NONNULL_END
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Created by Michael Kirk on 9/14/16.
2+
// Copyright © 2016 Open Whisper Systems. All rights reserved.
3+
4+
#import "OWSStaleNotificationObserver.h"
5+
#import "PushManager.h"
6+
#import <SignalServiceKit/OWSReadReceiptsProcessor.h>
7+
#import <SignalServiceKit/TSIncomingMessage.h>
8+
9+
NS_ASSUME_NONNULL_BEGIN
10+
11+
@interface OWSStaleNotificationObserver ()
12+
13+
@property (nonatomic, readonly) PushManager *pushManager;
14+
15+
@end
16+
17+
@implementation OWSStaleNotificationObserver
18+
19+
- (void)dealloc
20+
{
21+
[[NSNotificationCenter defaultCenter] removeObserver:self];
22+
}
23+
24+
- (instancetype)init
25+
{
26+
return [self initWithPushManager:[PushManager sharedManager]];
27+
}
28+
29+
- (instancetype)initWithPushManager:(PushManager *)pushManager
30+
{
31+
self = [super init];
32+
if (!self) {
33+
return self;
34+
}
35+
36+
_pushManager = pushManager;
37+
38+
return self;
39+
}
40+
41+
- (void)startObserving
42+
{
43+
[[NSNotificationCenter defaultCenter] addObserver:self
44+
selector:@selector(handleMessageRead:)
45+
name:OWSReadReceiptsProcessorMarkedMessageAsReadNotification
46+
object:nil];
47+
}
48+
49+
- (void)handleMessageRead:(NSNotification *)notification
50+
{
51+
if ([notification.object isKindOfClass:[TSIncomingMessage class]]) {
52+
TSIncomingMessage *message = (TSIncomingMessage *)notification.object;
53+
54+
DDLogDebug(@"%@ canceled notification for message:%@", self.tag, message);
55+
[self.pushManager cancelNotificationsWithThreadId:message.uniqueThreadId];
56+
}
57+
}
58+
59+
+ (NSString *)tag
60+
{
61+
return [NSString stringWithFormat:@"[%@]", self.class];
62+
}
63+
64+
- (NSString *)tag
65+
{
66+
return self.class.tag;
67+
}
68+
69+
@end
70+
71+
NS_ASSUME_NONNULL_END

Signal/src/network/PushManager.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//
88

99
#import <CollapsingFutures.h>
10-
#import <Foundation/Foundation.h>
10+
#import <PushKit/PushKit.h>
1111

1212
#define Signal_Thread_UserInfo_Key @"Signal_Thread_Id"
1313
#define Signal_Message_UserInfo_Key @"Signal_Message_Id"
@@ -33,7 +33,7 @@ typedef void (^pushTokensSuccessBlock)(NSString *pushToken, NSString *voipToken)
3333
* The Push Manager is responsible for registering the device for Signal push notifications.
3434
*/
3535

36-
@interface PushManager : NSObject
36+
@interface PushManager : NSObject <PKPushRegistryDelegate>
3737

3838
+ (PushManager *)sharedManager;
3939

@@ -65,6 +65,7 @@ typedef void (^pushTokensSuccessBlock)(NSString *pushToken, NSString *voipToken)
6565
- (BOOL)supportsVOIPPush;
6666
- (UILocalNotification *)closeVOIPBackgroundTask;
6767
- (void)presentNotification:(UILocalNotification *)notification;
68+
- (void)cancelNotificationsWithThreadId:(NSString *)threadId;
6869

6970
#pragma mark Push Notifications Delegate Methods
7071

Signal/src/network/PushManager.m

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
77
//
88

9-
#import <PushKit/PushKit.h>
10-
119
#import "AppDelegate.h"
1210
#import "OWSContactsManager.h"
1311
#import "InCallViewController.h"
@@ -22,7 +20,7 @@
2220

2321
#define pushManagerDomain @"org.whispersystems.pushmanager"
2422

25-
@interface PushManager () <PKPushRegistryDelegate>
23+
@interface PushManager ()
2624

2725
@property TOCFutureSource *registerWithServerFutureSource;
2826
@property UIAlertView *missingPermissionsAlertView;
@@ -298,7 +296,8 @@ - (TOCFuture *)registerPushNotificationFuture {
298296

299297
- (void)requestPushTokenWithSuccess:(pushTokensSuccessBlock)success failure:(failedPushRegistrationBlock)failure {
300298
if (!self.wantRemoteNotifications) {
301-
success(@"FakeToken", @"FakePushToken");
299+
DDLogWarn(@"%@ Using fake push tokens", self.tag);
300+
success(@"fakePushToken", @"fakeVoipToken");
302301
return;
303302
}
304303

@@ -451,4 +450,14 @@ - (void)cancelNotificationsWithThreadId:(NSString *)threadId {
451450
[self.currentNotifications removeObjectsInArray:toDelete];
452451
}
453452

453+
+ (NSString *)tag
454+
{
455+
return [NSString stringWithFormat:@"[%@]", self.class];
456+
}
457+
458+
- (NSString *)tag
459+
{
460+
return self.class.tag;
461+
}
462+
454463
@end

0 commit comments

Comments
 (0)