homer drops his donut, doh, homer spills his soda, doh, homer hits the doorway, doh, homer ruins his whole day, doh!
This commit is contained in:
+33
-26
@@ -7,7 +7,7 @@ import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"github.com/diamondburned/gotk4/pkg/gdk/v4"
|
||||
"github.com/diamondburned/gotk4/pkg/glib/v2"
|
||||
_ "github.com/diamondburned/gotk4/pkg/glib/v2"
|
||||
"github.com/diamondburned/gotk4/pkg/gtk/v4"
|
||||
"github.com/google/uuid"
|
||||
"github.com/jasonlovesdoggo/gopen"
|
||||
@@ -290,28 +290,22 @@ func generateMessageWidget(p stanza.Packet, blocked bool) (gtk.Widgetter, bool)
|
||||
if !ok {
|
||||
can_generate = false
|
||||
}
|
||||
im := gtk.NewImage()
|
||||
if can_generate {
|
||||
pres := mmmm.(stanza.Presence)
|
||||
var vu VCardUpdate
|
||||
pres.Get(&vu)
|
||||
im := createIdenticon(m.From, false)
|
||||
createIdenticon(m.From, false, im)
|
||||
im.SetPixelSize(40)
|
||||
im.AddCSSClass("author_img")
|
||||
authorBox.Append(im)
|
||||
|
||||
if vu.Photo != "" {
|
||||
go func() {
|
||||
new_im := getAvatar(m.From, vu.Photo)
|
||||
glib.IdleAdd(func() {
|
||||
new_im.SetPixelSize(40)
|
||||
new_im.AddCSSClass("author_img")
|
||||
authorBox.Remove(im)
|
||||
authorBox.Prepend(new_im)
|
||||
})
|
||||
}()
|
||||
go getAvatar(m.From, vu.Photo, im)
|
||||
}
|
||||
|
||||
} else {
|
||||
im := createIdenticon(m.From, false)
|
||||
createIdenticon(m.From, false, im)
|
||||
im.SetPixelSize(40)
|
||||
im.AddCSSClass("author_img")
|
||||
authorBox.Append(im)
|
||||
@@ -323,7 +317,8 @@ func generateMessageWidget(p stanza.Packet, blocked bool) (gtk.Widgetter, bool)
|
||||
authorBox.Append(al)
|
||||
|
||||
if m.Thread != "" {
|
||||
im := createIdenticon(m.Thread, true)
|
||||
im := gtk.NewImage()
|
||||
createIdenticon(m.Thread, true, im)
|
||||
im.SetPixelSize(10)
|
||||
authorBox.Append(im)
|
||||
}
|
||||
@@ -437,33 +432,39 @@ func getVAdjustment(scrolledWindow *gtk.ScrolledWindow) *gtk.Adjustment {
|
||||
return val
|
||||
}
|
||||
|
||||
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.
|
||||
func getAvatar(j, hash string, i *gtk.Image) { // TODO: This function probably shouldn't be here, and should probably be in xmpp-helpers or somewhere similar.
|
||||
oghash := hash
|
||||
p, err := ensureCache()
|
||||
if err != nil {
|
||||
return createIdenticon(j, false)
|
||||
createIdenticon(j, false, i)
|
||||
return
|
||||
}
|
||||
|
||||
if hash == "" {
|
||||
return createIdenticon(j, false)
|
||||
createIdenticon(j, false, i)
|
||||
return
|
||||
}
|
||||
|
||||
_, ok := invalidImages.Load(hash)
|
||||
if ok {
|
||||
return createIdenticon(j, false)
|
||||
createIdenticon(j, false, i)
|
||||
return
|
||||
}
|
||||
|
||||
hash = filepath.Join(p, hash)
|
||||
|
||||
_, err = os.ReadFile(hash)
|
||||
if err == nil {
|
||||
i, err := newImageFromPath(hash)
|
||||
/*
|
||||
i, err = newImageFromPath(hash)
|
||||
if err != nil {
|
||||
invalidImages.Store(oghash, true)
|
||||
return createIdenticon(j, false)
|
||||
createIdenticon(j, false, i)
|
||||
}
|
||||
// i.AddCSSClass(loadedConfig.CVD.String() + "_CVD")
|
||||
return i
|
||||
*/
|
||||
|
||||
setImageFromPath(hash, i)
|
||||
return
|
||||
}
|
||||
|
||||
iqResp, err := stanza.NewIQ(stanza.Attrs{
|
||||
@@ -488,13 +489,15 @@ func getAvatar(j, hash string) *gtk.Image { // TODO: This function probably shou
|
||||
result := <-mychan
|
||||
card, ok := result.Payload.(*VCard)
|
||||
if !ok {
|
||||
return createIdenticon(j, false)
|
||||
createIdenticon(j, false, i)
|
||||
return
|
||||
}
|
||||
|
||||
base64_data := card.Photo.Binval
|
||||
if card.Photo.Binval == "" || ((card.Photo.Type == "image/svg+xml" || card.Photo.Type == "image/webp") && (runtime.GOOS == "windows" || runtime.GOOS == "netbsd")) {
|
||||
invalidImages.Store(oghash, true)
|
||||
return createIdenticon(j, false)
|
||||
createIdenticon(j, false, i)
|
||||
return
|
||||
}
|
||||
|
||||
data, err := base64.StdEncoding.DecodeString(base64_data)
|
||||
@@ -507,11 +510,15 @@ func getAvatar(j, hash string) *gtk.Image { // TODO: This function probably shou
|
||||
panic(err)
|
||||
}
|
||||
|
||||
i, err := newImageFromPath(hash)
|
||||
err = setImageFromPath(hash, i)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
invalidImages.Store(oghash, true)
|
||||
return createIdenticon(j, false)
|
||||
createIdenticon(j, false, i)
|
||||
}
|
||||
|
||||
fmt.Println("Everything is OK. There should be an avatar!")
|
||||
|
||||
i.AddCSSClass(loadedConfig.CVD.String() + "_CVD")
|
||||
return i
|
||||
// return i
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user