lambda is free of this insane bug

This commit is contained in:
2026-07-17 17:15:41 +01:00
parent 120b0c2647
commit 006b43a590
9 changed files with 263 additions and 240 deletions
+201 -194
View File
@@ -23,6 +23,201 @@ import (
func init() {
}
func showUserWindow(u stanza.Presence, custom_nick string) {
var ocu OccupantID
u.Get(&ocu)
var id string
id = JidMustParse(u.From).Resource
win := gtk.NewWindow()
win.SetDefaultSize(400, 400)
win.SetResizable(false)
profile_box := gtk.NewBox(gtk.OrientationVertical, 0)
nick := gtk.NewLabel(JidMustParse(u.From).Resource)
if custom_nick != "" {
nick.SetText(custom_nick)
}
ver_text := gtk.NewLabel(loadedLocale["gettingVersion"])
ver_text.AddCSSClass("visitor")
win.SetTitle(JidMustParse(u.From).Resource)
nick.AddCSSClass("author")
nick.SetSelectable(true)
profile_box.Append(nick)
if u.Status != "" {
status_message := gtk.NewLabel(u.Status)
status_message.AddCSSClass("status")
profile_box.Append(status_message)
}
profile_box.Append(ver_text)
fr := gtk.NewLabel(u.From)
fr.AddCSSClass("jid")
fr.SetSelectable(true)
profile_box.Append(fr)
profile_box.Append(ver_text)
iqResp, err := stanza.NewIQ(stanza.Attrs{
Type: "get",
From: clientroot.Session.BindJid,
To: u.From,
Id: "vc2",
Lang: "en",
})
if err != nil {
panic(err)
}
iqResp.Payload = &stanza.Version{}
loading_version_text := gtk.NewLabel("...")
var hats Hats
ok := u.Get(&hats)
if ok {
for _, hat := range hats.Hats {
l := gtk.NewLabel(hat.Title)
l.AddCSSClass("hat")
profile_box.Append(l)
}
}
var mu MucUser
ok = u.Get(&mu)
if ok {
if mu.MucUserItem.JID != "" {
ji := (gtk.NewLabel(mu.MucUserItem.JID))
ji.AddCSSClass("jid")
ji.SetSelectable(true)
profile_box.Append(ji)
}
profile_box.Append(gtk.NewLabel(loadedLocale["connectedWithRole"] + mu.MucUserItem.Role))
var affil string
if mu.MucUserItem.Affiliation == "none" {
affil = loadedLocale["unaffiliated"]
} else {
affil = loadedLocale["affiliatedAs"] + mu.MucUserItem.Affiliation
}
profile_box.Append(gtk.NewLabel(affil))
}
if ocu.ID != "" {
ocu_label := gtk.NewLabel(ocu.ID)
ocu_label.AddCSSClass("jid")
ocu_label.SetSelectable(true)
profile_box.Append(ocu_label)
}
go func() {
myIQ, err := stanza.NewIQ(stanza.Attrs{
Type: "get",
From: clientroot.Session.BindJid,
To: u.From,
Id: "dicks",
Lang: "en",
})
if err != nil {
panic(err)
}
myIQ.Payload = &stanza.DiscoInfo{}
ctx := context.TODO()
mychan, err := client.SendIQ(ctx, myIQ)
if err == nil {
result := <-mychan
res, ok := result.Payload.(*stanza.DiscoInfo)
if ok {
idents := res.Identity
for i, ident := range idents {
profile_box.Append(gtk.NewLabel(fmt.Sprintf("%d: Name: %s, Category: %s, Type: %s", i+1, ident.Name, ident.Category, ident.Type)))
}
/*
s := fmt.Sprintf("%v", res.Features)
h := sha1.New()
h.Write([]byte(s))
sha1_hash := hex.EncodeToString(h.Sum(nil))
*/
sw := gtk.NewScrolledWindow()
s := ""
for _, feature := range res.Features {
s = s + feature.Var + "\n"
}
sw.SetChild(gtk.NewLabel(s))
profile_box.Append(sw)
}
}
}()
go func() {
ctx := context.TODO()
mychan, err := client.SendIQ(ctx, iqResp)
if err == nil {
result := <-mychan
ver, ok := result.Payload.(*stanza.Version)
if ok {
loading_version_text.SetVisible(false)
name := ver.Name
version := ver.Version
os := ver.OS
vr := fmt.Sprintf("%s %s %s", name, version, os)
if name == "" && version == "" && os == "" {
ver_text.SetText(loadedLocale["versionQueryEmpty"])
} else {
ver_text.SetText(vr)
ver_text.RemoveCSSClass("visitor")
}
} else if result.Error != nil && result.Error.Type != "" {
ver_text.SetText(loadedLocale["versionQueryError"])
ver_text.SetTooltipText(result.Error.Reason + ": " + result.Error.Text)
ver_text.RemoveCSSClass("visitor")
ver_text.AddCSSClass("error")
}
}
}()
go func() {
mo, _ := mucmembers.Load(JidMustParse(u.From).Bare())
mm := mo.(mucUnit)
mmm := mm.Members
mmmm, ok := mmm.Load(id)
if ok {
pres := mmmm.(stanza.Presence)
var vu VCardUpdate
pres.Get(&vu)
if vu.Photo != "" {
im := getAvatar(u.From, vu.Photo)
im.SetPixelSize(80)
im.AddCSSClass("author_img")
profile_box.Prepend(im)
} else {
im := createIdenticon(u.From, false)
im.SetPixelSize(80)
im.AddCSSClass("author_img")
profile_box.Prepend(im)
}
} else {
im := createIdenticon(u.From, false)
im.SetPixelSize(80)
im.AddCSSClass("author_img")
profile_box.Prepend(im)
}
}()
win.SetChild(profile_box)
win.SetTransientFor(win)
win.Present()
}
func scrollToBottomAfterUpdate(scrolledWindow *gtk.ScrolledWindow) {
glib.IdleAdd(func() bool {
vAdj := scrolledWindow.VAdjustment()
@@ -147,10 +342,9 @@ func switchToTab(jid string, w *gtk.Window) {
//id := ocu.ID
//if id == "" {
id := JidMustParse(u.From).Resource
// id := JidMustParse(u.From).Resource
//}
nick_label := gtk.NewLabel(JidMustParse(u.From).Resource)
var custom_nick string
@@ -166,15 +360,13 @@ func switchToTab(jid string, w *gtk.Window) {
ocu_nick, ok := loadedConfig.CustomNicks[ocu.ID]
if ok {
custom_nick = ocu_nick
custom_nick = ocu_nick
}
if custom_nick != "" {
nick_label.SetText(custom_nick)
}
nick_label.SetEllipsize(pango.EllipsizeEnd)
nick_label.AddCSSClass(mu.MucUserItem.Role)
if mu.MucUserItem.Role == "visitor" {
@@ -332,7 +524,7 @@ func switchToTab(jid string, w *gtk.Window) {
</query>
</iq>
`, clientroot.Session.BindJid, jid, the_entry.Text(), JidMustParse(mu.MucUserItem.JID).Bare()))
win.SetVisible(false)
win.Destroy()
})
box.Append(the_entry)
@@ -399,191 +591,7 @@ func switchToTab(jid string, w *gtk.Window) {
})
gesture.Connect("pressed", func(n_press, x, y int) {
win := gtk.NewWindow()
win.SetDefaultSize(400, 400)
win.SetResizable(false)
profile_box := gtk.NewBox(gtk.OrientationVertical, 0)
nick := gtk.NewLabel(JidMustParse(u.From).Resource)
if custom_nick != "" {
nick.SetText(custom_nick)
}
ver_text := gtk.NewLabel(loadedLocale["gettingVersion"])
ver_text.AddCSSClass("visitor")
win.SetTitle(JidMustParse(u.From).Resource)
nick.AddCSSClass("author")
nick.SetSelectable(true)
profile_box.Append(nick)
if u.Status != "" {
status_message := gtk.NewLabel(u.Status)
status_message.AddCSSClass("status")
profile_box.Append(status_message)
}
profile_box.Append(ver_text)
fr := gtk.NewLabel(u.From)
fr.AddCSSClass("jid")
fr.SetSelectable(true)
profile_box.Append(fr)
profile_box.Append(ver_text)
iqResp, err := stanza.NewIQ(stanza.Attrs{
Type: "get",
From: clientroot.Session.BindJid,
To: u.From,
Id: "vc2",
Lang: "en",
})
if err != nil {
panic(err)
}
iqResp.Payload = &stanza.Version{}
loading_version_text := gtk.NewLabel("...")
var hats Hats
ok := u.Get(&hats)
if ok {
for _, hat := range hats.Hats {
l := gtk.NewLabel(hat.Title)
l.AddCSSClass("hat")
profile_box.Append(l)
}
}
var mu MucUser
ok = u.Get(&mu)
if ok {
if mu.MucUserItem.JID != "" {
ji := (gtk.NewLabel(mu.MucUserItem.JID))
ji.AddCSSClass("jid")
ji.SetSelectable(true)
profile_box.Append(ji)
}
profile_box.Append(gtk.NewLabel(loadedLocale["connectedWithRole"] + mu.MucUserItem.Role))
var affil string
if mu.MucUserItem.Affiliation == "none" {
affil = loadedLocale["unaffiliated"]
} else {
affil = loadedLocale["affiliatedAs"] + mu.MucUserItem.Affiliation
}
profile_box.Append(gtk.NewLabel(affil))
}
if ocu.ID != "" {
ocu_label := gtk.NewLabel(ocu.ID)
ocu_label.AddCSSClass("jid")
ocu_label.SetSelectable(true)
profile_box.Append(ocu_label)
}
go func() {
myIQ, err := stanza.NewIQ(stanza.Attrs{
Type: "get",
From: clientroot.Session.BindJid,
To: u.From,
Id: "dicks",
Lang: "en",
})
if err != nil {
panic(err)
}
myIQ.Payload = &stanza.DiscoInfo{}
ctx := context.TODO()
mychan, err := client.SendIQ(ctx, myIQ)
if err == nil {
result := <-mychan
res, ok := result.Payload.(*stanza.DiscoInfo)
if ok {
idents := res.Identity
for i, ident := range idents {
profile_box.Append(gtk.NewLabel(fmt.Sprintf("%d: Name: %s, Category: %s, Type: %s", i+1, ident.Name, ident.Category, ident.Type)))
}
/*
s := fmt.Sprintf("%v", res.Features)
h := sha1.New()
h.Write([]byte(s))
sha1_hash := hex.EncodeToString(h.Sum(nil))
*/
sw := gtk.NewScrolledWindow()
s := ""
for _, feature := range res.Features {
s = s + feature.Var + "\n"
}
sw.SetChild(gtk.NewLabel(s))
profile_box.Append(sw)
}
}
}()
go func() {
ctx := context.TODO()
mychan, err := client.SendIQ(ctx, iqResp)
if err == nil {
result := <-mychan
ver, ok := result.Payload.(*stanza.Version)
if ok {
loading_version_text.SetVisible(false)
name := ver.Name
version := ver.Version
os := ver.OS
vr := fmt.Sprintf("%s %s %s", name, version, os)
if name == "" && version == "" && os == "" {
ver_text.SetText(loadedLocale["versionQueryEmpty"])
} else {
ver_text.SetText(vr)
ver_text.RemoveCSSClass("visitor")
}
} else if result.Error != nil && result.Error.Type != "" {
ver_text.SetText(loadedLocale["versionQueryError"])
ver_text.SetTooltipText(result.Error.Reason + ": " + result.Error.Text)
ver_text.RemoveCSSClass("visitor")
ver_text.AddCSSClass("error")
}
}
}()
go func() {
mo, _ := mucmembers.Load(JidMustParse(u.From).Bare())
mm := mo.(mucUnit)
mmm := mm.Members
mmmm, ok := mmm.Load(id)
if ok {
pres := mmmm.(stanza.Presence)
var vu VCardUpdate
pres.Get(&vu)
if vu.Photo != "" {
im := getAvatar(u.From, vu.Photo)
im.SetPixelSize(80)
im.AddCSSClass("author_img")
profile_box.Prepend(im)
} else {
im := createIdenticon(u.From, false)
im.SetPixelSize(80)
im.AddCSSClass("author_img")
profile_box.Prepend(im)
}
} else {
im := createIdenticon(u.From, false)
im.SetPixelSize(80)
im.AddCSSClass("author_img")
profile_box.Prepend(im)
}
}()
win.SetChild(profile_box)
win.SetTransientFor(win)
win.Present()
showUserWindow(u, custom_nick)
})
userbox.AddController(gesture)
@@ -625,7 +633,6 @@ func switchToTab(jid string, w *gtk.Window) {
} else {
memberList.SetChild(gtk.NewLabel(jid))
}
}
func showErrorDialog(err error, w *gtk.Window) {
@@ -641,7 +648,7 @@ func showErrorDialog(err error, w *gtk.Window) {
close_btn := gtk.NewButtonWithLabel(loadedLocale["close"])
close_btn.ConnectClicked(func() {
err_win.SetVisible(false)
err_win.Destroy()
})
box.Append(close_btn)
err_win.SetChild(box)
@@ -737,7 +744,7 @@ func jidBuilder(en *gtk.Entry) { // This function spawns a window that allows th
jid := localPart + at + domain + slash + resource
en.SetText(jid)
win.SetVisible(false)
win.Destroy()
})
box.Append(submit)