Skip to content

Commit

Permalink
Add a new :chats window that lists both DMs and Rooms (#184)
Browse files Browse the repository at this point in the history
Fixes #172
  • Loading branch information
FormindVER authored and ulyssa committed Feb 28, 2024
1 parent 88af9bf commit b7ae014
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 19 deletions.
19 changes: 17 additions & 2 deletions src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,7 @@ pub enum IambId {
/// A Matrix room.
Room(OwnedRoomId),

/// The `:rooms` window.
/// The `:dms` window.
DirectList,

/// The `:members` window for a given Matrix room.
Expand All @@ -1189,6 +1189,9 @@ pub enum IambId {

/// The `:welcome` window.
Welcome,

/// The `:chats` window.
ChatList,
}

impl Display for IambId {
Expand All @@ -1205,6 +1208,7 @@ impl Display for IambId {
IambId::SpaceList => f.write_str("iamb://spaces"),
IambId::VerifyList => f.write_str("iamb://verify"),
IambId::Welcome => f.write_str("iamb://welcome"),
IambId::ChatList => f.write_str("iamb://chats"),
}
}
}
Expand Down Expand Up @@ -1317,6 +1321,13 @@ impl<'de> Visitor<'de> for IambIdVisitor {

Ok(IambId::Welcome)
},
Some("chats") => {
if url.path() != "" {
return Err(E::custom("iamb://chats takes no path"));
}

Ok(IambId::ChatList)
},
Some(s) => Err(E::custom(format!("{s:?} is not a valid window"))),
None => Err(E::custom("Invalid iamb window URL")),
}
Expand Down Expand Up @@ -1374,6 +1385,9 @@ pub enum IambBufferId {

/// The buffer for the `:rooms` window.
Welcome,

/// The `:chats` window.
ChatList,
}

impl IambBufferId {
Expand All @@ -1388,6 +1402,7 @@ impl IambBufferId {
IambBufferId::SpaceList => Some(IambId::SpaceList),
IambBufferId::VerifyList => Some(IambId::VerifyList),
IambBufferId::Welcome => Some(IambId::Welcome),
IambBufferId::ChatList => Some(IambId::ChatList),
}
}
}
Expand All @@ -1410,7 +1425,6 @@ impl ApplicationInfo for IambInfo {
match content {
IambBufferId::Command(CommandType::Command) => complete_cmdbar(text, cursor, store),
IambBufferId::Command(CommandType::Search) => vec![],

IambBufferId::Room(_, RoomFocus::MessageBar) => complete_msgbar(text, cursor, store),
IambBufferId::Room(_, RoomFocus::Scrollback) => vec![],

Expand All @@ -1420,6 +1434,7 @@ impl ApplicationInfo for IambInfo {
IambBufferId::SpaceList => vec![],
IambBufferId::VerifyList => vec![],
IambBufferId::Welcome => vec![],
IambBufferId::ChatList => vec![],
}
}

Expand Down
16 changes: 16 additions & 0 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,17 @@ fn iamb_rooms(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
return Ok(step);
}

fn iamb_chats(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
if !desc.arg.text.is_empty() {
return Result::Err(CommandError::InvalidArgument);
}

let open = ctx.switch(OpenTarget::Application(IambId::ChatList));
let step = CommandStep::Continue(open, ctx.context.take());

return Ok(step);
}

fn iamb_spaces(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
if !desc.arg.text.is_empty() {
return Result::Err(CommandError::InvalidArgument);
Expand Down Expand Up @@ -495,6 +506,11 @@ fn add_iamb_commands(cmds: &mut ProgramCommands) {
aliases: vec![],
f: iamb_create,
});
cmds.add_command(ProgramCommand {
name: "chats".into(),
aliases: vec![],
f: iamb_chats,
});
cmds.add_command(ProgramCommand { name: "dms".into(), aliases: vec![], f: iamb_dms });
cmds.add_command(ProgramCommand {
name: "download".into(),
Expand Down
6 changes: 5 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ pub type UserOverrides = HashMap<OwnedUserId, UserDisplayTunables>;

fn merge_sorts(a: SortOverrides, b: SortOverrides) -> SortOverrides {
SortOverrides {
chats: b.chats.or(a.chats),
dms: b.dms.or(a.dms),
rooms: b.rooms.or(a.rooms),
spaces: b.spaces.or(a.spaces),
Expand Down Expand Up @@ -308,6 +309,7 @@ pub struct ImagePreviewProtocolValues {

#[derive(Clone)]
pub struct SortValues {
pub chats: Vec<SortColumn<SortFieldRoom>>,
pub dms: Vec<SortColumn<SortFieldRoom>>,
pub rooms: Vec<SortColumn<SortFieldRoom>>,
pub spaces: Vec<SortColumn<SortFieldRoom>>,
Expand All @@ -316,6 +318,7 @@ pub struct SortValues {

#[derive(Clone, Default, Deserialize)]
pub struct SortOverrides {
pub chats: Option<Vec<SortColumn<SortFieldRoom>>>,
pub dms: Option<Vec<SortColumn<SortFieldRoom>>>,
pub rooms: Option<Vec<SortColumn<SortFieldRoom>>>,
pub spaces: Option<Vec<SortColumn<SortFieldRoom>>>,
Expand All @@ -325,11 +328,12 @@ pub struct SortOverrides {
impl SortOverrides {
pub fn values(self) -> SortValues {
let rooms = self.rooms.unwrap_or_else(|| Vec::from(DEFAULT_ROOM_SORT));
let chats = self.chats.unwrap_or_else(|| rooms.clone());
let dms = self.dms.unwrap_or_else(|| rooms.clone());
let spaces = self.spaces.unwrap_or_else(|| rooms.clone());
let members = self.members.unwrap_or_else(|| Vec::from(DEFAULT_MEMBERS_SORT));

SortValues { rooms, members, dms, spaces }
SortValues { rooms, members, chats, dms, spaces }
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl Ord for MessageTimeStamp {

impl PartialOrd for MessageTimeStamp {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.cmp(other).into()
Some(self.cmp(other))
}
}

Expand Down Expand Up @@ -340,7 +340,7 @@ impl Ord for MessageCursor {

impl PartialOrd for MessageCursor {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.cmp(other).into()
Some(self.cmp(other))
}
}

Expand Down
Loading

0 comments on commit b7ae014

Please sign in to comment.