|
|
|
|
@ -944,4 +944,51 @@ export class FederationMatrix extends ServiceClass implements IFederationMatrixS |
|
|
|
|
|
|
|
|
|
void this.homeserverServices.edu.sendTypingNotification(room.federation.mrid, userMui, isTyping); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async verifyMatrixIds(matrixIds: string[]): Promise<{ [key: string]: string }> { |
|
|
|
|
const results = Object.fromEntries( |
|
|
|
|
await Promise.all( |
|
|
|
|
matrixIds.map(async (matrixId) => { |
|
|
|
|
// Split only on the first ':' (after the leading '@') so we keep any port in the homeserver
|
|
|
|
|
const separatorIndex = matrixId.indexOf(':', 1); |
|
|
|
|
if (separatorIndex === -1) { |
|
|
|
|
return [matrixId, 'UNABLE_TO_VERIFY']; |
|
|
|
|
} |
|
|
|
|
const userId = matrixId.slice(0, separatorIndex); |
|
|
|
|
const homeserverUrl = matrixId.slice(separatorIndex + 1); |
|
|
|
|
|
|
|
|
|
if (homeserverUrl === this.serverName) { |
|
|
|
|
const user = await Users.findOneByUsername(userId.slice(1)); |
|
|
|
|
return [matrixId, user ? 'VERIFIED' : 'UNVERIFIED']; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!homeserverUrl) { |
|
|
|
|
return [matrixId, 'UNABLE_TO_VERIFY']; |
|
|
|
|
} |
|
|
|
|
try { |
|
|
|
|
const result = await this.homeserverServices.request.get< |
|
|
|
|
| { |
|
|
|
|
avatar_url: string; |
|
|
|
|
displayname: string; |
|
|
|
|
} |
|
|
|
|
| { |
|
|
|
|
errcode: string; |
|
|
|
|
error: string; |
|
|
|
|
} |
|
|
|
|
>(homeserverUrl, `/_matrix/federation/v1/query/profile`, { user_id: matrixId }); |
|
|
|
|
|
|
|
|
|
if ('errcode' in result && result.errcode === 'M_NOT_FOUND') { |
|
|
|
|
return [matrixId, 'UNVERIFIED']; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return [matrixId, 'VERIFIED']; |
|
|
|
|
} catch (e) { |
|
|
|
|
return [matrixId, 'UNABLE_TO_VERIFY']; |
|
|
|
|
} |
|
|
|
|
}), |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
return results; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|