Add blocking, add note to self to tabs and add snit's default avatar img

This commit is contained in:
2026-07-30 01:39:31 +01:00
parent b07f92853d
commit 7a822e8eaf
6 changed files with 114 additions and 29 deletions
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 91 KiB

+6
View File
@@ -52,6 +52,12 @@ func showUserWindow(u stanza.Presence, custom_nick string) {
status_message.AddCSSClass("status")
profile_box.Append(status_message)
}
if loadedConfig.BlockingOI[ocu.ID] {
blocked_note := gtk.NewLabel("You have blocked this user!")
blocked_note.AddCSSClass("blocked")
profile_box.Prepend(blocked_note)
}
profile_box.Append(ver_text)
fr := gtk.NewLabel(u.From)
fr.AddCSSClass("jid")
+29 -9
View File
@@ -74,7 +74,7 @@ func generatePresenceWidget(p stanza.Packet) gtk.Widgetter {
return b
}
func generateMessageWidget(p stanza.Packet) (gtk.Widgetter, bool) {
func generateMessageWidget(p stanza.Packet, blocked bool) (gtk.Widgetter, bool) {
m, ok := p.(stanza.Message)
if !ok {
return gtk.NewLabel("Unsupported message."), true
@@ -233,12 +233,18 @@ func generateMessageWidget(p stanza.Packet) (gtk.Widgetter, bool) {
mainBox.AddController(gesture)
if name == "" {
name = JidMustParse(m.From).Bare()
}
if loadedConfig.CompactMode {
if m.Body == "" {
/*
mlabel.SetText(loadedLocale["noBodySet"])
mlabel.AddCSSClass("visitor")
*/
return nil, false
}
al := gtk.NewLabel(name)
ycbcr := xmpp_color.String(id, 255, loadedConfig.CVD)
r, g, b, _ := ycbcr.RGBA()
@@ -251,13 +257,6 @@ func generateMessageWidget(p stanza.Packet) (gtk.Widgetter, bool) {
mlabel := gtk.NewLabel(m.Body)
if m.Body == "" {
/*
mlabel.SetText(loadedLocale["noBodySet"])
mlabel.AddCSSClass("visitor")
*/
return nil, false
}
mlabel.SetWrap(true)
mlabel.SetSelectable(true)
// mlabel.SetHAlign(gtk.AlignFill)
@@ -404,6 +403,27 @@ func generateMessageWidget(p stanza.Packet) (gtk.Widgetter, bool) {
}
}
if loadedConfig.BlockingMode == Highlight && blocked {
mainBox.AddCSSClass("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())
})
blocked_part.Append(show_hide)
blocked_box.Append(blocked_part)
blocked_box.Append(mainBox)
return blocked_box, true
}
return mainBox, true
}
+42 -4
View File
@@ -208,15 +208,26 @@ func main() {
})
router.HandleFunc("message", func(s xmpp.Sender, p stanza.Packet) {
var blocked bool
m, ok := p.(stanza.Message)
if !ok {
return
}
e := stanza.PubSubEvent{}
ok = m.Get(&e)
oi := new(OccupantID)
ok = m.Get(oi)
if ok {
fmt.Println(e)
id := oi.ID
va, ok := loadedConfig.BlockingOI[id]
if ok {
if va {
if loadedConfig.BlockingMode == Drop {
return
} else {
blocked = true
}
}
}
}
originator := JidMustParse(m.From).Bare()
@@ -300,7 +311,7 @@ func main() {
fmt.Println("Got message when the tab does not exist!")
}
untyped_box, valid := generateMessageWidget(p)
untyped_box, valid := generateMessageWidget(p, blocked)
ba, converted_successfully := untyped_box.(*gtk.Box)
if valid && converted_successfully {
@@ -525,6 +536,33 @@ func main() {
</iq>
`, clientroot.Session.BindJid))
// Create note to self
jid := JidMustParse(clientroot.Session.BindJid).Bare()
name := "Note To Self"
createTab(jid, false, name)
glib.IdleAdd(func() {
box := gtk.NewBox(gtk.OrientationHorizontal, 10)
b := gtk.NewLabel(name)
gesture1 := gtk.NewGestureClick()
gesture1.SetButton(1)
gesture1.Connect("pressed", func() {
switchToTab(jid, &window.Window)
})
box.Append(b)
go func() {
new_im := getAvatar(jid, jid) // TODO: Use PEP avatar and do not use JID as hash
glib.IdleAdd(func() {
new_im.SetPixelSize(40)
box.Prepend(new_im)
})
}()
box.AddController(gesture1)
menu.Append(box)
menu.Append(gtk.NewSeparator(gtk.OrientationHorizontal))
})
// Fetch roster
i, err := stanza.NewIQ(stanza.Attrs{
Type: "get",
+5
View File
@@ -85,3 +85,8 @@
color: cyan;
font-family: serif;
}
.blocked {
background-color: orange;
color: black;
}
+16
View File
@@ -15,6 +15,14 @@ type chatTab struct {
muc_presence *stanza.Presence
}
type BlockingMode int
const (
Drop BlockingMode = iota
Hide
Highlight
)
type lambdaConfig struct {
Server string
Username string
@@ -23,14 +31,22 @@ type lambdaConfig struct {
Insecure bool
Nick string
JoinBookmarks bool
CVD color.CVD
Identicons bool
Debug bool
ShowPresenceUpdates bool
CompactMode bool
ShowAvatarsInMemberList bool
CustomNicks map[string]string // Anyone with a specific Occupant ID will have this nick
CustomNicksAV map[string]string // Anyone with a specific avatar hash will have this nick
BlockingOI map[string]bool // Any person who's Occupant ID is in this map will have their messages dropped
BlockingMode BlockingMode
CheckUpdate string
}