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

Add SYNC-3478 [v109] Poll for missing send tabs on interval #12377

Merged
merged 3 commits into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Client/Application/AppDelegate+SyncSentTabs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class AppSyncDelegate: SyncDelegate {
}

func displaySentTab(for url: URL, title: String, from deviceName: String?) {
DispatchQueue.main.sync {
if app.applicationState == .active {
DispatchQueue.main.async {
if self.app.applicationState == .active {
BrowserViewController.foregroundBVC().switchToTabForURLOrOpen(url)
return
}
Expand Down Expand Up @@ -63,7 +63,9 @@ class AppSyncDelegate: SyncDelegate {
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 0.1, repeats: false)

// The identifier for each notification request must be unique in order to be created
let requestIdentifier = "\(SentTabAction.TabSendCategory).\(url.absoluteString)"
// we attach a unique identifier in case the user sends the tab multiple times.
let uuidString = UUID()
let requestIdentifier = "\(uuidString).\(SentTabAction.TabSendCategory).\(url.absoluteString)"
tarikeshaq marked this conversation as resolved.
Show resolved Hide resolved
let request = UNNotificationRequest(identifier: requestIdentifier, content: notificationContent, trigger: trigger)

UNUserNotificationCenter.current().add(request) { error in
Expand Down
33 changes: 30 additions & 3 deletions Providers/Profile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ class CommandStoringSyncDelegate: SyncDelegate {
protocol Profile: AnyObject {

typealias HistoryFetcher = BrowserHistory & SyncableHistory & ResettableSyncStorage

var places: RustPlaces { get }
var prefs: Prefs { get }
var queue: TabQueue { get }
Expand Down Expand Up @@ -1039,15 +1038,43 @@ open class BrowserProfile: Profile {
}

let clientSynchronizer = ready.synchronizer(ClientsSynchronizer.self, delegate: delegate, prefs: prefs, why: why)
return clientSynchronizer.synchronizeLocalClients(self.profile.remoteClientsAndTabs, withServer: ready.client, info: ready.info) >>== { result in
let result = clientSynchronizer.synchronizeLocalClients(
self.profile.remoteClientsAndTabs,
withServer: ready.client,
info: ready.info
) >>== { result in
guard case .completed = result, let accountManager = self.profile.rustFxA.accountManager.peek() else {
return deferMaybe(result)
}
log.debug("Updating FxA devices list.")

accountManager.deviceConstellation()?.refreshState()
return deferMaybe(result)
}

log.debug("Polling for any missed commands")
let accountManager = self.profile.rustFxA.accountManager.peek()
accountManager?.deviceConstellation()?.pollForCommands { commands in
if let commands = try? commands.get() {
for command in commands {
switch command {
case .tabReceived(let sender, let tabData):
// The tabData.entries is the tabs history
// we only want the last item, which is the tab
// to display
let title = tabData.entries.last?.title ?? ""
let url = tabData.entries.last?.url ?? ""
if let json = try? accountManager?.gatherTelemetry() {
let events = FxATelemetry.parseTelemetry(fromJSONString: json)
events.forEach { $0.record(intoPrefs: self.profile.prefs) }
}
if let url = URL(string: url) {
self.profile.syncDelegate?.displaySentTab(for: url, title: title, from: sender?.displayName)
}
}
}
}
}
return result
}

fileprivate func syncLegacyHistoryWithDelegate(_ delegate: SyncDelegate, prefs: Prefs, ready: Ready, why: SyncReason) -> SyncResult {
Expand Down