621e8895c9
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
3.4 KiB
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. |
|
|
[]RoomSummary ordenado por LastEventTs DESC (rooms mas recientes primero). Si LastEventTs es 0 para todos, ordena alfabeticamente por Name. | false | error_go_core |
|
true |
|
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,
JoinedRoomspuede 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. SiLastEventTs == 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
parseRoomStateArrayllamaParseRawal deserializar el state. La funcion usaensureParsedque es no-op si ya esta parseado. - IsDirect puede ser false si m.direct no esta sincronizado: algunas implementaciones de Synapse no sincronizan
m.directinmediatamente. Si IsDirect es incorrecto, hacer un Sync completo primero.