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