i forgor to commit sorry

This commit is contained in:
2026-04-06 11:04:53 +01:00
parent 60d6a287e5
commit ce83000e0c
12 changed files with 327 additions and 55 deletions
+72 -10
View File
@@ -1,13 +1,22 @@
package main
import (
"bytes"
"context"
"fmt"
"github.com/boxes-ltd/imaging"
"github.com/crazy3lf/colorconv"
"github.com/diamondburned/gotk4/pkg/gdk/v4"
"github.com/diamondburned/gotk4/pkg/gdkpixbuf/v2"
"github.com/diamondburned/gotk4/pkg/glib/v2"
"github.com/diamondburned/gotk4/pkg/gtk/v4"
"github.com/diamondburned/gotk4/pkg/pango"
"github.com/rrivera/identicon"
"gosrc.io/xmpp/stanza"
"image"
"image/png"
xmpp_color "mellium.im/xmpp/color"
"strconv"
)
func scrollToBottomAfterUpdate(scrolledWindow *gtk.ScrolledWindow) {
@@ -62,7 +71,7 @@ func switchToTab(jid string, w *gtk.Window) {
gen := gtk.NewBox(gtk.OrientationVertical, 0)
i := 0
mm.Range(func(k, v any) bool {
rangeOrdered(&mm, (func(k, v any) bool {
i++
userbox := gtk.NewBox(gtk.OrientationHorizontal, 0)
@@ -71,6 +80,13 @@ func switchToTab(jid string, w *gtk.Window) {
var ocu OccupantID
u.Get(&mu)
u.Get(&ocu)
if mu.MucUserItem.Role == "moderator" {
gen.Prepend(userbox)
} else {
gen.Append(userbox)
}
//id := ocu.ID
//if id == "" {
id := JidMustParse(u.From).Resource
@@ -90,7 +106,29 @@ func switchToTab(jid string, w *gtk.Window) {
ok := u.Get(&hats)
if ok {
for _, hat := range hats.Hats {
tag := gtk.NewImageFromPaintable(clientAssets["tag"])
var val float64
if hat.Hue != "" {
tval, _ := strconv.Atoi(hat.Hue)
val = float64(tval)
} else {
xc := xmpp_color.String(hat.URI, 255, loadedConfig.CVD)
r, g, b, _ := xc.RGBA()
val, _, _ = colorconv.RGBToHSV(uint8(r), uint8(g), uint8(b))
}
tB := tagBytes
img, _, _ := image.Decode(bytes.NewReader(tB))
i_rgba := imaging.AdjustHue(img, val)
var buf bytes.Buffer
png.Encode(&buf, i_rgba)
tB = buf.Bytes()
loader := gdkpixbuf.NewPixbufLoader()
loader.Write(tB)
loader.Close()
tag := gtk.NewPictureForPaintable(gdk.NewTextureForPixbuf(loader.Pixbuf()))
tag.SetTooltipText(hat.Title)
userbox.Prepend(tag)
}
@@ -262,10 +300,12 @@ func switchToTab(jid string, w *gtk.Window) {
win.SetTitle(JidMustParse(u.From).Resource)
nick.AddCSSClass("author")
nick.SetSelectable(true)
profile_box.Append(nick)
profile_box.Append(ver_text)
fr := gtk.NewLabel(u.From)
fr.AddCSSClass("jid")
fr.SetSelectable(true)
profile_box.Append(fr)
profile_box.Append(ver_text)
@@ -300,6 +340,7 @@ func switchToTab(jid string, w *gtk.Window) {
if mu.MucUserItem.JID != "" {
ji := (gtk.NewLabel(mu.MucUserItem.JID))
ji.AddCSSClass("jid")
ji.SetSelectable(true)
profile_box.Append(ji)
}
profile_box.Append(gtk.NewLabel("Connected with role " + mu.MucUserItem.Role))
@@ -397,13 +438,13 @@ func switchToTab(jid string, w *gtk.Window) {
im.AddCSSClass("author_img")
profile_box.Prepend(im)
} else {
im := gtk.NewImageFromPaintable(clientAssets["DefaultAvatar"])
im := createIdenticon(u.From)
im.SetPixelSize(80)
im.AddCSSClass("author_img")
profile_box.Prepend(im)
}
} else {
im := gtk.NewImageFromPaintable(clientAssets["DefaultAvatar"])
im := createIdenticon(u.From)
im.SetPixelSize(80)
im.AddCSSClass("author_img")
profile_box.Prepend(im)
@@ -418,13 +459,8 @@ func switchToTab(jid string, w *gtk.Window) {
userbox.AddController(gesture)
userbox.AddController(mod_gesture)
if mu.MucUserItem.Role == "moderator" {
gen.Prepend(userbox)
} else {
gen.Append(userbox)
}
return true
})
}))
headerBox := gtk.NewBox(gtk.OrientationHorizontal, 0)
if i >= 500 {
@@ -450,3 +486,29 @@ func switchToTab(jid string, w *gtk.Window) {
func showErrorDialog(err error) {
fmt.Println(err.Error())
}
func createIdenticon(word string) *gtk.Image { // This function generates an identicon
if !loadedConfig.Identicons {
i := gtk.NewImageFromPaintable(clientAssets["DefaultAvatar"])
i.AddCSSClass(loadedConfig.CVD.String()+"_CVD")
return i
}
gen, _ := identicon.New("github", 5, 3)
ii, _ := gen.Draw(word)
im := ii.Image(25)
buf := new(bytes.Buffer)
err := png.Encode(buf, im)
if err != nil {
panic(err)
}
loader := gdkpixbuf.NewPixbufLoader()
loader.Write(buf.Bytes())
loader.Close()
i := gtk.NewImageFromPaintable(gdk.NewTextureForPixbuf(loader.Pixbuf()))
i.AddCSSClass(loadedConfig.CVD.String() + "_CVD")
return i
}