Skip to content

Commit

Permalink
fixes #217 - add support for jumping to quoted message
Browse files Browse the repository at this point in the history
  • Loading branch information
d99kris committed Apr 20, 2024
1 parent a9c33ae commit 60983eb
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 9 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ Interactive Commands for Selected Message:
Ctrl-w open link
Ctrl-x send reply to selected message
Ctrl-z edit selected message
Alt-w external message viewer
Alt-c copy selected message to clipboard
Alt-q jump to quoted/replied message
Alt-s add/remove reaction on selected message
Alt-w external message viewer

Interactive Commands for Text Input:

Expand Down
2 changes: 1 addition & 1 deletion lib/common/src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

#pragma once

#define NCHAT_VERSION "4.66"
#define NCHAT_VERSION "4.67"
3 changes: 2 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,9 +613,10 @@ void ShowHelp()
" Ctrl-w open link\n"
" Ctrl-x send reply to selected message\n"
" Ctrl-z edit selected message\n"
" Alt-w external message viewer\n"
" Alt-c copy selected message to clipboard\n"
" Alt-q jump to quoted/replied message\n"
" Alt-s add/remove reaction on selected message\n"
" Alt-w external message viewer\n"
"\n"
"Interactive Commands for Text Input:\n"
" Ctrl-a move cursor to start of line\n"
Expand Down
11 changes: 7 additions & 4 deletions src/nchat.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man.
.TH NCHAT "1" "April 2024" "nchat v4.66" "User Commands"
.TH NCHAT "1" "April 2024" "nchat v4.67" "User Commands"
.SH NAME
nchat \- ncurses chat
.SH SYNOPSIS
Expand Down Expand Up @@ -119,14 +119,17 @@ send reply to selected message
Ctrl\-z
edit selected message
.TP
Alt\-w
external message viewer
.TP
Alt\-c
copy selected message to clipboard
.TP
Alt\-q
jump to quoted/replied message
.TP
Alt\-s
add/remove reaction on selected message
.TP
Alt\-w
external message viewer
.SS "Interactive Commands for Text Input:"
.TP
Ctrl\-a
Expand Down
1 change: 1 addition & 0 deletions src/uikeyconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ void UiKeyConfig::Init(bool p_MapKeys)
{ "ext_edit", "\\33\\145" }, // alt/opt-e
{ "react", "\\33\\163" }, // alt/opt-s
{ "spell", "\\33\\44" }, // alt/opt-$
{ "jump_quoted", "\\33\\161" }, // alt/opt-q
{ "toggle_emoji", "KEY_CTRLY" },
{ "toggle_help", "KEY_CTRLG" },
{ "toggle_list", "KEY_CTRLL" },
Expand Down
4 changes: 2 additions & 2 deletions src/uikeydump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void UiKeyDump::Run()
curs_set(0);
timeout(0);

printw("key code dump mode - press ctrl-c or 'q' to exit\n");
printw("key code dump mode - press ctrl-c to exit\n");
refresh();

UiKeyConfig::Init(false);
Expand Down Expand Up @@ -82,7 +82,7 @@ void UiKeyDump::Run()
++count;
printw("\\%o", key);

if ((key == 3) || (key == 'q'))
if (key == 3)
{
running = false;
break;
Expand Down
44 changes: 44 additions & 0 deletions src/uimodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ void UiModel::KeyHandler(wint_t p_Key)
static wint_t keyReact = UiKeyConfig::GetKey("react");
static wint_t keySpell = UiKeyConfig::GetKey("spell");

static wint_t keyJumpQuoted = UiKeyConfig::GetKey("jump_quoted");

static wint_t keyToggleList = UiKeyConfig::GetKey("toggle_list");
static wint_t keyToggleTop = UiKeyConfig::GetKey("toggle_top");
static wint_t keyToggleHelp = UiKeyConfig::GetKey("toggle_help");
Expand Down Expand Up @@ -280,6 +282,10 @@ void UiModel::KeyHandler(wint_t p_Key)
{
ExternalCall();
}
else if (p_Key == keyJumpQuoted)
{
JumpQuoted();
}
else
{
EntryKeyHandler(p_Key);
Expand Down Expand Up @@ -3475,3 +3481,41 @@ void UiModel::GetAvailableEmojis(std::set<std::string>& p_AvailableEmojis, bool&

LOG_DEBUG("get available reactions %d pending %d", p_AvailableEmojis.size(), p_Pending);
}

void UiModel::JumpQuoted()
{
if (!GetSelectMessageActive() || GetEditMessageActive()) return;

std::unique_lock<std::mutex> lock(m_ModelMutex);

std::string quotedId;
const std::string profileId = m_CurrentChat.first;
const std::string chatId = m_CurrentChat.second;
const std::vector<std::string>& messageVec = m_MessageVec[profileId][chatId];
int& messageOffset = m_MessageOffset[profileId][chatId];
auto it = std::next(messageVec.begin(), messageOffset);
if (it == messageVec.end()) return;

std::string msgId = *it;
const std::unordered_map<std::string, ChatMessage>& messages = m_Messages[profileId][chatId];
auto mit = messages.find(msgId);
if (mit == messages.end())
{
LOG_WARNING("message %s not fetched by ui", msgId.c_str());
return;
}
else
{
quotedId = mit->second.quotedId;
}

for (auto mid = messageVec.begin(); mid != messageVec.end(); ++mid)
{
if (*mid == quotedId)
{
messageOffset = std::distance(messageVec.begin(), mid);
UpdateHistory();
break;
}
}
}
1 change: 1 addition & 0 deletions src/uimodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class UiModel
bool IsMultipleProfiles();
std::string GetProfileDisplayName(const std::string& p_ProfileId);
void GetAvailableEmojis(std::set<std::string>& p_AvailableEmojis, bool& p_Pending);
void JumpQuoted();

static bool IsAttachmentDownloaded(const FileInfo& p_FileInfo);
static bool IsAttachmentDownloadable(const FileInfo& p_FileInfo);
Expand Down

0 comments on commit 60983eb

Please sign in to comment.