Update to matrix-sdk@0.7.1 (#200)

This commit is contained in:
Ulyssa 2024-03-02 15:00:29 -08:00 committed by GitHub
parent 1948d80ec8
commit 9732971fc2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 1579 additions and 754 deletions

View file

@ -14,14 +14,16 @@ use url::Url;
use matrix_sdk::{
attachment::AttachmentConfig,
media::{MediaFormat, MediaRequest},
room::{Joined, Room as MatrixRoom},
room::Room as MatrixRoom,
ruma::{
events::reaction::{ReactionEventContent, Relation as Reaction},
events::reaction::ReactionEventContent,
events::relation::{Annotation, Replacement},
events::room::message::{
AddMentions,
ForwardThread,
MessageType,
OriginalRoomMessageEvent,
Relation,
Replacement,
RoomMessageEventContent,
TextMessageEventContent,
},
@ -29,6 +31,7 @@ use matrix_sdk::{
OwnedRoomId,
RoomId,
},
RoomState,
};
use ratatui::{
@ -126,8 +129,16 @@ impl ChatState {
}
}
fn get_joined(&self, worker: &Requester) -> Result<Joined, IambError> {
worker.client.get_joined_room(self.id()).ok_or(IambError::NotJoined)
fn get_joined(&self, worker: &Requester) -> Result<MatrixRoom, IambError> {
let Some(room) = worker.client.get_room(self.id()) else {
return Err(IambError::NotJoined);
};
if room.state() == RoomState::Joined {
Ok(room)
} else {
Err(IambError::NotJoined)
}
}
fn get_reply_to<'a>(&self, info: &'a RoomInfo) -> Option<&'a OriginalRoomMessageEvent> {
@ -356,9 +367,9 @@ impl ChatState {
},
};
let reaction = Reaction::new(event_id, emoji);
let reaction = Annotation::new(event_id, emoji);
let msg = ReactionEventContent::new(reaction);
let _ = room.send(msg, None).await.map_err(IambError::from)?;
let _ = room.send(msg).await.map_err(IambError::from)?;
Ok(None)
},
@ -449,12 +460,7 @@ impl ChatState {
_: ProgramContext,
store: &mut ProgramStore,
) -> IambResult<EditInfo> {
let room = store
.application
.worker
.client
.get_joined_room(self.id())
.ok_or(IambError::NotJoined)?;
let room = self.get_joined(&store.application.worker)?;
let info = store.application.rooms.get_or_default(self.id().to_owned());
let mut show_echo = true;
@ -475,18 +481,18 @@ impl ChatState {
if let Some((_, event_id)) = &self.editing {
msg.relates_to = Some(Relation::Replacement(Replacement::new(
event_id.clone(),
Box::new(msg.clone()),
msg.msgtype.clone().into(),
)));
show_echo = false;
} else if let Some(m) = self.get_reply_to(info) {
// XXX: Switch to RoomMessageEventContent::reply() once it's stable?
msg = msg.make_reply_to(m);
msg = msg.make_reply_to(m, ForwardThread::Yes, AddMentions::No);
}
// XXX: second parameter can be a locally unique transaction id.
// Useful for doing retries.
let resp = room.send(msg.clone(), None).await.map_err(IambError::from)?;
let resp = room.send(msg.clone()).await.map_err(IambError::from)?;
let event_id = resp.event_id;
// Reset message bar state now that it's been sent.
@ -506,7 +512,7 @@ impl ChatState {
let config = AttachmentConfig::new();
let resp = room
.send_attachment(name.as_ref(), &mime, bytes.as_ref(), config)
.send_attachment(name.as_ref(), &mime, bytes, config)
.await
.map_err(IambError::from)?;
@ -536,7 +542,7 @@ impl ChatState {
let config = AttachmentConfig::new();
let resp = room
.send_attachment(name.as_ref(), &mime, bytes.as_ref(), config)
.send_attachment(name.as_ref(), &mime, bytes, config)
.await
.map_err(IambError::from)?;

View file

@ -1,6 +1,6 @@
//! # Windows for Matrix rooms and spaces
use matrix_sdk::{
room::{Invited, Room as MatrixRoom},
room::Room as MatrixRoom,
ruma::{
events::{
room::{name::RoomNameEventContent, topic::RoomTopicEventContent},
@ -9,6 +9,7 @@ use matrix_sdk::{
RoomId,
},
DisplayName,
RoomState as MatrixRoomState,
};
use ratatui::{
@ -114,7 +115,7 @@ impl RoomState {
fn draw_invite(
&self,
invited: Invited,
invited: MatrixRoom,
area: Rect,
buf: &mut Buffer,
store: &mut ProgramStore,
@ -177,12 +178,12 @@ impl RoomState {
) -> IambResult<Vec<(Action<IambInfo>, ProgramContext)>> {
match act {
RoomAction::InviteAccept => {
if let Some(room) = store.application.worker.client.get_invited_room(self.id()) {
if let Some(room) = store.application.worker.client.get_room(self.id()) {
let details = room.invite_details().await.map_err(IambError::from)?;
let details = details.invitee.event().original_content();
let is_direct = details.and_then(|ev| ev.is_direct).unwrap_or_default();
room.accept_invitation().await.map_err(IambError::from)?;
room.join().await.map_err(IambError::from)?;
if is_direct {
room.set_is_direct(true).await.map_err(IambError::from)?;
@ -194,8 +195,8 @@ impl RoomState {
}
},
RoomAction::InviteReject => {
if let Some(room) = store.application.worker.client.get_invited_room(self.id()) {
room.reject_invitation().await.map_err(IambError::from)?;
if let Some(room) = store.application.worker.client.get_room(self.id()) {
room.leave().await.map_err(IambError::from)?;
Ok(vec![])
} else {
@ -203,7 +204,7 @@ impl RoomState {
}
},
RoomAction::InviteSend(user) => {
if let Some(room) = store.application.worker.client.get_joined_room(self.id()) {
if let Some(room) = store.application.worker.client.get_room(self.id()) {
room.invite_user_by_id(user.as_ref()).await.map_err(IambError::from)?;
Ok(vec![])
@ -212,7 +213,7 @@ impl RoomState {
}
},
RoomAction::Leave(skip_confirm) => {
if let Some(room) = store.application.worker.client.get_joined_room(self.id()) {
if let Some(room) = store.application.worker.client.get_room(self.id()) {
if skip_confirm {
room.leave().await.map_err(IambError::from)?;
@ -247,7 +248,7 @@ impl RoomState {
match field {
RoomField::Name => {
let ev = RoomNameEventContent::new(value.into());
let ev = RoomNameEventContent::new(value);
let _ = room.send_state_event(ev).await.map_err(IambError::from)?;
},
RoomField::Tag(tag) => {
@ -272,7 +273,7 @@ impl RoomState {
match field {
RoomField::Name => {
let ev = RoomNameEventContent::new(None);
let ev = RoomNameEventContent::new("".into());
let _ = room.send_state_event(ev).await.map_err(IambError::from)?;
},
RoomField::Tag(tag) => {
@ -381,12 +382,12 @@ impl TerminalCursor for RoomState {
impl WindowOps<IambInfo> for RoomState {
fn draw(&mut self, area: Rect, buf: &mut Buffer, focused: bool, store: &mut ProgramStore) {
if let MatrixRoom::Invited(_) = self.room() {
if self.room().state() == MatrixRoomState::Invited {
self.refresh_room(store);
}
if let MatrixRoom::Invited(invited) = self.room() {
self.draw_invite(invited.clone(), area, buf, store);
if self.room().state() == MatrixRoomState::Invited {
self.draw_invite(self.room().clone(), area, buf, store);
}
match self {