Commit 6d621928b8

6d621928b8759e14111cbdc261367a8dc7b788c4

parent: fd2dad00ba

Unsigned

Damir Jelić <poljar@termina.org.uk> · 2020-09-05 09:38 UTC

weechat-matrix: Merge our imports.

Layout: unified · split

src/commands/matrix.rs +10 −8
@@ -1,15 +1,17 @@
1use clap::App as Argparse; 1use clap::{
2use clap::AppSettings as ArgParseSettings; 2 App as Argparse, AppSettings as ArgParseSettings, Arg, ArgMatches,
3use clap::{Arg, ArgMatches, SubCommand}; 3 SubCommand,
4};
4use url::Url; 5use url::Url;
5 6
6use crate::PLUGIN_NAME; 7use crate::PLUGIN_NAME;
7 8
8use crate::config::ConfigHandle; 9use crate::{config::ConfigHandle, MatrixServer, Servers};
9use crate::{MatrixServer, Servers}; 10use weechat::{
10use weechat::buffer::Buffer; 11 buffer::Buffer,
11use weechat::hooks::{Command, CommandCallback, CommandSettings}; 12 hooks::{Command, CommandCallback, CommandSettings},
12use weechat::{Args, Weechat}; 13 Args, Weechat,
14};
13 15
14pub struct MatrixCommand { 16pub struct MatrixCommand {
15 servers: Servers, 17 servers: Servers,
src/commands/mod.rs +1 −2
@@ -1,5 +1,4 @@
1use crate::config::ConfigHandle; 1use crate::{config::ConfigHandle, Servers};
2use crate::Servers;
3use weechat::hooks::Command; 2use weechat::hooks::Command;
4 3
5mod matrix; 4mod matrix;
src/config.rs +11 −6
@@ -16,14 +16,19 @@
16//! the section will do so. 16//! the section will do so.
17 17
18use crate::{MatrixServer, Servers}; 18use crate::{MatrixServer, Servers};
19use weechat::config::{ 19use weechat::{
20 Conf, ConfigSection, ConfigSectionSettings, OptionChanged, 20 config,
21 SectionReadCallback, 21 config::{
22 Conf, ConfigSection, ConfigSectionSettings, OptionChanged,
23 SectionReadCallback,
24 },
25 Weechat,
22}; 26};
23use weechat::{config, Weechat};
24 27
25use std::cell::{Ref, RefCell, RefMut}; 28use std::{
26use std::rc::Rc; 29 cell::{Ref, RefCell, RefMut},
30 rc::Rc,
31};
27 32
28config!( 33config!(
29 "matrix-rust", 34 "matrix-rust",
src/debug.rs +1 −2
@@ -1,5 +1,4 @@
1use std::cell::RefMut; 1use std::{cell::RefMut, io};
2use std::io;
3 2
4use weechat::{ 3use weechat::{
5 buffer::{BufferBuilder, BufferHandle}, 4 buffer::{BufferBuilder, BufferHandle},
src/lib.rs +6 −6
@@ -7,9 +7,11 @@ mod render;
7mod room_buffer; 7mod room_buffer;
8mod server; 8mod server;
9 9
10use std::cell::{Ref, RefCell, RefMut}; 10use std::{
11use std::collections::HashMap; 11 cell::{Ref, RefCell, RefMut},
12use std::rc::Rc; 12 collections::HashMap,
13 rc::Rc,
14};
13 15
14use weechat::{ 16use 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
20use crate::commands::Commands; 22use crate::{commands::Commands, config::ConfigHandle, server::MatrixServer};
21use crate::config::ConfigHandle;
22use crate::server::MatrixServer;
23 23
24const PLUGIN_NAME: &str = "matrix"; 24const 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
25use matrix_sdk::events::room::member::{ 25use 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,
33use matrix_sdk::events::room::name::NameEventContent;
34use matrix_sdk::events::{
35 AnyPossiblyRedactedSyncMessageEvent, AnySyncMessageEvent, AnySyncRoomEvent,
36 AnySyncStateEvent, SyncStateEvent,
37}; 43};
38use matrix_sdk::identifiers::{RoomId, UserId};
39use matrix_sdk::{PossiblyRedactedExt, Room};
40use url::Url; 44use url::Url;
41 45
42use async_trait::async_trait; 46use async_trait::async_trait;
43use tracing::{debug, error, trace}; 47use tracing::{debug, error, trace};
44 48
45use crate::render::{render_membership, render_message}; 49use crate::{
46use crate::server::{Connection, TYPING_NOTICE_TIMEOUT}; 50 render::{render_membership, render_message},
47use std::cell::{Ref, RefCell, RefMut}; 51 server::{Connection, TYPING_NOTICE_TIMEOUT},
48use std::collections::HashMap; 52};
49use std::convert::TryFrom; 53use std::{
50use std::rc::Rc; 54 cell::{Ref, RefCell, RefMut},
51use std::sync::Mutex; 55 collections::HashMap,
52use std::time::Instant; 56 convert::TryFrom,
53use weechat::buffer::{ 57 rc::Rc,
54 Buffer, BufferBuilderAsync, BufferHandle, BufferInputCallbackAsync, 58 sync::Mutex,
55 NickSettings, 59 time::Instant,
60};
61use weechat::{
62 buffer::{
63 Buffer, BufferBuilderAsync, BufferHandle, BufferInputCallbackAsync,
64 NickSettings,
65 },
66 Weechat,
56}; 67};
57use weechat::Weechat;
58 68
59pub struct RoomBuffer { 69pub 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
57use async_std::sync::channel as async_channel; 57use async_std::sync::{channel as async_channel, Receiver, Sender};
58use async_std::sync::{Receiver, Sender}; 58use std::{
59use std::cell::{Ref, RefCell, RefMut}; 59 cell::{Ref, RefCell, RefMut},
60use std::collections::HashMap; 60 collections::HashMap,
61use std::path::PathBuf; 61 path::PathBuf,
62use std::rc::{Rc, Weak}; 62 rc::{Rc, Weak},
63use std::time::Duration; 63 time::Duration,
64};
64use tokio::runtime::Runtime; 65use tokio::runtime::Runtime;
65use tracing::error; 66use tracing::error;
66use url::Url; 67use 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
85use weechat::buffer::{BufferBuilder, BufferHandle}; 86use weechat::{
86use weechat::config::{ 87 buffer::{BufferBuilder, BufferHandle},
87 BooleanOptionSettings, ConfigSection, StringOptionSettings, 88 config::{BooleanOptionSettings, ConfigSection, StringOptionSettings},
89 JoinHandle, Weechat,
88}; 90};
89use weechat::JoinHandle;
90use weechat::Weechat;
91 91
92use crate::room_buffer::RoomBuffer; 92use crate::{config::Config, room_buffer::RoomBuffer, ConfigHandle};
93use crate::{config::Config, ConfigHandle};
94 93
95const DEFAULT_SYNC_TIMEOUT: Duration = Duration::from_secs(30); 94const DEFAULT_SYNC_TIMEOUT: Duration = Duration::from_secs(30);
96pub const TYPING_NOTICE_TIMEOUT: Duration = Duration::from_secs(4); 95pub 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