Skip to content

[SM#5] Schedule a failed scheduled message again as a new message - #4431

Merged
laevandus merged 11 commits into
developfrom
add/scheduled-messages-5-reschedule-failed
Nov 25, 2026
Merged

laevandus merged 11 commits into
developfrom
add/scheduled-messages-5-reschedule-failed

Conversation

@laevandus

@laevandus laevandus commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

🔗 Issue Links

Related: IOS-2255

🎯 Goal

Let users reschedule a scheduled message the server failed to send, and let the scheduled message calls wait for the server.

📝 Summary

  • Rescheduling a message the server failed to send schedules a copy with a new id and deletes the failed one. The completion returns the copy
  • updateScheduledMessage, updateScheduledReply and Chat.updateScheduledMessage do the same when given a new scheduledAt, with the new content. Without a date they fail
  • A message that failed because its channel was deleted can't be scheduled again
  • The copy keeps the thread, the quote, "Also send in channel", the mentions, every attachment, skipPush, and the channel name and members
  • An edit or send now that the server refuses because it failed the message meanwhile turns it into a failed message, so it can be rescheduled with the edit
  • Schedule, update, reschedule, resend and send now complete when the server answers, like Chat.sendMessage. Before, they completed after the local save
  • Without a connection, they fail right away with ClientError.ConnectionError. The changes stay pending and go out once connected
  • Send now on a message whose changes failed sends the changes again first
  • A message the server already sent or no longer has fails with ClientError.ScheduledMessageAlreadySent or ClientError.ScheduledMessageDoesNotExist, and is removed locally

🛠 Implementation

The server refuses to edit, reschedule or send now a failed message (scheduled_message_not_editable) and only allows deleting it. The copy is created and the failed message deleted locally in one write, then the failed message is deleted on the server. When that DELETE fails, for example offline, the call still succeeds and the failed message comes back on the next full list load. A message loaded from the server has skipPush off, because the scheduled message response has no skip_push.

The MessageScheduler keeps the waiters of these calls, like the MessageSender does for Chat.sendMessage.

🎨 Showcase

Before After
img img

🧪 Manual Testing Notes

None. The SwiftUI scheduled messages list and composer use these calls, and unit tests cover them.

☑️ Contributor Checklist

  • I have signed the Stream CLA (required)
  • This change should be manually QAed
  • Changelog is updated with client-facing changes
  • Changelog is updated with new localization keys
  • New code is covered by unit tests
  • Documentation has been updated in the docs-content repo

@laevandus
laevandus added this pull request to stack #4428 November 19, 2026 13:33
@laevandus laevandus changed the title add/scheduled messages 5 reschedule failed [SM#5] Schedule a failed scheduled message again as a new message Nov 19, 2026
@coderabbitai

coderabbitai Bot commented Nov 19, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@laevandus
laevandus force-pushed the add/scheduled-messages-5-reschedule-failed branch from 580f8cf to 880c4c7 Compare November 19, 2026 13:39
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
1 Warning
⚠️ Big PR

Generated by 🚫 Danger

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@laevandus laevandus changed the title [SM#5] Schedule a failed scheduled message again as a new message [skip-ci] [SM#5] Schedule a failed scheduled message again as a new message Nov 20, 2026
@laevandus
laevandus force-pushed the add/scheduled-messages-5-reschedule-failed branch from 880c4c7 to 7955d79 Compare November 20, 2026 08:51
@laevandus
laevandus force-pushed the add/scheduled-messages-5-reschedule-failed branch from 7955d79 to 0d61a03 Compare November 20, 2026 13:28
@laevandus
laevandus removed this pull request from stack #4428 November 20, 2026 13:29
@laevandus
laevandus added this pull request to stack #4434 November 20, 2026 13:29
@laevandus laevandus changed the title [skip-ci] [SM#5] Schedule a failed scheduled message again as a new message [SM#5] Schedule a failed scheduled message again as a new message Nov 20, 2026
@laevandus
laevandus force-pushed the add/scheduled-messages-5-reschedule-failed branch from 0d61a03 to 497245c Compare November 20, 2026 13:44
@laevandus
laevandus force-pushed the add/scheduled-messages-5-reschedule-failed branch from 67e77d1 to d72e654 Compare November 24, 2026 07:38
@laevandus
laevandus force-pushed the add/scheduled-messages-5-reschedule-failed branch from 3558629 to b91fe81 Compare November 24, 2026 09:44
@laevandus
laevandus force-pushed the add/scheduled-messages-5-reschedule-failed branch from 0e48f62 to d5e14ca Compare November 24, 2026 12:15
@laevandus
laevandus force-pushed the add/scheduled-messages-5-reschedule-failed branch from d5e14ca to 645d83d Compare November 24, 2026 15:15
@laevandus
laevandus force-pushed the add/scheduled-messages-5-reschedule-failed branch from 645d83d to b420b55 Compare November 25, 2026 09:19
@laevandus
laevandus force-pushed the add/scheduled-messages-5-reschedule-failed branch from b420b55 to 8825750 Compare November 25, 2026 09:26
@laevandus
laevandus force-pushed the add/scheduled-messages-5-reschedule-failed branch from c263202 to fbb7b51 Compare November 25, 2026 12:21
@laevandus laevandus changed the title [skip-ci] [SM#5] Schedule a failed scheduled message again as a new message [SM#5] Schedule a failed scheduled message again as a new message Nov 25, 2026
@laevandus
laevandus force-pushed the add/scheduled-messages-5-reschedule-failed branch from fbb7b51 to dfbde58 Compare November 25, 2026 12:49
@laevandus
laevandus marked this pull request as ready for review November 25, 2026 12:52
@laevandus
laevandus requested a review from a team as a code owner November 25, 2026 12:52
@laevandus
laevandus force-pushed the add/scheduled-messages-5-reschedule-failed branch from dfbde58 to b8cf395 Compare November 25, 2026 13:07
@stream-ios-release-bot

Copy link
Copy Markdown

StreamChat XCSize

Object Diff (bytes)
ScheduledMessageDTO.o +18681
CDNStorage.o +12840
ChatClient.o -9926
MessageSender.o +9428
ChannelController.o +7807
Show 37 more objects
Object Diff (bytes)
ScheduledMessagesRepository.o +7124
MessageScheduler.o +7035
ChannelUpdater.o +3753
Error+InternetNotAvailable.o +1606
Sequence+CompactMapLoggingError.o +1576
GroupedChannelListLinker.o +1396
ScheduledMessageList.o +964
ScheduledMessagesUsage.o +800
MessageController.o +788
ScheduledMessageListController.o +780
ChannelListPayload.o +570
ScheduledMessageChannelResponse.o +515
AnyAttachmentPayload.o +406
ScheduledMessageChannel.o +312
ScheduledMessageContentResponse.o +290
AttachmentQueueUploader.o +272
LivestreamChat.o -216
AppSettings+Extensions.o -188
Channel.o +172
ChannelListUpdater.o -164
CurrentUserUpdater.o -158
AttachmentDownloader.o +136
ReadStateHandler.o -112
UnreadCount.o -108
ScheduledMessageEvents.o +100
UserUpdater.o +96
Chat.o +95
UserGroupsRepository.o -90
ChannelSearch.o +68
MessageDTO.o -67
ActiveLiveLocationsEndTimeTracker.o +62
UserList.o -60
ChannelController+Combine.o -54
ChannelMemberUpdater.o -52
ThreadStateResponse.o -48
SyncOperations.o -48
LivestreamChannelController.o -44

@stream-ios-release-bot

Copy link
Copy Markdown

StreamChatCommonUI XCSize

Object Diff (bytes)
ScheduledMessageDateFormatter.o +8130
L10n.o +5677
Appearance+Images.o +4543
ScheduledMessageFailureFormatter.o +4343
Appearance+ColorPalette.o +1489
MarkdownFormatter.o -1033
AudioPlaybackRateFormatter.o +501
StreamChat.tbd +280
StreamMediaLoader.o -270
Foundation.tbd +108

@laevandus
laevandus force-pushed the add/scheduled-messages-5-reschedule-failed branch from b8cf395 to 9a7bf57 Compare November 25, 2026 13:34
@github-actions

Copy link
Copy Markdown

Public Interface

+ public final class ScheduledMessageHasACommand: ClientError, @unchecked Sendable

+ public final class ScheduledMessageDoesNotExist: ClientError, @unchecked Sendable

+ public final class ScheduledMessageAlreadySent: ClientError, @unchecked Sendable

+ public final class ScheduledMessageIsTooFarAhead: ClientError, @unchecked Sendable

+ public final class ScheduledMessageIsBeingSent: ClientError, @unchecked Sendable

+ public final class ScheduledMessageQuotesADeletedMessage: ClientError, @unchecked Sendable

+ public final class ScheduledMessagesUserLimitReached: ClientError, @unchecked Sendable

+ public final class ScheduledMessagesChannelLimitReached: ClientError, @unchecked Sendable

+ public final class ConnectionError: ClientError, @unchecked Sendable

+ public struct ScheduledMessagesUsage: Equatable, Sendable  
+ 
+   public let channelCount: Int
+   public let channelLimit: Int?
+   public let userCount: Int
+   public let userLimit: Int?

+ public final class ScheduledMessageIsTooSoon: ClientError, @unchecked Sendable



 public final class ScheduledMessageSentEvent: Event  
-   public var cid: ChannelId
+   public let isSentNow: Bool
-   public let createdAt: Date
+   public var cid: ChannelId
+   public let createdAt: Date

 public class ChatMessageController: DataController, DelegateCallable, DataStoreProvider, @unchecked Sendable  
-   public func scheduleReply(messageId: MessageId? = nil,text: String,attachments: [AnyAttachmentPayload] = [],mentionedUserIds: [UserId] = [],showReplyInChannel: Bool = false,quotedMessageId: MessageId? = nil,scheduledAt: Date,extraData: [String: RawJSON] = [:],completion: (@MainActor (Result<ScheduledMessage, Error>) -> Void)? = nil)
+   public func scheduleReply(messageId: MessageId? = nil,text: String,attachments: [AnyAttachmentPayload] = [],mentionedUserIds: [UserId] = [],mentionedHere: Bool = false,mentionedChannel: Bool = false,mentionedGroupIds: [String] = [],mentionedRoles: [String] = [],showReplyInChannel: Bool = false,silent: Bool = false,quotedMessageId: MessageId? = nil,skipPush: Bool = false,scheduledAt: Date,extraData: [String: RawJSON] = [:],completion: (@MainActor (Result<ScheduledMessage, Error>) -> Void)? = nil)
-   public func updateScheduledReply(id: String,text: String,attachments: [AnyAttachmentPayload] = [],mentionedUserIds: [UserId] = [],showReplyInChannel: Bool = false,quotedMessageId: MessageId? = nil,scheduledAt: Date? = nil,extraData: [String: RawJSON] = [:],completion: (@MainActor (Result<ScheduledMessage, Error>) -> Void)? = nil)
+   public func updateScheduledReply(id: String,text: String,attachments: [AnyAttachmentPayload] = [],mentionedUserIds: [UserId] = [],mentionedHere: Bool = false,mentionedChannel: Bool = false,mentionedGroupIds: [String] = [],mentionedRoles: [String] = [],showReplyInChannel: Bool = false,silent: Bool = false,quotedMessageId: MessageId? = nil,scheduledAt: Date? = nil,extraData: [String: RawJSON] = [:],completion: (@MainActor (Result<ScheduledMessage, Error>) -> Void)? = nil)

 public class ChatChannelController: DataController, DelegateCallable, DataStoreProvider, @unchecked Sendable  
-   public func scheduleMessage(messageId: MessageId? = nil,text: String,attachments: [AnyAttachmentPayload] = [],mentionedUserIds: [UserId] = [],quotedMessageId: MessageId? = nil,scheduledAt: Date,extraData: [String: RawJSON] = [:],completion: (@MainActor (Result<ScheduledMessage, Error>) -> Void)? = nil)
+   public func scheduledMessagesUsage(completion: @escaping @MainActor (Result<ScheduledMessagesUsage, Error>) -> Void)
-   public func updateScheduledMessage(id: String,text: String,attachments: [AnyAttachmentPayload] = [],mentionedUserIds: [UserId] = [],quotedMessageId: MessageId? = nil,scheduledAt: Date? = nil,extraData: [String: RawJSON] = [:],completion: (@MainActor (Result<ScheduledMessage, Error>) -> Void)? = nil)
+   public func validateForScheduling(text: String? = nil,quotedMessageId: MessageId? = nil,scheduledAt: Date? = nil,editing scheduledMessageId: String? = nil,completion: @escaping @MainActor (Error?) -> Void)
-   public func rescheduleMessage(id: String,scheduledAt: Date,completion: (@MainActor (Result<ScheduledMessage, Error>) -> Void)? = nil)
+   public func scheduleMessage(messageId: MessageId? = nil,text: String,silent: Bool = false,attachments: [AnyAttachmentPayload] = [],mentionedUserIds: [UserId] = [],mentionedHere: Bool = false,mentionedChannel: Bool = false,mentionedGroupIds: [String] = [],mentionedRoles: [String] = [],quotedMessageId: MessageId? = nil,skipPush: Bool = false,scheduledAt: Date,extraData: [String: RawJSON] = [:],completion: (@MainActor (Result<ScheduledMessage, Error>) -> Void)? = nil)
-   public func deleteScheduledMessage(id: String,completion: (@MainActor (Error?) -> Void)? = nil)
+   public func updateScheduledMessage(id: String,text: String,silent: Bool = false,attachments: [AnyAttachmentPayload] = [],mentionedUserIds: [UserId] = [],mentionedHere: Bool = false,mentionedChannel: Bool = false,mentionedGroupIds: [String] = [],mentionedRoles: [String] = [],quotedMessageId: MessageId? = nil,scheduledAt: Date? = nil,extraData: [String: RawJSON] = [:],completion: (@MainActor (Result<ScheduledMessage, Error>) -> Void)? = nil)
-   public func sendScheduledMessageNow(id: String,completion: (@MainActor (Error?) -> Void)? = nil)
+   public func rescheduleMessage(id: String,scheduledAt: Date,completion: (@MainActor (Result<ScheduledMessage, Error>) -> Void)? = nil)
+   public func deleteScheduledMessage(id: String,completion: (@MainActor (Error?) -> Void)? = nil)
+   public func sendScheduledMessageNow(id: String,completion: (@MainActor (Error?) -> Void)? = nil)

 public class Chat: @unchecked Sendable  
-   @discardableResult public func scheduleMessage(with text: String,attachments: [AnyAttachmentPayload] = [],quote quotedMessageId: MessageId? = nil,mentions: [UserId] = [],messageId: MessageId? = nil,scheduledAt: Date,extraData: [String: RawJSON] = [:])async throws -> ScheduledMessage
+   public func scheduledMessagesUsage()async throws -> ScheduledMessagesUsage
-   @discardableResult public func scheduleReply(to parentMessageId: MessageId,text: String,showReplyInChannel: Bool = false,attachments: [AnyAttachmentPayload] = [],quote quotedMessageId: MessageId? = nil,mentions: [UserId] = [],messageId: MessageId? = nil,scheduledAt: Date,extraData: [String: RawJSON] = [:])async throws -> ScheduledMessage
+   public func validateForScheduling(text: String? = nil,quote quotedMessageId: MessageId? = nil,scheduledAt: Date? = nil,editing scheduledMessageId: String? = nil)async throws 
-   @discardableResult public func updateScheduledMessage(id: String,text: String,attachments: [AnyAttachmentPayload] = [],quote quotedMessageId: MessageId? = nil,mentions: [UserId] = [],scheduledAt: Date? = nil,extraData: [String: RawJSON] = [:])async throws -> ScheduledMessage
+   @discardableResult public func scheduleMessage(with text: String,attachments: [AnyAttachmentPayload] = [],quote quotedMessageId: MessageId? = nil,mentions: [UserId] = [],mentionedHere: Bool = false,mentionedChannel: Bool = false,mentionedGroupIds: [String] = [],mentionedRoles: [String] = [],messageId: MessageId? = nil,scheduledAt: Date,extraData: [String: RawJSON] = [:],silent: Bool = false,skipPushNotification: Bool = false)async throws -> ScheduledMessage
-   @discardableResult public func rescheduleMessage(id: String,scheduledAt: Date)async throws -> ScheduledMessage
+   @discardableResult public func scheduleReply(to parentMessageId: MessageId,text: String,showReplyInChannel: Bool = false,attachments: [AnyAttachmentPayload] = [],quote quotedMessageId: MessageId? = nil,mentions: [UserId] = [],mentionedHere: Bool = false,mentionedChannel: Bool = false,mentionedGroupIds: [String] = [],mentionedRoles: [String] = [],messageId: MessageId? = nil,scheduledAt: Date,extraData: [String: RawJSON] = [:],silent: Bool = false,skipPushNotification: Bool = false)async throws -> ScheduledMessage
-   public func deleteScheduledMessage(id: String)async throws 
+   @discardableResult public func updateScheduledMessage(id: String,text: String,attachments: [AnyAttachmentPayload] = [],quote quotedMessageId: MessageId? = nil,mentions: [UserId] = [],mentionedHere: Bool = false,mentionedChannel: Bool = false,mentionedGroupIds: [String] = [],mentionedRoles: [String] = [],scheduledAt: Date? = nil,extraData: [String: RawJSON] = [:],silent: Bool = false)async throws -> ScheduledMessage
-   public func sendScheduledMessageNow(id: String)async throws 
+   @discardableResult public func rescheduleMessage(id: String,scheduledAt: Date)async throws -> ScheduledMessage
-   public func subscribe(toEvent event: E.Type,handler: @escaping @Sendable (E) -> Void)-> AnyCancellable
+   public func deleteScheduledMessage(id: String)async throws 
-   public func subscribe(_ handler: @escaping @Sendable (Event) -> Void)-> AnyCancellable
+   public func sendScheduledMessageNow(id: String)async throws 
-   public func sendEvent(_ payload: EventPayload)async throws 
+   public func subscribe(toEvent event: E.Type,handler: @escaping @Sendable (E) -> Void)-> AnyCancellable
-   public func enableSlowMode(cooldownDuration: Int)async throws 
+   public func subscribe(_ handler: @escaping @Sendable (Event) -> Void)-> AnyCancellable
-   public func disableSlowMode()async throws 
+   public func sendEvent(_ payload: EventPayload)async throws 
-   public func truncate(systemMessage: String? = nil,hardDelete: Bool = true,skipPush: Bool = false)async throws 
+   public func enableSlowMode(cooldownDuration: Int)async throws 
-   public func truncate(systemMessage: SystemMessage?,hardDelete: Bool = true,skipPush: Bool = false)async throws 
+   public func disableSlowMode()async throws 
-   public func keystroke(parentMessageId: MessageId? = nil)async throws 
+   public func truncate(systemMessage: String? = nil,hardDelete: Bool = true,skipPush: Bool = false)async throws 
-   public func stopTyping(parentMessageId: MessageId? = nil)async throws 
+   public func truncate(systemMessage: SystemMessage?,hardDelete: Bool = true,skipPush: Bool = false)async throws 
-   public func update(name: String?,imageURL: URL?,team: String? = nil,members: Set<UserId> = [],invites: Set<UserId> = [],filterTags: Set<String> = [],autoTranslationLanguages: Set<TranslationLanguage>? = nil,extraData: [String: RawJSON] = [:])async throws 
+   public func keystroke(parentMessageId: MessageId? = nil)async throws 
-   public func updatePartial(name: String? = nil,imageURL: URL? = nil,team: String? = nil,members: [UserId] = [],invites: [UserId] = [],filterTags: Set<String> = [],extraData: [String: RawJSON] = [:],unsetProperties: [String] = [])async throws 
+   public func stopTyping(parentMessageId: MessageId? = nil)async throws 
-   public func deleteFile(at url: URL)async throws 
+   public func update(name: String?,imageURL: URL?,team: String? = nil,members: Set<UserId> = [],invites: Set<UserId> = [],filterTags: Set<String> = [],autoTranslationLanguages: Set<TranslationLanguage>? = nil,extraData: [String: RawJSON] = [:])async throws 
-   public func deleteImage(at url: URL)async throws 
+   public func updatePartial(name: String? = nil,imageURL: URL? = nil,team: String? = nil,members: [UserId] = [],invites: [UserId] = [],filterTags: Set<String> = [],extraData: [String: RawJSON] = [:],unsetProperties: [String] = [])async throws 
-   public func uploadAttachment(with localFileURL: URL,type: AttachmentType,progress: (@Sendable (Double) -> Void)? = nil)async throws -> UploadedAttachment
+   public func deleteFile(at url: URL)async throws 
-   @discardableResult public func loadWatchers(with pagination: Pagination)async throws -> [ChatUser]
+   public func deleteImage(at url: URL)async throws 
-   @discardableResult public func loadMoreWatchers(limit: Int? = nil)async throws -> [ChatUser]
+   public func uploadAttachment(with localFileURL: URL,type: AttachmentType,progress: (@Sendable (Double) -> Void)? = nil)async throws -> UploadedAttachment
+   @discardableResult public func loadWatchers(with pagination: Pagination)async throws -> [ChatUser]
+   @discardableResult public func loadMoreWatchers(limit: Int? = nil)async throws -> [ChatUser]

 public final class ScheduledMessageChannel: Equatable, Sendable  
-   
+   public let memberCount: Int
- 
+   public let members: [ChatChannelMember]
-   public static func ==(lhs: ScheduledMessageChannel,rhs: ScheduledMessageChannel)-> Bool
+   
+ 
+   public static func ==(lhs: ScheduledMessageChannel,rhs: ScheduledMessageChannel)-> Bool

Base automatically changed from add/scheduled-messages-4-schedule-arguments to develop November 25, 2026 13:42
Schedule, update, reschedule, resend and send now complete when the request of the MessageScheduler finishes, like Chat.sendMessage waits for the MessageSender. A message the server already sent or no longer has fails with ScheduledMessageAlreadySent or ScheduledMessageDoesNotExist.
ChatChannelController and Chat run the checks of saving a scheduled message with no request, so the UI can disable scheduling and show why. The saves call the same validator. Waiters of a lost connection fail with ConnectionError, and the scheduled message limits of the server fail with the typed limit errors.
The scheduled message calls fail with it when the device has no connection and the changes are sent once connected.
validateForScheduling and the saves refuse a date sooner than the min lead time of the app, like the max lead time, so the UI can show it inline.
A scheduled message whose attachment fails to upload without a connection stays pending, so its scheduling calls complete like a request without a connection.
A failed message of a deleted channel is no longer refused on the device, and a server limit error is no longer mapped to the public limit errors. Overlapping tests are folded.
The connection flag can be reset by a reconnect on another thread, so the waiters no longer depend on reading it after the request.
@laevandus
laevandus force-pushed the add/scheduled-messages-5-reschedule-failed branch from 9a7bf57 to cd00abb Compare November 25, 2026 13:43
@laevandus
laevandus merged commit f7af98f into develop Nov 25, 2026
6 checks passed
@laevandus
laevandus deleted the add/scheduled-messages-5-reschedule-failed branch November 25, 2026 13:44
@stream-ios-release-bot

Copy link
Copy Markdown

SDK Size

title develop branch diff status
StreamChat 7.57 MB 7.57 MB 0 KB 🟢
StreamChatUI 3.4 MB 3.4 MB 0 KB 🟢
StreamChatCommonUI 1.07 MB 1.07 MB 0 KB 🟢
StreamChatAI 2.97 MB 2.97 MB 0 KB 🟢
StreamChatA2UI 1.21 MB 1.21 MB 0 KB 🟢
StreamChatOpenUI 2.9 MB 2.9 MB 0 KB 🟢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants