This commit is contained in:
Huong Nguyen 2024-04-29 08:55:02 +07:00
commit f686d2a6c7
No known key found for this signature in database
GPG Key ID: 40D88AB693A3E72A
2 changed files with 16 additions and 0 deletions

View File

@ -24,6 +24,12 @@ namespace communication_matrix;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class matrix_user_manager {
/**
* Prefix for Matrix usernames when they are detected as numeric.
*/
const MATRIX_USER_PREFIX = 'user';
/**
* Gets matrix user id from moodle.
*
@ -56,6 +62,11 @@ class matrix_user_manager {
$username = preg_replace('/[@#$%^&*()+{}|<>?!,]/i', '.', $username);
$username = ltrim(rtrim($username, '.'), '.');
// Matrix/Synapse servers will not allow numeric usernames.
if (is_numeric($username)) {
$username = self::MATRIX_USER_PREFIX . $username;
}
$homeserver = self::get_formatted_matrix_home_server();
return "@{$username}:{$homeserver}";

View File

@ -126,6 +126,11 @@ class matrix_user_manager_test extends \advanced_testcase {
'colin.creavey',
'@colin.creavey:matrix.example.org',
],
'numeric username' => [
'https://matrix.example.org',
'123456',
'@' . matrix_user_manager::MATRIX_USER_PREFIX . '123456:matrix.example.org',
],
];
}