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") status_message.AddCSSClass("status")
profile_box.Append(status_message) 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) profile_box.Append(ver_text)
fr := gtk.NewLabel(u.From) fr := gtk.NewLabel(u.From)
fr.AddCSSClass("jid") fr.AddCSSClass("jid")
+31 -11
View File
@@ -74,7 +74,7 @@ func generatePresenceWidget(p stanza.Packet) gtk.Widgetter {
return b 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) m, ok := p.(stanza.Message)
if !ok { if !ok {
return gtk.NewLabel("Unsupported message."), true return gtk.NewLabel("Unsupported message."), true
@@ -233,12 +233,18 @@ func generateMessageWidget(p stanza.Packet) (gtk.Widgetter, bool) {
mainBox.AddController(gesture) mainBox.AddController(gesture)
if name == "" { if name == "" {
name = JidMustParse(m.From).Bare() name = JidMustParse(m.From).Bare()
} }
if loadedConfig.CompactMode { if loadedConfig.CompactMode {
if m.Body == "" {
/*
mlabel.SetText(loadedLocale["noBodySet"])
mlabel.AddCSSClass("visitor")
*/
return nil, false
}
al := gtk.NewLabel(name) al := gtk.NewLabel(name)
ycbcr := xmpp_color.String(id, 255, loadedConfig.CVD) ycbcr := xmpp_color.String(id, 255, loadedConfig.CVD)
r, g, b, _ := ycbcr.RGBA() r, g, b, _ := ycbcr.RGBA()
@@ -251,13 +257,6 @@ func generateMessageWidget(p stanza.Packet) (gtk.Widgetter, bool) {
mlabel := gtk.NewLabel(m.Body) mlabel := gtk.NewLabel(m.Body)
if m.Body == "" {
/*
mlabel.SetText(loadedLocale["noBodySet"])
mlabel.AddCSSClass("visitor")
*/
return nil, false
}
mlabel.SetWrap(true) mlabel.SetWrap(true)
mlabel.SetSelectable(true) mlabel.SetSelectable(true)
// mlabel.SetHAlign(gtk.AlignFill) // mlabel.SetHAlign(gtk.AlignFill)
@@ -333,8 +332,8 @@ func generateMessageWidget(p stanza.Packet) (gtk.Widgetter, bool) {
mlabel := gtk.NewLabel(m.Body) mlabel := gtk.NewLabel(m.Body)
if m.Body == "" { if m.Body == "" {
/* /*
mlabel.SetText(loadedLocale["noBodySet"]) mlabel.SetText(loadedLocale["noBodySet"])
mlabel.AddCSSClass("visitor") mlabel.AddCSSClass("visitor")
*/ */
return nil, false return nil, false
} }
@@ -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 return mainBox, true
} }
+43 -5
View File
@@ -208,15 +208,26 @@ func main() {
}) })
router.HandleFunc("message", func(s xmpp.Sender, p stanza.Packet) { router.HandleFunc("message", func(s xmpp.Sender, p stanza.Packet) {
var blocked bool
m, ok := p.(stanza.Message) m, ok := p.(stanza.Message)
if !ok { if !ok {
return return
} }
e := stanza.PubSubEvent{} oi := new(OccupantID)
ok = m.Get(&e) ok = m.Get(oi)
if ok { 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() originator := JidMustParse(m.From).Bare()
@@ -300,13 +311,13 @@ func main() {
fmt.Println("Got message when the tab does not exist!") 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) ba, converted_successfully := untyped_box.(*gtk.Box)
if valid && converted_successfully { if valid && converted_successfully {
typed_tab.msgs.Append(b) typed_tab.msgs.Append(b)
b.Append(ba) b.Append(ba)
} }
}) })
}) })
@@ -525,6 +536,33 @@ func main() {
</iq> </iq>
`, clientroot.Session.BindJid)) `, 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 // Fetch roster
i, err := stanza.NewIQ(stanza.Attrs{ i, err := stanza.NewIQ(stanza.Attrs{
Type: "get", Type: "get",
+5
View File
@@ -85,3 +85,8 @@
color: cyan; color: cyan;
font-family: serif; font-family: serif;
} }
.blocked {
background-color: orange;
color: black;
}
+29 -13
View File
@@ -15,23 +15,39 @@ type chatTab struct {
muc_presence *stanza.Presence muc_presence *stanza.Presence
} }
type BlockingMode int
const (
Drop BlockingMode = iota
Hide
Highlight
)
type lambdaConfig struct { type lambdaConfig struct {
Server string Server string
Username string Username string
Resource string Resource string
Password string Password string
Insecure bool Insecure bool
Nick string Nick string
JoinBookmarks bool JoinBookmarks bool
CVD color.CVD
Identicons bool CVD color.CVD
Debug bool Identicons bool
Debug bool
ShowPresenceUpdates bool ShowPresenceUpdates bool
CompactMode bool CompactMode bool
ShowAvatarsInMemberList 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 CustomNicks map[string]string // Anyone with a specific Occupant ID will have this nick
CheckUpdate string 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
} }
type mucUnit struct { type mucUnit struct {