Files
lambda/helpers.go
T

53 lines
855 B
Go
Raw Normal View History

2026-04-06 11:04:53 +01:00
// Generic helpers
package main
import (
2026-08-25 20:17:23 +01:00
"errors"
"gosrc.io/xmpp/stanza"
2026-04-06 11:04:53 +01:00
"sort"
"sync"
2026-04-06 11:04:53 +01:00
)
func rangeOrdered(m *sync.Map, fn func(k, v any) bool) {
var keys []string
2026-04-06 11:04:53 +01:00
m.Range(func(k, v any) bool {
keys = append(keys, k.(string))
return true
})
2026-04-06 11:04:53 +01:00
sort.Strings(keys)
2026-04-06 11:04:53 +01:00
for _, k := range keys {
v, _ := m.Load(k)
if !fn(k, v) {
break
}
}
2026-04-06 11:04:53 +01:00
}
2026-08-25 20:17:23 +01:00
func getPresenceFromJIDMuc(jid *stanza.Jid) (*stanza.Presence, error) {
mo, ok := mucmembers.Load(jid.Bare())
if !ok {
return nil, errors.New("tab is not present in mucmembers")
}
mm, ok := mo.(mucUnit)
if !ok {
return nil, errors.New("mucUnit is nil")
}
mmm := mm.Members
mmmm, ok := mmm.Load(jid.Resource)
if !ok {
return nil, errors.New("user not in room")
}
pres, ok := mmmm.(stanza.Presence)
if !ok {
return nil, errors.New("presence is nil")
}
return &pres, nil
}