Update dependencies

legacy
Charlotte Som 2021-09-13 19:52:42 +01:00
parent f8ab672453
commit 06f7fb729a
4 changed files with 301 additions and 333 deletions

477
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -6,10 +6,10 @@ edition = "2018"
[dependencies] [dependencies]
bincode = "1.3.3" bincode = "1.3.3"
discord_message_format = { git = "https://git.lavender.software/charlotte/discord-message-format.git" } discord_message_format = { git = "https://git.lavender.software/charlotte/discord-message-format.git" }
matrix-sdk = { git = "https://github.com/matrix-org/matrix-rust-sdk.git" } matrix-sdk = "0.4"
serde = { version = "1.0.129", features = ["derive"] } serde = { version = "1.0.130", features = ["derive"] }
sled = "0.34.6" sled = "0.34.7"
tokio = { version = "1.10.1", features = ["full"] } tokio = { version = "1.11.0", features = ["full"] }
url = "2.2.2" url = "2.2.2"
log = "0.4.14" log = "0.4.14"
env_logger = "0.9.0" env_logger = "0.9.0"
@ -21,7 +21,3 @@ kuchiki = "0.8.1"
version = "0.10.9" version = "0.10.9"
default-features = false default-features = false
features = ["builder", "cache", "client", "gateway", "model", "http", "utils", "rustls_backend"] features = ["builder", "cache", "client", "gateway", "model", "http", "utils", "rustls_backend"]
[patch.crates-io]
olm-sys = { path = "./target/patch/olm-sys-1.1.2" }
# You gotta apply the patch or simply clone olm-sys to that location :>

View File

@ -1,38 +0,0 @@
--- olm/tests/test_base64.cpp 2021-09-12 01:51:01.587794700 +0100
+++ olm/tests/test_base64.cpp 2021-09-12 01:52:11.937270600 +0100
@@ -1,6 +1,8 @@
#include "olm/base64.hh"
#include "olm/base64.h"
#include "unittest.hh"
+#include <cstring>
+#include <vector>
int main() {
@@ -68,7 +70,6 @@
{
TestCase test_case("Decoding base64 of invalid length fails with -1");
-#include <iostream>
std::uint8_t input[] = "SGVsbG8gV29ybGQab";
std::size_t input_length = sizeof(input) - 1;
@@ -76,14 +77,12 @@
* Nothing will be written to the output buffer anyway because the input is
* invalid. */
std::size_t buf_length = olm::decode_base64_length(input_length + 1);
-std::uint8_t output[buf_length];
-std::uint8_t expected_output[buf_length];
-memset(output, 0, buf_length);
-memset(expected_output, 0, buf_length);
+std::vector<std::uint8_t> output(buf_length, 0);
+std::vector<std::uint8_t> expected_output(buf_length, 0);
-std::size_t output_length = ::_olm_decode_base64(input, input_length, output);
+std::size_t output_length = ::_olm_decode_base64(input, input_length, output.data());
assert_equals(std::size_t(-1), output_length);
-assert_equals(0, memcmp(output, expected_output, buf_length));
+assert_equals(0, memcmp(output.data(), expected_output.data(), buf_length));
}
}

View File

@ -1,5 +1,6 @@
use std::sync::Arc;
use matrix_sdk::{ use matrix_sdk::{
async_trait,
room::{Joined, Room}, room::{Joined, Room},
ruma::{ ruma::{
events::{ events::{
@ -13,7 +14,7 @@ use matrix_sdk::{
}, },
EventId, UserId, EventId, UserId,
}, },
ClientConfig, EventHandler, SyncSettings, ClientConfig, SyncSettings,
}; };
pub use matrix_sdk::{ruma::RoomId, Client}; pub use matrix_sdk::{ruma::RoomId, Client};
@ -100,10 +101,12 @@ impl MatrixHandler {
} }
} }
#[async_trait] async fn on_room_message_event(
impl EventHandler for MatrixHandler { ctx: Arc<MatrixHandler>,
async fn on_room_message(&self, room: Room, event: &SyncMessageEvent<MessageEventContent>) { event: SyncMessageEvent<MessageEventContent>,
if event.sender == self.current_user_id { room: Room,
) {
if event.sender == ctx.current_user_id {
return; return;
} }
@ -119,10 +122,10 @@ impl EventHandler for MatrixHandler {
match message_type { match message_type {
MessageType::Text(text) => { MessageType::Text(text) => {
let content = self.get_content(&text.body, &text.formatted); let content = ctx.get_content(&text.body, &text.formatted);
if let Some(author) = self.get_message_author(&room, &event.sender).await { if let Some(author) = ctx.get_message_author(&room, &event.sender).await {
let _ = self.message_tx.send(MessageEvent::Send(SentMessage { let _ = ctx.message_tx.send(MessageEvent::Send(SentMessage {
source: message_ref, source: message_ref,
content, content,
author, author,
@ -131,11 +134,11 @@ impl EventHandler for MatrixHandler {
} }
MessageType::Emote(emote) => { MessageType::Emote(emote) => {
let mut content = self.get_content(&emote.body, &emote.formatted); let mut content = ctx.get_content(&emote.body, &emote.formatted);
content.insert(0, MessageComponent::Plain("* ".to_string())); content.insert(0, MessageComponent::Plain("* ".to_string()));
if let Some(author) = self.get_message_author(&room, &event.sender).await { if let Some(author) = ctx.get_message_author(&room, &event.sender).await {
let _ = self.message_tx.send(MessageEvent::Send(SentMessage { let _ = ctx.message_tx.send(MessageEvent::Send(SentMessage {
source: message_ref, source: message_ref,
content, content,
author, author,
@ -149,7 +152,6 @@ impl EventHandler for MatrixHandler {
let _ = room.read_receipt(&event.event_id).await; let _ = room.read_receipt(&event.event_id).await;
} }
}
} }
pub async fn forward_to_matrix( pub async fn forward_to_matrix(
@ -198,11 +200,16 @@ pub async fn create_matrix_client(
let current_user_id = client.user_id().await.unwrap(); let current_user_id = client.user_id().await.unwrap();
let event_handler = MatrixHandler { let event_handler = Arc::new(MatrixHandler {
message_tx, message_tx,
current_user_id, current_user_id,
}; });
client.set_event_handler(Box::new(event_handler)).await;
client
.register_event_handler(move |ev, room| {
on_room_message_event(Arc::clone(&event_handler), ev, room)
})
.await;
client client
} }