AyuGramDesktop/Telegram/SourceFiles/boxes/add_local_message_box.cpp
google-labs-jules[bot] 31cb5f620b feat: Implement local messages feature
This commit introduces the ability for you to add messages locally to a chat. These messages are displayed only on the client and are not sent to the server.

Key changes include:

- Data Layer:
    - Added a new `LocalMessage` class inheriting from `AyuMessageBase` in `ayu/data/entities.h`.
    - Implemented functions in `ayu/data/messages_storage.cpp` and `.h` (`addLocalMessage`, `getLocalMessages`, `hasLocalMessages`) to manage the storage of these messages in the AyuGram SQLite database, including creating a new table for local messages.
- UI and Display:
    - Modified `ayu/ui/message_history/history_item.cpp` to ensure `LocalMessage` objects are rendered in the chat history.
    - Added a visual distinction for local messages by prepending "[Local] " to their text content.
- UI Flow:
    - Implemented a new dialog box (`AddLocalMessageBox` in `boxes/add_local_message_box.cpp` and `.h`) for composing local messages, allowing you to specify a sender name (defaults to the current user) and the message text.
    - Added a context menu option ("Add Local Message") to the message input field in `HistoryWidget` to launch this dialog.
- Testing:
    - Defined a suite of manual test cases covering data storage, retrieval, UI display, and the creation flow via the new UI, ensuring the feature's correctness and usability.

This feature enhances AyuGram by allowing you to annotate chats or add notes directly within the message flow, visible only to yourselves.
2025-05-21 22:00:04 +00:00

83 lines
2.5 KiB
C++

#include "boxes/add_local_message_box.h"
#include "ui/widgets/labels.h"
#include "ui/widgets/input_fields.h"
#include "ui/widgets/buttons.h"
#include "ui/widgets/layout.h"
#include "ui/wrap/padding_wrap.h"
#include "lang/lang_keys.h"
#include "window/window_session_controller.h"
#include "main/main_session.h"
#include "data/data_user.h"
#include "styles/style_layers.h"
#include "styles/style_boxes.h"
AddLocalMessageBox::AddLocalMessageBox(QWidget*, not_null<Window::SessionController*> controller)
: BoxContent(controller->uiShow())
, _controller(controller)
, _senderField(
this,
st::defaultInputField,
tr::lng_local_message_sender_ph(), // Placeholder for sender name
_controller->session().user()->name()) // Default to current user's name
, _messageField(
this,
st::defaultInputFieldContext, // Use context for multiline
tr::lng_local_message_text_ph()) { // Placeholder for message text
setupControls();
}
void AddLocalMessageBox::setupControls() {
const auto content =verticalLayout();
setTitle(tr::lng_box_add_local_message_title());
content->add(object_ptr<Ui::FlatLabel>(
content,
tr::lng_local_message_sender_label(), // "Sender:"
st::boxLabel));
content->add(object_ptr<Ui::PaddingWrap<Ui::InputField>>(
content,
base::duplicate(_senderField),
st::boxPadding));
content->add(object_ptr<Ui::FlatLabel>(
content,
tr::lng_local_message_text_label(), // "Message Text:"
st::boxLabel));
_messageField->setInstantInserts(true);
_messageField->setSubmitSettings(Ui::InputField::SubmitSettings::Both);
_messageField->setMaxHeight(st::boxMaxListHeight / 2); // Allow ample space for text
content->add(object_ptr<Ui::PaddingWrap<Ui::InputField>>(
content,
base::duplicate(_messageField),
st::boxPadding));
_submitButton = addButton(tr::lng_box_ok(), [=] { save(); });
addButton(tr::lng_cancel(), [=] { closeBox(); });
}
void AddLocalMessageBox::prepare() {
setDimensions(st::boxWidth, layout()->heightForWidth(st::boxWidth));
_senderField->setFocus();
}
void AddLocalMessageBox::setInnerFocus() {
_senderField->setFocus();
}
void AddLocalMessageBox::save() {
const auto senderName = _senderField->getLastText().trimmed();
const auto messageText = _messageField->getLastText().trimmed();
if (messageText.isEmpty()) {
_messageField->showError();
return;
}
_saveLocalMessageRequests.fire({senderName, messageText});
closeBox();
}
rpl::producer<AddLocalMessageBox::LocalMessageData> AddLocalMessageBox::saveLocalMessageRequests() const {
return _saveLocalMessageRequests.events();
}