Format remaining C++ sources
This commit is contained in:
@@ -9,19 +9,20 @@ namespace telegram_tui {
|
||||
|
||||
namespace {
|
||||
|
||||
std::string format_download_progress(std::int64_t downloaded_size, std::int64_t size_bytes, bool is_downloaded) {
|
||||
std::string format_download_progress(std::int64_t downloaded_size, std::int64_t size_bytes,
|
||||
bool is_downloaded) {
|
||||
if (is_downloaded) {
|
||||
return "100%";
|
||||
}
|
||||
if (size_bytes > 0) {
|
||||
const auto downloaded = std::min(downloaded_size, size_bytes);
|
||||
return std::to_string(static_cast<int>((downloaded * 100) / size_bytes)) + "% " +
|
||||
format_file_size(downloaded) + "/" + format_file_size(size_bytes);
|
||||
format_file_size(downloaded) + "/" + format_file_size(size_bytes);
|
||||
}
|
||||
return format_file_size(downloaded_size);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
bool App::process_updates() {
|
||||
bool changed = false;
|
||||
@@ -36,7 +37,7 @@ bool App::process_updates() {
|
||||
return changed;
|
||||
}
|
||||
|
||||
void App::handle_td_object(const json& object) {
|
||||
void App::handle_td_object(const json &object) {
|
||||
const std::string type = safe_string(object, "@type");
|
||||
if (type == "updateAuthorizationState") {
|
||||
authorization_state_ = object.value("authorization_state", json::object());
|
||||
@@ -48,7 +49,7 @@ void App::handle_td_object(const json& object) {
|
||||
return;
|
||||
}
|
||||
if (type == "updateChatOnlineMemberCount") {
|
||||
ChatInfo& chat = chats_[safe_i64(object, "chat_id")];
|
||||
ChatInfo &chat = chats_[safe_i64(object, "chat_id")];
|
||||
chat.id = safe_i64(object, "chat_id");
|
||||
chat.online_member_count = safe_i32(object, "online_member_count");
|
||||
chat.has_online_member_count = true;
|
||||
@@ -59,15 +60,19 @@ void App::handle_td_object(const json& object) {
|
||||
return;
|
||||
}
|
||||
if (type == "updateUserStatus") {
|
||||
update_user_status(safe_i64(object, "user_id"), object.value("status", json::object()));
|
||||
update_user_status(safe_i64(object, "user_id"),
|
||||
object.value("status", json::object()));
|
||||
return;
|
||||
}
|
||||
if (type == "updateBasicGroup" || type == "basicGroup") {
|
||||
upsert_basic_group(type == "basicGroup" ? object : object.value("basic_group", json::object()));
|
||||
upsert_basic_group(type == "basicGroup"
|
||||
? object
|
||||
: object.value("basic_group", json::object()));
|
||||
return;
|
||||
}
|
||||
if (type == "updateSupergroup" || type == "supergroup") {
|
||||
upsert_supergroup(type == "supergroup" ? object : object.value("supergroup", json::object()));
|
||||
upsert_supergroup(
|
||||
type == "supergroup" ? object : object.value("supergroup", json::object()));
|
||||
return;
|
||||
}
|
||||
if (type == "updateNewChat") {
|
||||
@@ -75,27 +80,28 @@ void App::handle_td_object(const json& object) {
|
||||
return;
|
||||
}
|
||||
if (type == "updateChatTitle") {
|
||||
ChatInfo& chat = chats_[safe_i64(object, "chat_id")];
|
||||
ChatInfo &chat = chats_[safe_i64(object, "chat_id")];
|
||||
chat.id = safe_i64(object, "chat_id");
|
||||
chat.title = safe_string(object, "title");
|
||||
resort_chats();
|
||||
return;
|
||||
}
|
||||
if (type == "updateChatPosition") {
|
||||
ChatInfo& chat = chats_[safe_i64(object, "chat_id")];
|
||||
ChatInfo &chat = chats_[safe_i64(object, "chat_id")];
|
||||
chat.id = safe_i64(object, "chat_id");
|
||||
apply_chat_position(chat, object.value("position", json::object()));
|
||||
resort_chats();
|
||||
return;
|
||||
}
|
||||
if (type == "updateChatLastMessage") {
|
||||
ChatInfo& chat = chats_[safe_i64(object, "chat_id")];
|
||||
ChatInfo &chat = chats_[safe_i64(object, "chat_id")];
|
||||
chat.id = safe_i64(object, "chat_id");
|
||||
chat.last_message_preview = preview_message(object.value("last_message", json::object()));
|
||||
chat.last_message_preview =
|
||||
preview_message(object.value("last_message", json::object()));
|
||||
if (object.contains("positions") && object.at("positions").is_array()) {
|
||||
chat.in_main_list = false;
|
||||
chat.main_order = 0;
|
||||
for (const auto& position : object.at("positions")) {
|
||||
for (const auto &position : object.at("positions")) {
|
||||
apply_chat_position(chat, position);
|
||||
}
|
||||
}
|
||||
@@ -103,14 +109,14 @@ void App::handle_td_object(const json& object) {
|
||||
return;
|
||||
}
|
||||
if (type == "updateChatReadInbox") {
|
||||
ChatInfo& chat = chats_[safe_i64(object, "chat_id")];
|
||||
ChatInfo &chat = chats_[safe_i64(object, "chat_id")];
|
||||
chat.id = safe_i64(object, "chat_id");
|
||||
chat.unread_count = safe_i32(object, "unread_count");
|
||||
chat.last_read_inbox_message_id = safe_i64(object, "last_read_inbox_message_id");
|
||||
return;
|
||||
}
|
||||
if (type == "updateChatReadOutbox") {
|
||||
ChatInfo& chat = chats_[safe_i64(object, "chat_id")];
|
||||
ChatInfo &chat = chats_[safe_i64(object, "chat_id")];
|
||||
chat.id = safe_i64(object, "chat_id");
|
||||
chat.last_read_outbox_message_id = safe_i64(object, "last_read_outbox_message_id");
|
||||
return;
|
||||
@@ -136,11 +142,12 @@ void App::handle_td_object(const json& object) {
|
||||
if (chat_it == chats_.end()) {
|
||||
return;
|
||||
}
|
||||
for (auto& message : chat_it->second.messages) {
|
||||
for (auto &message : chat_it->second.messages) {
|
||||
if (message.id == message_id) {
|
||||
const json content = object.value("new_content", json::object());
|
||||
message.text = content_to_text(content, true);
|
||||
if (const auto attachment = parse_attachment(content); attachment.has_value()) {
|
||||
if (const auto attachment = parse_attachment(content);
|
||||
attachment.has_value()) {
|
||||
message.has_attachment = true;
|
||||
message.attachment = *attachment;
|
||||
} else {
|
||||
@@ -158,14 +165,14 @@ void App::handle_td_object(const json& object) {
|
||||
return;
|
||||
}
|
||||
std::set<std::int64_t> deleted;
|
||||
for (const auto& id : object.value("message_ids", json::array())) {
|
||||
for (const auto &id : object.value("message_ids", json::array())) {
|
||||
if (id.is_number_integer()) {
|
||||
deleted.insert(id.get<std::int64_t>());
|
||||
}
|
||||
}
|
||||
std::vector<MessageInfo> kept;
|
||||
kept.reserve(chat_it->second.messages.size());
|
||||
for (const auto& message : chat_it->second.messages) {
|
||||
for (const auto &message : chat_it->second.messages) {
|
||||
if (deleted.find(message.id) == deleted.end()) {
|
||||
kept.push_back(message);
|
||||
}
|
||||
@@ -178,8 +185,8 @@ void App::handle_td_object(const json& object) {
|
||||
return;
|
||||
}
|
||||
if (type == "updateOption" || type == "ok" || type == "userFullInfo" ||
|
||||
type == "updateHavePendingNotifications" || type == "updateUnreadMessageCount" ||
|
||||
type == "updateUnreadChatCount") {
|
||||
type == "updateHavePendingNotifications" || type == "updateUnreadMessageCount" ||
|
||||
type == "updateUnreadChatCount") {
|
||||
return;
|
||||
}
|
||||
if (type == "error") {
|
||||
@@ -235,29 +242,29 @@ void App::handle_td_object(const json& object) {
|
||||
|
||||
void App::request_more_chats() {
|
||||
td_.send({
|
||||
{"@type", "getChats"},
|
||||
{"chat_list", {{"@type", "chatListMain"}}},
|
||||
{"limit", kChatPageSize},
|
||||
{"@extra", "main_chats"},
|
||||
{"@type", "getChats"},
|
||||
{"chat_list", {{"@type", "chatListMain"}}},
|
||||
{"limit", kChatPageSize},
|
||||
{"@extra", "main_chats"},
|
||||
});
|
||||
status_line_ = "Loading chats...";
|
||||
}
|
||||
|
||||
bool App::request_chat_history(std::int64_t chat_id, bool force) {
|
||||
ChatInfo& chat = chats_[chat_id];
|
||||
ChatInfo &chat = chats_[chat_id];
|
||||
chat.id = chat_id;
|
||||
if (chat.history_loading && !force) {
|
||||
return false;
|
||||
}
|
||||
chat.history_loading = true;
|
||||
td_.send({
|
||||
{"@type", "getChatHistory"},
|
||||
{"chat_id", chat_id},
|
||||
{"from_message_id", 0},
|
||||
{"offset", 0},
|
||||
{"limit", kHistoryBatchSize},
|
||||
{"only_local", false},
|
||||
{"@extra", "history:" + std::to_string(chat_id)},
|
||||
{"@type", "getChatHistory"},
|
||||
{"chat_id", chat_id},
|
||||
{"from_message_id", 0},
|
||||
{"offset", 0},
|
||||
{"limit", kHistoryBatchSize},
|
||||
{"only_local", false},
|
||||
{"@extra", "history:" + std::to_string(chat_id)},
|
||||
});
|
||||
return true;
|
||||
}
|
||||
@@ -283,7 +290,7 @@ void App::mark_chat_messages_as_read(std::int64_t chat_id) {
|
||||
|
||||
std::vector<std::int64_t> unread_message_ids;
|
||||
unread_message_ids.reserve(chat_it->second.messages.size());
|
||||
for (const auto& message : chat_it->second.messages) {
|
||||
for (const auto &message : chat_it->second.messages) {
|
||||
if (message.is_outgoing || message.id == 0) {
|
||||
continue;
|
||||
}
|
||||
@@ -295,18 +302,18 @@ void App::mark_chat_messages_as_read(std::int64_t chat_id) {
|
||||
|
||||
if (!unread_message_ids.empty()) {
|
||||
td_.send({
|
||||
{"@type", "viewMessages"},
|
||||
{"chat_id", chat_id},
|
||||
{"message_ids", unread_message_ids},
|
||||
{"source", {{"@type", "messageSourceChatHistory"}}},
|
||||
{"force_read", true},
|
||||
{"@type", "viewMessages"},
|
||||
{"chat_id", chat_id},
|
||||
{"message_ids", unread_message_ids},
|
||||
{"source", {{"@type", "messageSourceChatHistory"}}},
|
||||
{"force_read", true},
|
||||
});
|
||||
}
|
||||
|
||||
td_.send({
|
||||
{"@type", "toggleChatIsMarkedAsUnread"},
|
||||
{"chat_id", chat_id},
|
||||
{"is_marked_as_unread", false},
|
||||
{"@type", "toggleChatIsMarkedAsUnread"},
|
||||
{"chat_id", chat_id},
|
||||
{"is_marked_as_unread", false},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -316,11 +323,11 @@ void App::mark_message_as_read(std::int64_t chat_id, std::int64_t message_id) {
|
||||
}
|
||||
|
||||
td_.send({
|
||||
{"@type", "viewMessages"},
|
||||
{"chat_id", chat_id},
|
||||
{"message_ids", json::array({message_id})},
|
||||
{"source", {{"@type", "messageSourceChatHistory"}}},
|
||||
{"force_read", true},
|
||||
{"@type", "viewMessages"},
|
||||
{"chat_id", chat_id},
|
||||
{"message_ids", json::array({message_id})},
|
||||
{"source", {{"@type", "messageSourceChatHistory"}}},
|
||||
{"force_read", true},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -330,12 +337,12 @@ void App::set_open_chat(std::int64_t chat_id) {
|
||||
}
|
||||
|
||||
const bool changed_chat = open_chat_id_ != chat_id;
|
||||
ChatInfo& chat = chats_[chat_id];
|
||||
ChatInfo &chat = chats_[chat_id];
|
||||
chat.id = chat_id;
|
||||
if (tdlib_open_chat_id_ != 0 && tdlib_open_chat_id_ != chat_id) {
|
||||
td_.send({
|
||||
{"@type", "closeChat"},
|
||||
{"chat_id", tdlib_open_chat_id_},
|
||||
{"@type", "closeChat"},
|
||||
{"chat_id", tdlib_open_chat_id_},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -347,8 +354,8 @@ void App::set_open_chat(std::int64_t chat_id) {
|
||||
|
||||
if (tdlib_open_chat_id_ != chat_id) {
|
||||
td_.send({
|
||||
{"@type", "openChat"},
|
||||
{"chat_id", chat_id},
|
||||
{"@type", "openChat"},
|
||||
{"chat_id", chat_id},
|
||||
});
|
||||
tdlib_open_chat_id_ = chat_id;
|
||||
}
|
||||
@@ -358,25 +365,25 @@ void App::set_open_chat(std::int64_t chat_id) {
|
||||
if (changed_chat) {
|
||||
request_chat_details(chat_id);
|
||||
const bool should_request_history =
|
||||
auto_reload_chat_history_ || !chat.history_loaded || chat.messages.empty();
|
||||
auto_reload_chat_history_ || !chat.history_loaded || chat.messages.empty();
|
||||
const bool requested = should_request_history &&
|
||||
request_chat_history(chat_id, auto_reload_chat_history_);
|
||||
request_chat_history(chat_id, auto_reload_chat_history_);
|
||||
if (requested) {
|
||||
status_line_ = auto_reload_chat_history_ && chat.history_loaded
|
||||
? "Reloading chat history..."
|
||||
: "Loading chat history...";
|
||||
? "Reloading chat history..."
|
||||
: "Loading chat history...";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void App::sync_chat_ids_from_response(const json& response) {
|
||||
void App::sync_chat_ids_from_response(const json &response) {
|
||||
if (!response.contains("chat_ids") || !response.at("chat_ids").is_array()) {
|
||||
status_line_ = "Chat list response missing chat ids.";
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<std::int64_t> chat_ids;
|
||||
for (const auto& entry : response.at("chat_ids")) {
|
||||
for (const auto &entry : response.at("chat_ids")) {
|
||||
if (!entry.is_number_integer()) {
|
||||
continue;
|
||||
}
|
||||
@@ -384,8 +391,8 @@ void App::sync_chat_ids_from_response(const json& response) {
|
||||
chat_ids.push_back(chat_id);
|
||||
if (chats_.find(chat_id) == chats_.end()) {
|
||||
td_.send({
|
||||
{"@type", "getChat"},
|
||||
{"chat_id", chat_id},
|
||||
{"@type", "getChat"},
|
||||
{"chat_id", chat_id},
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -393,7 +400,8 @@ void App::sync_chat_ids_from_response(const json& response) {
|
||||
if (!chat_ids.empty()) {
|
||||
sorted_chat_ids_ = std::move(chat_ids);
|
||||
if (selected_chat_index_ >= static_cast<int>(sorted_chat_ids_.size())) {
|
||||
selected_chat_index_ = std::max(0, static_cast<int>(sorted_chat_ids_.size()) - 1);
|
||||
selected_chat_index_ =
|
||||
std::max(0, static_cast<int>(sorted_chat_ids_.size()) - 1);
|
||||
}
|
||||
if (!open_chat_id().has_value()) {
|
||||
const auto chat_id = highlighted_chat_id();
|
||||
@@ -410,10 +418,11 @@ void App::sync_chat_ids_from_response(const json& response) {
|
||||
}
|
||||
|
||||
void App::append_message(std::int64_t chat_id, MessageInfo message) {
|
||||
ChatInfo& chat = chats_[chat_id];
|
||||
ChatInfo &chat = chats_[chat_id];
|
||||
chat.id = chat_id;
|
||||
auto existing = std::find_if(chat.messages.begin(), chat.messages.end(),
|
||||
[&](const MessageInfo& item) { return item.id == message.id; });
|
||||
auto existing =
|
||||
std::find_if(chat.messages.begin(), chat.messages.end(),
|
||||
[&](const MessageInfo &item) { return item.id == message.id; });
|
||||
if (existing != chat.messages.end()) {
|
||||
*existing = std::move(message);
|
||||
} else {
|
||||
@@ -421,18 +430,18 @@ void App::append_message(std::int64_t chat_id, MessageInfo message) {
|
||||
}
|
||||
|
||||
std::sort(chat.messages.begin(), chat.messages.end(),
|
||||
[](const MessageInfo& lhs, const MessageInfo& rhs) {
|
||||
if (lhs.date != rhs.date) {
|
||||
return lhs.date < rhs.date;
|
||||
}
|
||||
return lhs.id < rhs.id;
|
||||
});
|
||||
[](const MessageInfo &lhs, const MessageInfo &rhs) {
|
||||
if (lhs.date != rhs.date) {
|
||||
return lhs.date < rhs.date;
|
||||
}
|
||||
return lhs.id < rhs.id;
|
||||
});
|
||||
|
||||
if (kMaxMessagesPerChat > 0 && chat.messages.size() > kMaxMessagesPerChat) {
|
||||
chat.messages.erase(
|
||||
chat.messages.begin(),
|
||||
chat.messages.begin() +
|
||||
static_cast<std::ptrdiff_t>(chat.messages.size() - kMaxMessagesPerChat));
|
||||
chat.messages.erase(chat.messages.begin(),
|
||||
chat.messages.begin() +
|
||||
static_cast<std::ptrdiff_t>(chat.messages.size() -
|
||||
kMaxMessagesPerChat));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -446,20 +455,18 @@ void App::remove_message(std::int64_t chat_id, std::int64_t message_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto& messages = chat_it->second.messages;
|
||||
auto &messages = chat_it->second.messages;
|
||||
messages.erase(
|
||||
std::remove_if(
|
||||
messages.begin(),
|
||||
messages.end(),
|
||||
[&](const MessageInfo& item) { return item.id == message_id; }),
|
||||
messages.end());
|
||||
std::remove_if(messages.begin(), messages.end(),
|
||||
[&](const MessageInfo &item) { return item.id == message_id; }),
|
||||
messages.end());
|
||||
}
|
||||
|
||||
void App::merge_history(std::int64_t chat_id, const json& messages) {
|
||||
ChatInfo& chat = chats_[chat_id];
|
||||
void App::merge_history(std::int64_t chat_id, const json &messages) {
|
||||
ChatInfo &chat = chats_[chat_id];
|
||||
chat.history_loading = false;
|
||||
chat.history_loaded = true;
|
||||
for (const auto& message : messages) {
|
||||
for (const auto &message : messages) {
|
||||
append_message(chat_id, parse_message(message));
|
||||
}
|
||||
if (chat_id == open_chat_id_) {
|
||||
@@ -468,13 +475,14 @@ void App::merge_history(std::int64_t chat_id, const json& messages) {
|
||||
status_line_ = "History loaded.";
|
||||
}
|
||||
|
||||
void App::update_attachment_file(const json& file) {
|
||||
void App::update_attachment_file(const json &file) {
|
||||
const std::int32_t file_id = safe_i32(file, "id");
|
||||
if (file_id == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const std::int64_t size_bytes = std::max(safe_i64(file, "size"), safe_i64(file, "expected_size"));
|
||||
const std::int64_t size_bytes =
|
||||
std::max(safe_i64(file, "size"), safe_i64(file, "expected_size"));
|
||||
const json local = file.value("local", json::object());
|
||||
const std::string local_path = safe_string(local, "path");
|
||||
const std::int64_t downloaded_size = safe_i64(local, "downloaded_size");
|
||||
@@ -483,9 +491,9 @@ void App::update_attachment_file(const json& file) {
|
||||
const bool can_be_downloaded = local.value("can_be_downloaded", false);
|
||||
const bool can_be_deleted = local.value("can_be_deleted", false);
|
||||
|
||||
for (auto& [chat_id, chat] : chats_) {
|
||||
(void) chat_id;
|
||||
for (auto& message : chat.messages) {
|
||||
for (auto &[chat_id, chat] : chats_) {
|
||||
(void)chat_id;
|
||||
for (auto &message : chat.messages) {
|
||||
if (!message.has_attachment || message.attachment.file_id != file_id) {
|
||||
continue;
|
||||
}
|
||||
@@ -502,7 +510,8 @@ void App::update_attachment_file(const json& file) {
|
||||
}
|
||||
|
||||
if (pending_attachment_open_.has_value() && pending_attachment_open_->file_id == file_id) {
|
||||
pending_attachment_open_->size_bytes = size_bytes > 0 ? size_bytes : pending_attachment_open_->size_bytes;
|
||||
pending_attachment_open_->size_bytes =
|
||||
size_bytes > 0 ? size_bytes : pending_attachment_open_->size_bytes;
|
||||
pending_attachment_open_->downloaded_size = downloaded_size;
|
||||
pending_attachment_open_->local_path = local_path;
|
||||
pending_attachment_open_->is_downloading_active = is_downloading_active;
|
||||
@@ -510,11 +519,11 @@ void App::update_attachment_file(const json& file) {
|
||||
pending_attachment_open_->can_be_downloaded = can_be_downloaded;
|
||||
pending_attachment_open_->can_be_deleted = can_be_deleted;
|
||||
if (!is_downloaded && is_downloading_active) {
|
||||
status_line_ = "Downloading attachment to open " +
|
||||
format_download_progress(
|
||||
pending_attachment_open_->downloaded_size,
|
||||
pending_attachment_open_->size_bytes,
|
||||
pending_attachment_open_->is_downloaded);
|
||||
status_line_ =
|
||||
"Downloading attachment to open " +
|
||||
format_download_progress(pending_attachment_open_->downloaded_size,
|
||||
pending_attachment_open_->size_bytes,
|
||||
pending_attachment_open_->is_downloaded);
|
||||
}
|
||||
if (is_downloaded && !local_path.empty()) {
|
||||
open_attachment(*pending_attachment_open_);
|
||||
@@ -522,9 +531,10 @@ void App::update_attachment_file(const json& file) {
|
||||
}
|
||||
}
|
||||
|
||||
if (pending_attachment_download_.has_value() && pending_attachment_download_->file_id == file_id) {
|
||||
if (pending_attachment_download_.has_value() &&
|
||||
pending_attachment_download_->file_id == file_id) {
|
||||
pending_attachment_download_->size_bytes =
|
||||
size_bytes > 0 ? size_bytes : pending_attachment_download_->size_bytes;
|
||||
size_bytes > 0 ? size_bytes : pending_attachment_download_->size_bytes;
|
||||
pending_attachment_download_->downloaded_size = downloaded_size;
|
||||
pending_attachment_download_->local_path = local_path;
|
||||
pending_attachment_download_->is_downloading_active = is_downloading_active;
|
||||
@@ -533,10 +543,10 @@ void App::update_attachment_file(const json& file) {
|
||||
pending_attachment_download_->can_be_deleted = can_be_deleted;
|
||||
if (!is_downloaded && is_downloading_active) {
|
||||
status_line_ = "Downloading attachment to ~/Downloads " +
|
||||
format_download_progress(
|
||||
pending_attachment_download_->downloaded_size,
|
||||
pending_attachment_download_->size_bytes,
|
||||
pending_attachment_download_->is_downloaded);
|
||||
format_download_progress(
|
||||
pending_attachment_download_->downloaded_size,
|
||||
pending_attachment_download_->size_bytes,
|
||||
pending_attachment_download_->is_downloaded);
|
||||
}
|
||||
if (is_downloaded && !local_path.empty()) {
|
||||
export_attachment_to_downloads(*pending_attachment_download_);
|
||||
@@ -545,4 +555,4 @@ void App::update_attachment_file(const json& file) {
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace telegram_tui
|
||||
} // namespace telegram_tui
|
||||
|
||||
Reference in New Issue
Block a user