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

highlight tabs only on unviewed messages #5649

Merged
merged 33 commits into from
Nov 2, 2024
Merged

Conversation

hemirt
Copy link
Contributor

@hemirt hemirt commented Oct 14, 2024

This draft tackles the problem of unnecessary higlighting of images viewed in currently selected notebook tab, as discussed here: #5412

It only tackles the part 1) do not highlight other tabs on messages shown in current tab, does not yet tackle the part 2) on selection unhiglight possible other tabs.

This is just a proof of concept, just to see what might be necessary to do these changes and to tackle the ideas.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

src/widgets/helper/NotebookTab.cpp Outdated Show resolved Hide resolved
src/widgets/helper/NotebookTab.cpp Outdated Show resolved Hide resolved
src/widgets/helper/NotebookTab.cpp Outdated Show resolved Hide resolved
src/widgets/splits/SplitContainer.cpp Outdated Show resolved Hide resolved
@hemirt
Copy link
Contributor Author

hemirt commented Oct 14, 2024

So far I haven't noticed any performance issues either, although the decisions surely could be condensed into a precomputed NotebookTab<->NotebookTab, (except maybe the filter stuff, as I had to figure out to do highlight other tabs when a current tab shows filtering splits and a message is received but filtered out. i.e. not shown),

the precomputed map could also be leveraged and used for 2) select tab unhighlight state change

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

src/widgets/splits/SplitContainer.cpp Outdated Show resolved Hide resolved
src/widgets/splits/SplitContainer.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@Nerixyz Nerixyz left a comment

Choose a reason for hiding this comment

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

Tests would be great. Unfortunately, we can't mock ChannelViews. Maybe we can find some way to test this.

src/widgets/helper/NotebookTab.cpp Outdated Show resolved Hide resolved
src/widgets/helper/NotebookTab.cpp Outdated Show resolved Hide resolved
src/widgets/helper/NotebookTab.cpp Outdated Show resolved Hide resolved
src/widgets/helper/ChannelView.hpp Outdated Show resolved Hide resolved
src/widgets/helper/NotebookTab.hpp Show resolved Hide resolved
Co-authored-by: nerix <nero.9@hotmail.de>
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

src/widgets/helper/NotebookTab.cpp Outdated Show resolved Hide resolved
src/widgets/helper/NotebookTab.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

src/widgets/helper/NotebookTab.cpp Outdated Show resolved Hide resolved
src/widgets/helper/NotebookTab.cpp Outdated Show resolved Hide resolved
src/widgets/helper/NotebookTab.hpp Outdated Show resolved Hide resolved
src/widgets/helper/NotebookTab.hpp Outdated Show resolved Hide resolved
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

src/widgets/helper/NotebookTab.cpp Outdated Show resolved Hide resolved
@hemirt
Copy link
Contributor Author

hemirt commented Oct 17, 2024

for now selecting a tab correctly unselects other tabs based on their status of viewed channels as a whole - for new messages

todo:

  • filtered channels / filters on select
  • mention highlights
  • check setHighlightState([one param]) used in duplicatePage
  • test adding new splits

Copy link
Contributor

@Nerixyz Nerixyz left a comment

Choose a reason for hiding this comment

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

From what I can tell, this works. Some test-cases would be great (not unit-tests, but written steps). For example:

Setup (could be the same for all tests):

  • Tab 1: [TwitchDev]
  • Tab 2: [TwitchDev]
  • Tab 3: empty

Steps:

  • Select Tab 3
  • (some other account): Write @{current-user} in TwitchDev (i.e. ping the current user)
  • expectation: Tab 1 and 2 are highlighted red
  • Select Tab 1
  • expectation: Tab 2 is no longer highlighted

If these get too long, you can use a <details> block (write /details and tab-complete):

<details><summary>Steps</summary>

text...
</details>

src/widgets/Notebook.hpp Outdated Show resolved Hide resolved
src/widgets/helper/NotebookTab.hpp Outdated Show resolved Hide resolved
src/widgets/helper/NotebookTab.hpp Show resolved Hide resolved
src/widgets/helper/NotebookTab.cpp Outdated Show resolved Hide resolved
@hemirt
Copy link
Contributor Author

hemirt commented Oct 22, 2024

From what I can tell, this works. Some test-cases would be great (not unit-tests, but written steps). For example:

Setup (could be the same for all tests):

  • Tab 1: [TwitchDev]
  • Tab 2: [TwitchDev]
  • Tab 3: empty

Steps:

  • Select Tab 3
  • (some other account): Write @{current-user} in TwitchDev (i.e. ping the current user)
  • expectation: Tab 1 and 2 are highlighted red
  • Select Tab 1
  • expectation: Tab 2 is no longer highlighted

If these get too long, you can use a <details> block (write /details and tab-complete):

<details><summary>Steps</summary>

text...
</details>

I'm unsure where I would even write these - (as a comment here?), or whats the verbiage on these actions.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

