Compare commits

..

No commits in common. 'e55b6fe70c8dc52fbb9a4882aa51605b3955c6c7' and '0c3d8eb50143f1924eb2ae2ef46d7a7bd068723c' have entirely different histories.

  1. 2
      .tito/packages/patrix
  2. 6
      patrix.spec
  3. 35
      scripts/patrix

@ -1 +1 @@
0.1.17-1 ./
0.1.16-1 ./

@ -1,5 +1,5 @@
Name: patrix
Version: 0.1.17
Version: 0.1.16
Release: 1%{?dist}
Summary: Command line client for Matrix
@ -53,10 +53,6 @@ room via the command line.
%{_bindir}/patrix
%changelog
* Thu Jul 04 2024 Daniel Berteaud <dbd@ehtrace.com> 0.1.17-1
- Use Authorization header instead of GET param to pass access_token
(dbd@ehtrace.com)
* Mon Feb 13 2023 Daniel Berteaud <dbd@ehtrace.com> 0.1.16-1
- Add HTML::Strip to Required (dbd@ehtrace.com)
- Add HTML::Strip and always support HTML messages (imagotrigger@gmail.com)

@ -159,9 +159,6 @@ sub send_request {
die "Missing an URI" unless $param->{uri};
my $req = HTTP::Request->new( $param->{method}, $param->{uri} );
$req->header('Content-Type' => $param->{content_type});
if (defined $opt->{access_token}){
$req->header('Authorization' => "Bearer $opt->{access_token}");
}
$req->content($param->{content});
my $resp = $lwp->request( $req );
debug("Server responded:\n" . to_json(from_json($resp->decoded_content), { pretty => 1 }));
@ -211,7 +208,7 @@ sub login {
# Invalidate the access_token
sub logout {
debug("Trying to logout");
my $uri = $opt->{server} . '/_matrix/client/r0/logout';
my $uri = $opt->{server} . '/_matrix/client/r0/logout?access_token=' . $opt->{access_token};
my $resp = send_request({
uri => $uri
});
@ -221,8 +218,8 @@ sub logout {
# Join the specified room, before we can send anything
sub join_room {
debug("Trying to join room $opt->{room}");
# Room must be escaped.
my $uri = $opt->{server} . '/_matrix/client/r0/join/' . uri_escape( $opt->{room} );
# Room must be escaped. if not and room is an alias, it'll start with # so the access_token won't be sent
my $uri = $opt->{server} . '/_matrix/client/r0/join/' . uri_escape( $opt->{room} ) . '?access_token=' . $opt->{access_token};
my $resp = send_request({
uri => $uri
});
@ -232,7 +229,7 @@ sub join_room {
# Retrieve the actual permissions for a room
sub get_room_permissions {
debug('Getting actual room state');
my $uri = $opt->{server} . '/_matrix/client/r0/rooms/' . $opt->{room} . '/state/m.room.power_levels';
my $uri = $opt->{server} . '/_matrix/client/r0/rooms/' . $opt->{room} . '/state/m.room.power_levels?access_token=' . $opt->{access_token};
my $resp = send_request({
method => 'GET',
uri => $uri
@ -253,7 +250,7 @@ sub who_am_i {
# Send a text message (either message or notice as both are similar)
sub send_msg {
my $uri = $opt->{server} . '/_matrix/client/r0/rooms/' . $opt->{room} . '/send/m.room.message';
my $uri = $opt->{server} . '/_matrix/client/r0/rooms/' . $opt->{room} . '/send/m.room.message?access_token=' . $opt->{access_token};
# Ignore --message if reading from stdin
if ($stdin){
$opt->{message} = '';
@ -285,7 +282,7 @@ sub send_file {
# Sending a file is a 2 steps operation. First we need to upload the file to the media store
# And then we post the uri on the room
debug("Uploading file $file to the media store");
my $uri = $opt->{server} . '/_matrix/media/v1/upload?filename=' . basename($file);
my $uri = $opt->{server} . '/_matrix/media/v1/upload?access_token=' . $opt->{access_token} . '&filename=' . basename($file);
my $mime = mimetype($file);
my $resp = send_request({
uri => $uri,
@ -299,7 +296,7 @@ sub send_file {
die "Server did not sent the file URI\n" unless ($file_uri);
debug("File uploaded, with the URI $file_uri\nNow Sending the file link to the room $opt->{room}");
# Now lets post a new message with the URI of the file
$uri = $opt->{server} . '/_matrix/client/r0/rooms/' . $opt->{room} . '/send/m.room.message';
$uri = $opt->{server} . '/_matrix/client/r0/rooms/' . $opt->{room} . '/send/m.room.message?access_token=' . $opt->{access_token};
my $json = {
msgtype => 'm.file',
body => basename($file),
@ -331,7 +328,7 @@ sub send_file {
# Note that there's no pagination handling yet, so you might not have all the results
sub list_room {
debug("Fetching list of public rooms on $opt->{server}");
my $uri = $opt->{server} . '/_matrix/client/r0/publicRooms';
my $uri = $opt->{server} . '/_matrix/client/r0/publicRooms?access_token=' . $opt->{access_token};
my $resp = send_request({
uri => $uri,
});
@ -349,7 +346,7 @@ sub list_room {
# Create a new room
sub create_room {
debug("Creating a new room on $opt->{server}");
my $uri = $opt->{server} . '/_matrix/client/r0/createRoom';
my $uri = $opt->{server} . '/_matrix/client/r0/createRoom?access_token=' . $opt->{access_token};
my $json = {};
my $resp = send_request({
uri => $uri,
@ -369,7 +366,7 @@ sub modify_room {
# A new alias should be added
if ($opt->{alias}){
debug('Adding ' . $opt->{alias} . ' as a room alias');
$uri = $opt->{server} . '/_matrix/client/r0/directory/room/' . uri_escape($opt->{alias});
$uri = $opt->{server} . '/_matrix/client/r0/directory/room/' . uri_escape($opt->{alias}) . '?access_token=' . $opt->{access_token};
$json = {
room_id => $opt->{room}
};
@ -384,7 +381,7 @@ sub modify_room {
# The name of the room is being updated
if ($opt->{name}){
debug('Changing the room name to ' . $opt->{name});
$uri = $opt->{server} . '/_matrix/client/r0/rooms/' . $opt->{room} . '/state/m.room.name';
$uri = $opt->{server} . '/_matrix/client/r0/rooms/' . $opt->{room} . '/state/m.room.name?access_token=' . $opt->{access_token};
$json = {
name => $opt->{name}
};
@ -399,7 +396,7 @@ sub modify_room {
# The topic is being updated
if ($opt->{topic}){
debug('Changing the room topic to ' . $opt->{topic});
$uri = $opt->{server} . '/_matrix/client/r0/rooms/' . $opt->{room} . '/state/m.room.topic';
$uri = $opt->{server} . '/_matrix/client/r0/rooms/' . $opt->{room} . '/state/m.room.topic?access_token=' . $opt->{access_token};
$json = {
topic => $opt->{topic}
};
@ -414,7 +411,7 @@ sub modify_room {
# Changing joining rules
if ($opt->{join_rules}){
debug('Changing the joining rules to '. $opt->{join_rules});
$uri = $opt->{server} . '/_matrix/client/r0/rooms/' . $opt->{room} . '/state/m.room.join_rules';
$uri = $opt->{server} . '/_matrix/client/r0/rooms/' . $opt->{room} . '/state/m.room.join_rules?access_token=' . $opt->{access_token};
$json = {
join_rules => $opt->{join_rules}
};
@ -478,7 +475,7 @@ sub modify_room {
}
my $perm = merge($current_perm, $new_perm);
debug("New permissions for this room will be:\n" . to_json($perm, { pretty => 1 }));
$uri = $opt->{server} . '/_matrix/client/r0/rooms/' . $opt->{room} . '/state/m.room.power_levels';
$uri = $opt->{server} . '/_matrix/client/r0/rooms/' . $opt->{room} . '/state/m.room.power_levels?access_token=' . $opt->{access_token};
$resp = send_request({
method => 'PUT',
uri => $uri,
@ -490,7 +487,7 @@ sub modify_room {
# New invitees should be added
if ($opt->{invite}){
debug('Inviting ' . join(',', @{$opt->{invite}}) . ' to join the room');
$uri = $opt->{server} . '/_matrix/client/r0/rooms/' . $opt->{room} . '/invite';
$uri = $opt->{server} . '/_matrix/client/r0/rooms/' . $opt->{room} . '/invite?access_token=' . $opt->{access_token};
foreach my $invite (@{$opt->{invite}}){
$json = {
user_id => $invite
@ -514,7 +511,7 @@ sub modify_room {
sub del_room_alias {
debug("Removing room alias $opt->{alias}");
my $uri = $opt->{server} . "/_matrix/client/r0/directory/room/" . uri_escape($opt->{alias});
my $uri = $opt->{server} . "/_matrix/client/r0/directory/room/" . uri_escape($opt->{alias}) . '?access_token=' . $opt->{access_token};
my $resp = send_request({
method => 'DELETE',
uri => $uri

Loading…
Cancel
Save