diff --git a/kordophone2/MessageEntryView.swift b/kordophone2/MessageEntryView.swift index 88e2715..deacbb8 100644 --- a/kordophone2/MessageEntryView.swift +++ b/kordophone2/MessageEntryView.swift @@ -54,7 +54,9 @@ struct MessageEntryView: View } .onChange(of: selectedConversation) { oldValue, newValue in - viewModel.draftText = "" + if oldValue?.id != newValue?.id { + viewModel.draftText = "" + } } } diff --git a/kordophone2/Transcript/TranscriptView.swift b/kordophone2/Transcript/TranscriptView.swift index a5076c0..fae1124 100644 --- a/kordophone2/Transcript/TranscriptView.swift +++ b/kordophone2/Transcript/TranscriptView.swift @@ -29,7 +29,7 @@ struct TranscriptView: View .padding() } .scaleEffect(CGSize(width: 1.0, height: -1.0)) - .id(model.displayedConversation) + .id(model.displayedConversation?.id) .task { await watchForMessageListChanges() } } @@ -39,7 +39,9 @@ struct TranscriptView: View case .attachmentDownloaded(let attachmentId): model.attachmentDownloaded(id: attachmentId) case .messagesUpdated(let conversationId): - if let displayedConversation = model.displayedConversation, conversationId == displayedConversation.id { + if let displayedConversation = model.displayedConversation, + conversationId == displayedConversation.id + { model.setNeedsReload(animated: true) } case .updateStreamReconnected: @@ -158,9 +160,15 @@ struct TranscriptView: View do { let clientMessages = try await client.getMessages(conversationId: displayedConversation.id) .map { Display.Message(from: $0) } - + + let newIds = Set(clientMessages.map(\.id)) + .subtracting(self.messages.map(\.id)) + + // Only animate for incoming messages. + let shouldAnimate = (newIds.count == 1) + self.messages = clientMessages - self.rebuildDisplayItems(animated: animated) + self.rebuildDisplayItems(animated: animated && shouldAnimate) } catch { print("Message fetch error: \(error)") }