src/widgets/helper/NotebookTab.hpp Outdated Show resolved Hide resolved
@hemirt
Copy link
Contributor Author

hemirt commented Oct 24, 2024

(Figured out what you meant by /details)

Wrote out a bunch of test scenarios, hopefully I didn't confuse myself somewhere there. They should cover pretty much everything (Ofcourse Scenarios 4 and 5 - Multiple tabs - could test instead of just two, maybe three or four).

Details

Common setup:

  • Account name: User
  • a message containing User will Highlight (red)
  • a message containing Hello will just NewMessage (white)
  • Tab 1: [Earth, Moon]
  • Tab 2: [Moon]
  • Tab 3: [Earth]
  • Tab 4: [Mars, Phobos, Deimos]

Scenario 1: (Messages in visible split)

  • Selected Tab 1 [Earth, Moon]
  • (other account) types (a) User / (b) Hello in Earth
  • Expectation: no tab is highlighted

Scenario 2: (Messages in nonvisible split)

  • Selected Tab 1 [Earth, Moon]
  • (other account) types (a) User / (b) Hello in Mars
  • Expectation: Tab 2 highlights in (a) Highlighted (red) / (b) NewMessage (white) state

Scenario 3: (Selecting single tab)

  • Selected Tab 4 [Mars, Phobos, Deimos]
  • (other account) types (a) User / (b) Hello in Earth
  • Expectation: Tab 1 [Earth, Moon] and Tab 3 [Earth] highlighted in (a) Highlighted (red) / (b) NewMessage (white) state
  • Select Tab 3 [Earth]
  • Expectation: Tab 1 [Earth, Moon] in unhighlight (gray) state
  • Expectation: Tab 3 [Earth] in active (blue) state

Scenario 4: (Selecting multiple tabs - same new state)

  • Selected Tab 4 [Mars, Phobos, Deimos]
  • (other account) types (a) User / (b) Hello in Earth
  • (other account) types (a) User / (b) Hello in Moon
  • Expectation: Tab 1, 2, 3 are (a) Highlighted (red) / (b) NewMessage (white) state
  • Subscenario i)
    -- Select Tab 1 [Earth, Moon]
    -- Expectations: Tab 1 active, Tab 2,3 unhighlighted (gray)
  • Subscenario ii)
    -- Select Tab 2 [Moon]
    -- Expectations: Tab 2 active, Tab 1, 3 still in (a) red / (b) white state
    -- Select Tab 3 [Earth]
    -- Expectations: Tab 3 active, Tab 1, 2 unhighlighted (gray)

Scenario 5: (Selecting multiple tabs - different new states)

  • Selected Tab 4 [Mars, Phobos, Deimos]
  • (other account) types User in Earth
  • (other account) types Hello in Moon
  • Expectations: Tab 1 [Earth, Moon] Highlighted (red), Tab 2 [Moon] NewMessage (white), Tab 3 [Earth] Highlighted (red)
  • Subscenario i)
    -- Select Tab 1 [Earth, Moon]
    -- Expectations: Tab 1 active, Tab 2, 3 unhighlighted (gray)
  • Subscenario ii)
    -- Select Tab 2 [Moon]
    -- Expectations: Tab 2 active, Tab 1, 3 still Highlighted (red)
  • Subscenario iii)
    -- Select Tab 3 [Earth]
    -- Expectations: Tab 3 active, Tab 1, 2 NewMessage (white)

Scenario 6: (Creating new split)

  • Selected Tab 2 [Moon]
  • (other account) types (a) User / (b) Hello in Earth
  • Expectations: Tab 1, 3 in (a) Highlighted (red) / (b) NewMessage (white) state
  • Create New Split with Channel Earth
  • Expectations: Tab 1, 3 in unhighlighted (gray) state

Scenario 7: (Deleting a split)

  • Selected Tab 1 [Earth, Moon]
  • Delete split Moon
  • (other account) types (a) User / (b) Hello in Moon
  • Expectations: Tab 2 [Moon] in (a) Highlighted (red) / (b) NewMessage (white) state

Scenario 8: (Deleting a split and selecting other tab)

  • Selected Tab 1 [Earth, Moon]
  • Delete split Moon
  • Select Tab 4 [Mars, Phobos, Deimos]
  • (other account) types (a) User / (b) Hello in Moon
  • Expectations: Tab 1 [Earth, Moon] still in unhighlighted (gray) state, Tab 2 [Moon] in (a) Highlighted (red) / (b) NewMessage (white) state

Copy link
Member

@pajlada pajlada left a comment

Choose a reason for hiding this comment

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

one "bug": Two splits with the same filter applied in two separate tabs will both highlight with the current code

Setup:
Tab 1: [Moon with filter (message.content contains "forsen")]
Tab 2: [Moon with the same filter (message.content contains "forsen")]

Scenario:
Other user types "forsen" in Moon - both tabs highlight

