-
Notifications
You must be signed in to change notification settings - Fork 13.7k
chore(federation): add settings watcher #37289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
f29e839
b48a1ae
1d4cfa6
616c805
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,16 @@ | ||
| import { License } from '@rocket.chat/core-services'; | ||
| import { Emitter } from '@rocket.chat/emitter'; | ||
| import type { HomeserverEventSignatures } from '@rocket.chat/federation-sdk'; | ||
| import { ConfigService, createFederationContainer } from '@rocket.chat/federation-sdk'; | ||
| import { ConfigService, createFederationContainer, getAllServices } from '@rocket.chat/federation-sdk'; | ||
| import { Logger } from '@rocket.chat/logger'; | ||
| import { Settings } from '@rocket.chat/models'; | ||
|
|
||
| import { registerEvents } from './events'; | ||
|
|
||
| const logger = new Logger('FederationSetup'); | ||
|
|
||
| let containerInitialized = false; | ||
|
|
||
| function validateDomain(domain: string): boolean { | ||
| const value = domain.trim(); | ||
|
|
||
|
|
@@ -40,6 +42,11 @@ export async function setupFederationMatrix(instanceId: string): Promise<boolean | |
| const settingEnabled = (await Settings.getValueById<boolean>('Federation_Service_Enabled')) || false; | ||
| const serverName = (await Settings.getValueById<string>('Federation_Service_Domain')) || ''; | ||
|
|
||
| const serviceEnabled = (await License.hasModule('federation')) && settingEnabled && validateDomain(serverName); | ||
| if (!serviceEnabled) { | ||
| return false; | ||
| } | ||
|
|
||
| const processEDUTyping = (await Settings.getValueById<boolean>('Federation_Service_EDU_Process_Typing')) || false; | ||
| const processEDUPresence = (await Settings.getValueById<boolean>('Federation_Service_EDU_Process_Presence')) || false; | ||
| const signingKey = (await Settings.getValueById<string>('Federation_Service_Matrix_Signing_Key')) || ''; | ||
|
|
@@ -52,7 +59,7 @@ export async function setupFederationMatrix(instanceId: string): Promise<boolean | |
| const mongoUri = process.env.MONGO_URL || 'mongodb://localhost:3001/meteor'; | ||
| const dbName = process.env.DATABASE_NAME || new URL(mongoUri).pathname.slice(1); | ||
|
|
||
| const config = new ConfigService({ | ||
| const configValues = { | ||
| instanceId, | ||
| serverName, | ||
| keyRefreshInterval: Number.parseInt(process.env.MATRIX_KEY_REFRESH_INTERVAL || '60', 10), | ||
|
|
@@ -89,26 +96,29 @@ export async function setupFederationMatrix(instanceId: string): Promise<boolean | |
| allowedEncryptedRooms, | ||
| allowedNonPrivateRooms, | ||
| }, | ||
| }); | ||
| }; | ||
|
|
||
| const eventHandler = new Emitter<HomeserverEventSignatures>(); | ||
| if (!containerInitialized) { | ||
| const config = new ConfigService(configValues); | ||
| const eventHandler = new Emitter<HomeserverEventSignatures>(); | ||
|
|
||
| await createFederationContainer( | ||
| { | ||
| emitter: eventHandler, | ||
| }, | ||
| config, | ||
| ); | ||
|
|
||
| const serviceEnabled = (await License.hasModule('federation')) && settingEnabled && validateDomain(serverName); | ||
| if (!serviceEnabled) { | ||
| return false; | ||
| await createFederationContainer( | ||
| { | ||
| emitter: eventHandler, | ||
| }, | ||
| config, | ||
| ); | ||
|
|
||
| registerEvents(eventHandler, serverName, { | ||
| typing: processEDUTyping, | ||
| presence: processEDUPresence, | ||
| }); | ||
|
|
||
| containerInitialized = true; | ||
| } else { | ||
| const services = getAllServices(); | ||
| services.config.updateConfig(configValues); | ||
| } | ||
|
Comment on lines
+118
to
121
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainFix TypeScript compilation error: The pipeline failure indicates that Verify the following: Additionally, check the package version of If the method doesn't exist yet, this PR should either:
🏁 Script executed: #!/bin/bash
# Check if updateConfig method exists in ConfigService type definition
ast-grep --pattern $'class ConfigService {
$$$
updateConfig($$$) {
$$$
}
$$$
}'Length of output: 0 🏁 Script executed: #!/bin/bash
# Check the version of federation-sdk in package.json files
fd -e json -x cat {} | jq -r 'select(.dependencies["@rocket.chat/federation-sdk"] or .devDependencies["@rocket.chat/federation-sdk"]) | {file: input_filename, version: (.dependencies["@rocket.chat/federation-sdk"] // .devDependencies["@rocket.chat/federation-sdk"])}'Length of output: 66 I need to take a different approach with simpler, more targeted searches. Let me verify the codebase more directly: Length of output: 27 🏁 Script executed: #!/bin/bash
# Search for getAllServices function definition
rg -nA3 "function getAllServices\|const getAllServices" --type ts --type tsxLength of output: 27 🏁 Script executed: #!/bin/bash
# Look at the actual setup.ts file around the problematic lines
cat ee/packages/federation-matrix/src/setup.ts | head -130 | tail -30Length of output: 568 🏁 Script executed: #!/bin/bash
# Search for updateConfig method definition anywhere
rg -nB2 -A5 "updateConfig\s*\(" --type ts --type tsxLength of output: 27 🏁 Script executed: #!/bin/bash
# Simple check of federation-sdk version in main package.json
grep -A2 -B2 "federation-sdk" package.jsonLength of output: 0 Let me fix the commands and retry with corrected search patterns: Length of output: 0 🏁 Script executed: #!/bin/bash
# Search for getAllServices function with simpler pattern
rg -nA3 "getAllServices" --type ts | head -50Length of output: 3057 🏁 Script executed: #!/bin/bash
# Check package.json in the federation-matrix directory
find ee/packages/federation-matrix -name "package.json" -exec grep -l "federation-sdk" {} \;Length of output: 42 🏁 Script executed: #!/bin/bash
# Look for updateConfig definition
rg -nB2 -A5 "updateConfig" --type ts | head -100Length of output: 1426 🏁 Script executed: #!/bin/bash
# Check federation-matrix package.json for dependencies
cat ee/packages/federation-matrix/package.json | grep -A5 -B5 "dependencies\|federation"Length of output: 642 Length of output: 0 🏁 Script executed: #!/bin/bash
# Search for federation-sdk source files or look for ConfigService type definitions
rg -l "federation-sdk" --type ts | grep -E "(node_modules|dist)" | head -10Length of output: 0 🏁 Script executed: #!/bin/bash
# Check if there's a federation-sdk package source in the workspace
find ee/packages -name "federation-sdk*" -o -name "*federation*sdk*" | head -20Length of output: 0 🏁 Script executed: #!/bin/bash
# Search for any type definitions or imports of ConfigService to understand its type
rg "ConfigService" --type ts -B2 -A2 | head -80Length of output: 903 💡 Result: Do you want the method signature, usage example, or the source code for ConfigService.updateConfig? I can look it up — shall I search the repo/npm docs now? 💡 Result: I couldn't find a published @rocket.chat/federation-sdk version 0.2.0 on the public registries. The package appears to have 0.1.x releases (latest listed ~0.1.18); no 0.2.0 release is shown. See registry listings. [1][2] If you intended to install the latest published release, use: Sources: Dependency blocker: The package appears to have 0.1.x releases; no 0.2.0 release is shown. The code at line 120 calls Action required:
🧰 Tools🪛 GitHub Actions: CI[error] 120-120: TS2339: Property 'updateConfig' does not exist on type 'ConfigService'. 🤖 Prompt for AI Agents
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @coderabbitai, the library exists in the Homeserver project (PR #289), and once it’s reviewed there, we’ll release an update to bump the library version here.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| registerEvents(eventHandler, serverName, { | ||
| typing: processEDUTyping, | ||
| presence: processEDUPresence, | ||
| }); | ||
|
|
||
| return true; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.