Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring #119

Merged
merged 2 commits into from Feb 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Pods
Submodule Pods updated from 67dbce to 2870e6
2 changes: 1 addition & 1 deletion Signal/Signal-Info.plist
Expand Up @@ -5,7 +5,7 @@
<key>BuildDetails</key>
<dict>
<key>CarthageVersion</key>
<string>0.34.0</string>
<string>0.33.0</string>
<key>OSXVersion</key>
<string>10.15.3</string>
<key>WebRTCCommit</key>
Expand Down
3 changes: 0 additions & 3 deletions Signal/src/AppDelegate.m
Expand Up @@ -316,9 +316,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
name:NSNotificationName_2FAStateDidChange
object:nil];

// Loki - Observe new messages received notifications
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(handleNewMessagesReceived:) name:NSNotification.newMessagesReceived object:nil];

// Loki - Observe thread deleted notifications
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(handleThreadDeleted:) name:NSNotification.threadDeleted object:nil];

Expand Down
20 changes: 10 additions & 10 deletions Signal/src/Loki/Components/ConversationTitleView.swift
Expand Up @@ -7,8 +7,8 @@ final class ConversationTitleView : UIView {
// MARK: Types
private enum Status : Int {
case calculatingPoW = 1
case contactingNetwork = 2
case sendingMessage = 3
case routing = 2
case messageSending = 3
case messageSent = 4
case messageFailed = 5
}
Expand Down Expand Up @@ -40,8 +40,8 @@ final class ConversationTitleView : UIView {
let notificationCenter = NotificationCenter.default
notificationCenter.addObserver(self, selector: #selector(handleProfileChangedNotification(_:)), name: NSNotification.Name(rawValue: kNSNotificationName_OtherUsersProfileDidChange), object: nil)
notificationCenter.addObserver(self, selector: #selector(handleCalculatingPoWNotification(_:)), name: .calculatingPoW, object: nil)
notificationCenter.addObserver(self, selector: #selector(handleContactingNetworkNotification(_:)), name: .contactingNetwork, object: nil)
notificationCenter.addObserver(self, selector: #selector(handleSendingMessageNotification(_:)), name: .sendingMessage, object: nil)
notificationCenter.addObserver(self, selector: #selector(handleRoutingNotification(_:)), name: .routing, object: nil)
notificationCenter.addObserver(self, selector: #selector(handleMessageSendingNotification(_:)), name: .messageSending, object: nil)
notificationCenter.addObserver(self, selector: #selector(handleMessageSentNotification(_:)), name: .messageSent, object: nil)
notificationCenter.addObserver(self, selector: #selector(handleMessageFailedNotification(_:)), name: .messageFailed, object: nil)
}
Expand Down Expand Up @@ -99,14 +99,14 @@ final class ConversationTitleView : UIView {
setStatusIfNeeded(to: .calculatingPoW, forMessageWithTimestamp: timestamp)
}

@objc private func handleContactingNetworkNotification(_ notification: Notification) {
@objc private func handleRoutingNotification(_ notification: Notification) {
guard let timestamp = notification.object as? NSNumber else { return }
setStatusIfNeeded(to: .contactingNetwork, forMessageWithTimestamp: timestamp)
setStatusIfNeeded(to: .routing, forMessageWithTimestamp: timestamp)
}

@objc private func handleSendingMessageNotification(_ notification: Notification) {
@objc private func handleMessageSendingNotification(_ notification: Notification) {
guard let timestamp = notification.object as? NSNumber else { return }
setStatusIfNeeded(to: .sendingMessage, forMessageWithTimestamp: timestamp)
setStatusIfNeeded(to: .messageSending, forMessageWithTimestamp: timestamp)
}

@objc private func handleMessageSentNotification(_ notification: Notification) {
Expand Down Expand Up @@ -147,8 +147,8 @@ final class ConversationTitleView : UIView {
self.subtitleLabel.isHidden = false
switch self.currentStatus {
case .calculatingPoW: self.subtitleLabel.text = NSLocalizedString("Encrypting message", comment: "")
case .contactingNetwork: self.subtitleLabel.text = NSLocalizedString("Tracing a path", comment: "")
case .sendingMessage: self.subtitleLabel.text = NSLocalizedString("Sending message", comment: "")
case .routing: self.subtitleLabel.text = NSLocalizedString("Tracing a path", comment: "")
case .messageSending: self.subtitleLabel.text = NSLocalizedString("Sending message", comment: "")
case .messageSent: self.subtitleLabel.text = NSLocalizedString("Message sent securely", comment: "")
case .messageFailed: self.subtitleLabel.text = NSLocalizedString("Message failed to send", comment: "")
case nil:
Expand Down
Expand Up @@ -429,12 +429,12 @@ - (void)addNotificationListeners
name:NSNotification.calculatingPoW
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleContactingNetworkNotification:)
name:NSNotification.contactingNetwork
selector:@selector(handleRoutingNotification:)
name:NSNotification.routing
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleSendingMessageNotification:)
name:NSNotification.sendingMessage
selector:@selector(handleMessageSendingNotification:)
name:NSNotification.messageSending
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleMessageSentNotification:)
Expand Down Expand Up @@ -5419,13 +5419,13 @@ - (void)handleCalculatingPoWNotification:(NSNotification *)notification
[self setProgressIfNeededTo:0.25f forMessageWithTimestamp:timestamp];
}

- (void)handleContactingNetworkNotification:(NSNotification *)notification
- (void)handleRoutingNotification:(NSNotification *)notification
{
NSNumber *timestamp = (NSNumber *)notification.object;
[self setProgressIfNeededTo:0.50f forMessageWithTimestamp:timestamp];
}

- (void)handleSendingMessageNotification:(NSNotification *)notification
- (void)handleMessageSendingNotification:(NSNotification *)notification
{
NSNumber *timestamp = (NSNumber *)notification.object;
[self setProgressIfNeededTo:0.75f forMessageWithTimestamp:timestamp];
Expand Down
3 changes: 2 additions & 1 deletion SignalServiceKit/src/Loki/API/LokiAPI+SwarmAPI.swift
@@ -1,7 +1,8 @@
import PromiseKit

public extension LokiAPI {


/// Only ever accessed from `LokiAPI.errorHandlingQueue` to avoid race conditions.
fileprivate static var failureCount: [LokiAPITarget:UInt] = [:]

// MARK: Settings
Expand Down
4 changes: 2 additions & 2 deletions SignalServiceKit/src/Loki/API/LokiAPI.swift
Expand Up @@ -187,10 +187,10 @@ public final class LokiAPI : NSObject {
func sendLokiMessageUsingSwarmAPI() -> Promise<Set<RawResponsePromise>> {
notificationCenter.post(name: .calculatingPoW, object: NSNumber(value: signalMessage.timestamp))
return lokiMessage.calculatePoW().then { lokiMessageWithPoW -> Promise<Set<RawResponsePromise>> in
notificationCenter.post(name: .contactingNetwork, object: NSNumber(value: signalMessage.timestamp))
notificationCenter.post(name: .routing, object: NSNumber(value: signalMessage.timestamp))
return getTargetSnodes(for: destination).map { swarm in
return Set(swarm.map { target in
notificationCenter.post(name: .sendingMessage, object: NSNumber(value: signalMessage.timestamp))
notificationCenter.post(name: .messageSending, object: NSNumber(value: signalMessage.timestamp))
return sendLokiMessage(lokiMessageWithPoW, to: target).map { rawResponse in
if let json = rawResponse as? JSON, let powDifficulty = json["difficulty"] as? Int {
guard powDifficulty != LokiAPI.powDifficulty else { return rawResponse }
Expand Down
@@ -1,36 +1,40 @@

public extension Notification.Name {

// State changes
public static let contactOnlineStatusChanged = Notification.Name("contactOnlineStatusChanged")
public static let newMessagesReceived = Notification.Name("newMessagesReceived")
public static let threadFriendRequestStatusChanged = Notification.Name("threadFriendRequestStatusChanged")
public static let messageFriendRequestStatusChanged = Notification.Name("messageFriendRequestStatusChanged")
public static let threadDeleted = Notification.Name("threadDeleted")
public static let dataNukeRequested = Notification.Name("dataNukeRequested")
public static let threadSessionRestoreDevicesChanged = Notification.Name("threadSessionRestoreDevicesChanged")
// Message statuses
// Message status changes
public static let calculatingPoW = Notification.Name("calculatingPoW")
public static let contactingNetwork = Notification.Name("contactingNetwork")
public static let sendingMessage = Notification.Name("sendingMessage")
public static let routing = Notification.Name("routing")
public static let messageSending = Notification.Name("messageSending")
public static let messageSent = Notification.Name("messageSent")
public static let messageFailed = Notification.Name("messageFailed")
// Onboarding
public static let seedViewed = Notification.Name("seedViewed")
// Interaction
public static let dataNukeRequested = Notification.Name("dataNukeRequested")
}

@objc public extension NSNotification {

// State changes
@objc public static let contactOnlineStatusChanged = Notification.Name.contactOnlineStatusChanged.rawValue as NSString
@objc public static let newMessagesReceived = Notification.Name.newMessagesReceived.rawValue as NSString
@objc public static let threadFriendRequestStatusChanged = Notification.Name.threadFriendRequestStatusChanged.rawValue as NSString
@objc public static let messageFriendRequestStatusChanged = Notification.Name.messageFriendRequestStatusChanged.rawValue as NSString
@objc public static let threadDeleted = Notification.Name.threadDeleted.rawValue as NSString
@objc public static let dataNukeRequested = Notification.Name.dataNukeRequested.rawValue as NSString
@objc public static let threadSessionRestoreDevicesChanged = Notification.Name.threadSessionRestoreDevicesChanged.rawValue as NSString
// Message statuses
@objc public static let calculatingPoW = Notification.Name.calculatingPoW.rawValue as NSString
@objc public static let contactingNetwork = Notification.Name.contactingNetwork.rawValue as NSString
@objc public static let sendingMessage = Notification.Name.sendingMessage.rawValue as NSString
@objc public static let routing = Notification.Name.routing.rawValue as NSString
@objc public static let messageSending = Notification.Name.messageSending.rawValue as NSString
@objc public static let messageSent = Notification.Name.messageSent.rawValue as NSString
@objc public static let messageFailed = Notification.Name.messageFailed.rawValue as NSString
// Onboarding
@objc public static let seedViewed = Notification.Name.seedViewed.rawValue as NSString
// Interaction
@objc public static let dataNukeRequested = Notification.Name.dataNukeRequested.rawValue as NSString
}