From 4b1190b695b236a40034c3944119e9e71763656b Mon Sep 17 00:00:00 2001 From: Kristofer Berggren Date: Sat, 14 Sep 2024 17:31:01 +0800 Subject: [PATCH] developer mode to show user id in contact and chat list dialogs --- lib/common/src/version.h | 2 +- src/nchat.1 | 2 +- src/uichatlistdialog.cpp | 9 +++++- src/uicontactlistdialog.cpp | 9 +++++- src/uistatusview.cpp | 64 +++++++++++++++++++++---------------- 5 files changed, 54 insertions(+), 32 deletions(-) diff --git a/lib/common/src/version.h b/lib/common/src/version.h index 9042235c..9673af3b 100644 --- a/lib/common/src/version.h +++ b/lib/common/src/version.h @@ -7,4 +7,4 @@ #pragma once -#define NCHAT_VERSION "5.2.10" +#define NCHAT_VERSION "5.2.11" diff --git a/src/nchat.1 b/src/nchat.1 index 7b1f19e6..22f3f6b5 100644 --- a/src/nchat.1 +++ b/src/nchat.1 @@ -1,5 +1,5 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man. -.TH NCHAT "1" "September 2024" "nchat 5.2.10" "User Commands" +.TH NCHAT "1" "September 2024" "nchat 5.2.11" "User Commands" .SH NAME nchat \- ncurses chat .SH SYNOPSIS diff --git a/src/uichatlistdialog.cpp b/src/uichatlistdialog.cpp index b1d9bfba..bfcb1af4 100644 --- a/src/uichatlistdialog.cpp +++ b/src/uichatlistdialog.cpp @@ -9,6 +9,7 @@ #include +#include "apputil.h" #include "log.h" #include "strutil.h" #include "uiconfig.h" @@ -69,9 +70,15 @@ void UiChatListDialog::UpdateList() (StrUtil::ToLower(name).find(StrUtil::ToLower(StrUtil::ToString(m_FilterStr))) != std::string::npos)) { static const bool isMultipleProfiles = m_Model->IsMultipleProfiles(); - const std::string displayName = name + + std::string displayName = name + (isMultipleProfiles ? " @ " + m_Model->GetProfileDisplayName(profileId) : ""); + static const bool developerMode = AppUtil::GetDeveloperMode(); + if (developerMode) + { + displayName += " [" + chatId + "]"; + } + UiChatListItem chatListItem; chatListItem.profileId = profileId; chatListItem.chatId = chatId; diff --git a/src/uicontactlistdialog.cpp b/src/uicontactlistdialog.cpp index 5b86d114..74eac556 100644 --- a/src/uicontactlistdialog.cpp +++ b/src/uicontactlistdialog.cpp @@ -9,6 +9,7 @@ #include +#include "apputil.h" #include "log.h" #include "uimodel.h" #include "strutil.h" @@ -90,9 +91,15 @@ void UiContactListDialog::UpdateList() (StrUtil::ToLower(name).find(StrUtil::ToLower(StrUtil::ToString(m_FilterStr))) != std::string::npos)) { static const bool isMultipleProfiles = m_Model->IsMultipleProfiles(); - const std::string displayName = name + + std::string displayName = name + (isMultipleProfiles ? " @ " + m_Model->GetProfileDisplayName(profileId) : ""); + static const bool developerMode = AppUtil::GetDeveloperMode(); + if (developerMode) + { + displayName += " [" + contactId + "]"; + } + UiContactListItem contactListItem; contactListItem.profileId = profileId; contactListItem.contactId = contactId; diff --git a/src/uistatusview.cpp b/src/uistatusview.cpp index 47ed451a..d002c410 100644 --- a/src/uistatusview.cpp +++ b/src/uistatusview.cpp @@ -42,43 +42,51 @@ void UiStatusView::Draw() wbkgd(m_Win, attribute | colorPair | ' '); wattron(m_Win, attribute | colorPair); - static bool isMultipleProfiles = m_Model->IsMultipleProfiles(); - std::string profileDisplayName = isMultipleProfiles ? " @ " + m_Model->GetProfileDisplayName(currentChat.first) : ""; + std::wstring wstatus; + if (currentChat.first.empty() && currentChat.second.empty()) + { + // Empty status bar until current chat is set + } + else + { + static bool isMultipleProfiles = m_Model->IsMultipleProfiles(); + std::string profileDisplayName = isMultipleProfiles ? " @ " + m_Model->GetProfileDisplayName(currentChat.first) : ""; - std::string chatStatus = m_Model->GetChatStatus(currentChat.first, currentChat.second); - std::wstring wstatus = std::wstring(statusVPad, ' ') + - StrUtil::ToWString(name).substr(0, m_W / 2) + - StrUtil::ToWString(profileDisplayName) + - StrUtil::ToWString(chatStatus); + std::string chatStatus = m_Model->GetChatStatus(currentChat.first, currentChat.second); + wstatus = std::wstring(statusVPad, ' ') + + StrUtil::ToWString(name).substr(0, m_W / 2) + + StrUtil::ToWString(profileDisplayName) + + StrUtil::ToWString(chatStatus); - static const std::string phoneNumberIndicator = UiConfig::GetStr("phone_number_indicator"); - if (!phoneNumberIndicator.empty()) - { - static std::string placeholder = "%1"; - static const bool isDynamicIndicator = (phoneNumberIndicator.find(placeholder) != std::string::npos); - if (isDynamicIndicator) + static const std::string phoneNumberIndicator = UiConfig::GetStr("phone_number_indicator"); + if (!phoneNumberIndicator.empty()) { - std::string dynamicIndicator = phoneNumberIndicator; - std::string phone = m_Model->GetContactPhone(currentChat.first, currentChat.second); - StrUtil::ReplaceString(dynamicIndicator, placeholder, phone); - wstatus += L" " + StrUtil::ToWString(dynamicIndicator); + static std::string placeholder = "%1"; + static const bool isDynamicIndicator = (phoneNumberIndicator.find(placeholder) != std::string::npos); + if (isDynamicIndicator) + { + std::string dynamicIndicator = phoneNumberIndicator; + std::string phone = m_Model->GetContactPhone(currentChat.first, currentChat.second); + StrUtil::ReplaceString(dynamicIndicator, placeholder, phone); + wstatus += L" " + StrUtil::ToWString(dynamicIndicator); + } + else + { + wstatus += L" " + StrUtil::ToWString(phoneNumberIndicator); + } } - else + + static const bool developerMode = AppUtil::GetDeveloperMode(); + if (developerMode) { - wstatus += L" " + StrUtil::ToWString(phoneNumberIndicator); + wstatus = wstatus + L" chat " + StrUtil::ToWString(currentChat.second); + int64_t lastMessageTime = m_Model->GetLastMessageTime(currentChat.first, currentChat.second); + wstatus = wstatus + L" time " + StrUtil::ToWString(std::to_string(lastMessageTime)); } - } - static const bool developerMode = AppUtil::GetDeveloperMode(); - if (developerMode) - { - wstatus = wstatus + L" chat " + StrUtil::ToWString(currentChat.second); - int64_t lastMessageTime = m_Model->GetLastMessageTime(currentChat.first, currentChat.second); - wstatus = wstatus + L" time " + StrUtil::ToWString(std::to_string(lastMessageTime)); + wstatus = StrUtil::TrimPadWString(wstatus, m_W); } - wstatus = StrUtil::TrimPadWString(wstatus, m_W); - mvwaddnwstr(m_Win, 0, 0, wstatus.c_str(), wstatus.size()); wattroff(m_Win, attribute | colorPair);