Force posting to matrix to use IPv4 resolution
This commit is contained in:
parent
1002309614
commit
881449a170
@ -45,12 +45,18 @@ class Echomail extends Matrix
|
|||||||
|
|
||||||
$user = sprintf('@%s:%s',$username,config('matrix.server'));
|
$user = sprintf('@%s:%s',$username,config('matrix.server'));
|
||||||
|
|
||||||
|
// @todo We need to force IP4 as running clrghouz in a container without a proper IPv6 address is problematic
|
||||||
|
$matrix = Http::withToken(config('matrix.as_token'))
|
||||||
|
->withOptions([
|
||||||
|
CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4,
|
||||||
|
]);
|
||||||
|
|
||||||
// Set topic if it is different:
|
// Set topic if it is different:
|
||||||
$subject = Http::withToken(config('matrix.as_token'))
|
$subject = $matrix
|
||||||
->get(sprintf('https://%s/_matrix/client/v3/rooms/%s/state/m.room.topic',config('matrix.server'),$room));
|
->get(sprintf('https://%s/_matrix/client/v3/rooms/%s/state/m.room.topic',config('matrix.server'),$room));
|
||||||
|
|
||||||
if (($x=preg_replace('/^RE:\s*/i','',$this->o->subject)) !== $subject->json('topic','Message from Matrix')) {
|
if (($x=preg_replace('/^RE:\s*/i','',$this->o->subject)) !== $subject->json('topic','Message from Matrix')) {
|
||||||
$topic = Http::withToken(config('matrix.as_token'))
|
$topic = $matrix
|
||||||
->put(sprintf('https://%s/_matrix/client/v3/rooms/%s/state/m.room.topic',config('matrix.server'),$room),[
|
->put(sprintf('https://%s/_matrix/client/v3/rooms/%s/state/m.room.topic',config('matrix.server'),$room),[
|
||||||
'topic'=>$x,
|
'topic'=>$x,
|
||||||
]);
|
]);
|
||||||
@ -61,7 +67,7 @@ class Echomail extends Matrix
|
|||||||
|
|
||||||
$omsg = preg_replace("/\r---.*$/U",'',$this->o->msg);
|
$omsg = preg_replace("/\r---.*$/U",'',$this->o->msg);
|
||||||
|
|
||||||
$msg = Http::withToken(config('matrix.as_token'))
|
$msg = $matrix
|
||||||
->withQueryParameters(['user_id'=>$user])
|
->withQueryParameters(['user_id'=>$user])
|
||||||
->post(sprintf('https://%s/_matrix/client/v3/rooms/%s/send/m.room.message',config('matrix.server'),$room),[
|
->post(sprintf('https://%s/_matrix/client/v3/rooms/%s/send/m.room.message',config('matrix.server'),$room),[
|
||||||
'msgtype'=>'m.text',
|
'msgtype'=>'m.text',
|
||||||
@ -81,7 +87,7 @@ class Echomail extends Matrix
|
|||||||
// If the user doesnt exist in matrix yet
|
// If the user doesnt exist in matrix yet
|
||||||
if (str_starts_with($msg->json('error'),'Application service has not registered this user')) {
|
if (str_starts_with($msg->json('error'),'Application service has not registered this user')) {
|
||||||
// Register user
|
// Register user
|
||||||
$msg = Http::withToken(config('matrix.as_token'))
|
$msg = $matrix
|
||||||
->post(sprintf('https://%s/_matrix/client/v3/register',config('matrix.server')),[
|
->post(sprintf('https://%s/_matrix/client/v3/register',config('matrix.server')),[
|
||||||
'type'=>'m.login.application_service',
|
'type'=>'m.login.application_service',
|
||||||
'username'=>$username,
|
'username'=>$username,
|
||||||
@ -94,7 +100,7 @@ class Echomail extends Matrix
|
|||||||
|
|
||||||
// @todo Test that the user has been invited
|
// @todo Test that the user has been invited
|
||||||
// Invite user
|
// Invite user
|
||||||
$msg = Http::withToken(config('matrix.as_token'))
|
$msg = $matrix
|
||||||
//->withQueryParameters(['user_id'=>$user])
|
//->withQueryParameters(['user_id'=>$user])
|
||||||
->post(sprintf('https://%s/_matrix/client/v3/rooms/%s/invite',config('matrix.server'),$room),[
|
->post(sprintf('https://%s/_matrix/client/v3/rooms/%s/invite',config('matrix.server'),$room),[
|
||||||
'user_id'=>$user,
|
'user_id'=>$user,
|
||||||
@ -106,7 +112,7 @@ class Echomail extends Matrix
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Join as user
|
// Join as user
|
||||||
$msg = Http::withToken(config('matrix.as_token'))
|
$msg = $matrix
|
||||||
->withQueryParameters(['user_id'=>$user])
|
->withQueryParameters(['user_id'=>$user])
|
||||||
->post(sprintf('https://%s/_matrix/client/v3/rooms/%s/join',config('matrix.server'),$room),[
|
->post(sprintf('https://%s/_matrix/client/v3/rooms/%s/join',config('matrix.server'),$room),[
|
||||||
'user_id'=>$user,
|
'user_id'=>$user,
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
"require": {
|
"require": {
|
||||||
"php": "^8.2|8.3",
|
"php": "^8.2|8.3",
|
||||||
"ext-bz2": "*",
|
"ext-bz2": "*",
|
||||||
|
"ext-curl": "*",
|
||||||
"ext-pcntl": "*",
|
"ext-pcntl": "*",
|
||||||
"ext-sockets": "*",
|
"ext-sockets": "*",
|
||||||
"ext-zip": "*",
|
"ext-zip": "*",
|
||||||
|
Loading…
Reference in New Issue
Block a user