format code, add confirmation to destroy muc, implement some disconnect logic

This commit is contained in:
2026-02-19 11:28:18 +00:00
parent 3f40d3da29
commit 39156af48a
4 changed files with 136 additions and 59 deletions

View File

@@ -80,6 +80,7 @@ func dropToSignInPage(err error) {
conf.Password = password_entry.Text() conf.Password = password_entry.Text()
conf.Nick = nickname_entry.Text() conf.Nick = nickname_entry.Text()
conf.Insecure = insecure_check.Active() conf.Insecure = insecure_check.Active()
conf.JoinBookmarks = true
var b bytes.Buffer var b bytes.Buffer
e := toml.NewEncoder(&b) e := toml.NewEncoder(&b)

82
main.go
View File

@@ -302,6 +302,7 @@ func main() {
Credential: xmpp.Password(loadedConfig.Password), Credential: xmpp.Password(loadedConfig.Password),
Insecure: loadedConfig.Insecure, Insecure: loadedConfig.Insecure,
StreamLogger: os.Stdout, StreamLogger: os.Stdout,
StreamManagementEnable: true,
} }
router := xmpp.NewRouter() router := xmpp.NewRouter()
@@ -525,9 +526,9 @@ func main() {
}) })
c, err := xmpp.NewClient(&config, router, func(err error) { c, err := xmpp.NewClient(&config, router, func(err error) {
showErrorDialog(err) connectionStatus.SetText(fmt.Sprintf("Disconnected: %s", err.Error()))
panic(err)
}) })
if err != nil { if err != nil {
showErrorDialog(err) showErrorDialog(err)
panic(err) panic(err)
@@ -540,6 +541,7 @@ func main() {
go func() { go func() {
for { for {
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
pingStatus.AddCSSClass("pending")
before := time.Now() before := time.Now()
iq := new(stanza.IQ) iq := new(stanza.IQ)
iq.From = clientroot.Session.BindJid iq.From = clientroot.Session.BindJid
@@ -549,16 +551,18 @@ func main() {
ctx, _ := context.WithTimeout(context.Background(), 30*time.Second) ctx, _ := context.WithTimeout(context.Background(), 30*time.Second)
mychan, err := client.SendIQ(ctx, iq) mychan, err := client.SendIQ(ctx, iq)
if err != nil { if err != nil {
panic(err) continue
} }
_ = <-mychan _ = <-mychan
pingStatus.RemoveCSSClass("pending")
pingStatus.SetText(fmt.Sprintf("%d ms", time.Since(before)/time.Millisecond)) pingStatus.SetText(fmt.Sprintf("%d ms", time.Since(before)/time.Millisecond))
} }
}() }()
connectionStatus.SetText(fmt.Sprintf("Connected as %s", JidMustParse(clientroot.Session.BindJid).Bare())) connectionStatus.SetText(fmt.Sprintf("Connected as %s", JidMustParse(clientroot.Session.BindJid).Bare()))
// Join rooms in bookmarks // Join rooms in bookmarks
if loadedConfig.JoinBookmarks {
books, err := stanza.NewItemsRequest("", "urn:xmpp:bookmarks:1", 0) books, err := stanza.NewItemsRequest("", "urn:xmpp:bookmarks:1", 0)
if err == nil { if err == nil {
mychan, err := c.SendIQ(context.TODO(), books) mychan, err := c.SendIQ(context.TODO(), books)
@@ -604,6 +608,7 @@ func main() {
} }
} }
} }
}
}) })
go func() { go func() {
@@ -611,8 +616,8 @@ func main() {
connectionStatus.SetText("Connecting...") connectionStatus.SetText("Connecting...")
err = cm.Run() err = cm.Run()
if err != nil { if err != nil {
showErrorDialog(err) fmt.Println(err.Error())
panic(err) connectionStatus.SetText(fmt.Sprintf("Disconnected: %s", err.Error()))
} }
}() }()
@@ -650,6 +655,29 @@ func activate(app *gtk.Application) {
destroymucAction := gio.NewSimpleAction("destroymuc", nil) destroymucAction := gio.NewSimpleAction("destroymuc", nil)
destroymucAction.ConnectActivate(func(p *glib.Variant) { destroymucAction.ConnectActivate(func(p *glib.Variant) {
cur, ok := tabs.Load(current)
if ok {
cur := cur.(*chatTab)
if cur.isMuc {
win := gtk.NewWindow()
win.SetTitle("Destroy MUC")
win.SetDefaultSize(400, 1)
win.SetResizable(false)
box := gtk.NewBox(gtk.OrientationVertical, 0)
box.Append(gtk.NewLabel("Are you sure? This MUC will be gone forever! (a very long time)"))
box.Append(gtk.NewLabel("If you wish to continue, type 'I understand'"))
cancel := gtk.NewButtonWithLabel("Cancel")
cancel.ConnectClicked(func() {
win.SetVisible(false)
})
en := gtk.NewEntry()
en.SetPlaceholderText("...")
submit := gtk.NewButtonWithLabel("Destroy")
submit.ConnectClicked(func() {
fmt.Println(en.Text())
if en.Text() == "I understand" {
cur, ok := tabs.Load(current) cur, ok := tabs.Load(current)
if ok { if ok {
cur := cur.(*chatTab) cur := cur.(*chatTab)
@@ -668,6 +696,48 @@ func activate(app *gtk.Application) {
`, clientroot.Session.BindJid, current, JidMustParse(clientroot.Session.BindJid).Bare())) `, clientroot.Session.BindJid, current, JidMustParse(clientroot.Session.BindJid).Bare()))
} }
} }
win.SetVisible(false)
}
})
box.Append(en)
box.Append(submit)
box.Append(cancel)
mu, ok := mucmembers.Load(current)
if ok {
typed_mu := mu.(mucUnit)
typed_mu.Members.Range(func(k, v any) bool {
user, ok := v.(stanza.Presence)
if ok {
mu := MucUser{}
ok := user.Get(&mu)
if ok {
if mu.MucUserItem.JID != "" {
if JidMustParse(mu.MucUserItem.JID).Bare() == JidMustParse(clientroot.Session.BindJid).Bare() {
if mu.MucUserItem.Affiliation != "owner" {
box.Append(gtk.NewLabel("You are not an owner of this MUC and thus will most likely not be able to delete it"))
}
// return false
}
}
} else {
panic("not ok")
}
} else {
panic("not ok")
}
return true
})
} else {
panic("not ok")
}
win.SetChild(box)
win.SetVisible(true)
}
}
}) })
joinAction := gio.NewSimpleAction("join", nil) joinAction := gio.NewSimpleAction("join", nil)
@@ -704,6 +774,7 @@ func activate(app *gtk.Application) {
win := gtk.NewWindow() win := gtk.NewWindow()
win.SetTitle("Join MUC") win.SetTitle("Join MUC")
win.SetDefaultSize(400, 1) win.SetDefaultSize(400, 1)
win.SetResizable(false)
win.SetChild(box) win.SetChild(box)
btn.ConnectClicked(func() { btn.ConnectClicked(func() {
@@ -766,7 +837,6 @@ func activate(app *gtk.Application) {
cBox.Append(connectionStatus) cBox.Append(connectionStatus)
statBar.Append(cBox) statBar.Append(cBox)
pBox := gtk.NewBox(gtk.OrientationHorizontal, 0) pBox := gtk.NewBox(gtk.OrientationHorizontal, 0)
pBox.SetTooltipText("Ping between you and your XMPP server") pBox.SetTooltipText("Ping between you and your XMPP server")
i := (gtk.NewImageFromPaintable(clientAssets["chart_bar"])) i := (gtk.NewImageFromPaintable(clientAssets["chart_bar"]))

View File

@@ -34,6 +34,11 @@
color: grey; color: grey;
} }
.pending {
color: grey;
transition-duration: 0.5s;
}
.hat { .hat {
background-color: orange; background-color: orange;
color: black; color: black;

View File

@@ -16,6 +16,7 @@ type lambdaConfig struct {
Password string Password string
Insecure bool Insecure bool
Nick string Nick string
JoinBookmarks bool
} }
type mucUnit struct { type mucUnit struct {