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/glib/v2"
|
||||||
"github.com/diamondburned/gotk4/pkg/gtk/v4"
|
"github.com/diamondburned/gotk4/pkg/gtk/v4"
|
||||||
"gosrc.io/xmpp/stanza"
|
"gosrc.io/xmpp/stanza"
|
||||||
Jid "mellium.im/xmpp/jid"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func scrollToBottomAfterUpdate(scrolledWindow *gtk.ScrolledWindow) {
|
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)
|
fmt.Println("Creating tab", jid, "isMuc:", isMuc)
|
||||||
_, ok := tabs.Load(jid)
|
_, ok := tabs.Load(jid)
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -29,7 +28,10 @@ func createTab(jid string, isMuc bool) {
|
|||||||
|
|
||||||
newTab.msgs.Append(gtk.NewButtonWithLabel("Get past messages..."))
|
newTab.msgs.Append(gtk.NewButtonWithLabel("Get past messages..."))
|
||||||
tabs.Store(jid, newTab)
|
tabs.Store(jid, newTab)
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func switchToTab(jid string, w *gtk.Window) {
|
func switchToTab(jid string, w *gtk.Window) {
|
||||||
@@ -57,9 +59,26 @@ func switchToTab(jid string, w *gtk.Window) {
|
|||||||
u.Get(&mu)
|
u.Get(&mu)
|
||||||
u.Get(&ocu)
|
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(nick_label)
|
||||||
|
userbox.Append(affil_label)
|
||||||
|
|
||||||
gesture := gtk.NewGestureClick()
|
gesture := gtk.NewGestureClick()
|
||||||
gesture.SetButton(3) // Right click
|
gesture.SetButton(3) // Right click
|
||||||
@@ -68,7 +87,7 @@ func switchToTab(jid string, w *gtk.Window) {
|
|||||||
win := gtk.NewWindow()
|
win := gtk.NewWindow()
|
||||||
win.SetDefaultSize(400, 400)
|
win.SetDefaultSize(400, 400)
|
||||||
profile_box := gtk.NewBox(gtk.OrientationVertical, 0)
|
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")
|
nick.AddCSSClass("author")
|
||||||
profile_box.Append(nick)
|
profile_box.Append(nick)
|
||||||
profile_box.Append(gtk.NewLabel(u.From))
|
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() {
|
go func() {
|
||||||
ctx := context.TODO()
|
ctx := context.TODO()
|
||||||
mychan, err := client.SendIQ(ctx, iqResp)
|
mychan, err := client.SendIQ(ctx, iqResp)
|
||||||
@@ -116,7 +143,7 @@ func switchToTab(jid string, w *gtk.Window) {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
mo, _ := mucmembers.Load(Jid.MustParse(u.From).Bare().String())
|
mo, _ := mucmembers.Load(JidMustParse(u.From).Bare())
|
||||||
mm := mo.(mucUnit)
|
mm := mo.(mucUnit)
|
||||||
mmm := mm.Members
|
mmm := mm.Members
|
||||||
mmmm, ok := mmm.Load(ocu.ID)
|
mmmm, ok := mmm.Load(ocu.ID)
|
||||||
|
|||||||
@@ -43,6 +43,15 @@ func generateMessageWidget(p stanza.Packet) gtk.Widgetter {
|
|||||||
if !ok {
|
if !ok {
|
||||||
return gtk.NewLabel("Unsupported message.")
|
return gtk.NewLabel("Unsupported message.")
|
||||||
}
|
}
|
||||||
|
fmt.Println(m.Body)
|
||||||
|
|
||||||
|
readmarker := Marker{}
|
||||||
|
ok = m.Get(&readmarker)
|
||||||
|
if ok {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
sid := StanzaID{}
|
sid := StanzaID{}
|
||||||
m.Get(&sid)
|
m.Get(&sid)
|
||||||
|
|
||||||
@@ -136,7 +145,6 @@ func generateMessageWidget(p stanza.Packet) gtk.Widgetter {
|
|||||||
|
|
||||||
authorBox.Append(al)
|
authorBox.Append(al)
|
||||||
mlabel := gtk.NewLabel(m.Body)
|
mlabel := gtk.NewLabel(m.Body)
|
||||||
// mlabel.SetMarkup(convertXEPToPango(m.Body))
|
|
||||||
mlabel.SetWrap(true)
|
mlabel.SetWrap(true)
|
||||||
mlabel.SetSelectable(true)
|
mlabel.SetSelectable(true)
|
||||||
mlabel.SetHAlign(gtk.AlignFill)
|
mlabel.SetHAlign(gtk.AlignFill)
|
||||||
|
|||||||
16
main.go
16
main.go
@@ -10,7 +10,7 @@ import (
|
|||||||
"github.com/diamondburned/gotk4/pkg/gio/v2"
|
"github.com/diamondburned/gotk4/pkg/gio/v2"
|
||||||
"github.com/diamondburned/gotk4/pkg/glib/v2"
|
"github.com/diamondburned/gotk4/pkg/glib/v2"
|
||||||
"github.com/diamondburned/gotk4/pkg/gtk/v4"
|
"github.com/diamondburned/gotk4/pkg/gtk/v4"
|
||||||
"github.com/kr/pretty"
|
_ "github.com/kr/pretty"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
@@ -67,7 +67,6 @@ func init() {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
p, err := ensureConfig()
|
p, err := ensureConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -100,7 +99,7 @@ func main() {
|
|||||||
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()
|
||||||
|
|
||||||
@@ -165,6 +164,7 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if m.Body == "" {
|
if m.Body == "" {
|
||||||
return
|
return
|
||||||
@@ -200,8 +200,6 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
pretty.Println(presence)
|
|
||||||
|
|
||||||
if presence.Error != *new(stanza.Err) {
|
if presence.Error != *new(stanza.Err) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -213,7 +211,8 @@ func main() {
|
|||||||
|
|
||||||
if ok { // This is a presence stanza from a user in a MUC
|
if ok { // This is a presence stanza from a user in a MUC
|
||||||
presence.Get(&ocu)
|
presence.Get(&ocu)
|
||||||
muc := jid.MustParse(presence.From).Bare().String()
|
from, _ := stanza.NewJid(presence.From)
|
||||||
|
muc := from.Bare()
|
||||||
_, ok = mucmembers.Load(muc)
|
_, ok = mucmembers.Load(muc)
|
||||||
if !ok {
|
if !ok {
|
||||||
mucmembers.Store(muc, mucUnit{})
|
mucmembers.Store(muc, mucUnit{})
|
||||||
@@ -259,8 +258,9 @@ func main() {
|
|||||||
_, ok := userdevices.Load(user)
|
_, ok := userdevices.Load(user)
|
||||||
_, mok := mucmembers.Load(user)
|
_, mok := mucmembers.Load(user)
|
||||||
if !ok && !mok { // FIXME: The initial muc presence gets picked up from this check
|
if !ok && !mok { // FIXME: The initial muc presence gets picked up from this check
|
||||||
|
ok := createTab(user, false)
|
||||||
|
if ok {
|
||||||
userdevices.Store(user, userUnit{})
|
userdevices.Store(user, userUnit{})
|
||||||
createTab(user, false)
|
|
||||||
|
|
||||||
b := gtk.NewButtonWithLabel(user)
|
b := gtk.NewButtonWithLabel(user)
|
||||||
b.ConnectClicked(func() {
|
b.ConnectClicked(func() {
|
||||||
@@ -269,10 +269,10 @@ func main() {
|
|||||||
})
|
})
|
||||||
menu.Append(b)
|
menu.Append(b)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
unit, ok := userdevices.Load(user)
|
unit, ok := userdevices.Load(user)
|
||||||
if !ok {
|
if !ok {
|
||||||
fmt.Println("Could not load user presence even after recreating it! Something weird is going on!")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
15
style.css
15
style.css
@@ -10,3 +10,18 @@
|
|||||||
.author_img {
|
.author_img {
|
||||||
border-radius 100%;
|
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
|
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