@@ -13,6 +13,8 @@ import {
1313 ActionExceptionKind ,
1414 ActionResult ,
1515 Ok ,
16+ Revision ,
17+ WatchedPolicyRoom ,
1618 isError ,
1719} from "matrix-protection-suite" ;
1820import {
@@ -29,11 +31,24 @@ import {
2931import { Draupnir } from "../Draupnir" ;
3032import { Result } from "@gnuxie/typescript-result" ;
3133import { DraupnirInterfaceAdaptor } from "./DraupnirCommandPrerequisites" ;
34+ import {
35+ groupWatchedPolicyRoomsByProtectionStatus ,
36+ renderPolicyList ,
37+ } from "./StatusCommand" ;
38+
39+ type RoomListItem = {
40+ // used for room pill rendering
41+ room : MatrixRoomID ;
42+ mostRecentRevision ?: Revision ;
43+ } ;
3244
3345type ListRoomsCommandInfo = {
34- joinedAndProtectedRooms : MatrixRoomID [ ] ;
35- joinedAndUnprotectedRooms : MatrixRoomID [ ] ;
36- partedAndProtectedRooms : MatrixRoomID [ ] ;
46+ joinedAndProtectedLists : WatchedPolicyRoom [ ] ;
47+ joinedAndWatchedLists : WatchedPolicyRoom [ ] ;
48+ partedAndWatchedLists : WatchedPolicyRoom [ ] ;
49+ joinedAndProtectedRooms : RoomListItem [ ] ;
50+ joinedAndUnprotectedRooms : RoomListItem [ ] ;
51+ partedAndProtectedRooms : RoomListItem [ ] ;
3752} ;
3853
3954export const DraupnirListProtectedRoomsCommand = describeCommand ( {
@@ -42,25 +57,62 @@ export const DraupnirListProtectedRoomsCommand = describeCommand({
4257 async executor ( draupnir : Draupnir ) : Promise < Result < ListRoomsCommandInfo > > {
4358 const allJoinedRooms = draupnir . clientRooms . currentRevision . allJoinedRooms ;
4459 const allProtectedRooms = draupnir . protectedRoomsSet . allProtectedRooms ;
60+ const listInfo = groupWatchedPolicyRoomsByProtectionStatus (
61+ draupnir . protectedRoomsSet . watchedPolicyRooms ,
62+ draupnir . clientRooms . currentRevision . allJoinedRooms ,
63+ draupnir . protectedRoomsSet . allProtectedRooms
64+ ) ;
65+ const makeRoomListItem = ( room : MatrixRoomID ) => {
66+ const revision = draupnir . protectedRoomsSet . setRoomState . getRevision (
67+ room . toRoomIDOrAlias ( )
68+ ) ;
69+ if ( revision ) {
70+ return { room, mostRecentRevision : revision . revisionID } ;
71+ } else {
72+ return { room } ;
73+ }
74+ } ;
4575 return Ok ( {
46- joinedAndProtectedRooms : allProtectedRooms . filter ( ( room ) =>
47- allJoinedRooms . includes ( room . toRoomIDOrAlias ( ) )
48- ) ,
76+ joinedAndProtectedLists : listInfo . subscribedAndProtectedLists ,
77+ joinedAndWatchedLists : listInfo . subscribedLists ,
78+ partedAndWatchedLists : listInfo . subscribedButPartedLists ,
79+ joinedAndProtectedRooms : allProtectedRooms
80+ . filter ( ( room ) => allJoinedRooms . includes ( room . toRoomIDOrAlias ( ) ) )
81+ . map ( makeRoomListItem ) ,
4982 joinedAndUnprotectedRooms : allJoinedRooms
5083 . filter (
5184 ( roomID ) =>
5285 ! allProtectedRooms . find ( ( room ) => room . toRoomIDOrAlias ( ) === roomID )
5386 )
54- . map ( ( roomID ) => MatrixRoomReference . fromRoomID ( roomID ) ) ,
55- partedAndProtectedRooms : allProtectedRooms . filter (
56- ( room ) => ! allJoinedRooms . includes ( room . toRoomIDOrAlias ( ) )
57- ) ,
87+ . map ( ( roomID ) =>
88+ makeRoomListItem ( MatrixRoomReference . fromRoomID ( roomID ) )
89+ ) ,
90+ partedAndProtectedRooms : allProtectedRooms
91+ . filter ( ( room ) => ! allJoinedRooms . includes ( room . toRoomIDOrAlias ( ) ) )
92+ . map ( makeRoomListItem ) ,
5893 } ) ;
5994 } ,
6095} ) ;
6196
97+ function renderPolicyLists (
98+ rooms : WatchedPolicyRoom [ ] ,
99+ options : { name : string }
100+ ) : DocumentNode {
101+ if ( rooms . length === 0 ) {
102+ return < fragment > </ fragment > ;
103+ }
104+ return (
105+ < details >
106+ < summary >
107+ { options . name } ({ rooms . length } ):
108+ </ summary >
109+ < ul > { rooms . map ( renderPolicyList ) } </ ul >
110+ </ details >
111+ ) ;
112+ }
113+
62114function renderRoomList (
63- rooms : MatrixRoomID [ ] ,
115+ rooms : RoomListItem [ ] ,
64116 options : { name : string }
65117) : DocumentNode {
66118 if ( rooms . length === 0 ) {
@@ -72,9 +124,20 @@ function renderRoomList(
72124 { options . name } ({ rooms . length } ):
73125 </ summary >
74126 < ul >
75- { rooms . map ( ( r ) => (
127+ { rooms . map ( ( item ) => (
76128 < li >
77- < a href = { r . toPermalink ( ) } > { r . toRoomIDOrAlias ( ) } </ a >
129+ < a href = { item . room . toPermalink ( ) } > { item . room . toRoomIDOrAlias ( ) } </ a > { " " }
130+ { "mostRecentRevision" in item ? (
131+ < fragment >
132+ (last update:{ " " }
133+ < code >
134+ { new Date ( item . mostRecentRevision . time ) . toLocaleString ( ) }
135+ </ code >
136+ )
137+ </ fragment >
138+ ) : (
139+ < fragment > </ fragment >
140+ ) }
78141 </ li >
79142 ) ) }
80143 </ ul >
@@ -94,6 +157,15 @@ DraupnirInterfaceAdaptor.describeRenderer(DraupnirListProtectedRoomsCommand, {
94157 ) : (
95158 < fragment > </ fragment >
96159 ) }
160+ { renderPolicyLists ( result . ok . joinedAndProtectedLists , {
161+ name : "Joined and protected policy rooms" ,
162+ } ) }
163+ { renderPolicyLists ( result . ok . joinedAndWatchedLists , {
164+ name : "Joined and watched unprotected policy rooms" ,
165+ } ) }
166+ { renderPolicyLists ( result . ok . partedAndWatchedLists , {
167+ name : "Parted policy rooms that are still marked as watched" ,
168+ } ) }
97169 { renderRoomList ( result . ok . joinedAndProtectedRooms , {
98170 name : "Protected rooms" ,
99171 } ) }
0 commit comments