Commit 6d621928b8
Unsigned
Layout: unified · split
src/commands/matrix.rs +10 −8
| @@ -1,15 +1,17 @@ | |||
| 1 | use clap::App as Argparse; | 1 | use clap::{ |
| 2 | use clap::AppSettings as ArgParseSettings; | 2 | App as Argparse, AppSettings as ArgParseSettings, Arg, ArgMatches, |
| 3 | use clap::{Arg, ArgMatches, SubCommand}; | 3 | SubCommand, |
| 4 | }; | ||
| 4 | use url::Url; | 5 | use url::Url; |
| 5 | 6 | ||
| 6 | use crate::PLUGIN_NAME; | 7 | use crate::PLUGIN_NAME; |
| 7 | 8 | ||
| 8 | use crate::config::ConfigHandle; | 9 | use crate::{config::ConfigHandle, MatrixServer, Servers}; |
| 9 | use crate::{MatrixServer, Servers}; | 10 | use weechat::{ |
| 10 | use weechat::buffer::Buffer; | 11 | buffer::Buffer, |
| 11 | use weechat::hooks::{Command, CommandCallback, CommandSettings}; | 12 | hooks::{Command, CommandCallback, CommandSettings}, |
| 12 | use weechat::{Args, Weechat}; | 13 | Args, Weechat, |
| 14 | }; | ||
| 13 | 15 | ||
| 14 | pub struct MatrixCommand { | 16 | pub struct MatrixCommand { |
| 15 | servers: Servers, | 17 | servers: Servers, |
src/commands/mod.rs +1 −2
| @@ -1,5 +1,4 @@ | |||
| 1 | use crate::config::ConfigHandle; | 1 | use crate::{config::ConfigHandle, Servers}; |
| 2 | use crate::Servers; | ||
| 3 | use weechat::hooks::Command; | 2 | use weechat::hooks::Command; |
| 4 | 3 | ||
| 5 | mod matrix; | 4 | mod matrix; |
src/config.rs +11 −6
| @@ -16,14 +16,19 @@ | |||
| 16 | //! the section will do so. | 16 | //! the section will do so. |
| 17 | 17 | ||
| 18 | use crate::{MatrixServer, Servers}; | 18 | use crate::{MatrixServer, Servers}; |
| 19 | use weechat::config::{ | 19 | use weechat::{ |
| 20 | Conf, ConfigSection, ConfigSectionSettings, OptionChanged, | 20 | config, |
| 21 | SectionReadCallback, | 21 | config::{ |
| 22 | Conf, ConfigSection, ConfigSectionSettings, OptionChanged, | ||
| 23 | SectionReadCallback, | ||
| 24 | }, | ||
| 25 | Weechat, | ||
| 22 | }; | 26 | }; |
| 23 | use weechat::{config, Weechat}; | ||
| 24 | 27 | ||
| 25 | use std::cell::{Ref, RefCell, RefMut}; | 28 | use std::{ |
| 26 | use std::rc::Rc; | 29 | cell::{Ref, RefCell, RefMut}, |
| 30 | rc::Rc, | ||
| 31 | }; | ||
| 27 | 32 | ||
| 28 | config!( | 33 | config!( |
| 29 | "matrix-rust", | 34 | "matrix-rust", |
src/debug.rs +1 −2
| @@ -1,5 +1,4 @@ | |||
| 1 | use std::cell::RefMut; | 1 | use std::{cell::RefMut, io}; |
| 2 | use std::io; | ||
| 3 | 2 | ||
| 4 | use weechat::{ | 3 | use weechat::{ |
| 5 | buffer::{BufferBuilder, BufferHandle}, | 4 | buffer::{BufferBuilder, BufferHandle}, |
src/lib.rs +6 −6
| @@ -7,9 +7,11 @@ mod render; | |||
| 7 | mod room_buffer; | 7 | mod room_buffer; |
| 8 | mod server; | 8 | mod server; |
| 9 | 9 | ||
| 10 | use std::cell::{Ref, RefCell, RefMut}; | 10 | use std::{ |
| 11 | use std::collections::HashMap; | 11 | cell::{Ref, RefCell, RefMut}, |
| 12 | use std::rc::Rc; | 12 | collections::HashMap, |
| 13 | rc::Rc, | ||
| 14 | }; | ||
| 13 | 15 | ||
| 14 | use weechat::{ | 16 | use weechat::{ |
| 15 | buffer::{Buffer, BufferHandle}, | 17 | buffer::{Buffer, BufferHandle}, |
| @@ -17,9 +19,7 @@ use weechat::{ | |||
| 17 | plugin, Args, Plugin, ReturnCode, Weechat, | 19 | plugin, Args, Plugin, ReturnCode, Weechat, |
| 18 | }; | 20 | }; |
| 19 | 21 | ||
| 20 | use crate::commands::Commands; | 22 | use crate::{commands::Commands, config::ConfigHandle, server::MatrixServer}; |
| 21 | use crate::config::ConfigHandle; | ||
| 22 | use crate::server::MatrixServer; | ||
| 23 | 23 | ||
| 24 | const PLUGIN_NAME: &str = "matrix"; | 24 | const PLUGIN_NAME: &str = "matrix"; |
| 25 | 25 | ||
src/render.rs +2 −4
| @@ -10,10 +10,8 @@ use matrix_sdk::{ | |||
| 10 | TextMessageEventContent, VideoMessageEventContent, | 10 | TextMessageEventContent, VideoMessageEventContent, |
| 11 | }, | 11 | }, |
| 12 | }, | 12 | }, |
| 13 | { | 13 | AnyMessageEventContent, AnyPossiblyRedactedSyncMessageEvent, |
| 14 | AnyMessageEventContent, AnyPossiblyRedactedSyncMessageEvent, | 14 | SyncStateEvent, |
| 15 | SyncStateEvent, | ||
| 16 | }, | ||
| 17 | }, | 15 | }, |
| 18 | PossiblyRedactedExt, | 16 | PossiblyRedactedExt, |
| 19 | }; | 17 | }; |
src/room_buffer.rs +35 −25
| @@ -22,39 +22,49 @@ | |||
| 22 | //! we're sending ourselves before we receive them in a sync response, or if we | 22 | //! we're sending ourselves before we receive them in a sync response, or if we |
| 23 | //! decrypt a previously undecryptable event. | 23 | //! decrypt a previously undecryptable event. |
| 24 | 24 | ||
| 25 | use matrix_sdk::events::room::member::{ | 25 | use matrix_sdk::{ |
| 26 | MemberEventContent, | 26 | events::{ |
| 27 | MembershipChange::{ | 27 | room::{ |
| 28 | Banned, InvitationRejected, InvitationRevoked, Invited, Joined, Kicked, | 28 | member::{ |
| 29 | KickedAndBanned, Left, ProfileChanged, | 29 | MemberEventContent, |
| 30 | MembershipChange::{ | ||
| 31 | Banned, InvitationRejected, InvitationRevoked, Invited, | ||
| 32 | Joined, Kicked, KickedAndBanned, Left, ProfileChanged, | ||
| 33 | }, | ||
| 34 | MembershipState, | ||
| 35 | }, | ||
| 36 | name::NameEventContent, | ||
| 37 | }, | ||
| 38 | AnyPossiblyRedactedSyncMessageEvent, AnySyncMessageEvent, | ||
| 39 | AnySyncRoomEvent, AnySyncStateEvent, SyncStateEvent, | ||
| 30 | }, | 40 | }, |
| 31 | MembershipState, | 41 | identifiers::{RoomId, UserId}, |
| 32 | }; | 42 | PossiblyRedactedExt, Room, |
| 33 | use matrix_sdk::events::room::name::NameEventContent; | ||
| 34 | use matrix_sdk::events::{ | ||
| 35 | AnyPossiblyRedactedSyncMessageEvent, AnySyncMessageEvent, AnySyncRoomEvent, | ||
| 36 | AnySyncStateEvent, SyncStateEvent, | ||
| 37 | }; | 43 | }; |
| 38 | use matrix_sdk::identifiers::{RoomId, UserId}; | ||
| 39 | use matrix_sdk::{PossiblyRedactedExt, Room}; | ||
| 40 | use url::Url; | 44 | use url::Url; |
| 41 | 45 | ||
| 42 | use async_trait::async_trait; | 46 | use async_trait::async_trait; |
| 43 | use tracing::{debug, error, trace}; | 47 | use tracing::{debug, error, trace}; |
| 44 | 48 | ||
| 45 | use crate::render::{render_membership, render_message}; | 49 | use crate::{ |
| 46 | use crate::server::{Connection, TYPING_NOTICE_TIMEOUT}; | 50 | render::{render_membership, render_message}, |
| 47 | use std::cell::{Ref, RefCell, RefMut}; | 51 | server::{Connection, TYPING_NOTICE_TIMEOUT}, |
| 48 | use std::collections::HashMap; | 52 | }; |
| 49 | use std::convert::TryFrom; | 53 | use std::{ |
| 50 | use std::rc::Rc; | 54 | cell::{Ref, RefCell, RefMut}, |
| 51 | use std::sync::Mutex; | 55 | collections::HashMap, |
| 52 | use std::time::Instant; | 56 | convert::TryFrom, |
| 53 | use weechat::buffer::{ | 57 | rc::Rc, |
| 54 | Buffer, BufferBuilderAsync, BufferHandle, BufferInputCallbackAsync, | 58 | sync::Mutex, |
| 55 | NickSettings, | 59 | time::Instant, |
| 60 | }; | ||
| 61 | use weechat::{ | ||
| 62 | buffer::{ | ||
| 63 | Buffer, BufferBuilderAsync, BufferHandle, BufferInputCallbackAsync, | ||
| 64 | NickSettings, | ||
| 65 | }, | ||
| 66 | Weechat, | ||
| 56 | }; | 67 | }; |
| 57 | use weechat::Weechat; | ||
| 58 | 68 | ||
| 59 | pub struct RoomBuffer { | 69 | pub struct RoomBuffer { |
| 60 | own_user_id: Rc<UserId>, | 70 | own_user_id: Rc<UserId>, |
src/server.rs +28 −20
| @@ -54,13 +54,14 @@ | |||
| 54 | //! receiver fetches events individually from a mpsc channel. This makes sure | 54 | //! receiver fetches events individually from a mpsc channel. This makes sure |
| 55 | //! that processing events will not block the Weechat mainloop for too long. | 55 | //! that processing events will not block the Weechat mainloop for too long. |
| 56 | 56 | ||
| 57 | use async_std::sync::channel as async_channel; | 57 | use async_std::sync::{channel as async_channel, Receiver, Sender}; |
| 58 | use async_std::sync::{Receiver, Sender}; | 58 | use std::{ |
| 59 | use std::cell::{Ref, RefCell, RefMut}; | 59 | cell::{Ref, RefCell, RefMut}, |
| 60 | use std::collections::HashMap; | 60 | collections::HashMap, |
| 61 | use std::path::PathBuf; | 61 | path::PathBuf, |
| 62 | use std::rc::{Rc, Weak}; | 62 | rc::{Rc, Weak}, |
| 63 | use std::time::Duration; | 63 | time::Duration, |
| 64 | }; | ||
| 64 | use tokio::runtime::Runtime; | 65 | use tokio::runtime::Runtime; |
| 65 | use tracing::error; | 66 | use tracing::error; |
| 66 | use url::Url; | 67 | use url::Url; |
| @@ -72,7 +73,7 @@ use matrix_sdk::{ | |||
| 72 | self, | 73 | self, |
| 73 | api::r0::{ | 74 | api::r0::{ |
| 74 | message::send_message_event::Response as RoomSendResponse, | 75 | message::send_message_event::Response as RoomSendResponse, |
| 75 | typing::create_typing_event::{Typing, Response as TypingResponse}, | 76 | typing::create_typing_event::{Response as TypingResponse, Typing}, |
| 76 | }, | 77 | }, |
| 77 | events::{ | 78 | events::{ |
| 78 | room::message::{MessageEventContent, TextMessageEventContent}, | 79 | room::message::{MessageEventContent, TextMessageEventContent}, |
| @@ -82,15 +83,13 @@ use matrix_sdk::{ | |||
| 82 | Client, ClientConfig, Result as MatrixResult, Room, SyncSettings, | 83 | Client, ClientConfig, Result as MatrixResult, Room, SyncSettings, |
| 83 | }; | 84 | }; |
| 84 | 85 | ||
| 85 | use weechat::buffer::{BufferBuilder, BufferHandle}; | 86 | use weechat::{ |
| 86 | use weechat::config::{ | 87 | buffer::{BufferBuilder, BufferHandle}, |
| 87 | BooleanOptionSettings, ConfigSection, StringOptionSettings, | 88 | config::{BooleanOptionSettings, ConfigSection, StringOptionSettings}, |
| 89 | JoinHandle, Weechat, | ||
| 88 | }; | 90 | }; |
| 89 | use weechat::JoinHandle; | ||
| 90 | use weechat::Weechat; | ||
| 91 | 91 | ||
| 92 | use crate::room_buffer::RoomBuffer; | 92 | use crate::{config::Config, room_buffer::RoomBuffer, ConfigHandle}; |
| 93 | use crate::{config::Config, ConfigHandle}; | ||
| 94 | 93 | ||
| 95 | const DEFAULT_SYNC_TIMEOUT: Duration = Duration::from_secs(30); | 94 | const DEFAULT_SYNC_TIMEOUT: Duration = Duration::from_secs(30); |
| 96 | pub const TYPING_NOTICE_TIMEOUT: Duration = Duration::from_secs(4); | 95 | pub const TYPING_NOTICE_TIMEOUT: Duration = Duration::from_secs(4); |
| @@ -154,7 +153,11 @@ impl Connection { | |||
| 154 | }); | 153 | }); |
| 155 | 154 | ||
| 156 | client | 155 | client |
| 157 | .room_send(&room_id, AnyMessageEventContent::RoomMessage(content), Some(Uuid::new_v4())) | 156 | .room_send( |
| 157 | &room_id, | ||
| 158 | AnyMessageEventContent::RoomMessage(content), | ||
| 159 | Some(Uuid::new_v4()), | ||
| 160 | ) | ||
| 158 | .await | 161 | .await |
| 159 | }) | 162 | }) |
| 160 | .await; | 163 | .await; |
| @@ -314,11 +317,16 @@ impl MatrixServer { | |||
| 314 | ); | 317 | ); |
| 315 | 318 | ||
| 316 | let mut server = server_ref.borrow_mut(); | 319 | let mut server = server_ref.borrow_mut(); |
| 317 | let homeserver = Url::parse(option.value().as_ref()).expect( | ||
| 318 | "Can't parse homeserver URL, did the check callback fail?", | ||
| 319 | ); | ||
| 320 | 320 | ||
| 321 | server.settings.homeserver = Some(homeserver) | 321 | if option.value().is_empty() { |
| 322 | let homeserver = Url::parse(option.value().as_ref()).expect( | ||
| 323 | "Can't parse homeserver URL, did the check callback fail?", | ||
| 324 | ); | ||
| 325 | |||
| 326 | server.settings.homeserver = Some(homeserver) | ||
| 327 | } else { | ||
| 328 | server.settings.homeserver = None; | ||
| 329 | } | ||
| 322 | }); | 330 | }); |
| 323 | 331 | ||
| 324 | server_section | 332 | server_section |