Skip to content

Commit

Permalink
add thumbsup command
Browse files Browse the repository at this point in the history
  • Loading branch information
kindlychung committed Nov 8, 2024
1 parent 6bcc592 commit c8d260d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 9 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 0.5.3

### Added

- Add 'thumbsup' command
- Use ctrl-t as shortcut for thumbsup

## 0.5.2

### Added
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "gurk"
description = "Signal messenger client for terminal"
version = "0.5.2-dev"
version = "0.5.3-dev"
authors = ["boxdot <d@zerovolt.org>"]
edition = "2021"
keywords = ["signal", "tui"]
Expand Down
28 changes: 21 additions & 7 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,12 @@ impl App {
}
Command::React => {
if let Some(idx) = self.channels.state.selected() {
self.add_reaction(idx);
self.add_reaction_from_input(idx);
}
}
Command::Thumbsup => {
if let Some(idx) = self.channels.state.selected() {
self.add_thumbsup(idx);
}
}
Command::OpenUrl => {
Expand Down Expand Up @@ -402,8 +407,7 @@ impl App {
}
}

pub fn add_reaction(&mut self, channel_idx: usize) -> Option<()> {
let reaction = self.take_reaction()?;
pub fn add_reaction(&mut self, channel_idx: usize, reaction: Option<String>) -> Option<()> {
let channel = self.storage.channel(self.channels.items[channel_idx])?;
let message = self.selected_message()?;
let remove = reaction.is_none();
Expand Down Expand Up @@ -439,6 +443,16 @@ impl App {
Some(())
}

pub fn add_reaction_from_input(&mut self, channel_idx: usize) -> Option<()> {
let reaction = self.take_reaction()?;
self.add_reaction(channel_idx, reaction)
}

pub fn add_thumbsup(&mut self, channel_idx: usize) -> Option<()> {
let reaction = Some("👍".to_string());
self.add_reaction(channel_idx, reaction)
}

fn reset_message_selection(&mut self) {
if let Some(channel_id) = self.channels.selected_item() {
if let Some(messages) = self.messages.get_mut(channel_id) {
Expand Down Expand Up @@ -1822,7 +1836,7 @@ pub(crate) mod tests {
.select(Some(0));

app.get_input().put_char('👍');
app.add_reaction(0);
app.add_reaction_from_input(0);

let arrived_at = app.messages[&channel_id].items[0];
let reactions = &app
Expand All @@ -1848,7 +1862,7 @@ pub(crate) mod tests {
for c in ":thumbsup:".chars() {
app.get_input().put_char(c);
}
app.add_reaction(0);
app.add_reaction_from_input(0);

let arrived_at = app.messages[&channel_id].items[0];
let reactions = &app
Expand Down Expand Up @@ -1879,7 +1893,7 @@ pub(crate) mod tests {
.into_owned();
message.reactions.push((app.user_id, "👍".to_string()));
app.storage.store_message(channel_id, message);
app.add_reaction(0);
app.add_reaction_from_input(0);

let reactions = &app
.storage
Expand All @@ -1902,7 +1916,7 @@ pub(crate) mod tests {
for c in ":thumbsup".chars() {
app.get_input().put_char(c);
}
app.add_reaction(0);
app.add_reaction_from_input(0);

assert_eq!(app.get_input().data, ":thumbsup");
let arrived_at = app.messages[&channel_id].items[0];
Expand Down
3 changes: 3 additions & 0 deletions src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ pub enum Command {
ToggleMultiline,
#[strum(props(desc = "Sends emoji from input line as reaction on selected message."))]
React,
#[strum(props(desc = "Sends thumbsup emoji as reaction on selected message."))]
Thumbsup,
#[strum(props(desc = "Scroll a widget", usage = "scroll help up|down entry"))]
#[strum(serialize = "scroll", to_string = "scroll {0} {1} {2}")]
Scroll(Widget, DirectionVertical, MoveAmountVisual),
Expand Down Expand Up @@ -417,6 +419,7 @@ end = "end_of_line"
ctrl-e = "end_of_line"
backspace = "delete_character previous"
tab = "react"
ctrl-t = "thumbsup"
[message_selected]
alt-y = "copy_message selected"
Expand Down

0 comments on commit c8d260d

Please sign in to comment.