ban, kick and change role&affil menu, status icons in muc, blocking avatars that are invalid so we dont fetch them over and over again
This commit is contained in:
162
gtk-helpers.go
162
gtk-helpers.go
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/diamondburned/gotk4/pkg/gdk/v4"
|
||||
"github.com/diamondburned/gotk4/pkg/glib/v2"
|
||||
"github.com/diamondburned/gotk4/pkg/gtk/v4"
|
||||
"github.com/diamondburned/gotk4/pkg/pango"
|
||||
@@ -82,7 +83,7 @@ func switchToTab(jid string, w *gtk.Window) {
|
||||
nick_label.SetOpacity(0.5)
|
||||
}
|
||||
|
||||
userbox.SetTooltipText(fmt.Sprintf("%s\n%s\n%s\nRight-click for more information", u.From, mu.MucUserItem.Role, mu.MucUserItem.Affiliation))
|
||||
userbox.SetTooltipText(fmt.Sprintf("%s\n%s\n%s\nClick for more information", u.From, mu.MucUserItem.Role, mu.MucUserItem.Affiliation))
|
||||
userbox.Append(nick_label)
|
||||
|
||||
var hats Hats
|
||||
@@ -95,6 +96,13 @@ func switchToTab(jid string, w *gtk.Window) {
|
||||
}
|
||||
}
|
||||
|
||||
status := gtk.NewImageFromPaintable(clientAssets["status_"+string(u.Show)])
|
||||
status.SetTooltipText(string(u.Show))
|
||||
|
||||
status.SetHAlign(gtk.AlignEnd)
|
||||
// medal.SetHExpand(true)
|
||||
userbox.Prepend(status)
|
||||
|
||||
medal := gtk.NewImageFromPaintable(clientAssets[mu.MucUserItem.Affiliation])
|
||||
medal.SetTooltipText(mu.MucUserItem.Affiliation)
|
||||
|
||||
@@ -103,7 +111,145 @@ func switchToTab(jid string, w *gtk.Window) {
|
||||
userbox.Append(medal)
|
||||
|
||||
gesture := gtk.NewGestureClick()
|
||||
gesture.SetButton(3) // Right click
|
||||
gesture.SetButton(1)
|
||||
|
||||
mod_gesture := gtk.NewGestureClick()
|
||||
mod_gesture.SetButton(3)
|
||||
|
||||
popover := gtk.NewPopover()
|
||||
popover.SetHasArrow(false)
|
||||
popover.SetParent(userbox)
|
||||
|
||||
rc_box := gtk.NewBox(gtk.OrientationVertical, 0)
|
||||
bb := gtk.NewButtonWithLabel("Ban")
|
||||
kb := gtk.NewButtonWithLabel("Kick")
|
||||
ab := gtk.NewButtonWithLabel("Set affil")
|
||||
rb := gtk.NewButtonWithLabel("Set role")
|
||||
|
||||
kb.ConnectClicked(func() {
|
||||
client.SendRaw(fmt.Sprintf(`
|
||||
<iq from='%s'
|
||||
id='kick1'
|
||||
to='%s'
|
||||
type='set'>
|
||||
<query xmlns='http://jabber.org/protocol/muc#admin'>
|
||||
<item nick='%s' role='none'>
|
||||
</item>
|
||||
</query>
|
||||
</iq>
|
||||
`, clientroot.Session.BindJid, jid, JidMustParse(u.From).Resource))
|
||||
})
|
||||
|
||||
bb.ConnectClicked(func() {
|
||||
var mu MucUser
|
||||
ok = u.Get(&mu)
|
||||
if ok {
|
||||
if mu.MucUserItem.JID != "" {
|
||||
client.SendRaw(fmt.Sprintf(`
|
||||
<iq from='%s'
|
||||
id='ban1'
|
||||
to='%s'
|
||||
type='set'>
|
||||
<query xmlns='http://jabber.org/protocol/muc#admin'>
|
||||
<item affiliation='outcast' jid='%s'/>
|
||||
</query>
|
||||
</iq>
|
||||
`, clientroot.Session.BindJid, jid, JidMustParse(mu.MucUserItem.JID).Bare()))
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
ab.ConnectClicked(func() {
|
||||
var mu MucUser
|
||||
ok = u.Get(&mu)
|
||||
if ok {
|
||||
if mu.MucUserItem.JID != "" {
|
||||
win := gtk.NewWindow()
|
||||
win.SetDefaultSize(400, 1)
|
||||
win.SetResizable(false)
|
||||
|
||||
box := gtk.NewBox(gtk.OrientationVertical, 0)
|
||||
box.Append(gtk.NewLabel("Set "+JidMustParse(u.From).Resource+"'s affiliation"))
|
||||
|
||||
the_entry := gtk.NewEntry()
|
||||
the_entry.SetText(mu.MucUserItem.Affiliation)
|
||||
|
||||
submit := gtk.NewButtonWithLabel("Submit")
|
||||
submit.ConnectClicked(func() {
|
||||
client.SendRaw(fmt.Sprintf(`
|
||||
<iq from='%s'
|
||||
id='ba1'
|
||||
to='%s'
|
||||
type='set'>
|
||||
<query xmlns='http://jabber.org/protocol/muc#admin'>
|
||||
<item affiliation='%s' jid='%s'/>
|
||||
</query>
|
||||
</iq>
|
||||
`, clientroot.Session.BindJid, jid, the_entry.Text(), JidMustParse(mu.MucUserItem.JID).Bare()))
|
||||
win.SetVisible(false)
|
||||
})
|
||||
|
||||
box.Append(the_entry)
|
||||
box.Append(submit)
|
||||
|
||||
win.SetChild(box)
|
||||
win.SetVisible(true)
|
||||
}}
|
||||
})
|
||||
|
||||
|
||||
rb.ConnectClicked(func() {
|
||||
var mu MucUser
|
||||
ok = u.Get(&mu)
|
||||
if ok {
|
||||
if mu.MucUserItem.JID != "" {
|
||||
win := gtk.NewWindow()
|
||||
win.SetDefaultSize(400, 1)
|
||||
win.SetResizable(false)
|
||||
|
||||
box := gtk.NewBox(gtk.OrientationVertical, 0)
|
||||
box.Append(gtk.NewLabel("Set "+JidMustParse(u.From).Resource+"'s role"))
|
||||
box.Append(gtk.NewLabel("Important: if you want this to be permanent, set their affiliation instead"))
|
||||
|
||||
the_entry := gtk.NewEntry()
|
||||
the_entry.SetText(mu.MucUserItem.Role)
|
||||
|
||||
submit := gtk.NewButtonWithLabel("Submit")
|
||||
submit.ConnectClicked(func() {
|
||||
|
||||
client.SendRaw(fmt.Sprintf(`
|
||||
<iq from='%s'
|
||||
id='kick1'
|
||||
to='%s'
|
||||
type='set'>
|
||||
<query xmlns='http://jabber.org/protocol/muc#admin'>
|
||||
<item nick='%s' role='%s'>
|
||||
</item>
|
||||
</query>
|
||||
</iq>
|
||||
`, clientroot.Session.BindJid, jid, JidMustParse(u.From).Resource, the_entry.Text()))
|
||||
})
|
||||
|
||||
box.Append(the_entry)
|
||||
box.Append(submit)
|
||||
|
||||
win.SetChild(box)
|
||||
win.SetVisible(true)
|
||||
}}
|
||||
})
|
||||
|
||||
rc_box.Append(bb)
|
||||
rc_box.Append(kb)
|
||||
rc_box.Append(ab)
|
||||
rc_box.Append(rb)
|
||||
|
||||
popover.SetChild(rc_box)
|
||||
|
||||
mod_gesture.Connect("pressed", func(n_press, x, y int) {
|
||||
rect := gdk.NewRectangle(x, y, 1, 1)
|
||||
popover.SetPointingTo(&rect)
|
||||
popover.Popup()
|
||||
})
|
||||
|
||||
gesture.Connect("pressed", func(n_press, x, y int) {
|
||||
win := gtk.NewWindow()
|
||||
@@ -218,8 +364,13 @@ func switchToTab(jid string, w *gtk.Window) {
|
||||
version := ver.Version
|
||||
os := ver.OS
|
||||
|
||||
ver_text.SetText(fmt.Sprintf("%s %s %s", name, version, os))
|
||||
ver_text.RemoveCSSClass("visitor")
|
||||
vr := fmt.Sprintf("%s %s %s", name, version, os)
|
||||
if name == "" && version == "" && os == "" {
|
||||
ver_text.SetText("Client responded with empty version")
|
||||
} else {
|
||||
ver_text.SetText(vr)
|
||||
ver_text.RemoveCSSClass("visitor")
|
||||
}
|
||||
} else if result.Error != nil && result.Error.Type != "" {
|
||||
ver_text.SetText("Got error trying to get version")
|
||||
ver_text.SetTooltipText(result.Error.Reason + ": " + result.Error.Text)
|
||||
@@ -262,7 +413,10 @@ func switchToTab(jid string, w *gtk.Window) {
|
||||
win.SetTransientFor(win)
|
||||
win.Present()
|
||||
})
|
||||
|
||||
userbox.AddController(gesture)
|
||||
userbox.AddController(mod_gesture)
|
||||
|
||||
if mu.MucUserItem.Role == "moderator" {
|
||||
gen.Prepend(userbox)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user