From a310f4190c1a58cfb4f4fd025ffee2befd5d7ab1 Mon Sep 17 00:00:00 2001 From: Deon George Date: Fri, 1 Nov 2024 13:40:18 +1100 Subject: [PATCH] MATRIX_SERVER configuration item is now a URL --- app/Events/Matrix/Base.php | 4 ++-- app/Notifications/Matrix/Echomail.php | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/Events/Matrix/Base.php b/app/Events/Matrix/Base.php index 136fe4d..60cf574 100644 --- a/app/Events/Matrix/Base.php +++ b/app/Events/Matrix/Base.php @@ -42,13 +42,13 @@ abstract class Base case 'room': $room_alias = Http::withToken(config('matrix.as_token')) - ->get(sprintf('https://%s/_matrix/client/v3/rooms/%s/state/m.room.canonical_alias',config('matrix.server'),$this->room_id)); + ->get(sprintf('%s/_matrix/client/v3/rooms/%s/state/m.room.canonical_alias',config('matrix.server'),$this->room_id)); return $room_alias->json('alias',$this->room_id); case 'topic': $subject = Http::withToken(config('matrix.as_token')) - ->get(sprintf('https://%s/_matrix/client/v3/rooms/%s/state/m.room.topic',config('matrix.server'),$this->room_id)); + ->get(sprintf('%s/_matrix/client/v3/rooms/%s/state/m.room.topic',config('matrix.server'),$this->room_id)); return $subject->json('topic','Message from Matrix'); diff --git a/app/Notifications/Matrix/Echomail.php b/app/Notifications/Matrix/Echomail.php index 2beb611..1aee5d1 100644 --- a/app/Notifications/Matrix/Echomail.php +++ b/app/Notifications/Matrix/Echomail.php @@ -43,15 +43,15 @@ class Echomail extends Matrix $this->o->fftn->point_id, ); - $user = sprintf('@%s:%s',$username,config('matrix.server')); + $user = sprintf('@%s:%s',$username,preg_replace('#^(http[s]?://)?([^:]+)(:[0-9]+)?$#','$2',config('matrix.server'))); // Set topic if it is different: $subject = Http::withToken(config('matrix.as_token')) - ->get(sprintf('https://%s/_matrix/client/v3/rooms/%s/state/m.room.topic',config('matrix.server'),$room)); + ->get(sprintf('%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')) { $topic = Http::withToken(config('matrix.as_token')) - ->put(sprintf('https://%s/_matrix/client/v3/rooms/%s/state/m.room.topic',config('matrix.server'),$room),[ + ->put(sprintf('%s/_matrix/client/v3/rooms/%s/state/m.room.topic',config('matrix.server'),$room),[ 'topic'=>$x, ]); @@ -63,7 +63,7 @@ class Echomail extends Matrix $msg = Http::withToken(config('matrix.as_token')) ->withQueryParameters(['user_id'=>$user]) - ->post(sprintf('https://%s/_matrix/client/v3/rooms/%s/send/m.room.message',config('matrix.server'),$room),[ + ->post(sprintf('%s/_matrix/client/v3/rooms/%s/send/m.room.message',config('matrix.server'),$room),[ 'msgtype'=>'m.text', 'format'=>'org.matrix.custom.html', 'body'=>mb_convert_encoding(str_replace("\r","\n",$omsg),'UTF-8','IBM850'), @@ -82,7 +82,7 @@ class Echomail extends Matrix if (str_starts_with($msg->json('error'),'Application service has not registered this user')) { // Register user $msg = Http::withToken(config('matrix.as_token')) - ->post(sprintf('https://%s/_matrix/client/v3/register',config('matrix.server')),[ + ->post(sprintf('%s/_matrix/client/v3/register',config('matrix.server')),[ 'type'=>'m.login.application_service', 'username'=>$username, ]); @@ -96,7 +96,7 @@ class Echomail extends Matrix // Invite user $msg = Http::withToken(config('matrix.as_token')) //->withQueryParameters(['user_id'=>$user]) - ->post(sprintf('https://%s/_matrix/client/v3/rooms/%s/invite',config('matrix.server'),$room),[ + ->post(sprintf('%s/_matrix/client/v3/rooms/%s/invite',config('matrix.server'),$room),[ 'user_id'=>$user, ]); @@ -108,7 +108,7 @@ class Echomail extends Matrix // Join as user $msg = Http::withToken(config('matrix.as_token')) ->withQueryParameters(['user_id'=>$user]) - ->post(sprintf('https://%s/_matrix/client/v3/rooms/%s/join',config('matrix.server'),$room),[ + ->post(sprintf('%s/_matrix/client/v3/rooms/%s/join',config('matrix.server'),$room),[ 'user_id'=>$user, ]);