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

Fix unread marker being removed from DOM #820

Merged
merged 1 commit into from
Dec 19, 2016

Conversation

xPaw
Copy link
Member

@xPaw xPaw commented Dec 19, 2016

Fixes #762.

@xPaw xPaw added the Type: Bug Issues that report and PRs that solve any defects that cause unexpected behaviors. label Dec 19, 2016
@xPaw xPaw added this to the 2.2.0 milestone Dec 19, 2016
@xPaw xPaw requested a review from AlMcKinlay December 19, 2016 10:51
Copy link
Member

@AlMcKinlay AlMcKinlay left a comment

Choose a reason for hiding this comment

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

Just 1 small issue.

@@ -1331,7 +1331,7 @@ $(function() {
} else {
var current = $(this);

if (current.attr("class") === "date-marker") {
if (current.hasClass("date-marker") && prev.hasClass("date-marker")) {
Copy link
Member

Choose a reason for hiding this comment

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

If we have the unread marker at the top, and we have 2 date markers straight after, this will not delete 1 of the date markers, will it? Because it'll drop into the else and stop there?

Copy link
Member Author

Choose a reason for hiding this comment

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

The intended behaviour is to keep the lowest date marker, does this code not accomplish this?

Copy link
Member

Choose a reason for hiding this comment

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

So, if we have:

  • unread-marker
  • date-marker
  • date-marker
  • message

We want to end up with

  • unread-marker
  • date-marker
  • message

Correct?

I'm pretty sure this code will not do that, because it will set the first to be unread-marker, then it will check that both 0 and 1 are date-markers, but they aren't. So it will return false. This will then stop it doing the job, I think.

Am I missing something?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's correct. And you might be right the code is flawed. Any ideas on how to improve it?

Copy link
Member

@AlMcKinlay AlMcKinlay Dec 19, 2016

Choose a reason for hiding this comment

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

Simplest thing I can think of is changing the first one.

Currently we do:

if (!prev) {
 	// Should always be a date-seperator, because it's always added
 	prev = $(this);
} else {
...

So, if we want to make sure that prev is always a date-marker, we can just do this:

if (!prev) {
	if ($(this).hasClass("date-marker")) {
		// We only want to deal with date-markers
	 	prev = $(this);
	}
} else {
...

Then you don't need to add this extra check for the date-marker on the previous one here, as we will always have a date marker on this one.

chat.find(".active .date-marker").remove();
chat
.find(".active")
.find(".show-more").addClass("show").end()
Copy link
Member

Choose a reason for hiding this comment

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

Dodgy indentation.

Copy link
Member

@AlMcKinlay AlMcKinlay left a comment

Choose a reason for hiding this comment

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

Yep, seems a much better solution.

@AlMcKinlay
Copy link
Member

Do we need a second review of this one, or is it small enough to go with 1?

@AlMcKinlay AlMcKinlay merged commit 6887b66 into master Dec 19, 2016
@AlMcKinlay AlMcKinlay deleted the xpaw/fix-unread-disappear branch December 19, 2016 19:11
@astorije
Copy link
Member

@xPaw is on a roll!! 👏

matburnham pushed a commit to matburnham/lounge that referenced this pull request Sep 6, 2017
…pear

Fix unread marker being removed from DOM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issues that report and PRs that solve any defects that cause unexpected behaviors.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants