format code, add confirmation to destroy muc, implement some disconnect logic
This commit is contained in:
@@ -80,6 +80,7 @@ func dropToSignInPage(err error) {
|
||||
conf.Password = password_entry.Text()
|
||||
conf.Nick = nickname_entry.Text()
|
||||
conf.Insecure = insecure_check.Active()
|
||||
conf.JoinBookmarks = true
|
||||
|
||||
var b bytes.Buffer
|
||||
e := toml.NewEncoder(&b)
|
||||
|
||||
82
main.go
82
main.go
@@ -302,6 +302,7 @@ func main() {
|
||||
Credential: xmpp.Password(loadedConfig.Password),
|
||||
Insecure: loadedConfig.Insecure,
|
||||
StreamLogger: os.Stdout,
|
||||
StreamManagementEnable: true,
|
||||
}
|
||||
router := xmpp.NewRouter()
|
||||
|
||||
@@ -525,9 +526,9 @@ func main() {
|
||||
})
|
||||
|
||||
c, err := xmpp.NewClient(&config, router, func(err error) {
|
||||
showErrorDialog(err)
|
||||
panic(err)
|
||||
connectionStatus.SetText(fmt.Sprintf("Disconnected: %s", err.Error()))
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
showErrorDialog(err)
|
||||
panic(err)
|
||||
@@ -540,6 +541,7 @@ func main() {
|
||||
go func() {
|
||||
for {
|
||||
time.Sleep(5 * time.Second)
|
||||
pingStatus.AddCSSClass("pending")
|
||||
before := time.Now()
|
||||
iq := new(stanza.IQ)
|
||||
iq.From = clientroot.Session.BindJid
|
||||
@@ -549,16 +551,18 @@ func main() {
|
||||
ctx, _ := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
mychan, err := client.SendIQ(ctx, iq)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
continue
|
||||
}
|
||||
_ = <-mychan
|
||||
|
||||
pingStatus.RemoveCSSClass("pending")
|
||||
pingStatus.SetText(fmt.Sprintf("%d ms", time.Since(before)/time.Millisecond))
|
||||
|
||||
}
|
||||
}()
|
||||
connectionStatus.SetText(fmt.Sprintf("Connected as %s", JidMustParse(clientroot.Session.BindJid).Bare()))
|
||||
// Join rooms in bookmarks
|
||||
if loadedConfig.JoinBookmarks {
|
||||
books, err := stanza.NewItemsRequest("", "urn:xmpp:bookmarks:1", 0)
|
||||
if err == nil {
|
||||
mychan, err := c.SendIQ(context.TODO(), books)
|
||||
@@ -604,6 +608,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
go func() {
|
||||
@@ -611,8 +616,8 @@ func main() {
|
||||
connectionStatus.SetText("Connecting...")
|
||||
err = cm.Run()
|
||||
if err != nil {
|
||||
showErrorDialog(err)
|
||||
panic(err)
|
||||
fmt.Println(err.Error())
|
||||
connectionStatus.SetText(fmt.Sprintf("Disconnected: %s", err.Error()))
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -650,6 +655,29 @@ func activate(app *gtk.Application) {
|
||||
|
||||
destroymucAction := gio.NewSimpleAction("destroymuc", nil)
|
||||
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)
|
||||
if ok {
|
||||
cur := cur.(*chatTab)
|
||||
@@ -668,6 +696,48 @@ func activate(app *gtk.Application) {
|
||||
`, 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)
|
||||
@@ -704,6 +774,7 @@ func activate(app *gtk.Application) {
|
||||
win := gtk.NewWindow()
|
||||
win.SetTitle("Join MUC")
|
||||
win.SetDefaultSize(400, 1)
|
||||
win.SetResizable(false)
|
||||
win.SetChild(box)
|
||||
|
||||
btn.ConnectClicked(func() {
|
||||
@@ -766,7 +837,6 @@ func activate(app *gtk.Application) {
|
||||
cBox.Append(connectionStatus)
|
||||
statBar.Append(cBox)
|
||||
|
||||
|
||||
pBox := gtk.NewBox(gtk.OrientationHorizontal, 0)
|
||||
pBox.SetTooltipText("Ping between you and your XMPP server")
|
||||
i := (gtk.NewImageFromPaintable(clientAssets["chart_bar"]))
|
||||
|
||||
@@ -34,6 +34,11 @@
|
||||
color: grey;
|
||||
}
|
||||
|
||||
.pending {
|
||||
color: grey;
|
||||
transition-duration: 0.5s;
|
||||
}
|
||||
|
||||
.hat {
|
||||
background-color: orange;
|
||||
color: black;
|
||||
|
||||
Reference in New Issue
Block a user