Update matrix_sdk to v0.18.0 and implement message pinning
This commit is contained in:
4 files changed
+909
-320
No files matched your search
Generated
+874
-310
File diff suppressed because it is too large.
Load diff
+1
-1
@@ -15,5 +15,5 @@ serde_json = "1.0"
|
||||
tracing-subscriber = "0.3.18"
|
||||
clap = { version = "4.6.7", features = ["derive"] }
|
||||
tokio = { version = "1.41", features = ["macros", "rt-multi-thread"] }
|
||||
matrix-sdk = { version = "0.8.0", default-features = false, features = [ "native-tls", "anyhow", "markdown" ] }
|
||||
matrix-sdk = { version = "0.18.0", default-features = false, features = [ "anyhow", "markdown" ] }
|
||||
rumqttc = "0.25"
|
||||
@@ -17,6 +17,8 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#![recursion_limit = "256"]
|
||||
|
||||
mod config;
|
||||
mod matrix;
|
||||
mod mqtt;
|
||||
|
||||
+32
-9
@@ -18,16 +18,20 @@
|
||||
*/
|
||||
|
||||
use matrix_sdk::{
|
||||
matrix_auth::{
|
||||
MatrixAuth,
|
||||
MatrixSession,
|
||||
MatrixSessionTokens
|
||||
authentication::{
|
||||
matrix::{
|
||||
MatrixAuth,
|
||||
MatrixSession,
|
||||
},
|
||||
SessionTokens,
|
||||
},
|
||||
SessionMeta,
|
||||
store::RoomLoadSettings,
|
||||
config::SyncSettings,
|
||||
ruma::events::room::{
|
||||
member::StrippedRoomMemberEvent,
|
||||
message::RoomMessageEventContent
|
||||
message::RoomMessageEventContent,
|
||||
pinned_events::RoomPinnedEventsEventContent,
|
||||
},
|
||||
ruma::{RoomId, OwnedUserId, device_id},
|
||||
Client, Room
|
||||
@@ -41,7 +45,7 @@ use tokio::{
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use tracing::{error, info};
|
||||
use tracing::{error, info, debug};
|
||||
use std::error::Error;
|
||||
|
||||
use crate::config::AuthConfig;
|
||||
@@ -86,7 +90,25 @@ async fn send_to_room(
|
||||
match room.client().join_room_by_id(room.room_id()).await {
|
||||
Ok(_) => {
|
||||
info!("Posting to room {}", room.room_id());
|
||||
room.send(RoomMessageEventContent::text_html(msg.clone(), msg)).await?;
|
||||
let res = room.send(RoomMessageEventContent::text_html(msg.clone(), msg)).await?;
|
||||
|
||||
debug!("Retrieving list of pinned events");
|
||||
let mut old_pinned_eids = room.pinned_event_ids().unwrap_or(Vec::new());
|
||||
let mut new_pinned_eids = Vec::with_capacity(old_pinned_eids.len());
|
||||
|
||||
for eid in old_pinned_eids.drain(..) {
|
||||
if let Ok(e) = room.event(eid.as_ref(), None).await {
|
||||
let client = room.client();
|
||||
|
||||
if client.user_id() != e.sender().as_deref() {
|
||||
new_pinned_eids.push(eid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
info!("Updating pinned events");
|
||||
new_pinned_eids.push(res.response.event_id);
|
||||
room.send_state_event(RoomPinnedEventsEventContent::new(new_pinned_eids)).await?;
|
||||
|
||||
Ok(())
|
||||
},
|
||||
@@ -114,11 +136,12 @@ async fn login(
|
||||
user_id: <OwnedUserId>::try_from(user_id.as_str())?,
|
||||
device_id: device_id!(device_id.as_str()).to_owned(),
|
||||
},
|
||||
tokens: MatrixSessionTokens {
|
||||
tokens: SessionTokens {
|
||||
access_token: access_token.to_owned(),
|
||||
refresh_token: None,
|
||||
}
|
||||
}
|
||||
},
|
||||
RoomLoadSettings::All
|
||||
).await?;
|
||||
},
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user