Skip to content

Commit

Permalink
fixes #276 - add support for hiding whatsapp status updates
Browse files Browse the repository at this point in the history
  • Loading branch information
d99kris committed Aug 10, 2024
1 parent 7630dca commit 35f1c95
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 11 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,6 @@ This configuration file holds general user interface settings. Default content:
mark_read_when_inactive=0
message_edit_command=
message_open_command=
mute_status_broadcast=1
muted_indicate_unread=1
muted_notify_unread=0
muted_position_by_timestamp=1
Expand All @@ -373,6 +372,7 @@ This configuration file holds general user interface settings. Default content:
read_indicator=✓
reactions_enabled=1
spell_check_command=
status_broadcast=1
syncing_indicator=⇄
terminal_bell_active=0
terminal_bell_inactive=1
Expand Down Expand Up @@ -540,11 +540,6 @@ Specifies a custom command to use for opening/viewing message text part. If
not specified, nchat will use `PAGER` environment variable if set, or
otherwise use `less`.

### mute_status_broadcast

Specifies whether (WhatsApp) status broadcast chat should be treated as
muted.

### muted_indicate_unread

Specifies whether chat list should indicate unread status `*` for muted chats.
Expand Down Expand Up @@ -595,6 +590,14 @@ Specifies a custom command to use for spell checking composed messages. If not
specified, nchat checks if `aspell` or `ispell` is available on the system (in
that order), and uses the first found.

### status_broadcast

Specifies (WhatsApp) Status Updates chat level of visibility:

0 = hidden
1 = visible and muted <- default
2 = visible

### syncing_indicator

Specifies text to suffix attachment filenames in message view for downloads
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 "5.1.24"
#define NCHAT_VERSION "5.1.25"
2 changes: 1 addition & 1 deletion 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" "August 2024" "nchat 5.1.24" "User Commands"
.TH NCHAT "1" "August 2024" "nchat 5.1.25" "User Commands"
.SH NAME
nchat \- ncurses chat
.SH SYNOPSIS
Expand Down
2 changes: 1 addition & 1 deletion src/uiconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ void UiConfig::Init()
{ "mark_read_when_inactive", "0" },
{ "message_edit_command", "" },
{ "message_open_command", "" },
{ "mute_status_broadcast", "1" },
{ "muted_indicate_unread", "1" },
{ "muted_notify_unread", "0" },
{ "muted_position_by_timestamp", "1" },
Expand All @@ -54,6 +53,7 @@ void UiConfig::Init()
{ "read_indicator", "\xe2\x9c\x93" },
{ "reactions_enabled", "1" },
{ "spell_check_command", "" },
{ "status_broadcast", "1" },
{ "syncing_indicator", "\xe2\x87\x84" },
{ "terminal_bell_active", "0" },
{ "terminal_bell_inactive", "1" },
Expand Down
19 changes: 17 additions & 2 deletions src/uimodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1625,8 +1625,9 @@ void UiModel::MessageHandler(std::shared_ptr<ServiceMessage> p_ServiceMessage)
for (auto& chatInfo : newChatsNotify->chatInfos)
{
LOG_TRACE("new chats %s", chatInfo.id.c_str());
static const bool muteStatusBroadcast = UiConfig::GetBool("mute_status_broadcast");
if (muteStatusBroadcast && (chatInfo.id == "status@broadcast"))
if (IsChatForceHidden(chatInfo.id)) continue;

if (IsChatForceMuted(chatInfo.id))
{
chatInfo.isMuted = true;
}
Expand Down Expand Up @@ -1657,6 +1658,8 @@ void UiModel::MessageHandler(std::shared_ptr<ServiceMessage> p_ServiceMessage)
{
bool hasNewMessage = false;
const std::string& chatId = newMessagesNotify->chatId;
if (IsChatForceHidden(chatId)) return;

std::unordered_map<std::string, ChatMessage>& messages = m_Messages[profileId][chatId];
std::vector<std::string>& messageVec = m_MessageVec[profileId][chatId];
const std::vector<ChatMessage>& chatMessages = newMessagesNotify->chatMessages;
Expand Down Expand Up @@ -3786,3 +3789,15 @@ void UiModel::ForwardMessage()

ReinitView();
}

bool UiModel::IsChatForceHidden(const std::string& p_ChatId)
{
static const bool statusBroadcastHidden = (UiConfig::GetNum("status_broadcast") == 0);
return statusBroadcastHidden && (p_ChatId == "status@broadcast");
}

bool UiModel::IsChatForceMuted(const std::string& p_ChatId)
{
static const bool statusBroadcastMuted = (UiConfig::GetNum("status_broadcast") == 1);
return statusBroadcastMuted && (p_ChatId == "status@broadcast");
}
2 changes: 2 additions & 0 deletions src/uimodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ class UiModel
void PerformFindNext();
void ClearFind();
void ForwardMessage();
bool IsChatForceHidden(const std::string& p_ChatId);
bool IsChatForceMuted(const std::string& p_ChatId);

private:
bool m_Running = true;
Expand Down

0 comments on commit 35f1c95

Please sign in to comment.