-
Notifications
You must be signed in to change notification settings - Fork 50
/
uistatusview.cpp
95 lines (79 loc) · 2.93 KB
/
uistatusview.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// uistatusview.cpp
//
// Copyright (c) 2019-2024 Kristofer Berggren
// All rights reserved.
//
// nchat is distributed under the MIT license, see LICENSE for details.
#include "uistatusview.h"
#include "apputil.h"
#include "strutil.h"
#include "uicolorconfig.h"
#include "uiconfig.h"
#include "uimodel.h"
UiStatusView::UiStatusView(const UiViewParams& p_Params)
: UiViewBase(p_Params)
{
}
void UiStatusView::Draw()
{
std::unique_lock<std::mutex> lock(m_ViewMutex);
if (!m_Enabled || !m_Dirty) return;
m_Dirty = false;
curs_set(0);
std::pair<std::string, std::string>& currentChat = m_Model->GetCurrentChat();
std::string name = m_Model->GetContactListName(currentChat.first, currentChat.second, true /*p_AllowId*/);
if (!m_Model->GetEmojiEnabled())
{
name = StrUtil::Textize(name);
}
int statusVPad = 1;
static int colorPair = UiColorConfig::GetColorPair("status_color");
static int attribute = UiColorConfig::GetAttribute("status_attr");
werase(m_Win);
wbkgd(m_Win, attribute | colorPair | ' ');
wattron(m_Win, attribute | colorPair);
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);
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)
{
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);
}
}
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);
}
mvwaddnwstr(m_Win, 0, 0, wstatus.c_str(), wstatus.size());
wattroff(m_Win, attribute | colorPair);
wrefresh(m_Win);
}