Files
fn_registry/functions/infra/matrix_room_list.md
T
egutierrez 621e8895c9 feat(infra): auto-commit con 86 cambios
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-26 19:38:15 +02:00

3.4 KiB

name, kind, lang, domain, version, purity, signature, description, tags, params, output, uses_functions, uses_types, returns, returns_optional, error_type, imports, tested, tests, test_file_path, file_path
name kind lang domain version purity signature description tags params output uses_functions uses_types returns returns_optional error_type imports tested tests test_file_path file_path
matrix_room_list function go infra 0.1.0 impure func MatrixRoomList(ctx context.Context, cfg MatrixRoomListConfig) ([]RoomSummary, error) Devuelve la lista de rooms Matrix en los que el usuario esta unido con metadata completa (nombre, alias, avatar, topic, encryption, space, DM, tags), ordenada por LastEventTs DESC.
matrix
mautrix
rooms
summary
state
infra
matrix-mas
name desc
ctx Context de la llamada. Cancela todas las HTTP requests en curso si se cancela.
name desc
cfg.Client Cliente mautrix autenticado. Debe haber completado al menos un Sync para que JoinedRooms devuelva datos frescos. No puede ser nil.
[]RoomSummary ordenado por LastEventTs DESC (rooms mas recientes primero). Si LastEventTs es 0 para todos, ordena alfabeticamente por Name.
false error_go_core
maunium.net/go/mautrix
maunium.net/go/mautrix/event
maunium.net/go/mautrix/id
true
3 rooms devueltos con metadata correcta
1 room sin m.room.name usa fallback name
IsDirect set correctamente segun m.direct
IsEncrypted set segun presencia de m.room.encryption
client nil devuelve error
functions/infra/matrix_room_list_test.go functions/infra/matrix_room_list.go

Ejemplo

rooms, err := MatrixRoomList(ctx, MatrixRoomListConfig{Client: client})
if err != nil {
    log.Fatal(err)
}
for _, r := range rooms {
    fmt.Printf("%s [%s] enc=%v dm=%v members=%d\n",
        r.Name, r.RoomID, r.IsEncrypted, r.IsDirect, r.MemberCount)
}
// Output ejemplo:
// General [!abc:server] enc=true dm=false members=12
// Alice [!xyz:server] enc=true dm=true members=2

Cuando usarla

Usar tras al menos un Sync completado, para poblar el sidebar de rooms en la UI. Llamar periodicamente con un TTL de 30s o tras recibir eventos m.room.* / m.direct en el sync stream. Ideal para el panel lateral de matrix_client_pc y admin_panel.

Gotchas

  • Costoso si muchos rooms: cada room genera 3+ HTTP calls (State, Messages, m.tag). Para N=50 rooms son ~150 HTTP calls. Cachear en el backend con TTL 30s antes de exponer al frontend.
  • Sin sync previo: si se llama antes del primer Sync completado, JoinedRooms puede devolver lista vacia o stale. Siempre hacer Sync primero.
  • LastEventTs puede ser 0: mautrix Store en memoria no persiste el timestamp del ultimo evento. Si el store es en memoria (default), Messages(limit=1) hace una HTTP call extra por room. Si LastEventTs == 0, el room cae al fondo del orden (orden alfabetico por Name como desempate).
  • UnreadCount siempre 0 en v0.1.0: los notification counters vienen del Sync response, no de la API de state. TODO: obtenerlos del Syncer internamente.
  • Spaces planos: esta funcion devuelve joined rooms planos. No enumera recursivamente los children de un Space. Para arbol de Space, implementar funcion separada.
  • Content.ParseRaw idempotente: mautrix parseRoomStateArray llama ParseRaw al deserializar el state. La funcion usa ensureParsed que es no-op si ya esta parseado.
  • IsDirect puede ser false si m.direct no esta sincronizado: algunas implementaciones de Synapse no sincronizan m.direct inmediatamente. Si IsDirect es incorrecto, hacer un Sync completo primero.