diff --git a/assets.go b/assets.go index 7752b07..c764e7a 100644 --- a/assets.go +++ b/assets.go @@ -143,6 +143,9 @@ var jabberBytes []byte //go:embed assets/fail.png var failBytes []byte +//go:embed assets/please_wait.gif +var pleaseWaitBytes []byte + func loadAsset(key string, data []byte) { loader := gdkpixbuf.NewPixbufLoader() loader.Write(data) @@ -197,6 +200,7 @@ func init() { "moderate": moderateBytes, "jabber": jabberBytes, "fail": failBytes, + "please_wait": pleaseWaitBytes, } { loadAsset(key, data) } diff --git a/assets/please_wait.gif b/assets/please_wait.gif new file mode 100644 index 0000000..942c1b4 Binary files /dev/null and b/assets/please_wait.gif differ diff --git a/gtk-helpers.go b/gtk-helpers.go index 9902fe7..8df8fe8 100644 --- a/gtk-helpers.go +++ b/gtk-helpers.go @@ -136,9 +136,11 @@ func switchToTab(jid string, w *gtk.Window) { u.Get(&ocu) if mu.MucUserItem.Role == "moderator" { + gen.Prepend(gtk.NewSeparator(gtk.OrientationHorizontal)) gen.Prepend(userbox) } else { gen.Append(userbox) + gen.Append(gtk.NewSeparator(gtk.OrientationHorizontal)) } //id := ocu.ID @@ -147,6 +149,10 @@ func switchToTab(jid string, w *gtk.Window) { //} nick_label := gtk.NewLabel(JidMustParse(u.From).Resource) + custom_nick, ok := loadedConfig.CustomNicks[ocu.ID] + if ok { + nick_label.SetText(custom_nick) + } nick_label.SetEllipsize(pango.EllipsizeEnd) nick_label.AddCSSClass(mu.MucUserItem.Role) if mu.MucUserItem.Role == "visitor" { @@ -366,6 +372,10 @@ func switchToTab(jid string, w *gtk.Window) { win.SetDefaultSize(400, 400) 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") @@ -418,6 +428,13 @@ func switchToTab(jid string, w *gtk.Window) { profile_box.Append(gtk.NewLabel(loadedLocale["affiliatedAs"] + mu.MucUserItem.Affiliation)) } + 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{ diff --git a/gtk-message.go b/gtk-message.go index a16afdf..55bc46b 100644 --- a/gtk-message.go +++ b/gtk-message.go @@ -149,6 +149,14 @@ func generateMessageWidget(p stanza.Packet) gtk.Widgetter { m.Get(&ocu) id := JidMustParse(m.From).Resource + custom_nick, ok := loadedConfig.CustomNicks[ocu.ID] + if ok { + id = custom_nick + } + + if id == "" { + id = JidMustParse(m.From).Bare() + } if loadedConfig.CompactMode { al := gtk.NewLabel(id) @@ -174,11 +182,8 @@ func generateMessageWidget(p stanza.Packet) gtk.Widgetter { } else { authorBox := gtk.NewBox(gtk.OrientationHorizontal, 10) contentBox := gtk.NewBox(gtk.OrientationHorizontal, 0) - n := JidMustParse(m.From).Resource - if n == "" { - n = JidMustParse(m.From).Resource - } - al := gtk.NewLabel(n) + + al := gtk.NewLabel(id) al.AddCSSClass("author") al.SetSelectable(true) diff --git a/main.go b/main.go index 7c1dddf..622b07a 100644 --- a/main.go +++ b/main.go @@ -16,6 +16,7 @@ import ( "github.com/go-analyze/charts" "golang.org/x/net/html/charset" "path/filepath" + "github.com/google/uuid" "github.com/BurntSushi/toml" "gosrc.io/xmpp" @@ -176,6 +177,8 @@ func main() { {Var: "http://jabber.org/protocol/muc"}, {Var: "λ"}, {Var: "urn:xmpp:attention:0"}, + {Var: "urn:xmpp:carbons:2"}, + {Var: "urn:xmpp:ping"}, }, } iqResp.Payload = &payload @@ -433,9 +436,10 @@ func main() { pingStatus.AddCSSClass("pending") before := time.Now() iq := new(stanza.IQ) + iq.Id = uuid.New().String() iq.From = clientroot.Session.BindJid - iq.To = iq.From iq.Type = "get" + iq.Payload = &Ping{} ctx, _ := context.WithTimeout(context.Background(), 30*time.Second) mychan, err := client.SendIQ(ctx, iq) @@ -1161,6 +1165,7 @@ func activate(app *gtk.Application) { i := (gtk.NewImageFromPaintable(clientAssets["chart_bar"])) i.AddCSSClass("icon") + pBox.Append(i) pingStatus = gtk.NewLabel("...") pBox.Append(pingStatus) diff --git a/types.go b/types.go index 5cf88d1..33dced8 100644 --- a/types.go +++ b/types.go @@ -26,6 +26,7 @@ type lambdaConfig struct { Debug bool ShowPresenceUpdates bool CompactMode bool + CustomNicks map[string]string } type mucUnit struct { diff --git a/xmpp-ping.go b/xmpp-ping.go new file mode 100644 index 0000000..a6c273f --- /dev/null +++ b/xmpp-ping.go @@ -0,0 +1,27 @@ +package main + +// Implementation of XEP-0199: XMPP Ping +// https://xmpp.org/extensions/xep-0199.html + +import ( + "encoding/xml" + "gosrc.io/xmpp/stanza" +) + +type Ping struct { + stanza.IQ + XMLName xml.Name `xml:"urn:xmpp:ping ping"` + ResultSet *stanza.ResultSet `xml:"set,omitempty"` +} + +func (v *Ping) Namespace() string { + return v.XMLName.Space +} + +func (v *Ping) GetSet() *stanza.ResultSet { + return v.ResultSet +} + +func init() { + stanza.TypeRegistry.MapExtension(stanza.PKTIQ, xml.Name{Space: "urn:xmpp:ping", Local: "ping"}, Ping{}) +} diff --git a/xmpp-vcard.go b/xmpp-vcard.go index 98eca16..7bbdafa 100644 --- a/xmpp-vcard.go +++ b/xmpp-vcard.go @@ -51,3 +51,4 @@ func init() { stanza.TypeRegistry.MapExtension(stanza.PKTIQ, xml.Name{Space: "vcard-temp", Local: "vCard"}, VCard{}) stanza.TypeRegistry.MapExtension(stanza.PKTPresence, xml.Name{Space: "vcard-temp:x:update", Local: "x"}, VCardUpdate{}) } +