@@ -75,6 +75,7 @@ export class BotImpl<TContextData> implements Bot<TContextData> {
75
75
readonly icon ?: URL ;
76
76
readonly image ?: URL ;
77
77
readonly properties : Record < string , Text < "block" | "inline" , TContextData > > ;
78
+ #properties: { pairs : PropertyValue [ ] ; tags : Link [ ] } | null ;
78
79
readonly kv : KvStore ;
79
80
readonly kvPrefixes : BotKvPrefixes ;
80
81
readonly software ?: Software ;
@@ -96,6 +97,7 @@ export class BotImpl<TContextData> implements Bot<TContextData> {
96
97
this . icon = options . icon ;
97
98
this . image = options . image ;
98
99
this . properties = options . properties ?? { } ;
100
+ this . #properties = null ;
99
101
this . kv = options . kv ;
100
102
this . kvPrefixes = {
101
103
keyPairs : [ "_botkit" , "keyPairs" ] ,
@@ -181,51 +183,68 @@ export class BotImpl<TContextData> implements Bot<TContextData> {
181
183
}
182
184
}
183
185
184
- async dispatchActor (
185
- ctx : Context < TContextData > ,
186
- identifier : string ,
187
- ) : Promise < Actor | null > {
188
- if ( this . identifier !== identifier ) return null ;
189
- const session = this . getSession ( ctx ) ;
190
- let summary : string | null = null ;
191
- let tags : Link [ ] = [ ] ;
192
- if ( this . summary != null ) {
193
- if ( this . #summary == null ) {
194
- summary = "" ;
195
- for await ( const chunk of this . summary . getHtml ( session ) ) {
196
- summary += chunk ;
197
- }
198
- for await ( const tag of this . summary . getTags ( session ) ) {
199
- tags . push ( tag ) ;
200
- }
201
- this . #summary = { text : summary , tags } ;
202
- } else {
203
- summary = this . #summary. text ;
204
- tags = this . #summary. tags ;
186
+ async #getSummary(
187
+ session : Session < TContextData > ,
188
+ ) : Promise < { text : string ; tags : Link [ ] } | null > {
189
+ if ( this . summary == null ) return null ;
190
+ if ( this . #summary == null ) {
191
+ let summary = "" ;
192
+ const tags : Link [ ] = [ ] ;
193
+ for await ( const chunk of this . summary . getHtml ( session ) ) {
194
+ summary += chunk ;
195
+ }
196
+ for await ( const tag of this . summary . getTags ( session ) ) {
197
+ tags . push ( tag ) ;
205
198
}
199
+ return this . #summary = { text : summary , tags } ;
206
200
}
207
- const attachments : ( Object | Link | PropertyValue ) [ ] = [ ] ;
201
+ return this . #summary;
202
+ }
203
+
204
+ async #getProperties(
205
+ session : Session < TContextData > ,
206
+ ) : Promise < { pairs : PropertyValue [ ] ; tags : Link [ ] } > {
207
+ if ( this . #properties != null ) return this . #properties;
208
+ const pairs : PropertyValue [ ] = [ ] ;
209
+ const tags : Link [ ] = [ ] ;
208
210
for ( const name in this . properties ) {
209
211
const value = this . properties [ name ] ;
210
212
const pair = new PropertyValue ( {
211
213
name,
212
214
value : ( await Array . fromAsync ( value . getHtml ( session ) ) ) . join ( "" ) ,
213
215
} ) ;
214
- attachments . push ( pair ) ;
216
+ pairs . push ( pair ) ;
215
217
for await ( const tag of value . getTags ( session ) ) {
216
218
tags . push ( tag ) ;
217
219
}
218
220
}
221
+ return this . #properties = { pairs, tags } ;
222
+ }
223
+
224
+ async dispatchActor (
225
+ ctx : Context < TContextData > ,
226
+ identifier : string ,
227
+ ) : Promise < Actor | null > {
228
+ if ( this . identifier !== identifier ) return null ;
229
+ const session = this . getSession ( ctx ) ;
230
+ const summary = await this . #getSummary( session ) ;
231
+ const { pairs, tags } = await this . #getProperties( session ) ;
232
+ const allTags = summary == null ? tags : [ ...tags , ...summary . tags ] ;
219
233
const keyPairs = await ctx . getActorKeyPairs ( identifier ) ;
220
234
return new this . class ( {
221
235
id : ctx . getActorUri ( identifier ) ,
222
236
preferredUsername : this . username ,
223
237
name : this . name ,
224
- summary,
225
- tags,
238
+ summary : summary == null ? null : summary . text ,
239
+ attachments : pairs ,
240
+ tags : allTags . filter ( ( tag , i ) =>
241
+ allTags . findIndex ( ( t ) =>
242
+ t . name ?. toString ( ) === tag . name ?. toString ( ) &&
243
+ t . href ?. href === tag . href ?. href
244
+ ) === i
245
+ ) ,
226
246
icon : new Image ( { url : this . icon } ) ,
227
247
image : new Image ( { url : this . image } ) ,
228
- attachments,
229
248
inbox : ctx . getInboxUri ( identifier ) ,
230
249
endpoints : new Endpoints ( {
231
250
sharedInbox : ctx . getInboxUri ( ) ,
0 commit comments