From 82aa2abfbd5343ceff2cf23e09676f968723a97f Mon Sep 17 00:00:00 2001 From: sunglocto Date: Sun, 3 May 2026 11:10:15 +0100 Subject: [PATCH] t --- gtk-helpers.go | 24 ++++++- gtk-message.go | 2 - main.go | 177 +++++++++++++++++++++++++++++-------------------- 3 files changed, 126 insertions(+), 77 deletions(-) diff --git a/gtk-helpers.go b/gtk-helpers.go index 952bde6..963a4d3 100644 --- a/gtk-helpers.go +++ b/gtk-helpers.go @@ -28,7 +28,9 @@ func scrollToBottomAfterUpdate(scrolledWindow *gtk.ScrolledWindow) { } func createTab(jid string, isMuc bool, name string) bool { - fmt.Println("Creating tab", jid, "isMuc:", isMuc) + if name == "" { + name = jid + } _, ok := tabs.Load(jid) _, uok := userdevices.Load(jid) _, mok := mucmembers.Load(jid) @@ -138,6 +140,7 @@ func switchToTab(jid string, w *gtk.Window) { } } + status := gtk.NewImageFromPaintable(clientAssets["status_"+string(u.Show)]) status.SetTooltipText(string(u.Show)) @@ -152,6 +155,22 @@ func switchToTab(jid string, w *gtk.Window) { medal.SetHExpand(true) userbox.Append(medal) + default_av := createIdenticon(u.From) + userbox.Prepend(default_av) + var vcu VCardUpdate + ok = u.Get(&vcu) + if ok { + photo := vcu.Photo + go func() { + new_im := getAvatar(u.From, photo) + glib.IdleAdd(func() { + userbox.Remove(default_av) + userbox.Prepend(new_im) + }) + }() + + } + gesture := gtk.NewGestureClick() gesture.SetButton(1) @@ -352,7 +371,6 @@ func switchToTab(jid string, w *gtk.Window) { } go func() { - fmt.Println("Attempting to get Disco info") myIQ, err := stanza.NewIQ(stanza.Attrs{ Type: "get", @@ -519,7 +537,7 @@ func createIdenticon(word string) *gtk.Image { // This function generates an ide gen, _ := identicon.New("github", 5, 3) ii, _ := gen.Draw(word) - im := ii.Image(25) + im := ii.Image(250) buf := new(bytes.Buffer) err := png.Encode(buf, im) diff --git a/gtk-message.go b/gtk-message.go index b6479de..ce0404d 100644 --- a/gtk-message.go +++ b/gtk-message.go @@ -294,13 +294,11 @@ func getAvatar(j, hash string) *gtk.Image { // TODO: This function probably shou } if hash == "" { - fmt.Println("Hash is nil!") return createIdenticon(j) } _, ok := invalidImages[hash] if ok { - fmt.Println("Image is invalid") return createIdenticon(j) } diff --git a/main.go b/main.go index ae63dad..d971be7 100644 --- a/main.go +++ b/main.go @@ -20,7 +20,6 @@ import ( "github.com/BurntSushi/toml" "gosrc.io/xmpp" "gosrc.io/xmpp/stanza" - "mellium.im/xmpp/jid" "time" _ "embed" @@ -396,44 +395,9 @@ func main() { } else { // This is a presence stanza from a regular user // The code is basically the exact same as above, we just don't check for mucuser - user := jid.MustParse(presence.From).Bare().String() - _, ok := userdevices.Load(user) - _, mok := mucmembers.Load(user) - if !ok && !mok { // FIXME: The initial muc presence gets picked up from this check - ok := createTab(user, false, user) - if ok { - userdevices.Store(user, userUnit{}) - b := gtk.NewLabel(user) - gesture1 := gtk.NewGestureClick() - gesture1.SetButton(1) - gesture1.Connect("pressed", func() { - switchToTab(user, &window.Window) - }) - - b.AddController(gesture1) - menu.Append(b) - } - } - - unit, ok := userdevices.Load(user) - if !ok { - return - } - - resource := jid.MustParse(presence.From).Resourcepart() - - typed_unit := unit.(userUnit) - - if presence.Type != "unavailable" { - typed_unit.Devices.Store(resource, presence) - } else { - typed_unit.Devices.Delete(resource) - } - - userdevices.Store(user, typed_unit) + // TODO: Presence handling code goes here } - time.Sleep(1 * time.Second) }) c, err := xmpp.NewClient(&config, router, func(err error) { @@ -482,33 +446,33 @@ func main() { // Throughput /* - var oldsize int64 - var newsize int64 - var diff float64 - go func() { - for { - time.Sleep(5 * time.Second) - stat, err := xmlLog.Stat() - if err != nil { - panic(err) - } + var oldsize int64 + var newsize int64 + var diff float64 + go func() { + for { + time.Sleep(5 * time.Second) + stat, err := xmlLog.Stat() + if err != nil { + panic(err) + } - newsize = stat.Size() - diff = float64(newsize-oldsize) / 1000 + newsize = stat.Size() + diff = float64(newsize-oldsize) / 1000 - ic := clientAssets["car"] - if diff >= 25 { - ic = clientAssets["car_high"] - } + ic := clientAssets["car"] + if diff >= 25 { + ic = clientAssets["car_high"] + } - glib.IdleAdd(func() { - sStatus.SetText(fmt.Sprintf("%.2f%s", diff, loadedLocale["KBPerSecond"])) - sIcon.SetFromPaintable(ic) - }) + glib.IdleAdd(func() { + sStatus.SetText(fmt.Sprintf("%.2f%s", diff, loadedLocale["KBPerSecond"])) + sIcon.SetFromPaintable(ic) + }) - oldsize = newsize - } - }() + oldsize = newsize + } + }() */ glib.IdleAdd(func() { @@ -526,6 +490,55 @@ func main() { `, clientroot.Session.BindJid)) + // Fetch roster + i, err := stanza.NewIQ(stanza.Attrs{ + Type: "get", + }) + if err != nil { + panic(err) + } + + roster := i.RosterItems() + i.Payload = roster + mychan, err := c.SendIQ(context.TODO(), i) + result := <-mychan + if err == nil { + items, ok := result.Payload.(*stanza.RosterItems) + if ok { + for _, v := range items.Items { + name := v.Name + jid := v.Jid + + if name == "" { + name = jid + } + + createTab(jid, false, name) + glib.IdleAdd(func() { + box := gtk.NewBox(gtk.OrientationHorizontal, 10) + b := gtk.NewLabel(name) + gesture1 := gtk.NewGestureClick() + gesture1.SetButton(1) + gesture1.Connect("pressed", func() { + switchToTab(jid, &window.Window) + }) + box.Append(b) + go func() { + new_im := getAvatar(jid, jid) // TODO: Use PEP avatar and do not use JID as hash + glib.IdleAdd(func() { + new_im.SetPixelSize(40) + box.Prepend(new_im) + }) + }() + + box.AddController(gesture1) + menu.Append(box) + menu.Append(gtk.NewSeparator(gtk.OrientationHorizontal)) + }) + } + } + } + // Join rooms in bookmarks if loadedConfig.JoinBookmarks { books, err := stanza.NewItemsRequest("", "urn:xmpp:bookmarks:1", 0) @@ -539,7 +552,7 @@ func main() { jid := item.Id node := item.Any autojoin := false - name := "" + name := jid password := "" nick := loadedConfig.Nick for _, attr := range node.Attrs { @@ -582,15 +595,25 @@ func main() { joinMuc(client, clientroot.Session.BindJid, jid, nick, password) createTab(jid, true, name) glib.IdleAdd(func() { + box := gtk.NewBox(gtk.OrientationHorizontal, 10) b := gtk.NewLabel(name) gesture1 := gtk.NewGestureClick() gesture1.SetButton(1) gesture1.Connect("pressed", func() { switchToTab(jid, &window.Window) }) + box.Append(b) + go func() { + new_im := getAvatar(jid, jid) + glib.IdleAdd(func() { + new_im.SetPixelSize(40) + box.Prepend(new_im) + }) + }() - b.AddController(gesture1) - menu.Append(b) + box.AddController(gesture1) + menu.Append(box) + menu.Append(gtk.NewSeparator(gtk.OrientationHorizontal)) }) } @@ -820,7 +843,16 @@ func activate(app *gtk.Application) { } createTab(t, true, n) + box := gtk.NewBox(gtk.OrientationHorizontal, 10) + go func() { + new_im := getAvatar(t, t) + glib.IdleAdd(func() { + new_im.SetPixelSize(40) + box.Prepend(new_im) + }) + }() b := gtk.NewLabel(n) + box.Append(b) gesture1 := gtk.NewGestureClick() gesture1.SetButton(1) gesture1.Connect("pressed", func() { @@ -828,7 +860,8 @@ func activate(app *gtk.Application) { }) b.AddController(gesture1) - menu.Append(b) + menu.Append(box) + menu.Append(gtk.NewSeparator(gtk.OrientationHorizontal)) } if !ok { @@ -1100,14 +1133,14 @@ func activate(app *gtk.Application) { statBar.Append(pBox) /* - sBox := gtk.NewBox(gtk.OrientationHorizontal, 0) - sIcon = gtk.NewImageFromPaintable(clientAssets["car"]) - sIcon.AddCSSClass("icon") - sStatus = gtk.NewLabel("-") - sBox.Append(sIcon) - sBox.Append(sStatus) - sStatus.SetTooltipText(loadedLocale["throughputTooltip"]) - statBar.Append(sBox) + sBox := gtk.NewBox(gtk.OrientationHorizontal, 0) + sIcon = gtk.NewImageFromPaintable(clientAssets["car"]) + sIcon.AddCSSClass("icon") + sStatus = gtk.NewLabel("-") + sBox.Append(sIcon) + sBox.Append(sStatus) + sStatus.SetTooltipText(loadedLocale["throughputTooltip"]) + statBar.Append(sBox) */ scrollerStatBar := gtk.NewScrolledWindow()