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

Account for unread messages for jtb button visibility #142

Conversation

smarizvi110
Copy link
Contributor

This should fix #131. This needs some more testing though I think and is a WIP. Also, I noticed that there was some redundancy in code regarding updating the button's visibility, in that since it isn't encased as a separate function, it's not quite clean code. I can clean this up though, just wasn't sure if I should considering how it was already written. Also, the new UI for Robrix is great but I realized the button should probably be moved a little more to the left as it's too close to the window border on the right. I haven't done that yet but can if it seems okay to do. And finally, would it not be a better idea to set it's colour hex code as some sort of constant rather than using it as a literal?

src/home/room_screen.rs Outdated Show resolved Hide resolved
src/home/room_screen.rs Outdated Show resolved Hide resolved
TimelineUpdate::NewItems {items, ..} => {
let portal_list = self.portal_list(id!(timeline.list));
if !portal_list.is_at_end() {
self.unread_message_count += items.len();
Copy link
Member

Choose a reason for hiding this comment

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

this logic doesn't quite seem correct; unfortunately, Matrix makes it quite difficult to correctly determine how many messages are unread.

I think you would want to determine the number of new items that were added beyond the last-known read marker of the current user. Doing this requires tracking the read marker (See #86), which we haven't yet finished.

So for now, you can just show a visual indicator of new messages existing at all, rather than attempting to count how many are considered "unread".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, sounds good!

Copy link
Contributor

@alanpoon alanpoon Oct 7, 2024

Choose a reason for hiding this comment

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

notification_count @kevinaboos @smarizvi110 @ZhangHanDong, The "unread" number got nothing to do with #86, it is based on backend data: unread_notifications' [unreadNotificationsCount](https://matrix-org.github.io/matrix-rust-sdk/matrix_sdk/sync/struct.UnreadNotificationsCount.html)

Without #86, unread notification count should be always increasing and not be able to reset to 0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me look into this.

@kevinaboos
Copy link
Member

Thanks, I wasn't sure if you were ready for me to review this but I left a few comments anyway.

Regarding clean encapsulation of the JTB button handling code, yes, of course you can move it into a separate function -- no problem there.

@smarizvi110
Copy link
Contributor Author

smarizvi110 commented Sep 15, 2024

Thanks, I wasn't sure if you were ready for me to review this but I left a few comments anyway.

Regarding clean encapsulation of the JTB button handling code, yes, of course you can move it into a separate function -- no problem there.

Whew, thank you for the review actually! I'll try to figure this thing out. Apologies for the delays, just a bit difficult to work on this amongst other things 😅Also on #86, I'll take a look there too. If that could be resolved, then this would be much easier

@smarizvi110
Copy link
Contributor Author

So a few things
The logic I'm thinking of running with is that whenever there's a new message and the user isn't at the bottom, an indicator should be shown. When jtb is pressed, the indicator should not be shown. As suggested, the bool governing this is in TimelineUiState.
Now this should also be the case when the user manually scrolls to the bottom. I just first want to confirm if I'm missing something or not considering what we can work with right now.
Secondly, I had a weird error that I'm not sure about the origins of. This wasn't an issue on the main branch. Specifically
https://github.com/smarizvi110/robrix/blob/jtb-visibility-on-timeline-update/src/home/room_screen.rs#L2683
throws this error at me, even though I don't think it should?

error[E0308]: mismatched types
    --> src\home\room_screen.rs:2683:13
     |
2683 |         let Some(mut inner) = self.borrow_mut() else {
     |             ^^^^^^^^^^^^^^^   ----------------- this expression has type `&mut MessageRef`
     |             |
     |             expected `MessageRef`, found `Option<_>`
     |
     = note: expected struct `MessageRef`
                  found enum `std::option::Option<_>`

@kevinaboos
Copy link
Member

Whew, thank you for the review actually! I'll try to figure this thing out. Apologies for the delays, just a bit difficult to work on this amongst other things

Of course, and no rush at all! Anything you're willing to contribute is more than welcome!

Also on #86, I'll take a look there too. If that could be resolved, then this would be much easier

Agreed. FYI, another contributor has already "claimed" that issue and is working on it currently.

@kevinaboos
Copy link
Member

The logic I'm thinking of running with is that whenever there's a new message and the user isn't at the bottom, an indicator should be shown. When jtb is pressed, the indicator should not be shown. As suggested, the bool governing this is in TimelineUiState.
Now this should also be the case when the user manually scrolls to the bottom. I just first want to confirm if I'm missing something or not considering what we can work with right now.

Yep! That's all perfectly accurate.

Secondly, I had a weird error that I'm not sure about the origins of. This wasn't an issue on the main branch. Specifically
https://github.com/smarizvi110/robrix/blob/jtb-visibility-on-timeline-update/src/home/room_screen.rs#L2683
throws this error at me, even though I don't think it should?

Yeah that's not right, that shouldn't cause an error. Not sure what's going on, perhaps there's another error elsewhere that's causing that false error. Are you still getting that error? If so, I can try to run your branch to attempt to reproduce it.

@smarizvi110
Copy link
Contributor Author

smarizvi110 commented Sep 25, 2024

Yep! That's all perfectly accurate.

Great then! I spent some time trying to refine the implementation of the logic but honestly what my branch currently has on github is as good as I could make it for now

Yeah that's not right, that shouldn't cause an error. Not sure what's going on, perhaps there's another error elsewhere that's causing that false error. Are you still getting that error? If so, I can try to run your branch to attempt to reproduce it.

Thank you I'd really appreciate that!

Apologies for the delays too once more. I was actually trying to clean up the logic I have currently as stated above while taking a look at #86 so that once it is fixed, the logic could be adjusted to allow for a count of unread messages too with ease but couldn't make much progress there. And yes, the error I mentioned prior with MessageRef I couldn't understand either. I was going through Rust docs and still couldn't understand 😅

@smarizvi110 smarizvi110 changed the title Account for unread messages for jtb button visibility and display their number Account for unread messages for jtb button visibility Sep 29, 2024
@kevinaboos
Copy link
Member

sorry, so should I go ahead and review/merge this in, or am I waiting for more changes from you or from a different PR first?

@smarizvi110
Copy link
Contributor Author

smarizvi110 commented Oct 1, 2024

sorry, so should I go ahead and review/merge this in, or am I waiting for more changes from you or from a different PR first?

I think this should be okay, as long as you think it works fine! As for the other PR, I think the code can be adjusted later on when that issue is solved for explicitly showing the number of messages that are unread! For now, I think this should show the presence of unread messages in general.

@smarizvi110
Copy link
Contributor Author

Okay #86 is apparently done, and an adjustment on it is ready to be approved by the author of the same PR. As soon as that's done, this here can be adjusted too to account for individual number of messages that are still unread

@alanpoon
Copy link
Contributor

alanpoon commented Oct 7, 2024

Hi @smarizvi110 , Could you merge main into your branch and resolve merge conflicts?

@smarizvi110
Copy link
Contributor Author

smarizvi110 commented Oct 7, 2024

Hi @smarizvi110 , Could you merge main into your branch and resolve merge conflicts?

Hey @alanpoon! Would it not be better for #172 to be merged first? The logic here is most likely going to need to be rewritten to adhere to your improved implementation of detecting when messages are read. Let me know, and I'll merge main if you think otherwise. Thank you!

@alanpoon
Copy link
Contributor

alanpoon commented Oct 7, 2024

Hi @smarizvi110 , Could you merge main into your branch and resolve merge conflicts?

Hey @alanpoon! Would it not be better for #172 to be merged first? The logic here is most likely going to need to be rewritten to adhere to your improved implementation of detecting when messages are read. Let me know, and I'll merge main if you think otherwise. Thank you!

Please merge. It has nothing to do with #172.

@kevinaboos
Copy link
Member

thanks for the review comments everyone! Sorry for the delay, I've been working hard on preparing Robrix for a conference talk in 10 days so I'm behind on reviews.

@kevinaboos
Copy link
Member

@smarizvi110 can you resolve the conflicts? ping me for a review afterwards. thanks!

@smarizvi110
Copy link
Contributor Author

smarizvi110 commented Oct 7, 2024

thanks for the review comments everyone! Sorry for the delay, I've been working hard on preparing Robrix for a conference talk in 10 days so I'm behind on reviews.

That's so cool! I hope it goes well!

@smarizvi110 can you resolve the conflicts? ping me for a review afterwards. thanks!

@kevinaboos right so the conflicts were resolved but I think the logic can be updated to show the number of unread messages based on what the Alan said in the review conversation above. I'm not sure if I properly understand it, so if anyone has anything further to add on that it'd be great

@smarizvi110
Copy link
Contributor Author

@kevinaboos based on the code review conversation above, I tried to work on implementing the logic for jtb visibility and unread badge visibility using the matrix SDK unread notification count, though I have not been able to test it properly primarily due to running into the same error as I mentioned above in the comment. If someone could help with this error and verifying if this is at least looks fine, it would be greatly appreciated

@alanpoon
Copy link
Contributor

alanpoon commented Oct 8, 2024

@kevinaboos based on the code review conversation above, I tried to work on implementing the logic for jtb visibility and unread badge visibility using the matrix SDK unread notification count, though I have not been able to test it properly primarily due to running into the same error as I mentioned above in the comment. If someone could help with this error and verifying if this is at least looks fine, it would be greatly appreciated

I saw this compile error in your branch before merging the main. Now it is no longer there. But there are still several other compilation errors. So far, I have not seen any of your commits that does not have compile error. It might be faster for me to create a new pull request than to resolve your compilation errors.

@alanpoon
Copy link
Contributor

alanpoon commented Oct 8, 2024

So a few things The logic I'm thinking of running with is that whenever there's a new message and the user isn't at the bottom, an indicator should be shown. When jtb is pressed, the indicator should not be shown. As suggested, the bool governing this is in TimelineUiState. Now this should also be the case when the user manually scrolls to the bottom. I just first want to confirm if I'm missing something or not considering what we can work with right now. Secondly, I had a weird error that I'm not sure about the origins of. This wasn't an issue on the main branch. Specifically https://github.com/smarizvi110/robrix/blob/jtb-visibility-on-timeline-update/src/home/room_screen.rs#L2683 throws this error at me, even though I don't think it should?

error[E0308]: mismatched types
    --> src\home\room_screen.rs:2683:13
     |
2683 |         let Some(mut inner) = self.borrow_mut() else {
     |             ^^^^^^^^^^^^^^^   ----------------- this expression has type `&mut MessageRef`
     |             |
     |             expected `MessageRef`, found `Option<_>`
     |
     = note: expected struct `MessageRef`
                  found enum `std::option::Option<_>`

Your MessageRef's set_data is missing "cx: &mut Cx" as second function parameter. MessageRef is tied to procedure macros generated in Message Struct.

impl MessageRef {
    pub fn set_data(&self, cx: &mut Cx, can_be_replied_to: bool, item_id: usize) {
        let Some(mut inner) = self.borrow_mut() else {
            return;
        };
        inner.set_data(can_be_replied_to, item_id);
    }
}

messageRef

Comment on lines +1147 to +1151
tokio::spawn(async move {
if let Err(e) = room_screen.update_unread_notifications().await {
log!("Failed to update unread notifications: {:?}", e);
}
});
Copy link
Contributor

Choose a reason for hiding this comment

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

You should be updating the Client state inside process_timeline_updates function instead of using tokio spawn when processing backend data.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How do you recommend going about that considering update_unread_notifications() is async?

@@ -940,9 +974,11 @@ struct RoomScreen {
#[rust] tl_state: Option<TimelineUiState>,
/// 5 secs timer when scroll ends
#[rust] fully_read_timer: Timer,
/// The Matrix SDK client (optional until initialized).
#[rust] client: Option<Client>,
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't put client here in the RoomScreen Struct

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you recommend letting this remain as global in the file, or do you have a better suggestion? The rationale for putting it here was because it's only used for the room in question that the user is using, and not elsewhere in this file.

Copy link
Contributor

Choose a reason for hiding this comment

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

I have created a new combine PR with the #86 issue here: #206 . Maybe you can see how I did it. You should be using sliding_async.rs for making matrix request

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@alanpoon Thank you so much! I'll take this opportunity to learn more.

}
}

fn handle_jump_to_bottom_visibility(&mut self, cx: &mut Cx, actions: &ActionsBuf) {
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no need to wrap an existing piece of code in a function that is used only once. This unnecessary code change makes it hard for other to review your code change.

@kevinaboos
Copy link
Member

Hi @smarizvi110, apologies for the lengthy delay in my review, was attending a conference and then had some travel, and got sick twice. 😑

I think the scope of this PR has grown far too much. Let's limit it to just one small targeted feature: re-showing the JTB button when new messages occur. That's it. Let's not try to overcomplicate it with calculating the number of unread messages.

If you can reduce it back down to just those changes (should only be like a dozen lines of code or so), then I'm happy to merge.

@smarizvi110
Copy link
Contributor Author

smarizvi110 commented Oct 30, 2024

Hi @smarizvi110, apologies for the lengthy delay in my review, was attending a conference and then had some travel, and got sick twice. 😑

I think the scope of this PR has grown far too much. Let's limit it to just one small targeted feature: re-showing the JTB button when new messages occur. That's it. Let's not try to overcomplicate it with calculating the number of unread messages.

If you can reduce it back down to just those changes (should only be like a dozen lines of code or so), then I'm happy to merge.

No worries at all @kevinaboos! It's so nice to hear from you! I hope your conference went well; I believe you mentioned it prior too. Sorry to hear you fell ill so severely. It really seems like that is inevitable at this time of the year. I hope you managed to recover fully!

As for this PR, I believe #206 does a lot of work regarding #86 which does try to account for the number of unread messages. I took a look at #206 again and noticed it needs a little more work based on your code review there. If you nonetheless think that this PR should go through with some edits, I'll try to do that. I'll have to look into [the Matrix SDK Unread Notifications Count]((https://matrix-org.github.io/matrix-rust-sdk/matrix_sdk/sync/struct.UnreadNotificationsCount.html) again though because I'm afraid I don't quite understand it based on the code reviews conducted by the author of #206, as well as their disapproving comments here and the contents of #206. Could I get some insight from you on this, if possible?

@kevinaboos
Copy link
Member

My previous comment was basically saying that this PR should completely skip trying to deal with the unread message count (which I don't think the other PR has perfectly nailed yet either), and then we can merge it such that your work here doesn't go to waste.

So, the re-summarize, this PR should just do one very simple thing: determine whether we should show the jump to bottom button based on two actions/events:

  1. (already done) the user scrolled up such that the bottom is no longer in the viewport.
  2. A new message was received in the timeline, but the user wouldn't know about it unless they manually scrolled down.

Recall that the entire point of this PR (and of issue #131) was only number 2 above. No need to complicate it with extra things.

If you are confused or don't wish to make the changes, that's fine, I am happy to do so. Just let me know, as I wanted to let you retain credit for your contributions-in-progress here.

@kevinaboos kevinaboos added the waiting-on-author This issue is waiting on the original author for a response label Nov 7, 2024
@kevinaboos
Copy link
Member

In order to sort things out a bit (as this PR and #206 are in a bit of a messy state), I have implemented this directly in #247, which required some fixes to makepad.

If you're interested in the sort of code I was looking for, check out #247.

@smarizvi110 thanks for your contributions here! I credited you with some contributions as a co-author in the merge commit of #247. Thanks!

@kevinaboos kevinaboos closed this Nov 9, 2024
@smarizvi110
Copy link
Contributor Author

In order to sort things out a bit (as this PR and #206 are in a bit of a messy state), I have implemented this directly in #247, which required some fixes to makepad.

If you're interested in the sort of code I was looking for, check out #247.

@smarizvi110 thanks for your contributions here! I credited you with some contributions as a co-author in the merge commit of #247. Thanks!

Thank you @kevinaboos! Yes I'd love to go over the changes you made to learn more about the codebase. Really sorry for being unresponsive, just swamped with coursework and graduate apps these days 😅

@kevinaboos
Copy link
Member

No problem at all, don't worry about it! I just wanted to go ahead and close this issue since some other folks were also debating about how to deal with things like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting-on-author This issue is waiting on the original author for a response
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update "jump to bottom" button visibility upon a change in timeline items
3 participants