Skip to content

Comments

Message Drafts#39

Merged
viktorstrate merged 5 commits intoviktorstrate:mainfrom
sloatescoan:31-save-message-draft
Feb 19, 2026
Merged

Message Drafts#39
viktorstrate merged 5 commits intoviktorstrate:mainfrom
sloatescoan:31-save-message-draft

Conversation

@scoates
Copy link
Contributor

@scoates scoates commented Feb 16, 2026

Saves and loads a draft of unsent room (and thread) messages.

Had to do a bit of restructuring in LiveTimeline to capture the focused thread ID (if there's a better way to get this, I'm game, but it wasn't obvious if it's possible).

(Also removed a stray old print.)

Replies are attached and restored. This was the most difficult part.

Thanks for pointing out the Matrix SDK facility for this. It's perfect and helped guide the implementation.

Closes #31.

@scoates
Copy link
Contributor Author

scoates commented Feb 16, 2026

Forgot to mention: I don't love the delay to wait for the inner Timeline to become available. Definitely open to other ideas here.

Thanks to @nicksloan for the idea of watching timeline.timeline for a change. No more sleep.

Copy link
Owner

@viktorstrate viktorstrate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much @scoates for all your work. I've added some comments on the use of async, if you have any ideas or comments don't hesitate to say so.

@Binding var height: CGFloat?
@AppStorage("fontSize") var fontSize: Int = 13

@State private var isLoaded: Bool = false
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename this to isDraftLoaded I was very confused reading this to begin with, because I though it was the talking about the timeline 😅


private func saveDraft() {
if chatInput.isEmpty {
clearDraft()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make clearDraft, saveDraft, and chatInputChanged async functions, and move the Task invocations to the call site of these functions?

Comment on lines 158 to 165
.onChange(of: chatInput) {
chatInputChanged()
}
.onChange(of: replyTo != nil) {
chatInputChanged()
}
.onChange(of: timeline.timeline != nil) { _, timelinePopulated in
Task {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If chatInputChanged became an async function (as mentioned above), it might make sense to use the .task(id:) view modifier instead of onChange(of:) to get cancellation if the value is changed before the async function finishes.

I suppose right now we can end up spawning multiple instances of loadDraft that run concurrently which could make the UI end up showing a wrong draft.

@scoates
Copy link
Contributor Author

scoates commented Feb 17, 2026

Good feedback. Thanks!

I'll make some changes (and look into the .task change, or at least explain better).
FWIW, the reason I used the weird non-async + Task method is that I was following what you have in sendMessage. I'll rework that a little, too, to match.

@viktorstrate
Copy link
Owner

Perfect thank you. Yes I know some of my code is also not perfect but I think it's a good idea to slowly improve it throughout the project, now where the general architecture is a little more settled.

@scoates
Copy link
Contributor Author

scoates commented Feb 17, 2026

(To be clear: I wasn't complaining about your code, and no one expects perfection (-: Just wanted to explain the reason I chose to do it that way, and I appreciate the call-out + permission to do it better.)

@scoates scoates force-pushed the 31-save-message-draft branch from a60aa96 to bf9f366 Compare February 19, 2026 02:53
@scoates
Copy link
Contributor Author

scoates commented Feb 19, 2026

I made the requested changes and rebased onto main to pull in the recent changes.

It's much cleaner now, I think. Good call on the .task(id:) pattern; I hadn't used that before.

@scoates scoates requested a review from viktorstrate February 19, 2026 03:03
@viktorstrate
Copy link
Owner

Looks great now, thank you!

@viktorstrate viktorstrate merged commit f670f12 into viktorstrate:main Feb 19, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Message room" input loses content when switching rooms

2 participants