General code changes + new pane
This commit is contained in:
67
main.go
67
main.go
@@ -10,6 +10,8 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
// gui - required
|
// gui - required
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
"fyne.io/fyne/v2/app"
|
"fyne.io/fyne/v2/app"
|
||||||
@@ -21,8 +23,11 @@ import (
|
|||||||
"fyne.io/fyne/v2/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
|
|
||||||
// xmpp - required
|
// xmpp - required
|
||||||
|
_ "mellium.im/xmlstream"
|
||||||
|
_ "mellium.im/xmpp"
|
||||||
"mellium.im/xmpp/jid"
|
"mellium.im/xmpp/jid"
|
||||||
"mellium.im/xmpp/muc"
|
"mellium.im/xmpp/muc"
|
||||||
|
_ "mellium.im/xmpp/stanza"
|
||||||
oasisSdk "pain.agency/oasis-sdk"
|
oasisSdk "pain.agency/oasis-sdk"
|
||||||
|
|
||||||
// gui - optional
|
// gui - optional
|
||||||
@@ -34,6 +39,8 @@ import (
|
|||||||
var version string = "3.1a"
|
var version string = "3.1a"
|
||||||
var statBar widget.Label
|
var statBar widget.Label
|
||||||
var chatInfo fyne.Container
|
var chatInfo fyne.Container
|
||||||
|
var chatSidebar fyne.Container
|
||||||
|
|
||||||
// by sunglocto
|
// by sunglocto
|
||||||
// license AGPL
|
// license AGPL
|
||||||
|
|
||||||
@@ -180,6 +187,8 @@ func addChatTab(isMuc bool, chatJid jid.JID, nick string) {
|
|||||||
selectedId = id
|
selectedId = id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scroller.CreateItem()
|
||||||
|
|
||||||
tabData.Scroller = scroller
|
tabData.Scroller = scroller
|
||||||
|
|
||||||
chatTabs[mucJidStr] = tabData
|
chatTabs[mucJidStr] = tabData
|
||||||
@@ -254,7 +263,7 @@ func dropToSignInPage(reason string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
muc.Since(time.Now())
|
||||||
config = piConfig{}
|
config = piConfig{}
|
||||||
|
|
||||||
bytes, err := os.ReadFile("./pi.xml")
|
bytes, err := os.ReadFile("./pi.xml")
|
||||||
@@ -328,12 +337,21 @@ func main() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
func(client *oasisSdk.XmppClient, muc *muc.Channel, msg *oasisSdk.XMPPChatMessage) {
|
func(client *oasisSdk.XmppClient, muc *muc.Channel, msg *oasisSdk.XMPPChatMessage) {
|
||||||
|
// HACK: IGNORING ALL MESSAGES FROM CLASSIC MUC HISTORY IN PREPARATION OF MAM SUPPORT
|
||||||
|
ignore := false
|
||||||
|
for _, v := range msg.Unknown {
|
||||||
|
if v.XMLName.Local == "delay" { // CLasic history message
|
||||||
|
ignore = true
|
||||||
|
fmt.Println("ignoring!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var ImageID string = ""
|
var ImageID string = ""
|
||||||
mucJidStr := msg.From.Bare().String()
|
mucJidStr := msg.From.Bare().String()
|
||||||
if tab, ok := chatTabs[mucJidStr]; ok {
|
if tab, ok := chatTabs[mucJidStr]; ok {
|
||||||
chatTabs[mucJidStr].Muc = muc
|
chatTabs[mucJidStr].Muc = muc
|
||||||
str := *msg.CleanedBody
|
str := *msg.CleanedBody
|
||||||
if notifications {
|
if !ignore && notifications {
|
||||||
if strings.Contains(str, login.DisplayName) || (msg.Reply != nil && strings.Contains(msg.Reply.To, login.DisplayName)) {
|
if strings.Contains(str, login.DisplayName) || (msg.Reply != nil && strings.Contains(msg.Reply.To, login.DisplayName)) {
|
||||||
a.SendNotification(fyne.NewNotification(fmt.Sprintf("Mentioned in %s", mucJidStr), str))
|
a.SendNotification(fyne.NewNotification(fmt.Sprintf("Mentioned in %s", mucJidStr), str))
|
||||||
}
|
}
|
||||||
@@ -371,7 +389,9 @@ func main() {
|
|||||||
Raw: *msg,
|
Raw: *msg,
|
||||||
ImageURL: ImageID,
|
ImageURL: ImageID,
|
||||||
}
|
}
|
||||||
tab.Messages = append(tab.Messages, myMessage)
|
if !ignore {
|
||||||
|
tab.Messages = append(tab.Messages, myMessage)
|
||||||
|
}
|
||||||
fyne.Do(func() {
|
fyne.Do(func() {
|
||||||
tab.Scroller.Refresh()
|
tab.Scroller.Refresh()
|
||||||
if scrollDownOnNewMessage {
|
if scrollDownOnNewMessage {
|
||||||
@@ -420,6 +440,29 @@ func main() {
|
|||||||
log.Fatalln("Could not create client - " + err.Error())
|
log.Fatalln("Could not create client - " + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
client.Session.Serve(xmpp.HandlerFunc(func(t xmlstream.TokenReadEncoder, start *xml.StartElement) error {
|
||||||
|
d := xml.NewTokenDecoder(t)
|
||||||
|
|
||||||
|
// Ignore anything that's not a message.
|
||||||
|
if start.Name.Local != "message" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
msg := struct {
|
||||||
|
stanza.Message
|
||||||
|
Body string `xml:"body"`
|
||||||
|
}{}
|
||||||
|
err := d.DecodeElement(&msg, start)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if msg.Body != "" {
|
||||||
|
log.Println("Got message: %q", msg.Body)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}))
|
||||||
|
*/
|
||||||
go func() {
|
go func() {
|
||||||
for connection {
|
for connection {
|
||||||
err = client.Connect()
|
err = client.Connect()
|
||||||
@@ -437,6 +480,8 @@ func main() {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
a = app.New()
|
a = app.New()
|
||||||
a.Settings().SetTheme(myTheme{})
|
a.Settings().SetTheme(myTheme{})
|
||||||
w = a.NewWindow("pi")
|
w = a.NewWindow("pi")
|
||||||
@@ -585,6 +630,9 @@ func main() {
|
|||||||
}, w)
|
}, w)
|
||||||
})*/
|
})*/
|
||||||
|
|
||||||
|
deb := fyne.NewMenuItem("DEBUG: Attempt to get MAM history from a user", func() {
|
||||||
|
//res, err := history.Fetch(client.Ctx, history.Query{}, jid.MustParse("ringen@muc.isekai.rocks"), client.Session)
|
||||||
|
})
|
||||||
mic := fyne.NewMenuItem("upload a file", func() {
|
mic := fyne.NewMenuItem("upload a file", func() {
|
||||||
var link string
|
var link string
|
||||||
var bytes []byte
|
var bytes []byte
|
||||||
@@ -633,7 +681,7 @@ func main() {
|
|||||||
}, w)
|
}, w)
|
||||||
})
|
})
|
||||||
|
|
||||||
menu_help := fyne.NewMenu("π", mit, reconnect)
|
menu_help := fyne.NewMenu("π", mit, reconnect,deb)
|
||||||
menu_changeroom := fyne.NewMenu("β", mic)
|
menu_changeroom := fyne.NewMenu("β", mic)
|
||||||
menu_configureview := fyne.NewMenu("γ", mia, mis, jtt, jtb)
|
menu_configureview := fyne.NewMenu("γ", mia, mis, jtt, jtb)
|
||||||
bit := fyne.NewMenuItem("mark selected message as read", func() {
|
bit := fyne.NewMenuItem("mark selected message as read", func() {
|
||||||
@@ -735,9 +783,18 @@ func main() {
|
|||||||
} else {
|
} else {
|
||||||
chatInfo = *container.NewHBox(widget.NewLabel(tab.Jid.String()))
|
chatInfo = *container.NewHBox(widget.NewLabel(tab.Jid.String()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if tab.isMuc {
|
||||||
|
fyne.Do(func() {
|
||||||
|
desc := widget.NewLabel("A MUC is a chatroom that can have multiple members. Eventually this pane will display information about this room, such as the members in it, the name of the MUC and its topic.")
|
||||||
|
desc.Wrapping = fyne.TextWrapBreak
|
||||||
|
chatSidebar = *container.NewStack(container.NewVScroll(container.NewVBox(widget.NewRichTextFromMarkdown(fmt.Sprintf("# %s", tab.Muc.Addr().Localpart())), widget.NewRichTextFromMarkdown(tab.Muc.Addr().String()), desc)))
|
||||||
|
//chatSidebar.Refresh()
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
statBar.SetText("nothing seems to be happening right now...")
|
statBar.SetText("nothing seems to be happening right now...")
|
||||||
w.SetContent(container.NewVSplit(container.NewVSplit(tabs, container.NewHSplit(entry, sendbtn)), container.NewHSplit(&statBar,&chatInfo)))
|
w.SetContent(container.NewVSplit(container.NewVSplit(container.NewHSplit(tabs, &chatSidebar), container.NewHSplit(entry, sendbtn)), container.NewHSplit(&statBar,&chatInfo)))
|
||||||
w.ShowAndRun()
|
w.ShowAndRun()
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user