Skip to content

Commit

Permalink
developer mode to show user id in contact and chat list dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
d99kris committed Sep 14, 2024
1 parent d994d4b commit 4b1190b
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 32 deletions.
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.2.10"
#define NCHAT_VERSION "5.2.11"
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" "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
Expand Down
9 changes: 8 additions & 1 deletion src/uichatlistdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <algorithm>

#include "apputil.h"
#include "log.h"
#include "strutil.h"
#include "uiconfig.h"
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 8 additions & 1 deletion src/uicontactlistdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <algorithm>

#include "apputil.h"
#include "log.h"
#include "uimodel.h"
#include "strutil.h"
Expand Down Expand Up @@ -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;
Expand Down
64 changes: 36 additions & 28 deletions src/uistatusview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 4b1190b

Please sign in to comment.