great reset

This commit is contained in:
2025-08-03 11:14:53 +01:00
parent 9706336a35
commit e013202e65
2 changed files with 1 additions and 216 deletions

44
go.mod
View File

@@ -1,45 +1,3 @@
module xmpptest2
module pi
go 1.24.5
require (
fyne.io/fyne/v2 v2.6.2
gosrc.io/xmpp v0.5.1
)
require (
fyne.io/systray v1.11.0 // indirect
github.com/BurntSushi/toml v1.4.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fredbi/uri v1.1.0 // indirect
github.com/fsnotify/fsnotify v1.9.0 // indirect
github.com/fyne-io/gl-js v0.2.0 // indirect
github.com/fyne-io/glfw-js v0.3.0 // indirect
github.com/fyne-io/image v0.1.1 // indirect
github.com/fyne-io/oksvg v0.1.0 // indirect
github.com/go-gl/gl v0.0.0-20231021071112-07e5d0ea2e71 // indirect
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a // indirect
github.com/go-text/render v0.2.0 // indirect
github.com/go-text/typesetting v0.2.1 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/google/uuid v1.1.1 // indirect
github.com/hack-pad/go-indexeddb v0.3.2 // indirect
github.com/hack-pad/safejs v0.1.0 // indirect
github.com/jeandeaual/go-locale v0.0.0-20250612000132-0ef82f21eade // indirect
github.com/jsummers/gobmp v0.0.0-20230614200233-a9de23ed2e25 // indirect
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
github.com/nicksnyder/go-i18n/v2 v2.5.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rymdport/portal v0.4.1 // indirect
github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c // indirect
github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef // indirect
github.com/stretchr/testify v1.10.0 // indirect
github.com/yuin/goldmark v1.7.8 // indirect
golang.org/x/image v0.24.0 // indirect
golang.org/x/net v0.35.0 // indirect
golang.org/x/sys v0.30.0 // indirect
golang.org/x/text v0.22.0 // indirect
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
nhooyr.io/websocket v1.6.5 // indirect
)

173
main.go
View File

@@ -1,173 +0,0 @@
package main
import (
"fmt"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
"gosrc.io/xmpp"
"gosrc.io/xmpp/stanza"
"log"
"os"
"time"
)
var client xmpp.Sender
type Account struct {
jid string
password string
server string
defaultNick string
Contacts []Chat
}
type Chat struct {
jid string
isMuc bool
nick string
}
type ActiveChat struct {
Chat Chat
Account Account
}
var ActiveChats []ActiveChat
var Accounts []Account
// TODO: LOAD ACCOUNTS FROM FILESYSTEM
func main() {
//createAccountGUI()
myAccount := Account{}
myAccount.jid = "moron@example.com"
myAccount.password = "123456789"
myAccount.defaultNick = "moron"
myAccount.server = "example.com:5222"
Accounts = append(Accounts, myAccount)
a := app.New()
w := a.NewWindow("pi")
w.Resize(fyne.NewSize(500, 400))
acc := Accounts[0]
NewChat := Chat{jid: "someguysmuc@muc.example.com", isMuc: true, nick: myAccount.defaultNick}
acc.Contacts = append(acc.Contacts, NewChat)
ActiveChats = append(ActiveChats, ActiveChat{NewChat, Accounts[0]})
// Chat area
chatLog := widget.NewMultiLineEntry()
chatLog.Wrapping = fyne.TextWrapWord
chatLog.Disable()
// Message entry
msgEntry := widget.NewEntry()
msgEntry.SetPlaceHolder("Type a message...")
// Send button
sendBtn := widget.NewButton("Send", func() {
if client != nil && msgEntry.Text != "" {
var typ stanza.StanzaType
if ActiveChats[0].Chat.isMuc {
typ = stanza.MessageTypeGroupchat
} else {
typ = stanza.MessageTypeChat
}
m := stanza.Message{
Attrs: stanza.Attrs{
To: ActiveChats[0].Chat.jid,
Type: typ, // FIXME: Change to MessageTypeGroupchat if isMuc is set to true
},
Body: msgEntry.Text,
}
client.Send(m)
//msgEntry.SetText("")
}
})
// Connect button
connectBtn := widget.NewButton("Connect", func() {
go func() {
config := xmpp.Config{
TransportConfiguration: xmpp.TransportConfiguration{
Address: ActiveChats[0].Account.server,
},
Jid: Accounts[0].jid,
Credential: xmpp.Password(Accounts[0].password),
StreamLogger: os.Stdout,
Insecure: true,
}
router := xmpp.NewRouter()
router.HandleFunc("message", func(s xmpp.Sender, p stanza.Packet) {
msg, ok := p.(stanza.Message)
if !ok {
return
}
if msg.Type == stanza.MessageTypeChat && msg.Body != "" {
fyne.DoAndWait(func() {
chatLog.SetText(chatLog.Text + fmt.Sprintf("[%s] %s\n", msg.From, msg.Body))
})
}
})
c, err := xmpp.NewClient(&config, router, func(err error) {
log.Println("Error:", err)
})
if err != nil {
chatLog.SetText(chatLog.Text + fmt.Sprintf("❌ Connection failed: %v\n", err))
return
}
client = c
// Join MUC and request MAM history
go func() {
if ActiveChats[0].Chat.isMuc {
time.Sleep(2 * time.Second)
joinPresence := stanza.Presence{
Attrs: stanza.Attrs{
From: ActiveChats[0].Account.jid,
To: fmt.Sprintf("%s/%s", ActiveChats[0].Chat.jid, ActiveChats[0].Chat.nick),
},
Extensions: []stanza.PresExtension{
stanza.MucPresence{},
},
}
client.Send(joinPresence)
chatLog.SetText(chatLog.Text + fmt.Sprintf("✅ Joined %s\n", ActiveChats[0].Chat.jid))
time.Sleep(1 * time.Second)
//requestMAMHistory(client, ActiveChats[0].Chat.jid, chatLog)
}
}()
cm := xmpp.NewStreamManager(c, nil)
cm.Run()
}()
})
// Layout
form := container.NewVBox(
connectBtn,
msgEntry,
chatLog,
sendBtn,
)
w.SetContent(form)
w.ShowAndRun()
}
// requestMAMHistory sends a simple MAM query for the given room.
// FIXME does not work right now, lol
func requestMAMHistory(s xmpp.Sender, roomJID string, chatLog *widget.Entry) {
// Basic MAM query IQ (latest messages)
raw := `
<iq type='set' id='mam1'>
<query xmlns='urn:xmpp:mam:2' queryid='f27'/>
</iq>`
s.SendRaw(raw)
chatLog.SetText(chatLog.Text + "(📜 Requested last 20 messages via MAM)\n")
}