1
0
forked from sunglocto/pi-im
This commit is contained in:
2026-01-02 11:37:33 +00:00
parent ff121b42d9
commit d5ec58be68

65
main.go
View File

@@ -33,6 +33,7 @@ import (
"mellium.im/xmpp/bookmarks" "mellium.im/xmpp/bookmarks"
"mellium.im/xmpp/jid" "mellium.im/xmpp/jid"
"mellium.im/xmpp/muc" "mellium.im/xmpp/muc"
"mellium.im/xmpp/pubsub"
oasisSdk "pain.agency/oasis-sdk" oasisSdk "pain.agency/oasis-sdk"
// TODO: integrated theme switcher // TODO: integrated theme switcher
) )
@@ -45,6 +46,7 @@ var replyNameIcon string = ">"
var replyBodyIcon string = ">" var replyBodyIcon string = ">"
var newlineIcon string = " |-> " var newlineIcon string = " |-> "
var agreesToSendingHotFuckIntoChannel bool = false var agreesToSendingHotFuckIntoChannel bool = false
var OccupantIdsToBlock = make(map[string]string)
// by sunglocto // by sunglocto
// license AGPL // license AGPL
@@ -180,6 +182,7 @@ func CreateUITab(chatJidStr string) ChatTabUI {
return container.NewVBox(replytext, container.NewHBox(ico, author), content, btn, reactions) return container.NewVBox(replytext, container.NewHBox(ico, author), content, btn, reactions)
}, },
func(i widget.ListItemID, co fyne.CanvasObject) { func(i widget.ListItemID, co fyne.CanvasObject) {
vbox := co.(*fyne.Container) vbox := co.(*fyne.Container)
authorBox := vbox.Objects[1].(*fyne.Container) authorBox := vbox.Objects[1].(*fyne.Container)
replytext := vbox.Objects[0].(*widget.Label) replytext := vbox.Objects[0].(*widget.Label)
@@ -196,6 +199,21 @@ func CreateUITab(chatJidStr string) ChatTabUI {
author := authorBox.Objects[1].(*widget.Label) author := authorBox.Objects[1].(*widget.Label)
content := vbox.Objects[2].(*widget.Label) content := vbox.Objects[2].(*widget.Label)
unknown_tags := chatTabs[chatJidStr].Messages[i].Raw.Unknown
for _, v := range unknown_tags {
if v.XMLName.Local == "occupant-id" {
for _, attr := range v.Attrs {
if attr.Name.Local == "id" {
reason, ok := OccupantIdsToBlock[attr.Value]
if ok {
author.SetText("Ignored user")
content.SetText("This user is ignored due to: " + reason)
return // message is from blocked user
}
}
}
}
}
btn := vbox.Objects[3].(*widget.Button) btn := vbox.Objects[3].(*widget.Button)
reactions := vbox.Objects[4].(*fyne.Container) reactions := vbox.Objects[4].(*fyne.Container)
reactions = container.NewVBox() reactions = container.NewVBox()
@@ -824,6 +842,9 @@ func main() {
text = fmt.Sprintf("%s %s", text, jid.MustParse(name).Resourcepart()) text = fmt.Sprintf("%s %s", text, jid.MustParse(name).Resourcepart())
} }
a := pubsub.Fetch(context.TODO(), client.Session, pubsub.Query{})
log.Println(a.Item())
err = client.SendText(jid.MustParse(activeMucJid).Bare(), text) err = client.SendText(jid.MustParse(activeMucJid).Bare(), text)
if err != nil { if err != nil {
dialog.ShowError(err, w) dialog.ShowError(err, w)
@@ -1364,6 +1385,48 @@ func main() {
dialog.ShowCustom("Message", "Close", pre, w) dialog.ShowCustom("Message", "Close", pre, w)
}) })
blck := fyne.NewMenuItem("ignore messages from this user", func() {
selectedScroller, ok := AppTabs.Selected().Content.(*widget.List)
if !ok {
return
}
var activeChatJid string
for jid, tabData := range UITabs {
if tabData.Scroller == selectedScroller {
activeChatJid = jid
break
}
}
m := chatTabs[activeChatJid].Messages[selectedId]
unknown_tags := m.Raw.Unknown
for _, v := range unknown_tags {
if v.XMLName.Local == "occupant-id" {
for _, attr := range v.Attrs {
if attr.Name.Local == "id" {
occupant_id := attr.Value
reason, ok := OccupantIdsToBlock[occupant_id]
if !ok {
dialog.ShowConfirm("ignore user", "All messages sent by users with an occupant ID of\n"+occupant_id+"\nwill be ignored. Continue?", func(b bool) {
if b {
OccupantIdsToBlock[occupant_id] = "User requested"
}
}, w)
} else {
dialog.ShowConfirm("unignore user", "This user is currently ignored due to:\n"+reason+"\nWould you like to unignore them?", func(b bool) {
if b {
delete(OccupantIdsToBlock, occupant_id)
}
}, w)
}
}
}
}
}
})
red := fyne.NewMenuItem("show read receipts on message", func() { red := fyne.NewMenuItem("show read receipts on message", func() {
pre := container.NewVBox() pre := container.NewVBox()
@@ -1400,7 +1463,7 @@ func main() {
dialog.ShowCustom("Message", "Close", pre, w) dialog.ShowCustom("Message", "Close", pre, w)
}) })
menu_messageoptions := fyne.NewMenu("Γ", bit, bia, bic, red) menu_messageoptions := fyne.NewMenu("Γ", bit, bia, bic, red, blck)
ma := fyne.NewMainMenu(menu_help, menu_changeroom, menu_configureview, menu_messageoptions, menu_jokes) ma := fyne.NewMainMenu(menu_help, menu_changeroom, menu_configureview, menu_messageoptions, menu_jokes)
w.SetMainMenu(ma) w.SetMainMenu(ma)