Add rendering forms to messages, add configuring mucs, add getting muc affiliations, add a bunch of other stuff idk man check the diff

This commit is contained in:
Sunglocto committed 2026-10-11 12:08:38 +01:00
1 parent 7a875f84a5
commit 34b885a770
19 files changed
+706 -101

No files matched your search

+69 -28
View File
@@ -6,19 +6,21 @@ import (
"context"
"encoding/base64"
"fmt"
"github.com/diamondburned/gotk4/pkg/gdk/v4"
"github.com/diamondburned/gotk4/pkg/glib/v2"
"github.com/diamondburned/gotk4/pkg/gtk/v4"
"github.com/google/uuid"
"github.com/jasonlovesdoggo/gopen"
"gosrc.io/xmpp/stanza"
xmpp_color "mellium.im/xmpp/color"
"mellium.im/xmpp/jid"
"os"
"path/filepath"
"runtime"
"strings"
"time"
"github.com/diamondburned/gotk4/pkg/gdk/v4"
"github.com/diamondburned/gotk4/pkg/glib/v2"
"github.com/diamondburned/gotk4/pkg/gtk/v4"
"github.com/google/uuid"
"github.com/jasonlovesdoggo/gopen"
"gosrc.io/xmpp/stanza"
xmpp_color "mellium.im/xmpp/color"
"mellium.im/xmpp/jid"
)
func generatePresenceWidget(p stanza.Packet) gtk.Widgetter {
@@ -102,7 +104,8 @@ func generateMessageWidget(p stanza.Packet, blocked bool, target string) (gtk.Wi
msg.ocu_id = ocu.ID
if sid.ID != "" {
typed_tab.msg_refsOSID[sid.ID] = msg
// typed_tab.msg_refsOSID[sid.ID] = msg
typed_tab.msg_refsOSID.Store(sid.ID, msg)
}
}
@@ -241,6 +244,7 @@ func generateMessageWidget(p stanza.Packet, blocked bool, target string) (gtk.Wi
live_edit := gtk.NewButtonWithLabel("Live edit")
live_edit.ConnectClicked(func() {
en := gtk.NewEntry()
en.SetText(m.Body)
en.ConnectChanged(func() {
client.SendRaw(fmt.Sprintf("<message id='%s' to='%s' type='%s'><body>%s</body><replace id='%s' xmlns='urn:xmpp:message-correct:0'/></message>",
uuid.NewString(),
@@ -277,7 +281,13 @@ func generateMessageWidget(p stanza.Packet, blocked bool, target string) (gtk.Wi
al := gtk.NewLabel(name)
ycbcr := xmpp_color.String(id, 255, loadedConfig.CVD)
r, g, b, _ := ycbcr.RGBA()
hexcolor := fmt.Sprintf("#%02x%02x%02x", r, g, b)
r = uint32((float32(r) / 65536) * 255)
g = uint32((float32(g) / 65536) * 255)
b = uint32((float32(b) / 65536) * 255)
hexcolor := fmt.Sprintf("#%x%x%x", r, g, b)
fmt.Println(hexcolor)
al.SetMarkup(fmt.Sprintf("<span foreground='%s'>%s</span>", hexcolor, name))
al.SetSelectable(true)
@@ -416,10 +426,19 @@ func generateMessageWidget(p stanza.Packet, blocked bool, target string) (gtk.Wi
body = XEPToPango(body, false)
mlabel := gtk.NewLabel("")
if m.Body == "" {
form := new(stanza.Form)
contains_form := m.Get(form)
if m.Body == "" && m.Subject == "" && !contains_form {
return nil, false
}
if m.Body == "" {
mlabel.SetText("No body set")
mlabel.AddCSSClass("visitor")
}
mlabel.SetMarkup(body)
mlabel.SetWrap(true)
mlabel.SetSelectable(true)
@@ -469,27 +488,49 @@ func generateMessageWidget(p stanza.Packet, blocked bool, target string) (gtk.Wi
mainBox.Append(lp_box)
}
if contains_form {
btn := gtk.NewButtonWithLabel(fmt.Sprintf("Open attached form - %s", form.Title))
btn.ConnectClicked(func() {
f, w, _ := showFormDialog(*form)
w.ConnectCloseRequest(func() (ok bool) {
go func() {
form_reply := stanza.NewMessage(stanza.Attrs{
Type: m.Type,
Id: m.Id,
To: m.From,
})
form_reply.Extensions = []stanza.MsgExtension{f}
client.Send(form_reply)
}()
return false
})
})
mainBox.Append(btn)
}
}
if loadedConfig.BlockingMode == Highlight && blocked {
mainBox.AddCSSClass("blocked")
}
if blocked {
switch loadedConfig.BlockingMode {
case Highlight:
mainBox.AddCSSClass("blocked")
case Hide:
mainBox.SetVisible(false)
blocked_box := gtk.NewBox(gtk.OrientationVertical, 0)
blocked_part := gtk.NewBox(gtk.OrientationHorizontal, 0)
blocked_part.Append(gtk.NewLabel("This message is from a user you have blocked. "))
if loadedConfig.BlockingMode == Hide && blocked {
mainBox.SetVisible(false)
blocked_box := gtk.NewBox(gtk.OrientationVertical, 0)
blocked_part := gtk.NewBox(gtk.OrientationHorizontal, 0)
blocked_part.Append(gtk.NewLabel("This message is from a user you have blocked. "))
show_hide := gtk.NewButtonWithLabel("Toggle")
show_hide.ConnectClicked(func() {
mainBox.SetVisible(!mainBox.IsVisible())
})
show_hide := gtk.NewButtonWithLabel("Toggle")
show_hide.ConnectClicked(func() {
mainBox.SetVisible(!mainBox.IsVisible())
})
blocked_part.Append(show_hide)
blocked_box.Append(blocked_part)
blocked_box.Append(mainBox)
return blocked_box, true
blocked_part.Append(show_hide)
blocked_box.Append(blocked_part)
blocked_box.Append(mainBox)
return blocked_box, true
}
}
return mainBox, true