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 Draft Messages Support #775

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Add draft previews to channel list item and thread list item
nuno-vieira committed Mar 6, 2025
commit a0154f24edbf552bceffe84a01a709d49fd38cd3
11 changes: 10 additions & 1 deletion DemoAppSwiftUI/PinChannelHelpers.swift
Original file line number Diff line number Diff line change
@@ -85,7 +85,16 @@ struct DemoAppChatChannelListItem: View {
TypingIndicatorView()
}
}
SubtitleText(text: injectedChannelInfo?.subtitle ?? channel.subtitleText)
if let draftText = channel.draftMessageText {
HStack(spacing: 2) {
Text("Draft:")
.font(fonts.caption1).bold()
.foregroundColor(Color(colors.highlightedAccentBackground))
SubtitleText(text: draftText)
}
} else {
SubtitleText(text: injectedChannelInfo?.subtitle ?? channel.subtitleText)
}
Spacer()
}
.accessibilityIdentifier("subtitleView")
Original file line number Diff line number Diff line change
@@ -106,7 +106,16 @@ public struct ChatChannelListItem<Factory: ViewFactory>: View {
TypingIndicatorView()
}
}
SubtitleText(text: injectedChannelInfo?.subtitle ?? channel.subtitleText)
if let draftText = channel.draftMessageText {
HStack {
Text("\(L10n.Message.Preview.draft):")
.font(fonts.caption1).bold()
.foregroundColor(Color(colors.highlightedAccentBackground))
SubtitleText(text: draftText)
}
} else {
SubtitleText(text: injectedChannelInfo?.subtitle ?? channel.subtitleText)
}
Spacer()
}
.accessibilityIdentifier("subtitleView")
@@ -288,7 +297,13 @@ extension ChatChannel {
let messageFormatter = InjectedValues[\.utils].messagePreviewFormatter
return messageFormatter.format(previewMessage)
}


public var draftMessageText: String? {
guard let draftMessage = draftMessage else { return nil }
let messageFormatter = InjectedValues[\.utils].messagePreviewFormatter
return messageFormatter.formatContent(for: ChatMessage(draftMessage))
}

public var lastMessageText: String? {
guard let latestMessage = latestMessages.first else { return nil }
let messageFormatter = InjectedValues[\.utils].messagePreviewFormatter
Original file line number Diff line number Diff line change
@@ -24,7 +24,8 @@ public struct ChatThreadListItem: View {
replyAuthorUrl: viewModel.latestReplyAuthorImageURL,
replyAuthorIsOnline: viewModel.isLatestReplyAuthorOnline,
replyMessageText: viewModel.latestReplyMessageText,
replyTimestampText: viewModel.latestReplyTimestampText
replyTimestampText: viewModel.latestReplyTimestampText,
draftText: viewModel.draftReplyText
)
}
}
@@ -77,6 +78,13 @@ public struct ChatThreadListItemViewModel {
)
}

/// The formatted draft reply text.
public var draftReplyText: String? {
guard let draftMessage = thread.parentMessage.draftReply else { return nil }
let messageFormatter = InjectedValues[\.utils].messagePreviewFormatter
return messageFormatter.formatContent(for: ChatMessage(draftMessage))
}

/// The number of unread replies.
public var unreadRepliesCount: Int {
let currentUserRead = thread.reads.first(
@@ -126,6 +134,7 @@ struct ChatThreadListItemContentView: View {
var replyAuthorIsOnline: Bool
var replyMessageText: String
var replyTimestampText: String
var draftText: String?

var body: some View {
VStack(alignment: .leading, spacing: 8) {
@@ -175,11 +184,24 @@ struct ChatThreadListItemContentView: View {
.foregroundColor(Color(colors.text))
.font(fonts.subheadlineBold)
HStack {
SubtitleText(text: replyMessageText)
if let draftText {
HStack {
draftPrefixView
SubtitleText(text: draftText)
}
} else {
SubtitleText(text: replyMessageText)
}
Spacer()
SubtitleText(text: replyTimestampText)
}
}
}
}

var draftPrefixView: some View {
Text("\(L10n.Message.Preview.draft):")
.font(fonts.caption1).bold()
.foregroundColor(Color(colors.highlightedAccentBackground))
}
}
4 changes: 4 additions & 0 deletions Sources/StreamChatSwiftUI/Generated/L10n.swift
Original file line number Diff line number Diff line change
@@ -502,6 +502,10 @@ internal enum L10n {
internal static var resultsTitle: String { L10n.tr("Localizable", "message.polls.toolbar.results-title") }
}
}
internal enum Preview {
/// Draft
internal static var draft: String { L10n.tr("Localizable", "message.preview.draft") }
}
internal enum Reactions {
/// You
internal static var currentUser: String { L10n.tr("Localizable", "message.reactions.currentUser") }
Original file line number Diff line number Diff line change
@@ -176,6 +176,8 @@

"message.bounce.title" = "Message was bounced";

"message.preview.draft" = "Draft";

"current-selection" = "%d of %d";

"attachment.max-size-exceeded" = "Attachment size exceed the limit.";