Skip to content

Commit

Permalink
add support for indicating away status in top bar
Browse files Browse the repository at this point in the history
  • Loading branch information
d99kris committed Nov 25, 2023
1 parent d9b2af5 commit 3a71206
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 14 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ This configuration file holds general user interface settings. Default content:

attachment_indicator=📎
attachment_open_command=
away_status_indication=0
call_command=
confirm_deletion=1
desktop_notify_active=0
Expand Down Expand Up @@ -367,6 +368,13 @@ macOS: `open '%1' &`
Note: Omit the trailing `&` for commands taking over the terminal, for
example `w3m -o confirm_qq=false '%1'` and `see '%1'`.

### away_status_indication

Specifies whether to indicate away status in the top bar while sharing away
status with other users. I.e. the status will read `Away` instead of `Online`
when the terminal is inactive (assuming `online_status_share=1` and
`online_status_dynamic=1`).

### call_command

Specifies a custom command to use for starting a call using an external
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 "3.99"
#define NCHAT_VERSION "4.00"
16 changes: 9 additions & 7 deletions lib/ncutil/src/status.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ void Status::Clear(uint32_t p_Flags)
m_Flags &= ~p_Flags;
}

std::string Status::ToString()
std::string Status::ToString(uint32_t p_Mask)
{
std::unique_lock<std::mutex> lock(m_Mutex);

if (m_Flags & FlagSyncing) return "Syncing";
if (m_Flags & FlagFetching) return "Fetching";
if (m_Flags & FlagSending) return "Sending";
if (m_Flags & FlagUpdating) return "Updating";
if (m_Flags & FlagOnline) return "Online";
const uint32_t maskedFlags = m_Flags & p_Mask;

if (maskedFlags & FlagSyncing) return "Syncing";
if (maskedFlags & FlagFetching) return "Fetching";
if (maskedFlags & FlagSending) return "Sending";
if (maskedFlags & FlagUpdating) return "Updating";
if (maskedFlags & FlagAway) return "Away";
if (maskedFlags & FlagOnline) return "Online";

return "Offline";
}
4 changes: 2 additions & 2 deletions lib/ncutil/src/status.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ class Status
FlagSending = (1 << 3),
FlagUpdating = (1 << 4),
FlagSyncing = (1 << 5),
FlagMax = FlagSyncing,
FlagAway = (1 << 6),
};

static uint32_t Get();
static void Set(uint32_t p_Flags);
static void Clear(uint32_t p_Flags);
static std::string ToString();
static std::string ToString(uint32_t p_Mask);

private:
static uint32_t m_Flags;
Expand Down
11 changes: 10 additions & 1 deletion lib/tgchat/src/tgchat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ void TgChat::Impl::PerformRequest(std::shared_ptr<RequestMessage> p_RequestMessa
auto set_option =
td::td_api::make_object<td::td_api::setOption>("online", std::move(option_value));
SendQuery(std::move(set_option),
[this, setStatusRequest](Object object)
[this, setStatusRequest, isOnline](Object object)
{
if (object->get_id() == td::td_api::error::ID) return;

Expand All @@ -1019,6 +1019,15 @@ void TgChat::Impl::PerformRequest(std::shared_ptr<RequestMessage> p_RequestMessa
setStatusNotify->success = true;
setStatusNotify->isOnline = setStatusRequest->isOnline;
CallMessageHandler(setStatusNotify);

if (isOnline)
{
Status::Clear(Status::FlagAway);
}
else
{
Status::Set(Status::FlagAway);
}
});
}
break;
Expand Down
7 changes: 6 additions & 1 deletion lib/wmchat/go/gowm.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ var FlagFetching = (1 << 2)
var FlagSending = (1 << 3)
var FlagUpdating = (1 << 4)
var FlagSyncing = (1 << 5)
var FlagMax = FlagSyncing
var FlagAway = (1 << 6)

func AddConn(conn *whatsmeow.Client, path string, sendType int) int {
mx.Lock()
Expand Down Expand Up @@ -2081,6 +2081,11 @@ func WmSendStatus(connId int, isOnline int) int {
LOG_WARNING("Failed to send presence")
} else {
LOG_TRACE("Sent presence ok")
if isOnline == 1 {
CWmClearStatus(FlagAway)
} else {
CWmSetStatus(FlagAway)
}
}

return 0
Expand Down
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" "November 2023" "nchat v3.99" "User Commands"
.TH NCHAT "1" "November 2023" "nchat v4.00" "User Commands"
.SH NAME
nchat \- ncurses chat
.SH SYNOPSIS
Expand Down
1 change: 1 addition & 0 deletions src/uiconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ void UiConfig::Init()
{
{ "attachment_indicator", "\xF0\x9F\x93\x8E" },
{ "attachment_open_command", "" },
{ "away_status_indication", "0" },
{ "call_command", "" },
{ "confirm_deletion", "1" },
{ "desktop_notify_active", "0" },
Expand Down
6 changes: 5 additions & 1 deletion src/uitopview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ void UiTopView::Draw()
return std::string("");
}();

const std::string statusStr = Status::ToString() + statusSuffixStr;
static const bool awayStatusIndication = UiConfig::GetBool("away_status_indication");
static const uint32_t fullMask = ~static_cast<uint32_t>(0);
static const uint32_t statusMask = fullMask & (awayStatusIndication ? fullMask : ~Status::FlagAway);

const std::string statusStr = Status::ToString(statusMask) + statusSuffixStr;
static const std::string appNameVersion = AppUtil::GetAppNameVersion();
std::wstring topWStrLeft = StrUtil::ToWString(std::string(topPadLeft, ' ') + appNameVersion);
std::wstring topWStrRight = StrUtil::ToWString(statusStr + std::string(topPadRight, ' '));
Expand Down

0 comments on commit 3a71206

Please sign in to comment.