@@ -26,10 +26,13 @@ type ProjectsListForUserResponseData = Endpoints["GET /users/{username}/projects
26
26
const md = new markdown ( ) ;
27
27
const log = new LogWrapper ( 'AdminRoom' ) ;
28
28
29
- export const BRIDGE_ROOM_TYPE = "uk.half-shot.matrix-github.room" ;
30
- export const BRIDGE_NOTIF_TYPE = "uk.half-shot.matrix-github.notif_state" ;
31
- export const BRIDGE_GITLAB_NOTIF_TYPE = "uk.half-shot.matrix-github.gitlab.notif_state" ;
29
+ export const LEGACY_BRIDGE_ROOM_TYPE = "uk.half-shot.matrix-github.room" ;
30
+ export const LEGACY_BRIDGE_NOTIF_TYPE = "uk.half-shot.matrix-github.notif_state" ;
31
+ export const LEGACY_BRIDGE_GITLAB_NOTIF_TYPE = "uk.half-shot.matrix-github.gitlab.notif_state" ;
32
32
33
+ export const BRIDGE_ROOM_TYPE = "uk.half-shot.matrix-hookshot.github.room" ;
34
+ export const BRIDGE_NOTIF_TYPE = "uk.half-shot.matrix-hookshot.github.notif_state" ;
35
+ export const BRIDGE_GITLAB_NOTIF_TYPE = "uk.half-shot.matrix-hookshot.gitlab.notif_state" ;
33
36
export interface AdminAccountData {
34
37
// eslint-disable-next-line camelcase
35
38
admin_user : string ;
@@ -109,19 +112,29 @@ export class AdminRoom extends EventEmitter {
109
112
public async getNotifSince ( type : "github" | "gitlab" , instanceName ?: string ) {
110
113
if ( type === "gitlab" ) {
111
114
try {
112
- const { since } = await this . botIntent . underlyingClient . getRoomAccountData (
113
- `${ BRIDGE_GITLAB_NOTIF_TYPE } :${ instanceName } ` , this . roomId
115
+ let accountData : null | { since : number } = await this . botIntent . underlyingClient . getSafeRoomAccountData (
116
+ `${ BRIDGE_GITLAB_NOTIF_TYPE } :${ instanceName } ` , this . roomId , null
114
117
) ;
115
- return since ;
118
+ if ( ! accountData ) {
119
+ accountData = await this . botIntent . underlyingClient . getSafeRoomAccountData (
120
+ `${ LEGACY_BRIDGE_GITLAB_NOTIF_TYPE } :${ instanceName } ` , this . roomId , { since : 0 }
121
+ ) ;
122
+ }
123
+ return accountData . since ;
116
124
} catch {
117
125
// TODO: We should look at this error.
118
126
return 0 ;
119
127
}
120
128
}
121
129
try {
122
- const { since } = await this . botIntent . underlyingClient . getRoomAccountData ( BRIDGE_NOTIF_TYPE , this . roomId ) ;
123
- log . debug ( `Got ${ type } notif-since to ${ since } ` ) ;
124
- return since ;
130
+ let accountData : null | { since : number } = await this . botIntent . underlyingClient . getSafeRoomAccountData ( BRIDGE_NOTIF_TYPE , this . roomId , { since : 0 } ) ;
131
+ if ( ! accountData ) {
132
+ accountData = await this . botIntent . underlyingClient . getSafeRoomAccountData (
133
+ `${ LEGACY_BRIDGE_NOTIF_TYPE } :${ instanceName } ` , this . roomId , { since : 0 }
134
+ ) ;
135
+ }
136
+ log . debug ( `Got ${ type } notif-since to ${ accountData . since } ` ) ;
137
+ return accountData . since ;
125
138
} catch ( ex ) {
126
139
log . warn ( `Filed to get ${ type } notif-since` , ex ) ;
127
140
// TODO: We should look at this error.
@@ -506,7 +519,7 @@ export class AdminRoom extends EventEmitter {
506
519
const users = parameters . filter ( param => param . toLowerCase ( ) . startsWith ( "users:" ) ) . map ( param => param . toLowerCase ( ) . substring ( "users:" . length ) . split ( "," ) ) . flat ( ) ;
507
520
const repos = parameters . filter ( param => param . toLowerCase ( ) . startsWith ( "repos:" ) ) . map ( param => param . toLowerCase ( ) . substring ( "repos:" . length ) . split ( "," ) ) . flat ( ) ;
508
521
if ( orgs . length + users . length + repos . length === 0 ) {
509
- return this . sendNotice ( "You must specify some filter options like 'orgs:matrix-org,half-shot', 'users:Half-Shot' or 'repos:matrix-github '" ) ;
522
+ return this . sendNotice ( "You must specify some filter options like 'orgs:matrix-org,half-shot', 'users:Half-Shot' or 'repos:matrix-hookshot '" ) ;
510
523
}
511
524
this . notifFilter . setFilter ( name , {
512
525
orgs,
@@ -533,9 +546,10 @@ export class AdminRoom extends EventEmitter {
533
546
}
534
547
535
548
private async saveAccountData ( updateFn : ( record : AdminAccountData ) => AdminAccountData ) {
536
- const oldData : AdminAccountData = await this . botIntent . underlyingClient . getRoomAccountData (
537
- BRIDGE_ROOM_TYPE , this . roomId ,
538
- ) ;
549
+ let oldData : AdminAccountData | null = await this . botIntent . underlyingClient . getSafeRoomAccountData ( BRIDGE_ROOM_TYPE , this . roomId , null ) ;
550
+ if ( ! oldData ) {
551
+ oldData = await this . botIntent . underlyingClient . getSafeRoomAccountData ( LEGACY_BRIDGE_ROOM_TYPE , this . roomId , { admin_user : this . userId } ) ;
552
+ }
539
553
const newData = updateFn ( oldData ) ;
540
554
await this . botIntent . underlyingClient . setRoomAccountData ( BRIDGE_ROOM_TYPE , this . roomId , newData ) ;
541
555
this . emit ( "settings.changed" , this , oldData , newData ) ;
0 commit comments