From d717ee5411fda8a5e7134d0f9eff48c6069473de Mon Sep 17 00:00:00 2001
From: Matthew Chen <matthew@signal.org>
Date: Wed, 12 Dec 2018 12:55:02 -0500
Subject: [PATCH] Parse and apply profile fetches off main thread.

---
 SignalMessaging/profiles/ProfileFetcherJob.swift | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/SignalMessaging/profiles/ProfileFetcherJob.swift b/SignalMessaging/profiles/ProfileFetcherJob.swift
index 1e699b46a..e3ad5b0f6 100644
--- a/SignalMessaging/profiles/ProfileFetcherJob.swift
+++ b/SignalMessaging/profiles/ProfileFetcherJob.swift
@@ -100,7 +100,7 @@ public class ProfileFetcherJob: NSObject {
 
         DispatchQueue.main.async {
             for recipientId in recipientIds {
-                self.updateProfile(recipientId: recipientId)
+                self.getAndUpdateProfile(recipientId: recipientId)
             }
         }
     }
@@ -109,8 +109,8 @@ public class ProfileFetcherJob: NSObject {
         case throttled(lastTimeInterval: TimeInterval)
     }
 
-    public func updateProfile(recipientId: String, remainingRetries: Int = 3) {
-        self.getProfile(recipientId: recipientId).map { profile in
+    public func getAndUpdateProfile(recipientId: String, remainingRetries: Int = 3) {
+        self.getProfile(recipientId: recipientId).map(on: DispatchQueue.global()) { profile in
             self.updateProfile(signalServiceProfile: profile)
         }.catch { error in
             switch error {
@@ -120,7 +120,7 @@ public class ProfileFetcherJob: NSObject {
                 Logger.warn("skipping updateProfile retry. Invalid profile for: \(recipientId) error: \(error)")
             default:
                 if remainingRetries > 0 {
-                    self.updateProfile(recipientId: recipientId, remainingRetries: remainingRetries - 1)
+                    self.getAndUpdateProfile(recipientId: recipientId, remainingRetries: remainingRetries - 1)
                 } else {
                     Logger.error("failed to get profile with error: \(error)")
                 }
@@ -153,7 +153,7 @@ public class ProfileFetcherJob: NSObject {
             udAccess = udManager.udAccess(forRecipientId: recipientId,
                                           requireSyncAccess: false)
         }
-        
+
         return requestProfile(recipientId: recipientId,
                               udAccess: udAccess,
                               canFailoverUDAuth: true)
@@ -175,7 +175,7 @@ public class ProfileFetcherJob: NSObject {
            udAccess: udAccess,
            canFailoverUDAuth: canFailoverUDAuth)
         return requestMaker.makeRequest()
-            .map { (result: RequestMakerResult) -> SignalServiceProfile in
+            .map(on: DispatchQueue.global()) { (result: RequestMakerResult) -> SignalServiceProfile in
                 try SignalServiceProfile(recipientId: recipientId, responseObject: result.responseObject)
         }
     }