@@ -44,7 +44,7 @@ const MAX_STORE = 3;
4444export default class NetworkManager {
4545 private readonly scheduler : Scheduler ;
4646 private readonly antiSpamMap : Collection < string , AntiSpamUserOpts > ;
47- private _connectionCache : Collection < string , Connection > ;
47+ private _connectionCache : Collection < string , connectedList > ;
4848 private cachePopulated = false ;
4949
5050 constructor ( ) {
@@ -61,10 +61,7 @@ export default class NetworkManager {
6161
6262 protected async populateConnectionCache ( ) {
6363 Logger . debug ( '[InterChat]: Populating connection cache.' ) ;
64- const connections = await db . connectedList . findMany ( {
65- where : { connected : true } ,
66- include : { hub : true } ,
67- } ) ;
64+ const connections = await db . connectedList . findMany ( { where : { connected : true } } ) ;
6865
6966 // populate all at once without time delay
7067 this . _connectionCache = new Collection ( connections . map ( ( c ) => [ c . channelId , c ] ) ) ;
@@ -91,12 +88,15 @@ export default class NetworkManager {
9188 const locale = await message . client . getUserLocale ( message . author . id ) ;
9289 message . author . locale = locale ;
9390
94- const connection = this . _connectionCache . get ( message . channelId ) ;
95-
9691 // check if the message was sent in a network channel
97- if ( ! connection ?. connected || ! connection . hub ) return ;
92+ const connection = this . connectionCache . get ( message . channel . id ) ;
93+ if ( ! connection ?. connected ) return ;
94+
95+ const hub = await db . hubs . findFirst ( { where : { id : connection ?. hubId } } ) ;
96+ if ( ! hub ) return ;
9897
99- const settings = new HubSettingsBitField ( connection . hub . settings ) ;
98+ const settings = new HubSettingsBitField ( hub . settings ) ;
99+ const hubConnections = this . connectionCache . filter ( ( con ) => con . hubId === connection . hubId ) ;
100100
101101 const attachment = message . attachments . first ( ) ;
102102 const attachmentURL = attachment
@@ -108,7 +108,6 @@ export default class NetworkManager {
108108 return ;
109109 }
110110
111- const hubConnections = this . _connectionCache . filter ( ( con ) => con . hubId === connection . hubId ) ;
112111
113112 const censoredContent = censor ( message . content ) ;
114113
@@ -189,8 +188,8 @@ export default class NetworkManager {
189188 let messageFormat : WebhookMessageCreateOptions = {
190189 components : jumpButton ? [ jumpButton ] : undefined ,
191190 embeds : [ otherConnection . profFilter ? censoredEmbed : embed ] ,
192- username : `${ connection . hub ? .name } ` ,
193- avatarURL : connection . hub ? .iconUrl ,
191+ username : `${ hub . name } ` ,
192+ avatarURL : hub . iconUrl ,
194193 threadId : otherConnection . parentId ? otherConnection . channelId : undefined ,
195194 allowedMentions : { parse : [ ] } ,
196195 } ;
@@ -284,7 +283,7 @@ export default class NetworkManager {
284283 { phrase : 'network.welcome' , locale } ,
285284 {
286285 user : message . author . toString ( ) ,
287- hub : connection . hub . name ,
286+ hub : hub . name ,
288287 channel : message . channel . toString ( ) ,
289288 totalServers : hubConnections . size . toString ( ) ,
290289 emoji : emojis . wave_anim ,
0 commit comments