@@ -5,6 +5,7 @@ import { PentaDb } from "./db/PentaDb";
5
5
import { PentabarfParser } from "./PentabarfParser" ;
6
6
import * as fetch from "node-fetch" ;
7
7
import { LogService } from "matrix-bot-sdk" ;
8
+ import { IDbTalk } from "./db/DbTalk" ;
8
9
9
10
10
11
export class PentaBackend implements IScheduleBackend {
@@ -69,12 +70,23 @@ export class PentaBackend implements IScheduleBackend {
69
70
private async hydrateTalk ( talk : ITalk ) : Promise < void > {
70
71
const dbTalk = await this . db . getTalk ( talk . id ) ;
71
72
if ( dbTalk === null ) return ;
73
+ this . rehydrateTalkFrom ( talk , dbTalk ) ;
74
+ }
72
75
76
+ private rehydrateTalkFrom ( talk : ITalk , dbTalk : IDbTalk ) : void {
73
77
if ( talk . qa_startTime !== null ) {
74
78
// hydrate Q&A time if enabled
79
+ // Rationale for hydrating Q&A time: it's not available in the Pentabarf XML.
75
80
talk . qa_startTime = dbTalk . qa_start_datetime ;
76
81
}
82
+
77
83
talk . livestream_endTime = dbTalk . livestream_end_datetime ;
84
+
85
+ // Rationale for hydrating talk start & end time: there can be short-notice alterations to the schedule
86
+ // (and rehydrating talks is how `refreshShortTerm` is implemented)
87
+ // and during testing, the PentaDB can have a time shift set which changes the time of talks compared to the XML.
88
+ talk . startTime = dbTalk . start_datetime ;
89
+ talk . endTime = dbTalk . end_datetime ;
78
90
}
79
91
80
92
private async hydratePerson ( person : IPerson ) : Promise < void > {
@@ -114,6 +126,23 @@ export class PentaBackend implements IScheduleBackend {
114
126
throw new Error ( "refresh() not implemented for Penta backend." ) ;
115
127
}
116
128
129
+ /**
130
+ * See description on `IScheduleBackend`.
131
+ *
132
+ * For the penta backend, we consult the database for short-notice alterations and rehydrate any affected talks.
133
+ */
134
+ async refreshShortTerm ( lookaheadSeconds : number ) : Promise < void > {
135
+ const talksOfInterest = await this . db . getTalksWithUpcomingEvents ( lookaheadSeconds / 60 ) ;
136
+ for ( const dbTalk of talksOfInterest ) {
137
+ const talk = this . talks . get ( dbTalk . event_id ) ;
138
+ if ( talk === undefined ) {
139
+ LogService . warn ( "PentaBackend" , `refreshShortTerm: DB talk '${ dbTalk . event_id } ' is upcoming but has no talk entry to hydrate.` ) ;
140
+ continue ;
141
+ }
142
+ this . rehydrateTalkFrom ( talk , dbTalk ) ;
143
+ }
144
+ }
145
+
117
146
conference : IConference ;
118
147
talks : Map < TalkId , ITalk > ;
119
148
auditoriums : Map < AuditoriumId , IAuditorium > ;
0 commit comments