diff --git a/gtk-helpers.go b/gtk-helpers.go index 2886b93..86ee942 100644 --- a/gtk-helpers.go +++ b/gtk-helpers.go @@ -6,7 +6,6 @@ import ( "github.com/diamondburned/gotk4/pkg/glib/v2" "github.com/diamondburned/gotk4/pkg/gtk/v4" "gosrc.io/xmpp/stanza" - Jid "mellium.im/xmpp/jid" ) func scrollToBottomAfterUpdate(scrolledWindow *gtk.ScrolledWindow) { @@ -17,7 +16,7 @@ func scrollToBottomAfterUpdate(scrolledWindow *gtk.ScrolledWindow) { }) } -func createTab(jid string, isMuc bool) { +func createTab(jid string, isMuc bool) bool { fmt.Println("Creating tab", jid, "isMuc:", isMuc) _, ok := tabs.Load(jid) if !ok { @@ -29,7 +28,10 @@ func createTab(jid string, isMuc bool) { newTab.msgs.Append(gtk.NewButtonWithLabel("Get past messages...")) tabs.Store(jid, newTab) + return true } + + return false } func switchToTab(jid string, w *gtk.Window) { @@ -57,10 +59,27 @@ func switchToTab(jid string, w *gtk.Window) { u.Get(&mu) u.Get(&ocu) - nick_label := gtk.NewLabel(Jid.MustParse(u.From).Resourcepart()) + nick_label := gtk.NewLabel(JidMustParse(u.From).Resource) + affil_label := gtk.NewLabel("") + switch mu.MucUserItem.Affiliation { + case "owner": + affil_label.SetText("O") + case "admin": + affil_label.SetText("A") + case "member": + affil_label.SetText("M") + case "none": + affil_label.SetText("-") + } + affil_label.SetHAlign(gtk.AlignEnd) + affil_label.SetHExpand(true) + + + affil_label.AddCSSClass(mu.MucUserItem.Affiliation) userbox.Append(nick_label) - + userbox.Append(affil_label) + gesture := gtk.NewGestureClick() gesture.SetButton(3) // Right click @@ -68,7 +87,7 @@ func switchToTab(jid string, w *gtk.Window) { win := gtk.NewWindow() win.SetDefaultSize(400, 400) profile_box := gtk.NewBox(gtk.OrientationVertical, 0) - nick := gtk.NewLabel(Jid.MustParse(u.From).Resourcepart()) + nick := gtk.NewLabel(JidMustParse(u.From).Resource) nick.AddCSSClass("author") profile_box.Append(nick) profile_box.Append(gtk.NewLabel(u.From)) @@ -96,6 +115,14 @@ func switchToTab(jid string, w *gtk.Window) { } } + var mu MucUser + ok = u.Get(&mu) + if ok { + if mu.MucUserItem.JID != "" { + profile_box.Append(gtk.NewLabel(mu.MucUserItem.JID)) + } + } + go func() { ctx := context.TODO() mychan, err := client.SendIQ(ctx, iqResp) @@ -116,7 +143,7 @@ func switchToTab(jid string, w *gtk.Window) { }() go func() { - mo, _ := mucmembers.Load(Jid.MustParse(u.From).Bare().String()) + mo, _ := mucmembers.Load(JidMustParse(u.From).Bare()) mm := mo.(mucUnit) mmm := mm.Members mmmm, ok := mmm.Load(ocu.ID) diff --git a/gtk-message.go b/gtk-message.go index a1f9e11..d53bea8 100644 --- a/gtk-message.go +++ b/gtk-message.go @@ -43,6 +43,15 @@ func generateMessageWidget(p stanza.Packet) gtk.Widgetter { if !ok { return gtk.NewLabel("Unsupported message.") } + fmt.Println(m.Body) + + readmarker := Marker{} + ok = m.Get(&readmarker) + if ok { + return nil + } + + sid := StanzaID{} m.Get(&sid) @@ -136,7 +145,6 @@ func generateMessageWidget(p stanza.Packet) gtk.Widgetter { authorBox.Append(al) mlabel := gtk.NewLabel(m.Body) - // mlabel.SetMarkup(convertXEPToPango(m.Body)) mlabel.SetWrap(true) mlabel.SetSelectable(true) mlabel.SetHAlign(gtk.AlignFill) diff --git a/main.go b/main.go index ba4c3fd..0a9e816 100644 --- a/main.go +++ b/main.go @@ -10,7 +10,7 @@ import ( "github.com/diamondburned/gotk4/pkg/gio/v2" "github.com/diamondburned/gotk4/pkg/glib/v2" "github.com/diamondburned/gotk4/pkg/gtk/v4" - "github.com/kr/pretty" + _ "github.com/kr/pretty" "path/filepath" "github.com/BurntSushi/toml" @@ -67,7 +67,6 @@ func init() { }() } - func main() { p, err := ensureConfig() if err != nil { @@ -97,10 +96,10 @@ func main() { TransportConfiguration: xmpp.TransportConfiguration{ Address: loadedConfig.Server, }, - Jid: loadedConfig.Username + "/lambda."+str, - Credential: xmpp.Password(loadedConfig.Password), - Insecure: loadedConfig.Insecure, - // StreamLogger: os.Stdout, + Jid: loadedConfig.Username + "/lambda." + str, + Credential: xmpp.Password(loadedConfig.Password), + Insecure: loadedConfig.Insecure, + StreamLogger: os.Stdout, } router := xmpp.NewRouter() @@ -165,10 +164,11 @@ func main() { return } + /* - if m.Body == "" { - return - } + if m.Body == "" { + return + } */ originator := jid.MustParse(m.From).Bare().String() @@ -200,8 +200,6 @@ func main() { return } - pretty.Println(presence) - if presence.Error != *new(stanza.Err) { return } @@ -213,7 +211,8 @@ func main() { if ok { // This is a presence stanza from a user in a MUC presence.Get(&ocu) - muc := jid.MustParse(presence.From).Bare().String() + from, _ := stanza.NewJid(presence.From) + muc := from.Bare() _, ok = mucmembers.Load(muc) if !ok { mucmembers.Store(muc, mucUnit{}) @@ -259,20 +258,21 @@ func main() { _, ok := userdevices.Load(user) _, mok := mucmembers.Load(user) if !ok && !mok { // FIXME: The initial muc presence gets picked up from this check - userdevices.Store(user, userUnit{}) - createTab(user, false) + ok := createTab(user, false) + if ok { + userdevices.Store(user, userUnit{}) - b := gtk.NewButtonWithLabel(user) - b.ConnectClicked(func() { - b.AddCSSClass("accent") - switchToTab(user, &window.Window) - }) - menu.Append(b) + b := gtk.NewButtonWithLabel(user) + b.ConnectClicked(func() { + b.AddCSSClass("accent") + switchToTab(user, &window.Window) + }) + menu.Append(b) + } } unit, ok := userdevices.Load(user) if !ok { - fmt.Println("Could not load user presence even after recreating it! Something weird is going on!") return } diff --git a/style.css b/style.css index d282138..768d44e 100644 --- a/style.css +++ b/style.css @@ -10,3 +10,18 @@ .author_img { border-radius 100%; } + +.owner { + background-color: red; + color: white; +} + +.admin { + background-color: orange; + color: white; +} + +.member { + background-color: lime; + color: white; +} diff --git a/xmpp-helpers.go b/xmpp-helpers.go index 851e614..34899a9 100644 --- a/xmpp-helpers.go +++ b/xmpp-helpers.go @@ -46,3 +46,14 @@ func joinMuc(c xmpp.Sender, jid string, muc string, nick string) error { } return nil } + +// jid MustParse but using gosrc's instead of mellium +// This function will panic if its an invalid JID + +func JidMustParse(s string) (*stanza.Jid) { + j, err := stanza.NewJid(s) + if err != nil { + panic(err) + } + return j +}