From 779142ea0c9eeea5a4a89b42bfa738abc69487a0 Mon Sep 17 00:00:00 2001 From: Evan Hahn Date: Wed, 15 Jun 2022 12:14:56 -0500 Subject: [PATCH] Fix crash when opening wallpaper/chat color view MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit _I recommend reviewing this with whitespace changes disabled._ Previously, Settings → Appearance → Chat Color & Wallpaper → Chat Color would cause a crash. This was because we had a re-entrant database transaction. This fixes that by removing the re-entrant transaction—a fairly simple fix. There was also a function here that was immediately called and not used elsewhere, so I removed the function and inlined its contents. Not strictly related to the crash. I believe it was originally added in 0574d23b6f06b4ccd8e9e6d6972e1151b2188219. --- Signal/src/views/MockConversationView.swift | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/Signal/src/views/MockConversationView.swift b/Signal/src/views/MockConversationView.swift index 7058548945..74f87f2005 100644 --- a/Signal/src/views/MockConversationView.swift +++ b/Signal/src/views/MockConversationView.swift @@ -129,18 +129,16 @@ class MockConversationView: UIView { chatColor: chatColor ) for item in model.items { - func buildInteraction() -> TSInteraction { - switch item { - case .date: - return DateHeaderInteraction(thread: self.thread, - timestamp: NSDate.ows_millisecondTimeStamp()) - case .outgoing(let text): - return databaseStorage.read { MockOutgoingMessage(messageBody: text, thread: self.thread, transaction: $0) } - case .incoming(let text): - return MockIncomingMessage(messageBody: text, thread: self.thread) - } + let interaction: TSInteraction + switch item { + case .date: + interaction = DateHeaderInteraction(thread: self.thread, timestamp: NSDate.ows_millisecondTimeStamp()) + case .outgoing(let text): + interaction = MockOutgoingMessage(messageBody: text, thread: self.thread, transaction: transaction) + case .incoming(let text): + interaction = MockIncomingMessage(messageBody: text, thread: self.thread) } - let interaction = buildInteraction() + guard let renderItem = CVLoader.buildStandaloneRenderItem( interaction: interaction, thread: self.thread,