somehow sunglocto returned
This commit is contained in:
@@ -78,6 +78,8 @@ var pingTimes = [][]float64{}
|
||||
|
||||
var clientAssets map[string]gdk.Paintabler = make(map[string]gdk.Paintabler)
|
||||
|
||||
var xmlLog *os.File
|
||||
|
||||
func init() {
|
||||
beeep.AppName = "Lambda"
|
||||
|
||||
@@ -94,13 +96,6 @@ func init() {
|
||||
}
|
||||
|
||||
func main() {
|
||||
// Setup log
|
||||
xmlLog, err := os.CreateTemp("", "xmpp-log")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
defer os.Remove(xmlLog.Name())
|
||||
|
||||
pingTimes = append(pingTimes, []float64{})
|
||||
p, err := ensureConfig()
|
||||
@@ -112,7 +107,6 @@ func main() {
|
||||
if err != nil {
|
||||
dropToSignInPage(err)
|
||||
return
|
||||
// panic(err)
|
||||
}
|
||||
|
||||
_, err = toml.Decode(string(b), &loadedConfig)
|
||||
@@ -125,6 +119,17 @@ func main() {
|
||||
loadedConfig.Resource = randomClientResource()
|
||||
}
|
||||
|
||||
if !loadedConfig.Debug {
|
||||
xmlLog, err = os.CreateTemp("", "xmpp-log")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
defer os.Remove(xmlLog.Name())
|
||||
} else {
|
||||
xmlLog = os.Stdout
|
||||
}
|
||||
|
||||
config := xmpp.Config{
|
||||
TransportConfiguration: xmpp.TransportConfiguration{
|
||||
Address: loadedConfig.Server,
|
||||
@@ -393,7 +398,7 @@ 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)
|
||||
ok := createTab(user, false, user)
|
||||
if ok {
|
||||
userdevices.Store(user, userUnit{})
|
||||
|
||||
@@ -484,10 +489,18 @@ func main() {
|
||||
|
||||
newsize = stat.Size()
|
||||
diff := float64(newsize-oldsize) / 1000
|
||||
|
||||
if diff > 100 {
|
||||
sIcon.SetFromPaintable(clientAssets["car_high"])
|
||||
} else {
|
||||
sIcon.SetFromPaintable(clientAssets["car"])
|
||||
}
|
||||
|
||||
sStatus.SetText(fmt.Sprintf("%.2fKB/s", diff))
|
||||
oldsize = stat.Size()
|
||||
}
|
||||
}()
|
||||
|
||||
connectionStatus.SetText(fmt.Sprintf("Connected as %s", JidMustParse(clientroot.Session.BindJid).Bare()))
|
||||
connectionStatus.SetTooltipText(fmt.Sprintf("Binded JID: %s\nUsing TLS: %t", clientroot.Session.BindJid, clientroot.Session.TlsEnabled))
|
||||
connectionIcon.SetFromPaintable(clientAssets["connect"])
|
||||
@@ -514,15 +527,24 @@ func main() {
|
||||
jid := item.Id
|
||||
node := item.Any
|
||||
autojoin := false
|
||||
name := ""
|
||||
for _, attr := range node.Attrs {
|
||||
if attr.Name.Local == "autojoin" {
|
||||
autojoin = attr.Value == "true"
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
for _, attr := range node.Attrs {
|
||||
if attr.Name.Local == "name" {
|
||||
name = attr.Value
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
_, ok := tabs.Load(jid)
|
||||
if !ok && autojoin {
|
||||
createTab(jid, true)
|
||||
createTab(jid, true, name)
|
||||
b := gtk.NewLabel(jid)
|
||||
gesture1 := gtk.NewGestureClick()
|
||||
gesture1.SetButton(1)
|
||||
@@ -544,17 +566,19 @@ func main() {
|
||||
for _, attr := range node.Attrs {
|
||||
if attr.Name.Local == "autojoin" {
|
||||
autojoin = attr.Value == "true"
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
for _, node := range node.Nodes {
|
||||
if node.XMLName.Local == "nick" {
|
||||
nick = node.Content
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if autojoin {
|
||||
err := joinMuc(client, clientroot.Session.BindJid, jid, nick)
|
||||
err := joinMuc(client, clientroot.Session.BindJid, jid, nick, "")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -707,9 +731,11 @@ func activate(app *gtk.Application) {
|
||||
box := gtk.NewBox(gtk.OrientationVertical, 0)
|
||||
jid_box := gtk.NewBox(gtk.OrientationHorizontal, 0)
|
||||
nick_box := gtk.NewBox(gtk.OrientationHorizontal, 0)
|
||||
disco_box := gtk.NewBox(gtk.OrientationHorizontal, 0)
|
||||
|
||||
jid_entry := gtk.NewEntry()
|
||||
nick_entry := gtk.NewEntry()
|
||||
disco_check := gtk.NewCheckButton()
|
||||
|
||||
jid_entry.SetHAlign(gtk.AlignEnd)
|
||||
jid_entry.SetHExpand(true)
|
||||
@@ -725,8 +751,14 @@ func activate(app *gtk.Application) {
|
||||
nick_box.Append(gtk.NewLabel("Nick:"))
|
||||
nick_box.Append(nick_entry)
|
||||
|
||||
disco_check.SetActive(true)
|
||||
disco_box.Append(gtk.NewLabel("Check MUC features before joining"))
|
||||
disco_box.Append(disco_check)
|
||||
disco_box.SetTooltipText("If you are creating a MUC through this window then turn this off")
|
||||
|
||||
box.Append(jid_box)
|
||||
box.Append(nick_box)
|
||||
box.Append(disco_box)
|
||||
|
||||
btn := gtk.NewButtonWithLabel("Submit")
|
||||
btn.SetVAlign(gtk.AlignBaseline)
|
||||
@@ -742,14 +774,14 @@ func activate(app *gtk.Application) {
|
||||
btn.ConnectClicked(func() {
|
||||
t := jid_entry.Text()
|
||||
_, ok := tabs.Load(t)
|
||||
jm := func() {
|
||||
|
||||
err := joinMuc(client, clientroot.Session.BindJid, t, nick_entry.Text())
|
||||
jm := func(n string, pw string) {
|
||||
err := joinMuc(client, clientroot.Session.BindJid, t, nick_entry.Text(), pw)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
showErrorDialog(err)
|
||||
return
|
||||
}
|
||||
|
||||
createTab(t, true)
|
||||
createTab(t, true, n)
|
||||
b := gtk.NewLabel(t)
|
||||
gesture1 := gtk.NewGestureClick()
|
||||
gesture1.SetButton(1)
|
||||
@@ -761,7 +793,14 @@ func activate(app *gtk.Application) {
|
||||
menu.Append(b)
|
||||
}
|
||||
if !ok {
|
||||
// First check the MUC's disco and see if it's semianon
|
||||
|
||||
if !disco_check.Active() {
|
||||
jm(t, "")
|
||||
win.SetVisible(false)
|
||||
return
|
||||
}
|
||||
|
||||
var res *stanza.DiscoInfo
|
||||
allowed := true
|
||||
fmt.Println("Attempting to get Disco info")
|
||||
|
||||
@@ -783,55 +822,137 @@ func activate(app *gtk.Application) {
|
||||
mychan, err := client.SendIQ(ctx, myIQ)
|
||||
if err == nil {
|
||||
result := <-mychan
|
||||
res, ok := result.Payload.(*stanza.DiscoInfo)
|
||||
res, ok = result.Payload.(*stanza.DiscoInfo)
|
||||
if ok {
|
||||
semianon := false
|
||||
features := res.Features
|
||||
allowed = false
|
||||
password_protected := false
|
||||
password := ""
|
||||
warning_win := gtk.NewWindow()
|
||||
warning_win.SetTitle(fmt.Sprintf("Joining %s", res.Identity[0].Name))
|
||||
warning_win.SetDefaultSize(400, 400)
|
||||
warning_win.SetResizable(false)
|
||||
|
||||
buttons := gtk.NewBox(gtk.OrientationHorizontal, 0)
|
||||
join_button := gtk.NewButtonWithLabel("Join")
|
||||
join_button.ConnectClicked(func() {
|
||||
warning_win.SetVisible(false)
|
||||
if password_protected {
|
||||
allowed = false
|
||||
|
||||
password_win := gtk.NewWindow()
|
||||
password_win.SetTitle("Password required")
|
||||
password_win.SetDefaultSize(400, 1)
|
||||
password_win.SetResizable(false)
|
||||
box := gtk.NewBox(gtk.OrientationVertical, 0)
|
||||
en := gtk.NewEntry()
|
||||
en.SetPlaceholderText("Password")
|
||||
submit := gtk.NewButtonWithLabel("Submit")
|
||||
submit.ConnectClicked(func() {
|
||||
password = en.Text()
|
||||
jm(res.Identity[0].Name, password)
|
||||
password_win.SetVisible(false)
|
||||
})
|
||||
box.Append(en)
|
||||
box.Append(submit)
|
||||
password_win.SetChild(box)
|
||||
password_win.SetVisible(true)
|
||||
}
|
||||
|
||||
jm(res.Identity[0].Name, password)
|
||||
})
|
||||
|
||||
cancel_button := gtk.NewButtonWithLabel("Cancel")
|
||||
cancel_button.ConnectClicked(func() {
|
||||
warning_win.SetVisible(false)
|
||||
})
|
||||
|
||||
buttons.Append(join_button)
|
||||
buttons.Append(cancel_button)
|
||||
warning_box := gtk.NewBox(gtk.OrientationVertical, 0)
|
||||
header := gtk.NewLabel(res.Identity[0].Name)
|
||||
warning_box.Append(header)
|
||||
for _, feature := range features {
|
||||
if feature.Var == "muc_nonanonymous" {
|
||||
semianon = false
|
||||
break
|
||||
} else if feature.Var == "muc_semianonymous" {
|
||||
semianon = true
|
||||
break
|
||||
switch feature.Var {
|
||||
case "muc_passwordprotected":
|
||||
password_protected = true
|
||||
box := gtk.NewBox(gtk.OrientationHorizontal, 0)
|
||||
box.Append(gtk.NewImageFromPaintable(clientAssets["muc_passwordprotected"]))
|
||||
box.Append(gtk.NewLabel("This MUC is password-protected"))
|
||||
warning_box.Append(box)
|
||||
case "muc_unsecured":
|
||||
box := gtk.NewBox(gtk.OrientationHorizontal, 0)
|
||||
box.Append(gtk.NewImageFromPaintable(clientAssets["muc_unsecured"]))
|
||||
box.Append(gtk.NewLabel("This MUC does not require a password"))
|
||||
warning_box.Append(box)
|
||||
case "muc_membersonly":
|
||||
box := gtk.NewBox(gtk.OrientationHorizontal, 0)
|
||||
box.Append(gtk.NewImageFromPaintable(clientAssets["muc_membersonly"]))
|
||||
box.Append(gtk.NewLabel("Only members can join this MUC"))
|
||||
warning_box.Append(box)
|
||||
case "muc_open":
|
||||
box := gtk.NewBox(gtk.OrientationHorizontal, 0)
|
||||
box.Append(gtk.NewImageFromPaintable(clientAssets["muc_open"]))
|
||||
box.Append(gtk.NewLabel("Anyone can join this MUC"))
|
||||
warning_box.Append(box)
|
||||
case "muc_moderated":
|
||||
box := gtk.NewBox(gtk.OrientationHorizontal, 0)
|
||||
box.Append(gtk.NewImageFromPaintable(clientAssets["muc_moderated"]))
|
||||
box.Append(gtk.NewLabel("Only members can speak in this MUC"))
|
||||
warning_box.Append(box)
|
||||
case "muc_unmoderated":
|
||||
box := gtk.NewBox(gtk.OrientationHorizontal, 0)
|
||||
box.Append(gtk.NewImageFromPaintable(clientAssets["muc_unmoderated"]))
|
||||
box.Append(gtk.NewLabel("Anyone can speak in this MUC"))
|
||||
warning_box.Append(box)
|
||||
case "muc_nonanonymous":
|
||||
box := gtk.NewBox(gtk.OrientationHorizontal, 0)
|
||||
box.Append(gtk.NewImageFromPaintable(clientAssets["muc_nonanonymous"]))
|
||||
box.Append(gtk.NewLabel("This MUC is non-anonymous, your JID will be visible to other users"))
|
||||
warning_box.Append(box)
|
||||
case "muc_semianonymous":
|
||||
box := gtk.NewBox(gtk.OrientationHorizontal, 0)
|
||||
box.Append(gtk.NewImageFromPaintable(clientAssets["muc_semianonymous"]))
|
||||
box.Append(gtk.NewLabel("This MUC is semi-anonymous, only moderators will see your full JID"))
|
||||
warning_box.Append(box)
|
||||
case "muc_persistent":
|
||||
box := gtk.NewBox(gtk.OrientationHorizontal, 0)
|
||||
box.Append(gtk.NewImageFromPaintable(clientAssets["muc_persistent"]))
|
||||
box.Append(gtk.NewLabel("This MUC is persistent, it will not be deleted when the last user leaves"))
|
||||
warning_box.Append(box)
|
||||
case "muc_temporary":
|
||||
box := gtk.NewBox(gtk.OrientationHorizontal, 0)
|
||||
box.Append(gtk.NewImageFromPaintable(clientAssets["muc_temporary"]))
|
||||
box.Append(gtk.NewLabel("This MUC is temporary, it will be deleted when the last user leaves"))
|
||||
warning_box.Append(box)
|
||||
case "muc_public":
|
||||
box := gtk.NewBox(gtk.OrientationHorizontal, 0)
|
||||
box.Append(gtk.NewImageFromPaintable(clientAssets["muc_public"]))
|
||||
box.Append(gtk.NewLabel("This MUC can be found in directories and search engines"))
|
||||
warning_box.Append(box)
|
||||
case "muc_hidden":
|
||||
box := gtk.NewBox(gtk.OrientationHorizontal, 0)
|
||||
box.Append(gtk.NewImageFromPaintable(clientAssets["muc_hidden"]))
|
||||
box.Append(gtk.NewLabel("This MUC is hidden and cannot be found in directories or search engines"))
|
||||
warning_box.Append(box)
|
||||
}
|
||||
}
|
||||
|
||||
if !semianon {
|
||||
allowed = false
|
||||
warning_win := gtk.NewWindow()
|
||||
warning_win.SetTitle("Warning")
|
||||
warning_win.SetDefaultSize(400, 400)
|
||||
warning_win.SetResizable(false)
|
||||
|
||||
warning_box := gtk.NewBox(gtk.OrientationVertical, 0)
|
||||
warning_label := gtk.NewLabel("This muc is not semi-anonymous. Your JID will be revealed to non-moderators if you join. Continue?")
|
||||
|
||||
buttons := gtk.NewBox(gtk.OrientationHorizontal, 0)
|
||||
join_button := gtk.NewButtonWithLabel("Join")
|
||||
join_button.ConnectClicked(func() {
|
||||
warning_win.SetVisible(false)
|
||||
jm()
|
||||
})
|
||||
|
||||
cancel_button := gtk.NewButtonWithLabel("Cancel")
|
||||
cancel_button.ConnectClicked(func() {
|
||||
warning_win.SetVisible(false)
|
||||
})
|
||||
|
||||
buttons.Append(join_button)
|
||||
buttons.Append(cancel_button)
|
||||
|
||||
warning_box.Append(warning_label)
|
||||
warning_box.Append(buttons)
|
||||
warning_win.SetChild(warning_box)
|
||||
warning_win.Present()
|
||||
warning_box.Append(buttons)
|
||||
warning_win.SetChild(warning_box)
|
||||
warning_win.Present()
|
||||
} else {
|
||||
allowed = false
|
||||
if result.Error != nil {
|
||||
showErrorDialog(fmt.Errorf("Failed to get disco info: %s - %s", result.Error.Reason, result.Error.Text))
|
||||
} else {
|
||||
showErrorDialog(fmt.Errorf("Failed to get disco info"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if allowed {
|
||||
jm()
|
||||
jm(res.Identity[0].Name, "")
|
||||
}
|
||||
}
|
||||
win.SetVisible(false)
|
||||
|
||||
Reference in New Issue
Block a user