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;
2use clap::AppSettings as ArgParseSettings;
3use clap::{Arg, ArgMatches, SubCommand};
1use clap::{
2 App as Argparse, AppSettings as ArgParseSettings, Arg, ArgMatches,
3 SubCommand,
4};
45use url::Url;
56
67use crate::PLUGIN_NAME;
78
8use crate::config::ConfigHandle;
9use crate::{MatrixServer, Servers};
10use weechat::buffer::Buffer;
11use weechat::hooks::{Command, CommandCallback, CommandSettings};
12use weechat::{Args, Weechat};
9use crate::{config::ConfigHandle, MatrixServer, Servers};
10use weechat::{
11 buffer::Buffer,
12 hooks::{Command, CommandCallback, CommandSettings},
13 Args, Weechat,
14};
1315
1416pub struct MatrixCommand {
1517 servers: Servers,
src/commands/mod.rs +1 −2
@@ -1,5 +1,4 @@
1use crate::config::ConfigHandle;
2use crate::Servers;
1use crate::{config::ConfigHandle, Servers};
32use weechat::hooks::Command;
43
54mod matrix;
src/config.rs +11 −6
@@ -16,14 +16,19 @@
1616//! the section will do so.
1717
1818use crate::{MatrixServer, Servers};
19use weechat::config::{
20 Conf, ConfigSection, ConfigSectionSettings, OptionChanged,
21 SectionReadCallback,
19use weechat::{
20 config,
21 config::{
22 Conf, ConfigSection, ConfigSectionSettings, OptionChanged,
23 SectionReadCallback,
24 },
25 Weechat,
2226};
23use weechat::{config, Weechat};
2427
25use std::cell::{Ref, RefCell, RefMut};
26use std::rc::Rc;
28use std::{
29 cell::{Ref, RefCell, RefMut},
30 rc::Rc,
31};
2732
2833config!(
2934 "matrix-rust",
src/debug.rs +1 −2
@@ -1,5 +1,4 @@
1use std::cell::RefMut;
2use std::io;
1use std::{cell::RefMut, io};
32
43use weechat::{
54 buffer::{BufferBuilder, BufferHandle},
src/lib.rs +6 −6
@@ -7,9 +7,11 @@ mod render;
77mod room_buffer;
88mod server;
99
10use std::cell::{Ref, RefCell, RefMut};
11use std::collections::HashMap;
12use std::rc::Rc;
10use std::{
11 cell::{Ref, RefCell, RefMut},
12 collections::HashMap,
13 rc::Rc,
14};
1315
1416use weechat::{
1517 buffer::{Buffer, BufferHandle},
@@ -17,9 +19,7 @@ use weechat::{
1719 plugin, Args, Plugin, ReturnCode, Weechat,
1820};
1921
20use crate::commands::Commands;
21use crate::config::ConfigHandle;
22use crate::server::MatrixServer;
22use crate::{commands::Commands, config::ConfigHandle, server::MatrixServer};
2323
2424const PLUGIN_NAME: &str = "matrix";
2525
src/render.rs +2 −4
@@ -10,10 +10,8 @@ use matrix_sdk::{
1010 TextMessageEventContent, VideoMessageEventContent,
1111 },
1212 },
13 {
14 AnyMessageEventContent, AnyPossiblyRedactedSyncMessageEvent,
15 SyncStateEvent,
16 },
13 AnyMessageEventContent, AnyPossiblyRedactedSyncMessageEvent,
14 SyncStateEvent,
1715 },
1816 PossiblyRedactedExt,
1917};
src/room_buffer.rs +35 −25
@@ -22,39 +22,49 @@
2222//! we're sending ourselves before we receive them in a sync response, or if we
2323//! decrypt a previously undecryptable event.
2424
25use matrix_sdk::events::room::member::{
26 MemberEventContent,
27 MembershipChange::{
28 Banned, InvitationRejected, InvitationRevoked, Invited, Joined, Kicked,
29 KickedAndBanned, Left, ProfileChanged,
25use 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,
3040 },
31 MembershipState,
32};
33use matrix_sdk::events::room::name::NameEventContent;
34use matrix_sdk::events::{
35 AnyPossiblyRedactedSyncMessageEvent, AnySyncMessageEvent, AnySyncRoomEvent,
36 AnySyncStateEvent, SyncStateEvent,
41 identifiers::{RoomId, UserId},
42 PossiblyRedactedExt, Room,
3743};
38use matrix_sdk::identifiers::{RoomId, UserId};
39use matrix_sdk::{PossiblyRedactedExt, Room};
4044use url::Url;
4145
4246use async_trait::async_trait;
4347use tracing::{debug, error, trace};
4448
45use crate::render::{render_membership, render_message};
46use crate::server::{Connection, TYPING_NOTICE_TIMEOUT};
47use std::cell::{Ref, RefCell, RefMut};
48use std::collections::HashMap;
49use std::convert::TryFrom;
50use std::rc::Rc;
51use std::sync::Mutex;
52use std::time::Instant;
53use weechat::buffer::{
54 Buffer, BufferBuilderAsync, BufferHandle, BufferInputCallbackAsync,
55 NickSettings,
49use crate::{
50 render::{render_membership, render_message},
51 server::{Connection, TYPING_NOTICE_TIMEOUT},
52};
53use std::{
54 cell::{Ref, RefCell, RefMut},
55 collections::HashMap,
56 convert::TryFrom,
57 rc::Rc,
58 sync::Mutex,
59 time::Instant,
60};
61use weechat::{
62 buffer::{
63 Buffer, BufferBuilderAsync, BufferHandle, BufferInputCallbackAsync,
64 NickSettings,
65 },
66 Weechat,
5667};
57use weechat::Weechat;
5868
5969pub struct RoomBuffer {
6070 own_user_id: Rc<UserId>,
src/server.rs +28 −20
@@ -54,13 +54,14 @@
5454//! receiver fetches events individually from a mpsc channel. This makes sure
5555//! that processing events will not block the Weechat mainloop for too long.
5656
57use async_std::sync::channel as async_channel;
58use async_std::sync::{Receiver, Sender};
59use std::cell::{Ref, RefCell, RefMut};
60use std::collections::HashMap;
61use std::path::PathBuf;
62use std::rc::{Rc, Weak};
63use std::time::Duration;
57use async_std::sync::{channel as async_channel, Receiver, Sender};
58use std::{
59 cell::{Ref, RefCell, RefMut},
60 collections::HashMap,
61 path::PathBuf,
62 rc::{Rc, Weak},
63 time::Duration,
64};
6465use tokio::runtime::Runtime;
6566use tracing::error;
6667use url::Url;
@@ -72,7 +73,7 @@ use matrix_sdk::{
7273 self,
7374 api::r0::{
7475 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},
7677 },
7778 events::{
7879 room::message::{MessageEventContent, TextMessageEventContent},
@@ -82,15 +83,13 @@ use matrix_sdk::{
8283 Client, ClientConfig, Result as MatrixResult, Room, SyncSettings,
8384};
8485
85use weechat::buffer::{BufferBuilder, BufferHandle};
86use weechat::config::{
87 BooleanOptionSettings, ConfigSection, StringOptionSettings,
86use weechat::{
87 buffer::{BufferBuilder, BufferHandle},
88 config::{BooleanOptionSettings, ConfigSection, StringOptionSettings},
89 JoinHandle, Weechat,
8890};
89use weechat::JoinHandle;
90use weechat::Weechat;
9191
92use crate::room_buffer::RoomBuffer;
93use crate::{config::Config, ConfigHandle};
92use crate::{config::Config, room_buffer::RoomBuffer, ConfigHandle};
9493
9594const DEFAULT_SYNC_TIMEOUT: Duration = Duration::from_secs(30);
9695pub const TYPING_NOTICE_TIMEOUT: Duration = Duration::from_secs(4);
@@ -154,7 +153,11 @@ impl Connection {
154153 });
155154
156155 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 )
158161 .await
159162 })
160163 .await;
@@ -314,11 +317,16 @@ impl MatrixServer {
314317 );
315318
316319 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 );
320320
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 }
322330 });
323331
324332 server_section