AVATAR
This commit is contained in:
1
go.mod
1
go.mod
@@ -6,6 +6,7 @@ require (
|
||||
github.com/BurntSushi/toml v1.6.0
|
||||
github.com/diamondburned/gotk4/pkg v0.3.1
|
||||
github.com/google/uuid v1.1.1
|
||||
github.com/jacoblockett/sanitizefilename v1.0.1
|
||||
github.com/jasonlovesdoggo/gopen v0.0.0-20250130105607-39c98c645030
|
||||
github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f
|
||||
github.com/kr/pretty v0.1.0
|
||||
|
||||
2
go.sum
2
go.sum
@@ -35,6 +35,8 @@ github.com/google/pprof v0.0.0-20190908185732-236ed259b199/go.mod h1:zfwlbNMJ+OI
|
||||
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
|
||||
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/jacoblockett/sanitizefilename v1.0.1 h1:HhPMoPp05U5aKjhht+d7lsqhyF4trKSBme0FE6S/1C4=
|
||||
github.com/jacoblockett/sanitizefilename v1.0.1/go.mod h1:/cQHSz2fHeR1iDKpHTSW/MIyONa+Uqj0eszbvPuIxNs=
|
||||
github.com/jasonlovesdoggo/gopen v0.0.0-20250130105607-39c98c645030 h1:NFCJG3BerP/5ZLXwu08x9xDs+9p7AYFMeo5IXjGANxw=
|
||||
github.com/jasonlovesdoggo/gopen v0.0.0-20250130105607-39c98c645030/go.mod h1:+YdGDBjXJho3QTsEntqzdm0YaiALOsz3sL6b67QLC8M=
|
||||
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
|
||||
|
||||
@@ -3,12 +3,16 @@ package main
|
||||
// This file contains the function that generates message widgets depending on message stanza
|
||||
|
||||
import (
|
||||
"os"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/diamondburned/gotk4/pkg/gtk/v4"
|
||||
"gosrc.io/xmpp/stanza"
|
||||
"mellium.im/xmpp/jid"
|
||||
"github.com/google/uuid"
|
||||
"github.com/jasonlovesdoggo/gopen"
|
||||
"encoding/base64"
|
||||
"github.com/jacoblockett/sanitizefilename"
|
||||
)
|
||||
|
||||
func generateMessageWidget(p stanza.Packet) gtk.Widgetter {
|
||||
@@ -65,11 +69,16 @@ func generateMessageWidget(p stanza.Packet) gtk.Widgetter {
|
||||
mainBox.Append(replyBox)
|
||||
}
|
||||
|
||||
ocu := OccupantID{}
|
||||
m.Get(&ocu)
|
||||
|
||||
|
||||
authorBox := gtk.NewBox(gtk.OrientationHorizontal, 10)
|
||||
contentBox := gtk.NewBox(gtk.OrientationHorizontal, 0)
|
||||
im := newImageFromPath("debug.png")
|
||||
// im := newImageFromPath("debug.png")
|
||||
|
||||
// authorBox.Append(im)
|
||||
im := getAvatar(m.From, ocu.ID)
|
||||
im.SetPixelSize(40)
|
||||
authorBox.Append(im)
|
||||
al := gtk.NewLabel(jid.MustParse(m.From).Resourcepart())
|
||||
@@ -104,6 +113,8 @@ func generateMessageWidget(p stanza.Packet) gtk.Widgetter {
|
||||
authorBox.Append(mbtn)
|
||||
}
|
||||
|
||||
|
||||
|
||||
return mainBox
|
||||
}
|
||||
|
||||
@@ -111,3 +122,56 @@ func getVAdjustment(scrolledWindow *gtk.ScrolledWindow) *gtk.Adjustment {
|
||||
val := scrolledWindow.ObjectProperty("vadjustment").(*gtk.Adjustment)
|
||||
return val
|
||||
}
|
||||
|
||||
func getAvatar(j, hash string) *gtk.Image {
|
||||
hash = sanitizefilename.Sanitize(hash)
|
||||
|
||||
_, err := os.ReadFile(hash)
|
||||
if err == nil {
|
||||
return newImageFromPath(hash)
|
||||
}
|
||||
|
||||
iqResp, err := stanza.NewIQ(stanza.Attrs{
|
||||
Type: "get",
|
||||
From: clientroot.Session.BindJid,
|
||||
To: j,
|
||||
Id: "vc2",
|
||||
Lang: "e",
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
iqResp.Payload = &VCard{}
|
||||
|
||||
ctx := context.TODO()
|
||||
mychan, err := client.SendIQ(ctx, iqResp)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
result := <- mychan
|
||||
card, ok := result.Payload.(*VCard)
|
||||
if !ok {
|
||||
return newImageFromPath("debug.png")
|
||||
}
|
||||
|
||||
base64_data := card.Photo.Binval
|
||||
if card.Photo.Binval == "" {
|
||||
return newImageFromPath("debug.png")
|
||||
}
|
||||
|
||||
data, err := base64.StdEncoding.DecodeString(base64_data)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
|
||||
err = os.WriteFile(hash, data, 0644)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// TODO: Implement caching!
|
||||
return newImageFromPath(hash)
|
||||
}
|
||||
|
||||
3
main.go
3
main.go
@@ -19,7 +19,6 @@ import (
|
||||
|
||||
_ "embed"
|
||||
"encoding/xml"
|
||||
"github.com/kr/pretty"
|
||||
)
|
||||
|
||||
var loadedConfig lambdaConfig
|
||||
@@ -132,6 +131,7 @@ func main() {
|
||||
s.Send(iqResp)
|
||||
})
|
||||
|
||||
|
||||
router.HandleFunc("message", func(s xmpp.Sender, p stanza.Packet) {
|
||||
m, ok := p.(stanza.Message)
|
||||
if !ok {
|
||||
@@ -167,7 +167,6 @@ func main() {
|
||||
|
||||
router.HandleFunc("presence", func(s xmpp.Sender, p stanza.Packet) {
|
||||
presence, ok := p.(stanza.Presence)
|
||||
pretty.Println(presence)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -11,12 +11,17 @@ import (
|
||||
type VCard struct {
|
||||
XMLName xml.Name `xml:"vcard-temp vCard"`
|
||||
Photo Photo `xml:"PHOTO"`
|
||||
ResultSet *stanza.ResultSet `xml:"set,omitempty"`
|
||||
}
|
||||
|
||||
func (v *VCard) Namespace() string {
|
||||
return v.XMLName.Space
|
||||
}
|
||||
|
||||
func (v *VCard) GetSet() *stanza.ResultSet {
|
||||
return v.ResultSet
|
||||
}
|
||||
|
||||
type Photo struct {
|
||||
Type string `xml:"TYPE"`
|
||||
Binval string `xml:"BINVAL"`
|
||||
|
||||
Reference in New Issue
Block a user