Format code, remove use of Mellium JID parser, and add indicator for messages originating from WebXDC apps

This commit is contained in:
2026-02-14 22:38:32 +00:00
parent 713cb24508
commit 29ef37e237
3 changed files with 60 additions and 10 deletions

View File

@@ -33,9 +33,9 @@ func generatePresenceWidget(p stanza.Packet) gtk.Widgetter {
} }
} }
return gtk.NewLabel(jid.MustParse(presence.From).Resourcepart() + " left the MUC") return gtk.NewLabel(JidMustParse(presence.From).Resource + " left the MUC")
} else { } else {
return gtk.NewLabel(jid.MustParse(presence.From).Resourcepart() + " joined the MUC") return gtk.NewLabel(JidMustParse(presence.From).Resource + " joined the MUC")
} }
} }
@@ -140,6 +140,7 @@ func generateMessageWidget(p stanza.Packet) gtk.Widgetter {
} }
authorBox := gtk.NewBox(gtk.OrientationHorizontal, 10) authorBox := gtk.NewBox(gtk.OrientationHorizontal, 10)
contentBox := gtk.NewBox(gtk.OrientationHorizontal, 0) contentBox := gtk.NewBox(gtk.OrientationHorizontal, 0)
// im := newImageFromPath("debug.png") // im := newImageFromPath("debug.png")
@@ -180,6 +181,13 @@ func generateMessageWidget(p stanza.Packet) gtk.Widgetter {
} }
authorBox.Append(al) authorBox.Append(al)
wxdc := XDCEl{}
ok = m.Get(&wxdc)
if ok {
authorBox.Append(gtk.NewLabel("🎮"))
}
mlabel := gtk.NewLabel(m.Body) mlabel := gtk.NewLabel(m.Body)
mlabel.SetWrap(true) mlabel.SetWrap(true)
mlabel.SetSelectable(true) mlabel.SetSelectable(true)

37
main.go
View File

@@ -22,9 +22,9 @@ import (
_ "embed" _ "embed"
"encoding/base64" "encoding/base64"
"encoding/xml" "encoding/xml"
"github.com/kr/pretty"
"math/rand/v2" "math/rand/v2"
"runtime" "runtime"
"github.com/kr/pretty"
) )
var loadedConfig lambdaConfig var loadedConfig lambdaConfig
@@ -196,9 +196,9 @@ func main() {
TransportConfiguration: xmpp.TransportConfiguration{ TransportConfiguration: xmpp.TransportConfiguration{
Address: loadedConfig.Server, Address: loadedConfig.Server,
}, },
Jid: loadedConfig.Username + "/lambda." + str, Jid: loadedConfig.Username + "/lambda." + str,
Credential: xmpp.Password(loadedConfig.Password), Credential: xmpp.Password(loadedConfig.Password),
Insecure: loadedConfig.Insecure, Insecure: loadedConfig.Insecure,
StreamLogger: os.Stdout, StreamLogger: os.Stdout,
} }
router := xmpp.NewRouter() router := xmpp.NewRouter()
@@ -282,10 +282,6 @@ func main() {
glib.IdleAdd(func() { glib.IdleAdd(func() {
//uiQueue <- func() { //uiQueue <- func() {
b := gtk.NewBox(gtk.OrientationVertical, 0) b := gtk.NewBox(gtk.OrientationVertical, 0)
ba, ok := generateMessageWidget(p).(*gtk.Box)
if ok {
b = ba
}
tab, ok := tabs.Load(originator) tab, ok := tabs.Load(originator)
typed_tab := tab.(*chatTab) typed_tab := tab.(*chatTab)
@@ -296,6 +292,11 @@ func main() {
} else { } else {
fmt.Println("Got message when the tab does not exist!") fmt.Println("Got message when the tab does not exist!")
} }
ba, ok := generateMessageWidget(p).(*gtk.Box)
if ok {
b.Append(ba)
}
//} //}
}) })
}) })
@@ -336,6 +337,26 @@ func main() {
typed_unit := unit.(mucUnit) typed_unit := unit.(mucUnit)
if presence.Type != "unavailable" { if presence.Type != "unavailable" {
_, ok := typed_unit.Members.Load(id)
if !ok {
glib.IdleAdd(func() {
b := gtk.NewLabel("")
ba, ok := generatePresenceWidget(p).(*gtk.Label)
if ok {
b = ba
}
tab, ok := tabs.Load(muc)
typed_tab := tab.(*chatTab)
if ok {
typed_tab.msgs.Append(b)
scrollToBottomAfterUpdate(scroller)
} else {
fmt.Println("Got message when the tab does not exist!")
}
})
}
typed_unit.Members.Store(id, presence) typed_unit.Members.Store(id, presence)
} else { } else {
typed_unit.Members.Delete(id) typed_unit.Members.Delete(id)

21
xmpp-webxdc.go Normal file
View File

@@ -0,0 +1,21 @@
package main
// Implementation of XEP-0491: WebXDC
// https://xmpp.org/extensions/xep-0491.html
import (
"encoding/xml"
"gosrc.io/xmpp/stanza"
)
type XDCEl struct {
stanza.MsgExtension
XMLName xml.Name `xml:"urn:xmpp:webxdc:0 x"`
Document string `xml:"document"`
Summary string `xml:"summary"`
Payload string `xml:"urn:xmpp:json:0 json"` // TODO: Independent JSOn container type (XEP-0335)
}
func init() {
stanza.TypeRegistry.MapExtension(stanza.PKTMessage, xml.Name{Space: "urn:xmpp:webxdc:0", Local: "x"}, XDCEl{})
}