Skip to content

Ping support#40

Merged
creesch merged 13 commits intoTildes-MC:mainfrom
danthedaniel:pings
Dec 26, 2024
Merged

Ping support#40
creesch merged 13 commits intoTildes-MC:mainfrom
danthedaniel:pings

Conversation

@danthedaniel
Copy link
Copy Markdown
Member

@danthedaniel danthedaniel commented Dec 21, 2024

Fixes: #7

Screenshots:

Screenshot 2024-12-25 at 11 02 01 PM Screenshot 2024-12-25 at 10 58 36 PM Screenshot 2024-12-25 at 11 07 12 PM

@creesch
Copy link
Copy Markdown
Collaborator

creesch commented Dec 22, 2024

I was thinking, we might want to put in at tildes special and detect the "x is y in tildes" message and add the tildes names to the list temporarily?

* Adds a "Ping on username" checkbox
* Adds a "Extra ping keywords" list option
@danthedaniel danthedaniel marked this pull request as ready for review December 26, 2024 03:59
@danthedaniel
Copy link
Copy Markdown
Member Author

@creesch I'm ready for a review - although I'm not content with the visuals. I'm looking for some feedback there.

messageJson,
JsonObject.class
))
.isPing(false)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

As discussed in #7 - unless we record an isPing flag in the database we can't accurately give this field to the client for scrollback.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I was thinking of ways we could, but in the end it all makes it more complex than needed. Let's add a column to the database.

@danthedaniel
Copy link
Copy Markdown
Member Author

I was thinking, we might want to put in at tildes special and detect the "x is y in tildes" message and add the tildes names to the list temporarily?

I'm kinda resistant to that. It would feel hacky. What if someone doesn't like that? We offer the option to disable ping on username. With that change we'd need another flag to give a consistent level of control "Disable Tildes message parsing" or something similar.

@danthedaniel danthedaniel changed the title WIP - Start work on ping support Ping support Dec 26, 2024
* Messages with a ping have a magenta border to their left
* When the tab is not focused, adds a red circle to the favicon
The import was still there but unused anywhere in the code
@creesch
Copy link
Copy Markdown
Collaborator

creesch commented Dec 26, 2024

I'm kinda resistant to that. It would feel hacky. What if someone doesn't like that? We offer the option to disable ping on username. With that change we'd need another flag to give a consistent level of control "Disable Tildes message parsing" or something similar.

You are right. People can also add their tildes name to the list anyway.


// Used for the favicon
let messageCount = 0;
let hasPing = false;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nitpick, now we have two variables related this might be an object.

@creesch
Copy link
Copy Markdown
Collaborator

creesch commented Dec 26, 2024

@creesch I'm ready for a review - although I'm not content with the visuals. I'm looking for some feedback there.

Overall looks good, replied to a few comments.

Visuals

As far as the visuals go.

Message indicator

I think that for the ping indicator in chat the magenta doesn't really work. It stands out, but also doesn't fit. What if we use the same green as used for buttons? Possibly also use that on the background of the message with a high opacity.

image

Personally I like it. It is noticeable enough without being overly shouty.

Favicon

The favicon one is very subtle. To be honest I wasn't entirely happy with the message counter either. I did a bit of experimenting, and I think I realized what the issue is. The chat icon with the chat lines isn't a good basis to draw on and in addition to that can be used as part of the indicator as well.

Continuing with the green theme for pings:
image

Regular counter:
image

Adjusted favicon function

function updateFavicon(count, hasPing) {
    const sizes = [16, 32];

    sizes.forEach(size => {
        /** @type {HTMLLinkElement | null} */
        const link = document.querySelector(`link[rel="icon"][sizes="${size}x${size}"]`);
        if (!link) {
            return;
        }

        const canvas = document.createElement('canvas');
        canvas.width = size;
        canvas.height = size;
        const ctx = canvas.getContext('2d');
        if (!ctx) {
            return;
        }

        const img = new Image();

        // Pings should not happen without a count
        if (hasPing && count > 0) {
            img.src = `img/icon_${size}_ping.png`;
        } else if (count > 0) {
            img.src = `img/icon_${size}_blank.png`;
        } else {
            // Default image, will restore the favicon.
            img.src = `img/icon_${size}.png`;
        }
        
        img.onload = () => {
            ctx.drawImage(img, 0, 0, size, size);

            if (count > 0) {
                const x = size / 2;
                const y = (size / 2) - (size * 0.05); // The middle of the chat icon is not exactly in the center.

                ctx.font = `bold ${size * 0.5}px "Arial Black"`;
                ctx.textAlign = 'center';
                ctx.textBaseline = 'middle';
                ctx.fillStyle = '#000000';
                ctx.fillText(count > 99 ? '99+' : `${count}`, x, y);
            }

            link.href = canvas.toDataURL();
        };
    });
}

And the blank icon variants created for this:

icon_16_blank
icon_16_ping
icon_32_blank
icon_32_ping

Tangent

Bit of a tangent, I picked a green close enough to minecraft (creeper) green but never checked if it is the same green. Not terribly important but just remembered. :P

@danthedaniel
Copy link
Copy Markdown
Member Author

Here's my implementation:
Screenshot 2024-12-26 at 8 32 15 AM

@danthedaniel
Copy link
Copy Markdown
Member Author

If you have files tested and prepared locally I'd be fine with you just committing them to my PR. But perhaps that's not possible because this branch is hosted on my fork? Do you want to give me some amount of write access to this repo and then I will open PRs from branches on creesch/minecraft-web-chat? Then you'd be able to commit to my branches.

@creesch
Copy link
Copy Markdown
Collaborator

creesch commented Dec 26, 2024

If you have files tested and prepared locally I'd be fine with you just committing them to my PR. But perhaps that's not possible because this branch is hosted on my fork? Do you want to give me some amount of write access to this repo and then I will open PRs from branches on creesch/minecraft-web-chat? Then you'd be able to commit to my branches.

I invited you as collaborator. I'll still ask before committing things to branches you will be working on (because I don't always like unprompted changes either) but it should make things easier indeed.

A few things before merging the PR.

  • I realize that for testing it was easier but we probably don't want to ping for own messages? Maybe we can add a section with dev/debug toggles in the settings for this.
  • Do you want to do the ping column in the message repository in this PR or a future one? (Doesn't need a version schema change as far as I am concerned as we didn't do a release in between).

@danthedaniel
Copy link
Copy Markdown
Member Author

I realize that for testing it was easier but we probably don't want to ping for own messages? Maybe we can add a section with dev/debug toggles in the settings for this.

I can do that. Should system messages ping?

Do you want to do the ping column in the message repository in this PR or a future one? (Doesn't need a version schema change as far as I am concerned as we didn't do a release in between).

I can do it here easily enough. Without a migration you'll need to manually delete your local database.

@creesch
Copy link
Copy Markdown
Collaborator

creesch commented Dec 26, 2024

need to manually delete update your local database.

I can do that ;)

PR looks good!

@creesch creesch merged commit 19a5b61 into Tildes-MC:main Dec 26, 2024
@danthedaniel danthedaniel deleted the pings branch December 26, 2024 20:31
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.

User ping and/or keyword based ping

2 participants