not a final review, unit tests would be super handy but it's not something I think you should try to tackle in this PR

src/widgets/helper/ChannelView.hpp Outdated Show resolved Hide resolved
src/widgets/helper/ChannelView.hpp Show resolved Hide resolved
* @brief Sets the highlight state of this tab clearing highlight sources
*
* Obeys the HighlightsEnabled setting and highlight states hierarchy
*/
void setHighlightState(HighlightState style);
Copy link
Member

Choose a reason for hiding this comment

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

Looks like setHighlightState is unused now (except for in unit tests) - should be removed then imo.
If you'd like, you can wait with this for a bit as I'd like to try to see if we can get ChannelView unit tests going

Comment on lines 129 to 130
std::unordered_set<ChannelView::ChannelViewID> newMessageSource;
std::unordered_set<ChannelView::ChannelViewID> highlightedSource;
Copy link
Member

Choose a reason for hiding this comment

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

Document these members - I'm not sold on the naming of highlight source, so my thought is that with these documented to better describe your intent I might understand whether the name is ok or not

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the source in here refers to the split in which the message appears, I'll add this as a comment there

@hemirt
Copy link
Contributor Author

hemirt commented Oct 26, 2024

one "bug": Two splits with the same filter applied in two separate tabs will both highlight with the current code

Setup: Tab 1: [Moon with filter (message.content contains "forsen")] Tab 2: [Moon with the same filter (message.content contains "forsen")]

Scenario: Other user types "forsen" in Moon - both tabs highlight

not a final review, unit tests would be super handy but it's not something I think you should try to tackle in this PR

Not sure on which Tab youre actually selected, but if youre selected on a different Tab, e.g. Tab 3, then both Tab 1 and Tab 2 should highlight, then selecting either tab will unhiglight the other tab.

Fixed the issue when you're on Tab 1 and Tab 2 gets highlighted, when it shouldn't (as you're viewing the same thing in Tab 1).

I.e. each split (view) acts based on its own Identity (ID), i.e. having different filters will act as if its a different channel.

Copy link
Member

@pajlada pajlada left a comment

Choose a reason for hiding this comment

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

Nitpicky, but I think it will help me understand it more

I'd prefer if instead of storing "sources" of highlights, we store "unread highlights"

Instead of storing newMessage and highlighted unread highlights in separate sets, store them in a single map instead (e.g. map<ChannelViewID, HighlightState> where the HighlightState is the "highest" highlight state). If for some reason we must store both the new message and highlighted highlight states of an unread highlight, we could instead use a FlagsEnum, but I'd like to understand why that would be necessary first

Then, instead of having separate removeNewMessageSource etc it would be called markHighlightsFromChannelsAsRead(ChannelViewID) or something without having to specify the highlight type

let me know if there's anything in that feedback that doesn't make sense

@hemirt
Copy link
Contributor Author

hemirt commented Oct 26, 2024

My bad, read it wrong

> Instead of storing `newMessage` and `highlighted` unread highlights in separate sets, store them in a single map instead (e.g. `map` where the HighlightState is the "highest" highlight state). If for some reason we must store both the `new message` and `highlighted` highlight states of an unread highlight, we could instead use a `FlagsEnum`, but I'd like to understand why that would be necessary first

It is needed in this scenario

Tab 1: [Earth, Moon]
Tab 2: [Earth]
Tab 3: [Moon]

you're on Tab 4 [Mars]

if you in channel #Earth get a new message (white)
and in channel #Moon get pinged (red)

then Tab 1 shows as red (i.e. the highest state)

If you select the Tab 3: [Moon] and view this ping message, then Tab 1 goes to the new message state (as you have yet to see the new message in channel #Earth

Just state flags on a Tab would not work (as I see it) since you need to know who is the source of the highlight state (and as said above, also which state), to properly unmark them.


Yes, I believe we only need the highest state of any given source, as it gets all removed on selection. So it might be possible, gonna take a look and try to implement it that way.

@hemirt
Copy link
Contributor Author

hemirt commented Oct 26, 2024

Yes, I believe we only need the highest state of any given source, as it gets all removed on selection. So it might be possible, gonna take a look and try to implement it that way.

incorporated the changes in 05ab3b2

@pajlada pajlada enabled auto-merge (squash) November 2, 2024 12:55
@pajlada pajlada merged commit db8047e into Chatterino:master Nov 2, 2024
18 checks passed
@Felanbird
Copy link
Collaborator

Am I misunderstanding what this PR was supposed to do? from what I can see it still sets the duplicates of a tab as unread, even when you have one of them focused

@pajlada
Copy link
Member

pajlada commented Nov 5, 2024

Am I misunderstanding what this PR was supposed to do? from what I can see it still sets the duplicates of a tab as unread, even when you have one of them focused

Are you using any filters in any of those tabs? Filter support with this is not perfect

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.

4 participants