Commit 54ce042384
Unregistered key
Layout: unified · split
README.md +2 −2
| @@ -58,8 +58,8 @@ two other TUI clients and Element Web: | |||
| 58 | | Pushrules | :x: | :heavy_check_mark: | :x: | :heavy_check_mark: | | 58 | | Pushrules | :x: | :heavy_check_mark: | :x: | :heavy_check_mark: | |
| 59 | | Send read markers | :x: ([#11]) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | 59 | | Send read markers | :x: ([#11]) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | |
| 60 | | Display read markers | :x: ([#11]) | :x: | :x: | :heavy_check_mark: | | 60 | | Display read markers | :x: ([#11]) | :x: | :x: | :heavy_check_mark: | |
| 61 | | Sending Invites | :x: ([#7]) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | 61 | | Sending Invites | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | |
| 62 | | Accepting Invites | :x: ([#7]) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | 62 | | Accepting Invites | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | |
| 63 | | Typing Notification | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | 63 | | Typing Notification | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | |
| 64 | | E2E | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | 64 | | E2E | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | |
| 65 | | Replies | :x: ([#3]) | :heavy_check_mark: | :x: | :heavy_check_mark: | | 65 | | Replies | :x: ([#3]) | :heavy_check_mark: | :x: | :heavy_check_mark: | |
src/base.rs +7 −1
| @@ -72,6 +72,9 @@ pub enum SetRoomField { | |||
| 72 | 72 | ||
| 73 | #[derive(Clone, Debug, Eq, PartialEq)] | 73 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 74 | pub enum RoomAction { | 74 | pub enum RoomAction { |
| 75 | InviteAccept, | ||
| 76 | InviteReject, | ||
| 77 | InviteSend(OwnedUserId), | ||
| 75 | Members(Box<CommandContext<ProgramContext>>), | 78 | Members(Box<CommandContext<ProgramContext>>), |
| 76 | Set(SetRoomField), | 79 | Set(SetRoomField), |
| 77 | } | 80 | } |
| @@ -180,7 +183,7 @@ pub type IambResult<T> = UIResult<T, IambInfo>; | |||
| 180 | 183 | ||
| 181 | #[derive(thiserror::Error, Debug)] | 184 | #[derive(thiserror::Error, Debug)] |
| 182 | pub enum IambError { | 185 | pub enum IambError { |
| 183 | #[error("Unknown room identifier: {0}")] | 186 | #[error("Invalid user identifier: {0}")] |
| 184 | InvalidUserId(String), | 187 | InvalidUserId(String), |
| 185 | 188 | ||
| 186 | #[error("Invalid verification user/device pair: {0}")] | 189 | #[error("Invalid verification user/device pair: {0}")] |
| @@ -213,6 +216,9 @@ pub enum IambError { | |||
| 213 | #[error("Current window is not a room")] | 216 | #[error("Current window is not a room")] |
| 214 | NoSelectedRoom, | 217 | NoSelectedRoom, |
| 215 | 218 | ||
| 219 | #[error("You do not have a current invitation to this room")] | ||
| 220 | NotInvited, | ||
| 221 | |||
| 216 | #[error("You need to join the room before you can do that")] | 222 | #[error("You need to join the room before you can do that")] |
| 217 | NotJoined, | 223 | NotJoined, |
| 218 | 224 | ||
src/commands.rs +90
| @@ -1,3 +1,7 @@ | |||
| 1 | use std::convert::TryFrom; | ||
| 2 | |||
| 3 | use matrix_sdk::ruma::OwnedUserId; | ||
| 4 | |||
| 1 | use modalkit::{ | 5 | use modalkit::{ |
| 2 | editing::base::OpenTarget, | 6 | editing::base::OpenTarget, |
| 3 | env::vim::command::{CommandContext, CommandDescription}, | 7 | env::vim::command::{CommandContext, CommandDescription}, |
| @@ -21,6 +25,53 @@ use crate::base::{ | |||
| 21 | type ProgContext = CommandContext<ProgramContext>; | 25 | type ProgContext = CommandContext<ProgramContext>; |
| 22 | type ProgResult = CommandResult<ProgramCommand>; | 26 | type ProgResult = CommandResult<ProgramCommand>; |
| 23 | 27 | ||
| 28 | fn iamb_invite(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { | ||
| 29 | let args = desc.arg.strings()?; | ||
| 30 | |||
| 31 | if args.is_empty() { | ||
| 32 | return Err(CommandError::InvalidArgument); | ||
| 33 | } | ||
| 34 | |||
| 35 | let ract = match args[0].as_str() { | ||
| 36 | "accept" => { | ||
| 37 | if args.len() != 1 { | ||
| 38 | return Err(CommandError::InvalidArgument); | ||
| 39 | } | ||
| 40 | |||
| 41 | RoomAction::InviteAccept | ||
| 42 | }, | ||
| 43 | "reject" => { | ||
| 44 | if args.len() != 1 { | ||
| 45 | return Err(CommandError::InvalidArgument); | ||
| 46 | } | ||
| 47 | |||
| 48 | RoomAction::InviteReject | ||
| 49 | }, | ||
| 50 | "send" => { | ||
| 51 | if args.len() != 2 { | ||
| 52 | return Err(CommandError::InvalidArgument); | ||
| 53 | } | ||
| 54 | |||
| 55 | if let Ok(user) = OwnedUserId::try_from(args[1].as_str()) { | ||
| 56 | RoomAction::InviteSend(user) | ||
| 57 | } else { | ||
| 58 | let msg = format!("Invalid user identifier: {}", args[1]); | ||
| 59 | let err = CommandError::Error(msg); | ||
| 60 | |||
| 61 | return Err(err); | ||
| 62 | } | ||
| 63 | }, | ||
| 64 | _ => { | ||
| 65 | return Err(CommandError::InvalidArgument); | ||
| 66 | }, | ||
| 67 | }; | ||
| 68 | |||
| 69 | let iact = IambAction::from(ract); | ||
| 70 | let step = CommandStep::Continue(iact.into(), ctx.context.take()); | ||
| 71 | |||
| 72 | return Ok(step); | ||
| 73 | } | ||
| 74 | |||
| 24 | fn iamb_verify(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { | 75 | fn iamb_verify(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { |
| 25 | let mut args = desc.arg.strings()?; | 76 | let mut args = desc.arg.strings()?; |
| 26 | 77 | ||
| @@ -182,6 +233,7 @@ fn iamb_download(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult | |||
| 182 | fn add_iamb_commands(cmds: &mut ProgramCommands) { | 233 | fn add_iamb_commands(cmds: &mut ProgramCommands) { |
| 183 | cmds.add_command(ProgramCommand { names: vec!["dms".into()], f: iamb_dms }); | 234 | cmds.add_command(ProgramCommand { names: vec!["dms".into()], f: iamb_dms }); |
| 184 | cmds.add_command(ProgramCommand { names: vec!["download".into()], f: iamb_download }); | 235 | cmds.add_command(ProgramCommand { names: vec!["download".into()], f: iamb_download }); |
| 236 | cmds.add_command(ProgramCommand { names: vec!["invite".into()], f: iamb_invite }); | ||
| 185 | cmds.add_command(ProgramCommand { names: vec!["join".into()], f: iamb_join }); | 237 | cmds.add_command(ProgramCommand { names: vec!["join".into()], f: iamb_join }); |
| 186 | cmds.add_command(ProgramCommand { names: vec!["members".into()], f: iamb_members }); | 238 | cmds.add_command(ProgramCommand { names: vec!["members".into()], f: iamb_members }); |
| 187 | cmds.add_command(ProgramCommand { names: vec!["rooms".into()], f: iamb_rooms }); | 239 | cmds.add_command(ProgramCommand { names: vec!["rooms".into()], f: iamb_rooms }); |
| @@ -203,6 +255,7 @@ pub fn setup_commands() -> ProgramCommands { | |||
| 203 | #[cfg(test)] | 255 | #[cfg(test)] |
| 204 | mod tests { | 256 | mod tests { |
| 205 | use super::*; | 257 | use super::*; |
| 258 | use matrix_sdk::ruma::user_id; | ||
| 206 | use modalkit::editing::action::WindowAction; | 259 | use modalkit::editing::action::WindowAction; |
| 207 | 260 | ||
| 208 | #[test] | 261 | #[test] |
| @@ -315,4 +368,41 @@ mod tests { | |||
| 315 | let res = cmds.input_cmd("set room.topic A B C", ctx.clone()); | 368 | let res = cmds.input_cmd("set room.topic A B C", ctx.clone()); |
| 316 | assert_eq!(res, Err(CommandError::InvalidArgument)); | 369 | assert_eq!(res, Err(CommandError::InvalidArgument)); |
| 317 | } | 370 | } |
| 371 | |||
| 372 | #[test] | ||
| 373 | fn test_cmd_invite() { | ||
| 374 | let mut cmds = setup_commands(); | ||
| 375 | let ctx = ProgramContext::default(); | ||
| 376 | |||
| 377 | let res = cmds.input_cmd("invite accept", ctx.clone()).unwrap(); | ||
| 378 | let act = IambAction::Room(RoomAction::InviteAccept); | ||
| 379 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | ||
| 380 | |||
| 381 | let res = cmds.input_cmd("invite reject", ctx.clone()).unwrap(); | ||
| 382 | let act = IambAction::Room(RoomAction::InviteReject); | ||
| 383 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | ||
| 384 | |||
| 385 | let res = cmds.input_cmd("invite send @user:example.com", ctx.clone()).unwrap(); | ||
| 386 | let act = | ||
| 387 | IambAction::Room(RoomAction::InviteSend(user_id!("@user:example.com").to_owned())); | ||
| 388 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | ||
| 389 | |||
| 390 | let res = cmds.input_cmd("invite", ctx.clone()); | ||
| 391 | assert_eq!(res, Err(CommandError::InvalidArgument)); | ||
| 392 | |||
| 393 | let res = cmds.input_cmd("invite foo", ctx.clone()); | ||
| 394 | assert_eq!(res, Err(CommandError::InvalidArgument)); | ||
| 395 | |||
| 396 | let res = cmds.input_cmd("invite accept @user:example.com", ctx.clone()); | ||
| 397 | assert_eq!(res, Err(CommandError::InvalidArgument)); | ||
| 398 | |||
| 399 | let res = cmds.input_cmd("invite reject @user:example.com", ctx.clone()); | ||
| 400 | assert_eq!(res, Err(CommandError::InvalidArgument)); | ||
| 401 | |||
| 402 | let res = cmds.input_cmd("invite send", ctx.clone()); | ||
| 403 | assert_eq!(res, Err(CommandError::InvalidArgument)); | ||
| 404 | |||
| 405 | let res = cmds.input_cmd("invite @user:example.com", ctx.clone()); | ||
| 406 | assert_eq!(res, Err(CommandError::InvalidArgument)); | ||
| 407 | } | ||
| 318 | } | 408 | } |
src/windows/mod.rs +2 −2
| @@ -343,10 +343,10 @@ impl WindowOps<IambInfo> for IambWindow { | |||
| 343 | .render(area, buf, state); | 343 | .render(area, buf, state); |
| 344 | }, | 344 | }, |
| 345 | IambWindow::RoomList(state) => { | 345 | IambWindow::RoomList(state) => { |
| 346 | let joined = store.application.worker.joined_rooms(); | 346 | let joined = store.application.worker.active_rooms(); |
| 347 | let mut items = joined | 347 | let mut items = joined |
| 348 | .into_iter() | 348 | .into_iter() |
| 349 | .map(|(id, name)| RoomItem::new(id, name, store)) | 349 | .map(|(room, name)| RoomItem::new(room, name, store)) |
| 350 | .collect::<Vec<_>>(); | 350 | .collect::<Vec<_>>(); |
| 351 | items.sort(); | 351 | items.sort(); |
| 352 | 352 | ||
src/windows/room/chat.rs +6
| @@ -92,6 +92,12 @@ impl ChatState { | |||
| 92 | } | 92 | } |
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | pub fn refresh_room(&mut self, store: &mut ProgramStore) { | ||
| 96 | if let Some(room) = store.application.worker.client.get_room(self.id()) { | ||
| 97 | self.room = room; | ||
| 98 | } | ||
| 99 | } | ||
| 100 | |||
| 95 | pub async fn message_command( | 101 | pub async fn message_command( |
| 96 | &mut self, | 102 | &mut self, |
| 97 | act: MessageAction, | 103 | act: MessageAction, |
src/windows/room/mod.rs +85 −4
| @@ -1,11 +1,15 @@ | |||
| 1 | use matrix_sdk::{room::Room as MatrixRoom, ruma::RoomId, DisplayName}; | 1 | use matrix_sdk::{ |
| 2 | room::{Invited, Room as MatrixRoom}, | ||
| 3 | ruma::RoomId, | ||
| 4 | DisplayName, | ||
| 5 | }; | ||
| 2 | 6 | ||
| 3 | use modalkit::tui::{ | 7 | use modalkit::tui::{ |
| 4 | buffer::Buffer, | 8 | buffer::Buffer, |
| 5 | layout::Rect, | 9 | layout::{Alignment, Rect}, |
| 6 | style::{Modifier as StyleModifier, Style}, | 10 | style::{Modifier as StyleModifier, Style}, |
| 7 | text::{Span, Spans}, | 11 | text::{Span, Spans, Text}, |
| 8 | widgets::StatefulWidget, | 12 | widgets::{Paragraph, StatefulWidget, Widget}, |
| 9 | }; | 13 | }; |
| 10 | 14 | ||
| 11 | use modalkit::{ | 15 | use modalkit::{ |
| @@ -93,6 +97,48 @@ impl RoomState { | |||
| 93 | } | 97 | } |
| 94 | } | 98 | } |
| 95 | 99 | ||
| 100 | pub fn refresh_room(&mut self, store: &mut ProgramStore) { | ||
| 101 | match self { | ||
| 102 | RoomState::Chat(chat) => chat.refresh_room(store), | ||
| 103 | RoomState::Space(space) => space.refresh_room(store), | ||
| 104 | } | ||
| 105 | } | ||
| 106 | |||
| 107 | fn draw_invite( | ||
| 108 | &self, | ||
| 109 | invited: Invited, | ||
| 110 | area: Rect, | ||
| 111 | buf: &mut Buffer, | ||
| 112 | store: &mut ProgramStore, | ||
| 113 | ) { | ||
| 114 | let inviter = store.application.worker.get_inviter(invited.clone()); | ||
| 115 | |||
| 116 | let name = match invited.canonical_alias() { | ||
| 117 | Some(alias) => alias.to_string(), | ||
| 118 | None => format!("{:?}", store.application.get_room_title(self.id())), | ||
| 119 | }; | ||
| 120 | |||
| 121 | let mut invited = vec![Span::from(format!( | ||
| 122 | "You have been invited to join {}", | ||
| 123 | name | ||
| 124 | ))]; | ||
| 125 | |||
| 126 | if let Ok(Some(inviter)) = &inviter { | ||
| 127 | invited.push(Span::from(" by ")); | ||
| 128 | invited.push(store.application.settings.get_user_span(inviter.user_id())); | ||
| 129 | } | ||
| 130 | |||
| 131 | let l1 = Spans(invited); | ||
| 132 | let l2 = Spans::from( | ||
| 133 | "You can run `:invite accept` or `:invite reject` to accept or reject this invitation.", | ||
| 134 | ); | ||
| 135 | let text = Text { lines: vec![l1, l2] }; | ||
| 136 | |||
| 137 | Paragraph::new(text).alignment(Alignment::Center).render(area, buf); | ||
| 138 | |||
| 139 | return; | ||
| 140 | } | ||
| 141 | |||
| 96 | pub async fn message_command( | 142 | pub async fn message_command( |
| 97 | &mut self, | 143 | &mut self, |
| 98 | act: MessageAction, | 144 | act: MessageAction, |
| @@ -124,6 +170,33 @@ impl RoomState { | |||
| 124 | store: &mut ProgramStore, | 170 | store: &mut ProgramStore, |
| 125 | ) -> IambResult<Vec<(Action<IambInfo>, ProgramContext)>> { | 171 | ) -> IambResult<Vec<(Action<IambInfo>, ProgramContext)>> { |
| 126 | match act { | 172 | match act { |
| 173 | RoomAction::InviteAccept => { | ||
| 174 | if let Some(room) = store.application.worker.client.get_invited_room(self.id()) { | ||
| 175 | room.accept_invitation().await.map_err(IambError::from)?; | ||
| 176 | |||
| 177 | Ok(vec![]) | ||
| 178 | } else { | ||
| 179 | Err(IambError::NotInvited.into()) | ||
| 180 | } | ||
| 181 | }, | ||
| 182 | RoomAction::InviteReject => { | ||
| 183 | if let Some(room) = store.application.worker.client.get_invited_room(self.id()) { | ||
| 184 | room.reject_invitation().await.map_err(IambError::from)?; | ||
| 185 | |||
| 186 | Ok(vec![]) | ||
| 187 | } else { | ||
| 188 | Err(IambError::NotInvited.into()) | ||
| 189 | } | ||
| 190 | }, | ||
| 191 | RoomAction::InviteSend(user) => { | ||
| 192 | if let Some(room) = store.application.worker.client.get_joined_room(self.id()) { | ||
| 193 | room.invite_user_by_id(user.as_ref()).await.map_err(IambError::from)?; | ||
| 194 | |||
| 195 | Ok(vec![]) | ||
| 196 | } else { | ||
| 197 | Err(IambError::NotJoined.into()) | ||
| 198 | } | ||
| 199 | }, | ||
| 127 | RoomAction::Members(mut cmd) => { | 200 | RoomAction::Members(mut cmd) => { |
| 128 | let width = Count::Exact(30); | 201 | let width = Count::Exact(30); |
| 129 | let act = | 202 | let act = |
| @@ -234,6 +307,14 @@ impl TerminalCursor for RoomState { | |||
| 234 | 307 | ||
| 235 | impl WindowOps<IambInfo> for RoomState { | 308 | impl WindowOps<IambInfo> for RoomState { |
| 236 | fn draw(&mut self, area: Rect, buf: &mut Buffer, focused: bool, store: &mut ProgramStore) { | 309 | fn draw(&mut self, area: Rect, buf: &mut Buffer, focused: bool, store: &mut ProgramStore) { |
| 310 | if let MatrixRoom::Invited(_) = self.room() { | ||
| 311 | self.refresh_room(store); | ||
| 312 | } | ||
| 313 | |||
| 314 | if let MatrixRoom::Invited(invited) = self.room() { | ||
| 315 | self.draw_invite(invited.clone(), area, buf, store); | ||
| 316 | } | ||
| 317 | |||
| 237 | match self { | 318 | match self { |
| 238 | RoomState::Chat(chat) => chat.draw(area, buf, focused, store), | 319 | RoomState::Chat(chat) => chat.draw(area, buf, focused, store), |
| 239 | RoomState::Space(space) => { | 320 | RoomState::Space(space) => { |
src/windows/room/space.rs +13 −1
| @@ -31,6 +31,12 @@ impl SpaceState { | |||
| 31 | SpaceState { room_id, room, list } | 31 | SpaceState { room_id, room, list } |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | pub fn refresh_room(&mut self, store: &mut ProgramStore) { | ||
| 35 | if let Some(room) = store.application.worker.client.get_room(self.id()) { | ||
| 36 | self.room = room; | ||
| 37 | } | ||
| 38 | } | ||
| 39 | |||
| 34 | pub fn room(&self) -> &MatrixRoom { | 40 | pub fn room(&self) -> &MatrixRoom { |
| 35 | &self.room | 41 | &self.room |
| 36 | } | 42 | } |
| @@ -88,7 +94,13 @@ impl<'a> StatefulWidget for Space<'a> { | |||
| 88 | type State = SpaceState; | 94 | type State = SpaceState; |
| 89 | 95 | ||
| 90 | fn render(self, area: Rect, buffer: &mut Buffer, state: &mut Self::State) { | 96 | fn render(self, area: Rect, buffer: &mut Buffer, state: &mut Self::State) { |
| 91 | let members = self.store.application.worker.space_members(state.room_id.clone()).unwrap(); | 97 | let members = |
| 98 | if let Ok(m) = self.store.application.worker.space_members(state.room_id.clone()) { | ||
| 99 | m | ||
| 100 | } else { | ||
| 101 | return; | ||
| 102 | }; | ||
| 103 | |||
| 92 | let items = members | 104 | let items = members |
| 93 | .into_iter() | 105 | .into_iter() |
| 94 | .filter_map(|id| { | 106 | .filter_map(|id| { |
src/worker.rs +74 −22
| @@ -17,7 +17,7 @@ use matrix_sdk::{ | |||
| 17 | encryption::verification::{SasVerification, Verification}, | 17 | encryption::verification::{SasVerification, Verification}, |
| 18 | event_handler::Ctx, | 18 | event_handler::Ctx, |
| 19 | reqwest, | 19 | reqwest, |
| 20 | room::{Messages, MessagesOptions, Room as MatrixRoom, RoomMember}, | 20 | room::{Invited, Messages, MessagesOptions, Room as MatrixRoom, RoomMember}, |
| 21 | ruma::{ | 21 | ruma::{ |
| 22 | api::client::{ | 22 | api::client::{ |
| 23 | room::create_room::v3::{Request as CreateRoomRequest, RoomPreset}, | 23 | room::create_room::v3::{Request as CreateRoomRequest, RoomPreset}, |
| @@ -98,13 +98,14 @@ fn oneshot<T>() -> (ClientReply<T>, ClientResponse<T>) { | |||
| 98 | } | 98 | } |
| 99 | 99 | ||
| 100 | pub enum WorkerTask { | 100 | pub enum WorkerTask { |
| 101 | ActiveRooms(ClientReply<Vec<(MatrixRoom, DisplayName)>>), | ||
| 101 | DirectMessages(ClientReply<Vec<(MatrixRoom, DisplayName)>>), | 102 | DirectMessages(ClientReply<Vec<(MatrixRoom, DisplayName)>>), |
| 102 | Init(AsyncProgramStore, ClientReply<()>), | 103 | Init(AsyncProgramStore, ClientReply<()>), |
| 103 | LoadOlder(OwnedRoomId, Option<String>, u32, ClientReply<MessageFetchResult>), | 104 | LoadOlder(OwnedRoomId, Option<String>, u32, ClientReply<MessageFetchResult>), |
| 104 | Login(LoginStyle, ClientReply<IambResult<EditInfo>>), | 105 | Login(LoginStyle, ClientReply<IambResult<EditInfo>>), |
| 106 | GetInviter(Invited, ClientReply<IambResult<Option<RoomMember>>>), | ||
| 105 | GetRoom(OwnedRoomId, ClientReply<IambResult<(MatrixRoom, DisplayName)>>), | 107 | GetRoom(OwnedRoomId, ClientReply<IambResult<(MatrixRoom, DisplayName)>>), |
| 106 | JoinRoom(String, ClientReply<IambResult<OwnedRoomId>>), | 108 | JoinRoom(String, ClientReply<IambResult<OwnedRoomId>>), |
| 107 | JoinedRooms(ClientReply<Vec<(MatrixRoom, DisplayName)>>), | ||
| 108 | Members(OwnedRoomId, ClientReply<IambResult<Vec<RoomMember>>>), | 109 | Members(OwnedRoomId, ClientReply<IambResult<Vec<RoomMember>>>), |
| 109 | SpaceMembers(OwnedRoomId, ClientReply<IambResult<Vec<OwnedRoomId>>>), | 110 | SpaceMembers(OwnedRoomId, ClientReply<IambResult<Vec<OwnedRoomId>>>), |
| 110 | Spaces(ClientReply<Vec<(MatrixRoom, DisplayName)>>), | 111 | Spaces(ClientReply<Vec<(MatrixRoom, DisplayName)>>), |
| @@ -117,6 +118,9 @@ pub enum WorkerTask { | |||
| 117 | impl Debug for WorkerTask { | 118 | impl Debug for WorkerTask { |
| 118 | fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> { | 119 | fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> { |
| 119 | match self { | 120 | match self { |
| 121 | WorkerTask::ActiveRooms(_) => { | ||
| 122 | f.debug_tuple("WorkerTask::ActiveRooms").field(&format_args!("_")).finish() | ||
| 123 | }, | ||
| 120 | WorkerTask::DirectMessages(_) => { | 124 | WorkerTask::DirectMessages(_) => { |
| 121 | f.debug_tuple("WorkerTask::DirectMessages") | 125 | f.debug_tuple("WorkerTask::DirectMessages") |
| 122 | .field(&format_args!("_")) | 126 | .field(&format_args!("_")) |
| @@ -142,6 +146,9 @@ impl Debug for WorkerTask { | |||
| 142 | .field(&format_args!("_")) | 146 | .field(&format_args!("_")) |
| 143 | .finish() | 147 | .finish() |
| 144 | }, | 148 | }, |
| 149 | WorkerTask::GetInviter(invite, _) => { | ||
| 150 | f.debug_tuple("WorkerTask::GetInviter").field(invite).finish() | ||
| 151 | }, | ||
| 145 | WorkerTask::GetRoom(room_id, _) => { | 152 | WorkerTask::GetRoom(room_id, _) => { |
| 146 | f.debug_tuple("WorkerTask::GetRoom") | 153 | f.debug_tuple("WorkerTask::GetRoom") |
| 147 | .field(room_id) | 154 | .field(room_id) |
| @@ -154,9 +161,6 @@ impl Debug for WorkerTask { | |||
| 154 | .field(&format_args!("_")) | 161 | .field(&format_args!("_")) |
| 155 | .finish() | 162 | .finish() |
| 156 | }, | 163 | }, |
| 157 | WorkerTask::JoinedRooms(_) => { | ||
| 158 | f.debug_tuple("WorkerTask::JoinedRooms").field(&format_args!("_")).finish() | ||
| 159 | }, | ||
| 160 | WorkerTask::Members(room_id, _) => { | 164 | WorkerTask::Members(room_id, _) => { |
| 161 | f.debug_tuple("WorkerTask::Members") | 165 | f.debug_tuple("WorkerTask::Members") |
| 162 | .field(room_id) | 166 | .field(room_id) |
| @@ -245,6 +249,14 @@ impl Requester { | |||
| 245 | return response.recv(); | 249 | return response.recv(); |
| 246 | } | 250 | } |
| 247 | 251 | ||
| 252 | pub fn get_inviter(&self, invite: Invited) -> IambResult<Option<RoomMember>> { | ||
| 253 | let (reply, response) = oneshot(); | ||
| 254 | |||
| 255 | self.tx.send(WorkerTask::GetInviter(invite, reply)).unwrap(); | ||
| 256 | |||
| 257 | return response.recv(); | ||
| 258 | } | ||
| 259 | |||
| 248 | pub fn get_room(&self, room_id: OwnedRoomId) -> IambResult<(MatrixRoom, DisplayName)> { | 260 | pub fn get_room(&self, room_id: OwnedRoomId) -> IambResult<(MatrixRoom, DisplayName)> { |
| 249 | let (reply, response) = oneshot(); | 261 | let (reply, response) = oneshot(); |
| 250 | 262 | ||
| @@ -261,10 +273,10 @@ impl Requester { | |||
| 261 | return response.recv(); | 273 | return response.recv(); |
| 262 | } | 274 | } |
| 263 | 275 | ||
| 264 | pub fn joined_rooms(&self) -> Vec<(MatrixRoom, DisplayName)> { | 276 | pub fn active_rooms(&self) -> Vec<(MatrixRoom, DisplayName)> { |
| 265 | let (reply, response) = oneshot(); | 277 | let (reply, response) = oneshot(); |
| 266 | 278 | ||
| 267 | self.tx.send(WorkerTask::JoinedRooms(reply)).unwrap(); | 279 | self.tx.send(WorkerTask::ActiveRooms(reply)).unwrap(); |
| 268 | 280 | ||
| 269 | return response.recv(); | 281 | return response.recv(); |
| 270 | } | 282 | } |
| @@ -406,13 +418,17 @@ impl ClientWorker { | |||
| 406 | assert!(self.initialized); | 418 | assert!(self.initialized); |
| 407 | reply.send(self.join_room(room_id).await); | 419 | reply.send(self.join_room(room_id).await); |
| 408 | }, | 420 | }, |
| 421 | WorkerTask::GetInviter(invited, reply) => { | ||
| 422 | assert!(self.initialized); | ||
| 423 | reply.send(self.get_inviter(invited).await); | ||
| 424 | }, | ||
| 409 | WorkerTask::GetRoom(room_id, reply) => { | 425 | WorkerTask::GetRoom(room_id, reply) => { |
| 410 | assert!(self.initialized); | 426 | assert!(self.initialized); |
| 411 | reply.send(self.get_room(room_id).await); | 427 | reply.send(self.get_room(room_id).await); |
| 412 | }, | 428 | }, |
| 413 | WorkerTask::JoinedRooms(reply) => { | 429 | WorkerTask::ActiveRooms(reply) => { |
| 414 | assert!(self.initialized); | 430 | assert!(self.initialized); |
| 415 | reply.send(self.joined_rooms().await); | 431 | reply.send(self.active_rooms().await); |
| 416 | }, | 432 | }, |
| 417 | WorkerTask::LoadOlder(room_id, fetch_id, limit, reply) => { | 433 | WorkerTask::LoadOlder(room_id, fetch_id, limit, reply) => { |
| 418 | assert!(self.initialized); | 434 | assert!(self.initialized); |
| @@ -716,6 +732,12 @@ impl ClientWorker { | |||
| 716 | } | 732 | } |
| 717 | } | 733 | } |
| 718 | 734 | ||
| 735 | async fn get_inviter(&mut self, invited: Invited) -> IambResult<Option<RoomMember>> { | ||
| 736 | let details = invited.invite_details().await.map_err(IambError::from)?; | ||
| 737 | |||
| 738 | Ok(details.inviter) | ||
| 739 | } | ||
| 740 | |||
| 719 | async fn get_room(&mut self, room_id: OwnedRoomId) -> IambResult<(MatrixRoom, DisplayName)> { | 741 | async fn get_room(&mut self, room_id: OwnedRoomId) -> IambResult<(MatrixRoom, DisplayName)> { |
| 720 | if let Some(room) = self.client.get_room(&room_id) { | 742 | if let Some(room) = self.client.get_room(&room_id) { |
| 721 | let name = room.display_name().await.map_err(IambError::from)?; | 743 | let name = room.display_name().await.map_err(IambError::from)?; |
| @@ -749,33 +771,53 @@ impl ClientWorker { | |||
| 749 | } | 771 | } |
| 750 | } | 772 | } |
| 751 | 773 | ||
| 752 | async fn direct_messages(&mut self) -> Vec<(MatrixRoom, DisplayName)> { | 774 | async fn direct_messages(&self) -> Vec<(MatrixRoom, DisplayName)> { |
| 753 | let mut rooms = vec![]; | 775 | let mut rooms = vec![]; |
| 754 | 776 | ||
| 755 | for room in self.client.joined_rooms().into_iter() { | 777 | for room in self.client.invited_rooms().into_iter() { |
| 756 | if room.is_space() || !room.is_direct() { | 778 | if !room.is_direct() { |
| 757 | continue; | 779 | continue; |
| 758 | } | 780 | } |
| 759 | 781 | ||
| 760 | if let Ok(name) = room.display_name().await { | 782 | let name = room.display_name().await.unwrap_or(DisplayName::Empty); |
| 761 | rooms.push((MatrixRoom::from(room), name)) | 783 | |
| 784 | rooms.push((room.into(), name)); | ||
| 785 | } | ||
| 786 | |||
| 787 | for room in self.client.joined_rooms().into_iter() { | ||
| 788 | if !room.is_direct() { | ||
| 789 | continue; | ||
| 762 | } | 790 | } |
| 791 | |||
| 792 | let name = room.display_name().await.unwrap_or(DisplayName::Empty); | ||
| 793 | |||
| 794 | rooms.push((room.into(), name)); | ||
| 763 | } | 795 | } |
| 764 | 796 | ||
| 765 | return rooms; | 797 | return rooms; |
| 766 | } | 798 | } |
| 767 | 799 | ||
| 768 | async fn joined_rooms(&mut self) -> Vec<(MatrixRoom, DisplayName)> { | 800 | async fn active_rooms(&self) -> Vec<(MatrixRoom, DisplayName)> { |
| 769 | let mut rooms = vec![]; | 801 | let mut rooms = vec![]; |
| 770 | 802 | ||
| 771 | for room in self.client.joined_rooms().into_iter() { | 803 | for room in self.client.invited_rooms().into_iter() { |
| 772 | if room.is_space() || room.is_direct() { | 804 | if room.is_space() || room.is_direct() { |
| 773 | continue; | 805 | continue; |
| 774 | } | 806 | } |
| 775 | 807 | ||
| 776 | if let Ok(name) = room.display_name().await { | 808 | let name = room.display_name().await.unwrap_or(DisplayName::Empty); |
| 777 | rooms.push((MatrixRoom::from(room), name)) | 809 | |
| 810 | rooms.push((room.into(), name)); | ||
| 811 | } | ||
| 812 | |||
| 813 | for room in self.client.joined_rooms().into_iter() { | ||
| 814 | if room.is_space() || room.is_direct() { | ||
| 815 | continue; | ||
| 778 | } | 816 | } |
| 817 | |||
| 818 | let name = room.display_name().await.unwrap_or(DisplayName::Empty); | ||
| 819 | |||
| 820 | rooms.push((room.into(), name)); | ||
| 779 | } | 821 | } |
| 780 | 822 | ||
| 781 | return rooms; | 823 | return rooms; |
| @@ -857,17 +899,27 @@ impl ClientWorker { | |||
| 857 | Ok(rooms) | 899 | Ok(rooms) |
| 858 | } | 900 | } |
| 859 | 901 | ||
| 860 | async fn spaces(&mut self) -> Vec<(MatrixRoom, DisplayName)> { | 902 | async fn spaces(&self) -> Vec<(MatrixRoom, DisplayName)> { |
| 861 | let mut spaces = vec![]; | 903 | let mut spaces = vec![]; |
| 862 | 904 | ||
| 863 | for room in self.client.joined_rooms().into_iter() { | 905 | for room in self.client.invited_rooms().into_iter() { |
| 864 | if !room.is_space() { | 906 | if !room.is_space() { |
| 865 | continue; | 907 | continue; |
| 866 | } | 908 | } |
| 867 | 909 | ||
| 868 | if let Ok(name) = room.display_name().await { | 910 | let name = room.display_name().await.unwrap_or(DisplayName::Empty); |
| 869 | spaces.push((MatrixRoom::from(room), name)); | 911 | |
| 912 | spaces.push((room.into(), name)); | ||
| 913 | } | ||
| 914 | |||
| 915 | for room in self.client.joined_rooms().into_iter() { | ||
| 916 | if !room.is_space() { | ||
| 917 | continue; | ||
| 870 | } | 918 | } |
| 919 | |||
| 920 | let name = room.display_name().await.unwrap_or(DisplayName::Empty); | ||
| 921 | |||
| 922 | spaces.push((room.into(), name)); | ||
| 871 | } | 923 | } |
| 872 | 924 | ||
| 873 | return spaces; | 925 | return spaces; |