Attention and experimental mentions impl
This commit is contained in:
88
main.go
88
main.go
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/diamondburned/gotk4/pkg/gtk/v4"
|
||||
"github.com/gen2brain/beeep"
|
||||
"github.com/go-analyze/charts"
|
||||
"golang.org/x/net/html/charset"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
@@ -25,6 +26,7 @@ import (
|
||||
"encoding/xml"
|
||||
"github.com/kr/pretty"
|
||||
"runtime"
|
||||
"io"
|
||||
)
|
||||
|
||||
var loadedConfig lambdaConfig
|
||||
@@ -49,6 +51,7 @@ var current string
|
||||
var scroller *gtk.ScrolledWindow
|
||||
var memberList *gtk.ScrolledWindow
|
||||
var menu *gtk.Box
|
||||
var message_en *gtk.Entry
|
||||
|
||||
//go:embed style.css
|
||||
var styleCSS string
|
||||
@@ -111,10 +114,13 @@ func main() {
|
||||
config := xmpp.Config{
|
||||
TransportConfiguration: xmpp.TransportConfiguration{
|
||||
Address: loadedConfig.Server,
|
||||
CharsetReader: func(c string, input io.Reader) (io.Reader, error) {
|
||||
return charset.NewReaderLabel(c, input)
|
||||
},
|
||||
},
|
||||
Jid: loadedConfig.Username + "/" + loadedConfig.Resource,
|
||||
Credential: xmpp.Password(loadedConfig.Password),
|
||||
Insecure: loadedConfig.Insecure,
|
||||
Jid: loadedConfig.Username + "/" + loadedConfig.Resource,
|
||||
Credential: xmpp.Password(loadedConfig.Password),
|
||||
Insecure: loadedConfig.Insecure,
|
||||
// StreamLogger: os.Stdout,
|
||||
StreamManagementEnable: true,
|
||||
}
|
||||
@@ -149,6 +155,7 @@ func main() {
|
||||
{Var: "urn:xmpp:delegation:1"},
|
||||
{Var: "http://jabber.org/protocol/muc"},
|
||||
{Var: "λ"},
|
||||
{Var: "urn:xmpp:attention:0"},
|
||||
},
|
||||
}
|
||||
iqResp.Payload = &payload
|
||||
@@ -197,11 +204,49 @@ func main() {
|
||||
originator := JidMustParse(m.From).Bare()
|
||||
mStatus.SetText(originator)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
sc := new(SentCarbon)
|
||||
ok = m.Get(sc)
|
||||
if ok {
|
||||
fm, ok := sc.Forwarded.Stanza.(stanza.Message)
|
||||
if ok {
|
||||
if JidMustParse(fm.From).Bare() == JidMustParse(m.From).Bare() {
|
||||
p = sc.Forwarded.Stanza
|
||||
m = sc.Forwarded.Stanza.(stanza.Message)
|
||||
} else {
|
||||
panic(fmt.Sprintln("Impersonation: ", fm.From, m.From))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rc := new(SentCarbon)
|
||||
ok = m.Get(rc)
|
||||
if ok {
|
||||
fm, ok := rc.Forwarded.Stanza.(stanza.Message)
|
||||
if ok {
|
||||
if JidMustParse(fm.From).Bare() == JidMustParse(m.From).Bare() {
|
||||
p = rc.Forwarded.Stanza
|
||||
m = rc.Forwarded.Stanza.(stanza.Message)
|
||||
} else {
|
||||
panic(fmt.Sprintln("Impersonation: ", fm.From, m.From))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
glib.IdleAdd(func() {
|
||||
//uiQueue <- func() {
|
||||
b := gtk.NewBox(gtk.OrientationVertical, 0)
|
||||
|
||||
tab, ok := tabs.Load(originator)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
typed_tab := tab.(*chatTab)
|
||||
|
||||
if ok {
|
||||
@@ -383,6 +428,16 @@ func main() {
|
||||
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"])
|
||||
// Enable carbons
|
||||
client.SendRaw(fmt.Sprintf(
|
||||
`<iq xmlns='jabber:client'
|
||||
from='%s'
|
||||
id='enable1'
|
||||
type='set'>
|
||||
<enable xmlns='urn:xmpp:carbons:2'/>
|
||||
</iq>
|
||||
`, clientroot.Session.BindJid))
|
||||
|
||||
// Join rooms in bookmarks
|
||||
if loadedConfig.JoinBookmarks {
|
||||
books, err := stanza.NewItemsRequest("", "urn:xmpp:bookmarks:1", 0)
|
||||
@@ -778,12 +833,15 @@ func activate(app *gtk.Application) {
|
||||
|
||||
entry_box := gtk.NewBox(gtk.OrientationHorizontal, 0)
|
||||
|
||||
en := gtk.NewEntry()
|
||||
en.SetPlaceholderText("Say something, what else are you gonna do here?")
|
||||
oob_en := gtk.NewEntry()
|
||||
oob_en.SetPlaceholderText("Embed URL")
|
||||
|
||||
message_en = gtk.NewEntry()
|
||||
message_en.SetPlaceholderText("Say something, what else are you gonna do here?")
|
||||
b := gtk.NewButtonWithLabel("Send")
|
||||
|
||||
sendtxt := func() {
|
||||
t := en.Text()
|
||||
t := message_en.Text()
|
||||
if t == "" {
|
||||
dialog := >k.AlertDialog{}
|
||||
dialog.SetDetail("detail")
|
||||
@@ -803,21 +861,29 @@ func activate(app *gtk.Application) {
|
||||
message_type = stanza.MessageTypeGroupchat
|
||||
}
|
||||
|
||||
err := sendMessage(client, current, message_type, t, "", "")
|
||||
exts := []stanza.MsgExtension{}
|
||||
if oob_en.Text() != "" {
|
||||
new_oob := new(stanza.OOB)
|
||||
new_oob.URL = oob_en.Text()
|
||||
exts = append(exts, new_oob)
|
||||
}
|
||||
|
||||
err := sendMessage(client, current, message_type, t, "", "", exts)
|
||||
if err != nil {
|
||||
panic(err) // TODO: Show error message via GTK
|
||||
}
|
||||
en.SetText("")
|
||||
message_en.SetText("")
|
||||
scrollToBottomAfterUpdate(scroller)
|
||||
}
|
||||
|
||||
en.Connect("activate", sendtxt)
|
||||
message_en.Connect("activate", sendtxt)
|
||||
|
||||
b.ConnectClicked(sendtxt)
|
||||
|
||||
en.SetHExpand(true)
|
||||
message_en.SetHExpand(true)
|
||||
|
||||
entry_box.Append(en)
|
||||
entry_box.Append(oob_en)
|
||||
entry_box.Append(message_en)
|
||||
entry_box.Append(b)
|
||||
|
||||
box.Append(entry_box)
|
||||
|
||||
Reference in New Issue
Block a user