remove some occurences of mellium jid lib and try to add experimental affiliation displays
This commit is contained in:
@@ -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,9 +59,26 @@ 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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
18
main.go
18
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,
|
||||
Jid: loadedConfig.Username + "/lambda." + str,
|
||||
Credential: xmpp.Password(loadedConfig.Password),
|
||||
Insecure: loadedConfig.Insecure,
|
||||
// StreamLogger: os.Stdout,
|
||||
StreamLogger: os.Stdout,
|
||||
}
|
||||
router := xmpp.NewRouter()
|
||||
|
||||
@@ -165,6 +164,7 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
if m.Body == "" {
|
||||
return
|
||||
@@ -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,8 +258,9 @@ func main() {
|
||||
_, ok := userdevices.Load(user)
|
||||
_, mok := mucmembers.Load(user)
|
||||
if !ok && !mok { // FIXME: The initial muc presence gets picked up from this check
|
||||
ok := createTab(user, false)
|
||||
if ok {
|
||||
userdevices.Store(user, userUnit{})
|
||||
createTab(user, false)
|
||||
|
||||
b := gtk.NewButtonWithLabel(user)
|
||||
b.ConnectClicked(func() {
|
||||
@@ -269,10 +269,10 @@ func main() {
|
||||
})
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
15
style.css
15
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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user