Skip to content

Commit 97bdea0

Browse files
authored
Keep the typed text when sending a sticker or GIF from the panel (#151)
* Keep the typed text when sending a sticker or GIF from the panel sendAppFile finishes with _afterSentTransition(false) so the input is kept, but _afterSentTransition reset the input state unconditionally right after the flushInput check, so every sticker or GIF sent from the panel erased the draft. Remove the unconditional reset. Every other send path passes true and still clears the field, and sticker suggestions clear the input themselves. iOS keeps the typed text in the same case. * Keep the link preview and effect with the text kept after a sticker When a sticker or GIF is sent without flushing the input, keep the dismissed link preview, the current preview and the chosen message effect that belong to the kept text, and reset them only when the input is flushed. * Reset the compose state with the text when the input ends up empty Sticker suggestions and the media preview clear the input themselves before the send completes, so keeping the link preview and the effect whenever the input was not flushed left them applied to the next message. Keep them, and the suggested post too, only when the input still has text after the send. * Keep suggestions with the kept text and reset while editing When the input text is kept after a sticker or GIF, keep the mention, command or sticker suggestion list for it too. While a message is being edited, reset the compose state as before, since the kept-text check would otherwise look at the hidden draft instead of the edit. * Run the pending after-send handler before a sticker send sets its own A sticker or GIF sent from the panel before the history update of a just-sent text message replaced that message's handler, so the sent text stayed in the field. The pending handler now runs first and clears it. * Reset the effect with a sticker send and keep its reply The message effect and suggested post were kept with the text after a sticker or GIF send; they are now reset, as on iOS. The pending after-send step of an earlier send runs before the forwards are checked, so a stale forward flag no longer sends an empty composer, while the sticker still takes the reply. A scheduled sticker runs its step right away, as sendMessage does.
1 parent 6be9999 commit 97bdea0

1 file changed

Lines changed: 18 additions & 11 deletions

File tree

‎packages/ChatUI/Sources/ChatUI/ChatController.swift‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4518,19 +4518,19 @@ open class ChatController<Context: AccountContextProtocol>: TelegramGenericViewC
45184518

45194519
let _afterSentTransition:(Bool)->Void = { [weak self] flushInput in
45204520
self?.chatInteraction.update({ presentation in
4521-
return presentation.updatedInputQueryResult {_ in
4522-
return nil
4521+
let keepsInput = !flushInput && presentation.interfaceState.editState == nil && !presentation.interfaceState.inputState.inputText.isEmpty
4522+
return presentation.updatedInputQueryResult { current in
4523+
return keepsInput ? current : nil
45234524
}.updatedInterfaceState { current in
45244525

45254526
var value: ChatInterfaceState = current
4526-
if flushInput {
4527+
if !keepsInput {
45274528
value = value
45284529
.withUpdatedInputState(ChatTextInputState())
4530+
.withUpdatedComposeDisableUrlPreview(nil)
45294531
}
45304532
value = value.withUpdatedReplyMessageId(nil)
4531-
.withUpdatedInputState(ChatTextInputState())
45324533
.withUpdatedForwardMessageIds([])
4533-
.withUpdatedComposeDisableUrlPreview(nil)
45344534
.withUpdatedMessageEffect(nil)
45354535
.withUpdatedSuggestPost(nil)
45364536
.withoutEditMessage()
@@ -4541,7 +4541,7 @@ open class ChatController<Context: AccountContextProtocol>: TelegramGenericViewC
45414541
}
45424542
}
45434543
return value
4544-
}.updatedUrlPreview(nil).updateBotMenu({ current in
4544+
}.updatedUrlPreview(keepsInput ? presentation.urlPreview : nil).updateBotMenu({ current in
45454545
var current = current
45464546
current?.revealed = false
45474547
return current
@@ -6761,26 +6761,33 @@ open class ChatController<Context: AccountContextProtocol>: TelegramGenericViewC
67616761
if peer.canSendMessage(strongSelf.mode.isThreadMode, media: file, threadData: strongSelf.chatInteraction.presentation.threadInfo, cachedData: strongSelf.chatInteraction.presentation.cachedData) {
67626762

67636763
let invoke:()->Void = { [strongSelf] in
6764-
let hasFwd = !strongSelf.chatInteraction.presentation.interfaceState.forwardMessageIds.isEmpty
67656764
func apply(_ controller: ChatController, atDate: Date?, repeatPeriod: Int32?) {
6765+
let replyId = takeReplyId()
6766+
_ = controller.nextTransaction.execute()
6767+
let hasFwd = !controller.chatInteraction.presentation.interfaceState.forwardMessageIds.isEmpty
67666768
let completed: () -> Void = {
67676769
scrollAfterSend()
67686770
}
67696771
if let caption = caption {
6770-
let _ = (Sender.enqueue(media: [file], caption: caption, context: context, peerId: makePeerId(), replyId: takeReplyId(), threadId: threadId64(), silent: silent, atDate: atDate, repeatPeriod: repeatPeriod, query: query, collectionId: collectionId, customChatContents: customChatContents, sendPaidMessageStars: takePaidMessageStars()) |> deliverOnMainQueue).start(completed: completed)
6772+
let _ = (Sender.enqueue(media: [file], caption: caption, context: context, peerId: makePeerId(), replyId: replyId, threadId: threadId64(), silent: silent, atDate: atDate, repeatPeriod: repeatPeriod, query: query, collectionId: collectionId, customChatContents: customChatContents, sendPaidMessageStars: takePaidMessageStars()) |> deliverOnMainQueue).start(completed: completed)
67716773
} else {
6772-
let _ = (Sender.enqueue(media: file, context: context, peerId: makePeerId(), replyId: takeReplyId(), threadId: threadId64(), silent: silent, atDate: atDate, repeatPeriod: repeatPeriod, query: query, collectionId: collectionId, customChatContents: customChatContents, sendPaidMessageStars: takePaidMessageStars()) |> deliverOnMainQueue).start(next: { ids in
6774+
let _ = (Sender.enqueue(media: file, context: context, peerId: makePeerId(), replyId: replyId, threadId: threadId64(), silent: silent, atDate: atDate, repeatPeriod: repeatPeriod, query: query, collectionId: collectionId, customChatContents: customChatContents, sendPaidMessageStars: takePaidMessageStars()) |> deliverOnMainQueue).start(next: { ids in
67736775
}, completed: completed)
67746776
}
6775-
controller.nextTransaction.set(handler: {
6777+
let afterSent: () -> Void = {
67766778
if hasFwd {
67776779
DispatchQueue.main.async {
67786780
self?.chatInteraction.sendMessage(false, nil, self?.chatInteraction.presentation.messageEffect)
67796781
}
67806782
} else {
67816783
_afterSentTransition(false)
67826784
}
6783-
})
6785+
}
6786+
if atDate != nil {
6787+
afterSent()
6788+
} else {
6789+
controller.nextTransaction.set(handler: afterSent)
6790+
}
67846791
}
67856792

67866793
if let preSchedule = preSchedule {

0 commit comments

Comments
 (0)