Files
lambda/gtk-helpers.go

77 lines
1.5 KiB
Go
Raw Normal View History

2026-01-29 21:35:36 +00:00
package main
import (
2026-01-30 15:56:58 +00:00
"fmt"
2026-01-29 21:35:36 +00:00
"github.com/diamondburned/gotk4/pkg/glib/v2"
"github.com/diamondburned/gotk4/pkg/gtk/v4"
2026-01-30 10:40:38 +00:00
"gosrc.io/xmpp/stanza"
Jid "mellium.im/xmpp/jid"
2026-01-29 21:35:36 +00:00
)
func scrollToBottomAfterUpdate(scrolledWindow *gtk.ScrolledWindow) {
glib.IdleAdd(func() bool {
vAdj := scrolledWindow.VAdjustment()
vAdj.SetValue(vAdj.Upper() - vAdj.PageSize())
return false // Return false to run only once
})
}
func createTab(jid string, isMuc bool) {
fmt.Println("Creating tab", jid, "isMuc:", isMuc)
_, ok := tabs.Load(jid)
2026-01-29 21:35:36 +00:00
if !ok {
newTab := new(chatTab)
newTab.isMuc = isMuc
newTab.msgs = gtk.NewListBox()
newTab.msgs.SetVExpand(true)
newTab.msgs.SetShowSeparators(true)
newTab.msgs.Append(gtk.NewButtonWithLabel("Get past messages..."))
tabs.Store(jid, newTab)
2026-01-29 21:35:36 +00:00
}
}
func switchToTab(jid string) {
current = jid
tab, ok := tabs.Load(current)
if !ok {
return
}
2026-01-30 10:40:38 +00:00
typed_tab := tab.(*chatTab)
2026-01-30 15:56:58 +00:00
scroller.SetChild(typed_tab.msgs)
if typed_tab.isMuc {
m, _ := mucmembers.Load(jid)
ma := m.(mucUnit)
mm := ma.Members
gen := gtk.NewBox(gtk.OrientationVertical, 0)
2026-01-30 15:56:58 +00:00
mm.Range(func(k, v any) bool {
userbox := gtk.NewBox(gtk.OrientationHorizontal, 0)
2026-01-30 15:56:58 +00:00
u := v.(stanza.Presence)
var mu MucUser
var ocu OccupantID
u.Get(&mu)
u.Get(&ocu)
2026-01-30 15:56:58 +00:00
nick_label := gtk.NewLabel(Jid.MustParse(u.From).Resourcepart())
2026-01-30 10:40:38 +00:00
userbox.Append(nick_label)
gen.Append(userbox)
return true
})
memberList.SetChild(gen)
} else {
memberList.SetChild(gtk.NewLabel(jid))
}
2026-01-30 10:40:38 +00:00
2026-01-29 21:35:36 +00:00
}
func showErrorDialog(err error) {
fmt.Println(err.Error())
2026-01-29 21:35:36 +00:00
}