Do not let ebassi see this code

This commit is contained in:
2026-04-28 12:58:00 +01:00
parent fc0ed5ac2c
commit a97c42323c
7 changed files with 323 additions and 426 deletions
+87 -106
View File
@@ -47,10 +47,8 @@ var typingStatus *gtk.Label
var pingStatus *gtk.Label
// var msgs *gtk.ListBox
var content *gtk.Widgetter
// var tabs map[string]*chatTab = make(map[string]*chatTab)
var tabs sync.Map
var current string
@@ -81,7 +79,7 @@ var clientAssets map[string]gdk.Paintabler = make(map[string]gdk.Paintabler)
var xmlLog *os.File
func init() {
beeep.AppName = "Lambda"
beeep.AppName = loadedLocale["appName"]
go func() {
for fn := range uiQueue {
@@ -115,7 +113,7 @@ func main() {
}
if loadedConfig.Resource == "" {
fmt.Println("Config resource is empty! Generating a random one")
fmt.Println(loadedLocale["configResourceEmptyWarning"])
loadedConfig.Resource = randomClientResource()
}
@@ -196,7 +194,7 @@ func main() {
}
v := &stanza.Version{}
v = v.SetInfo("Lambda", lambda_version, runtime.GOOS) // TODO: Allow spoofing on user request
v = v.SetInfo(loadedLocale["appName"], lambda_version, runtime.GOOS) // TODO: Allow spoofing on user request
iqResp.Payload = v
s.Send(iqResp)
@@ -226,7 +224,7 @@ func main() {
at := new(Attention)
ok = m.Get(at)
if ok {
beeep.Notify("Attention", fmt.Sprintf("%s: %s", JidMustParse(m.From).Resource, m.Body), commentBytes) // TODO: Use localpart if DM
beeep.Notify(loadedLocale["attention"], fmt.Sprintf("%s: %s", JidMustParse(m.From).Resource, m.Body), commentBytes) // TODO: Use localpart if DM
}
// Handle mentions
@@ -270,7 +268,7 @@ func main() {
composing := stanza.StateComposing{}
ok = m.Get(&composing)
if ok && current == JidMustParse(m.From).Bare() {
typingStatus.SetText(fmt.Sprintf("%s is typing...", m.From))
typingStatus.SetText(fmt.Sprintf("%s %s", m.From, loadedLocale["isTyping"]))
return
}
@@ -435,7 +433,7 @@ func main() {
})
c, err := xmpp.NewClient(&config, router, func(err error) {
connectionStatus.SetText(fmt.Sprintf("Disconnected: %s", err.Error()))
connectionStatus.SetText(fmt.Sprintf("%s%s", loadedLocale["disconnected"], err.Error()))
connectionIcon.SetFromPaintable(clientAssets["disconnect"])
})
@@ -469,7 +467,7 @@ func main() {
pingStatus.RemoveCSSClass("pending")
delay := time.Since(before) / time.Millisecond
pingStatus.SetText(fmt.Sprintf("%d ms", delay))
pingStatus.SetText(fmt.Sprintf("%d %s", delay, loadedLocale["milliseconds"]))
pingTimes[0] = append(pingTimes[0], float64(delay))
}()
@@ -496,13 +494,13 @@ func main() {
sIcon.SetFromPaintable(clientAssets["car"])
}
sStatus.SetText(fmt.Sprintf("%.2fKB/s", diff))
sStatus.SetText(fmt.Sprintf("%.2f%s", diff, loadedLocale["KBPerSecond"]))
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))
connectionStatus.SetText(fmt.Sprintf("%s%s", loadedLocale["connectedAs"], JidMustParse(clientroot.Session.BindJid).Bare()))
connectionStatus.SetTooltipText(fmt.Sprintf("%s%s\n%s%t", loadedLocale["bindedJid"], clientroot.Session.BindJid, loadedLocale["usingTLS"], clientroot.Session.TlsEnabled))
connectionIcon.SetFromPaintable(clientAssets["connect"])
// Enable carbons
client.SendRaw(fmt.Sprintf(
@@ -593,13 +591,13 @@ func main() {
conc := func() {
time.Sleep(3 * time.Second)
connectionStatus.SetText("Connecting...")
connectionStatus.SetText(loadedLocale["connecting"])
connectionIcon.SetFromPaintable(clientAssets["hourglass"])
err = cm.Run()
if err != nil {
fmt.Println(err.Error())
connectionStatus.SetText(fmt.Sprintf("Disconnected: %s", err.Error()))
connectionStatus.SetText(fmt.Sprintf("%s%s", loadedLocale["disconnected"], err.Error()))
connectionIcon.SetFromPaintable(clientAssets["disconnect"])
}
}
@@ -626,9 +624,9 @@ func activate(app *gtk.Application) {
the_menu := gio.NewMenu()
fileMenu := gio.NewMenu()
fileMenu.Append("Join MUC", "app.join")
fileMenu.Append("Start DM", "app.dm")
fileMenu.Append("Destroy MUC", "app.destroymuc")
fileMenu.Append(loadedLocale["joinMUCMenu"], "app.join")
fileMenu.Append(loadedLocale["startDMMenu"], "app.dm")
fileMenu.Append(loadedLocale["destroyMUCMenu"], "app.destroymuc")
helpMenu := gio.NewMenu()
helpMenu.Append("About", "app.about")
@@ -646,24 +644,24 @@ func activate(app *gtk.Application) {
cur := cur.(*chatTab)
if cur.isMuc {
win := gtk.NewWindow()
win.SetTitle("Destroy MUC")
win.SetTitle(loadedLocale["destroyMUCMenu"])
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")
box := gtk.NewBox(gtk.OrientationVertical, 10)
box.Append(gtk.NewLabel(loadedLocale["destroyMUCWarningOne"]))
box.Append(gtk.NewLabel(loadedLocale["destroyMUCWarningTwo"]))
cancel := gtk.NewButtonWithLabel(loadedLocale["cancel"])
cancel.ConnectClicked(func() {
win.SetVisible(false)
})
en := gtk.NewEntry()
en.SetPlaceholderText("...")
submit := gtk.NewButtonWithLabel("Destroy")
submit := gtk.NewButtonWithLabel(loadedLocale["destroyMUCActionButton"])
submit.ConnectClicked(func() {
fmt.Println(en.Text())
if en.Text() == "I understand" {
if en.Text() == loadedLocale["destroyMUCPassword"] {
cur, ok := tabs.Load(current)
if ok {
cur := cur.(*chatTab)
@@ -675,11 +673,11 @@ func activate(app *gtk.Application) {
type='set'>
<query xmlns='http://jabber.org/protocol/muc#owner'>
<destroy jid='%s'>
<reason>User requested</reason>
<reason>%s</reason>
</destroy>
</query>
</iq>
`, clientroot.Session.BindJid, current, JidMustParse(clientroot.Session.BindJid).Bare()))
`, clientroot.Session.BindJid, current, JidMustParse(clientroot.Session.BindJid).Bare(), loadedLocale["userRequested"]))
}
}
win.SetVisible(false)
@@ -702,7 +700,7 @@ func activate(app *gtk.Application) {
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"))
box.Append(gtk.NewLabel(loadedLocale["destroyMUCNotOwnerWarning"]))
}
// return false
}
@@ -728,10 +726,10 @@ func activate(app *gtk.Application) {
joinAction := gio.NewSimpleAction("join", nil)
joinAction.ConnectActivate(func(p *glib.Variant) {
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)
box := gtk.NewBox(gtk.OrientationVertical, 10)
jid_box := gtk.NewBox(gtk.OrientationHorizontal, 10)
nick_box := gtk.NewBox(gtk.OrientationHorizontal, 10)
disco_box := gtk.NewBox(gtk.OrientationHorizontal, 10)
jid_entry := gtk.NewEntry()
nick_entry := gtk.NewEntry()
@@ -745,28 +743,28 @@ func activate(app *gtk.Application) {
nick_entry.SetText(loadedConfig.Nick)
jid_box.Append(gtk.NewLabel("MUC JID:"))
jid_box.Append(gtk.NewLabel(loadedLocale["joinMUCJIDEntry"]))
jid_box.Append(jid_entry)
nick_box.Append(gtk.NewLabel("Nick:"))
nick_box.Append(gtk.NewLabel(loadedLocale["joinMUCNickEntry"]))
nick_box.Append(nick_entry)
disco_check.SetActive(true)
disco_box.Append(gtk.NewLabel("Check MUC features before joining"))
disco_box.Append(gtk.NewLabel(loadedLocale["joinMUCDiscoCheck"]))
disco_box.Append(disco_check)
disco_box.SetTooltipText("If you are creating a MUC through this window then turn this off")
disco_box.SetTooltipText(loadedLocale["joinMUCDiscoCheckTooltip"])
box.Append(jid_box)
box.Append(nick_box)
box.Append(disco_box)
btn := gtk.NewButtonWithLabel("Submit")
btn := gtk.NewButtonWithLabel(loadedLocale["submit"])
btn.SetVAlign(gtk.AlignBaseline)
box.Append(btn)
win := gtk.NewWindow()
win.SetTitle("Join MUC")
win.SetTitle(loadedLocale["joinMUCMenu"])
win.SetDefaultSize(400, 1)
win.SetResizable(false)
win.SetChild(box)
@@ -829,11 +827,12 @@ func activate(app *gtk.Application) {
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.SetTitle(fmt.Sprintf("%s%s", loadedLocale["joinPreviewTitle"], res.Identity[0].Name))
warning_win.SetDefaultSize(400, 1)
warning_win.SetResizable(false)
buttons := gtk.NewBox(gtk.OrientationHorizontal, 0)
buttons := gtk.NewBox(gtk.OrientationHorizontal, 10)
join_button := gtk.NewButtonWithLabel("Join")
join_button.ConnectClicked(func() {
warning_win.SetVisible(false)
@@ -841,13 +840,12 @@ func activate(app *gtk.Application) {
allowed = false
password_win := gtk.NewWindow()
password_win.SetTitle("Password required")
password_win.SetTitle(loadedLocale["joinPasswordRequired"])
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")
box := gtk.NewBox(gtk.OrientationVertical, 10)
en := gtk.NewPasswordEntry()
submit := gtk.NewButtonWithLabel(loadedLocale["submit"])
submit.ConnectClicked(func() {
password = en.Text()
jm(res.Identity[0].Name, password)
@@ -862,79 +860,62 @@ func activate(app *gtk.Application) {
jm(res.Identity[0].Name, password)
})
cancel_button := gtk.NewButtonWithLabel("Cancel")
cancel_button := gtk.NewButtonWithLabel(loadedLocale["cancel"])
cancel_button.ConnectClicked(func() {
warning_win.SetVisible(false)
})
join_button.SetHExpand(true)
cancel_button.SetHExpand(true)
buttons.Append(join_button)
buttons.Append(cancel_button)
warning_box := gtk.NewBox(gtk.OrientationVertical, 0)
warning_box := gtk.NewBox(gtk.OrientationVertical, 10)
header := gtk.NewLabel(res.Identity[0].Name)
warning_box.Append(header)
addFeature := func(icon string, description string) {
box := gtk.NewBox(gtk.OrientationHorizontal, 10)
box.Append(gtk.NewImageFromPaintable(clientAssets[icon]))
box.Append(gtk.NewLabel(description))
warning_box.Append(box)
}
for _, feature := range features {
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)
addFeature("muc_passwordprotected", loadedLocale["muc_passwordprotected_description"])
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)
addFeature("muc_unsecured", loadedLocale["muc_unsecured_description"])
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)
addFeature("muc_membersonly", loadedLocale["muc_membersonly_description"])
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)
addFeature("muc_open", loadedLocale["muc_open_description"])
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)
addFeature("muc_moderated", loadedLocale["muc_moderated_description"])
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)
addFeature("muc_unmoderated", loadedLocale["muc_unmoderated_description"])
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)
addFeature("muc_nonanonymous", loadedLocale["muc_nonanonymous_description"])
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)
addFeature("muc_semianonymous", loadedLocale["muc_semianonymous_description"])
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)
addFeature("muc_persistent", loadedLocale["muc_persistent_description"])
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)
addFeature("muc_temporary", loadedLocale["muc_temporary_description"])
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)
addFeature("muc_public", loadedLocale["muc_public_description"])
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)
addFeature("muc_hidden", loadedLocale["muc_hidden_description"])
case "urn:xmpp:mam:0":
addFeature("ok", loadedLocale["urn:xmpp:mam_description"])
case "urn:xmpp:message-moderate:0":
addFeature("moderate", loadedLocale["urn:xmpp:message-moderate_description"])
/*
default:
addFeature("comment", feature.Var)
*/
}
}
@@ -944,9 +925,9 @@ func activate(app *gtk.Application) {
} else {
allowed = false
if result.Error != nil {
showErrorDialog(fmt.Errorf("Failed to get disco info: %s - %s", result.Error.Reason, result.Error.Text))
showErrorDialog(fmt.Errorf("%s: %s - %s", loadedLocale["discoFail"], result.Error.Reason, result.Error.Text))
} else {
showErrorDialog(fmt.Errorf("Failed to get disco info"))
showErrorDialog(fmt.Errorf(loadedLocale["discoFail"]))
}
}
}
@@ -995,7 +976,7 @@ func activate(app *gtk.Application) {
cBox := gtk.NewBox(gtk.OrientationHorizontal, 0)
connectionIcon = gtk.NewImageFromPaintable((clientAssets["disconnect"]))
connectionIcon.AddCSSClass("icon")
connectionStatus = gtk.NewLabel("Disconnected")
connectionStatus = gtk.NewLabel(loadedLocale["disconnected"])
cBox.Append(connectionIcon)
cBox.Append(connectionStatus)
@@ -1022,13 +1003,13 @@ func activate(app *gtk.Application) {
statBar.Append(mBox)
pBox := gtk.NewBox(gtk.OrientationHorizontal, 0)
pBox.SetTooltipText("Ping between you and your XMPP server\nRight-click to see graph")
pBox.SetTooltipText(loadedLocale["pingBarTooltip"])
gesture := gtk.NewGestureClick()
gesture.SetButton(3)
gesture.Connect("pressed", func() {
opt := charts.NewLineChartOptionWithData(pingTimes)
opt.Title = charts.TitleOption{
Text: "Server latency",
Text: loadedLocale["pingGraphTitle"],
}
/*
opt.XAxis.Labels = []string{
@@ -1037,7 +1018,7 @@ func activate(app *gtk.Application) {
}*/
opt.Legend = charts.LegendOption{
SeriesNames: []string{
"Ping (ms)",
loadedLocale["pingGraphYAxis"],
},
}
@@ -1064,7 +1045,7 @@ func activate(app *gtk.Application) {
i := gtk.NewPictureForPaintable(gdk.NewTextureForPixbuf(loader.Pixbuf()))
win := gtk.NewWindow()
win.SetDefaultSize(600, 400)
win.SetTitle("Server latency")
win.SetTitle(loadedLocale["pingGraphTitle"])
box := gtk.NewBox(gtk.OrientationVertical, 0)
box.Append(i)
win.SetChild(box)
@@ -1085,7 +1066,7 @@ func activate(app *gtk.Application) {
sStatus = gtk.NewLabel("-")
sBox.Append(sIcon)
sBox.Append(sStatus)
sStatus.SetTooltipText("Throughput of your XMPP connection in KB/s")
sStatus.SetTooltipText(loadedLocale["throughputTooltip"])
statBar.Append(sBox)
scrollerStatBar := gtk.NewScrolledWindow()
@@ -1118,11 +1099,11 @@ func activate(app *gtk.Application) {
entry_box := gtk.NewBox(gtk.OrientationHorizontal, 0)
oob_en := gtk.NewEntry()
oob_en.SetPlaceholderText("Embed URL")
oob_en.SetPlaceholderText("URL")
message_en = gtk.NewEntry()
message_en.SetPlaceholderText("Say something, what else are you gonna do here?")
b := gtk.NewButtonWithLabel("Send")
message_en.SetPlaceholderText(loadedLocale["messageEntryPlaceholder"])
b := gtk.NewButtonWithLabel(loadedLocale["send"])
sendtxt := func() {
t := message_en.Text()