a lodda changes my guy

This commit is contained in:
2026-01-30 15:56:58 +00:00
parent d82dc87af1
commit 63ad9247bc
10 changed files with 101 additions and 82 deletions

View File

@@ -3,16 +3,17 @@ package main
// This file contains the function that generates message widgets depending on message stanza
import (
"os"
"context"
"encoding/base64"
"fmt"
"github.com/diamondburned/gotk4/pkg/gtk/v4"
"github.com/google/uuid"
"github.com/jacoblockett/sanitizefilename"
"github.com/jasonlovesdoggo/gopen"
"gosrc.io/xmpp/stanza"
"mellium.im/xmpp/jid"
"github.com/google/uuid"
"github.com/jasonlovesdoggo/gopen"
"encoding/base64"
"github.com/jacoblockett/sanitizefilename"
"os"
"path/filepath"
)
func generateMessageWidget(p stanza.Packet) gtk.Widgetter {
@@ -31,7 +32,7 @@ func generateMessageWidget(p stanza.Packet) gtk.Widgetter {
reactions := gtk.NewBox(gtk.OrientationHorizontal, 0)
reactions.SetVisible(false)
reaction := []string{"👍", "👎", "♥️", "🤣", "😭",}
reaction := []string{"👍", "👎", "♥️", "🤣", "😭"}
for _, v := range reaction {
like := gtk.NewButton()
like.SetLabel(v)
@@ -72,7 +73,6 @@ func generateMessageWidget(p stanza.Packet) gtk.Widgetter {
ocu := OccupantID{}
m.Get(&ocu)
authorBox := gtk.NewBox(gtk.OrientationHorizontal, 10)
contentBox := gtk.NewBox(gtk.OrientationHorizontal, 0)
// im := newImageFromPath("debug.png")
@@ -80,6 +80,7 @@ func generateMessageWidget(p stanza.Packet) gtk.Widgetter {
// authorBox.Append(im)
im := getAvatar(m.From, ocu.ID)
im.SetPixelSize(40)
im.AddCSSClass("author_img")
authorBox.Append(im)
al := gtk.NewLabel(jid.MustParse(m.From).Resourcepart())
al.AddCSSClass("author")
@@ -101,20 +102,18 @@ func generateMessageWidget(p stanza.Packet) gtk.Widgetter {
oob := stanza.OOB{}
ok = m.Get(&oob)
if ok {
// media := newPictureFromWeb(oob.URL)
// media := newPictureFromWeb(oob.URL)
// media.SetCanShrink(false)
// mainBox.Append(media)
// media.AddCSSClass("chat_image")
mbtn := gtk.NewButtonWithLabel("🖼️")
// mbtn.SetChild(newImageFromWeb(oob.URL))
mbtn.ConnectClicked(func(){
mbtn.ConnectClicked(func() {
gopen.Open(oob.URL)
})
authorBox.Append(mbtn)
}
return mainBox
}
@@ -123,10 +122,15 @@ func getVAdjustment(scrolledWindow *gtk.ScrolledWindow) *gtk.Adjustment {
return val
}
func getAvatar(j, hash string) *gtk.Image {
hash = sanitizefilename.Sanitize(hash)
func getAvatar(j, hash string) *gtk.Image { // TODO: This function probably shouldn't be here, and should probably be in xmpp-helpers or somewhere similar.
p, err := ensureCache()
if err != nil {
return newImageFromPath("debug.png")
}
_, err := os.ReadFile(hash)
hash = filepath.Join(p, sanitizefilename.Sanitize(hash))
_, err = os.ReadFile(hash)
if err == nil {
return newImageFromPath(hash)
}
@@ -134,9 +138,9 @@ func getAvatar(j, hash string) *gtk.Image {
iqResp, err := stanza.NewIQ(stanza.Attrs{
Type: "get",
From: clientroot.Session.BindJid,
To: j,
Id: "vc2",
Lang: "e",
To: j,
Id: "vc2",
Lang: "en",
})
if err != nil {
@@ -150,7 +154,7 @@ func getAvatar(j, hash string) *gtk.Image {
if err != nil {
panic(err)
}
result := <- mychan
result := <-mychan
card, ok := result.Payload.(*VCard)
if !ok {
return newImageFromPath("debug.png")
@@ -166,12 +170,10 @@ func getAvatar(j, hash string) *gtk.Image {
panic(err)
}
err = os.WriteFile(hash, data, 0644)
if err != nil {
panic(err)
}
// TODO: Implement caching!
return newImageFromPath(hash)
}
}