diamondburned / dissent

Tiny native Discord app
https://flathub.org/apps/details/so.libdb.dissent
GNU General Public License v3.0
1.23k stars 39 forks source link

Message spoilers #175

Closed tfuxu closed 2 months ago

tfuxu commented 10 months ago

This PR implements custom Spoiler widget used as a overlay on messages wrapped in || tags.

Note: Putting this as a draft for now, as there are a couple MarkdownViewer bugs that needs to be fixed beforehand, and the current spoiler style definitely needs some polishing.

Fixes #152

TODO:

Screenshots:

Simple message hidden:

Screenshot from 2023-10-11 19-24-18

Simple message visible:

Screenshot from 2023-10-11 19-25-43

Textblock/multi-line message hidden:

Screenshot from 2023-10-11 19-24-30

diamondburned commented 10 months ago

Does this not work for inline spoiler tags, e.g. hello ||world||?

tfuxu commented 10 months ago

Does this not work for inline spoiler tags, e.g. hello ||world||?

Ah, I completely forgot about this 🤦‍♂️️ I'll think of another solution for this, since the overlay probably isn't as flexible to put only on a specific section of the message (at least not with the current implementation).

diamondburned commented 10 months ago

You can use a hover/tap EventController combined with method.TextView.get_iter_at_position and method.TextView.window_to_buffer_coords to obtain the character mark at the hovering point, then check if it has a spoiler tag and set its opacity to 1 if there is any.

You'll also need to keep a last spoiler tag:

var lastSpoilerTag *gtk.TextTag
func(spoilerTag *gtk.TextTag) { // callback
    if lastSpoilerTag == spoilerTag {
        return
    }

    if lastSpoilerTag != nil {
        lastSpoilerTag.SetProperty("opacity", 0)
    }

    spoilerTag.SetProperty("opacity", 1)
}
diamondburned commented 2 months ago

Partially implemented in https://github.com/diamondburned/dissent/commit/a52c614ea157324770a72333a61ede960365bafb.

tfuxu commented 2 months ago

Cool! Closing as there is a new solution implemented. I've also created a tracking issue for currently unsupported types of spoilers #282