Added sent date info to tooltip of messages in admin log.

Fixed #5706.
This commit is contained in:
23rd 2021-01-22 04:24:15 +03:00 committed by John Preston
parent dc631ef631
commit 3d1f21bd05
5 changed files with 61 additions and 22 deletions

View file

@ -1187,6 +1187,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_in_reply_to" = "In reply to"; "lng_in_reply_to" = "In reply to";
"lng_edited" = "edited"; "lng_edited" = "edited";
"lng_edited_date" = "Edited: {date}"; "lng_edited_date" = "Edited: {date}";
"lng_sent_date" = "Sent: {date}";
"lng_admin_badge" = "admin"; "lng_admin_badge" = "admin";
"lng_owner_badge" = "owner"; "lng_owner_badge" = "owner";
"lng_channel_badge" = "channel"; "lng_channel_badge" = "channel";

View file

@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "chat_helpers/message_field.h" #include "chat_helpers/message_field.h"
#include "boxes/sticker_set_box.h" #include "boxes/sticker_set_box.h"
#include "base/platform/base_platform_info.h" #include "base/platform/base_platform_info.h"
#include "base/unixtime.h"
#include "mainwindow.h" #include "mainwindow.h"
#include "mainwidget.h" #include "mainwidget.h"
#include "core/application.h" #include "core/application.h"
@ -509,8 +510,17 @@ QString InnerWidget::tooltipText() const {
if (_mouseCursorState == CursorState::Date if (_mouseCursorState == CursorState::Date
&& _mouseAction == MouseAction::None) { && _mouseAction == MouseAction::None) {
if (const auto view = App::hoveredItem()) { if (const auto view = App::hoveredItem()) {
auto dateText = view->dateTime().toString( const auto format = QLocale::system().dateTimeFormat(
QLocale::system().dateTimeFormat(QLocale::LongFormat)); QLocale::LongFormat);
auto dateText = view->dateTime().toString(format);
const auto sentIt = _itemDates.find(view->data());
if (sentIt != end(_itemDates)) {
dateText += '\n' + tr::lng_sent_date(
tr::now,
lt_date,
base::unixtime::parse(sentIt->second).toString(format));
}
return dateText; return dateText;
} }
} else if (_mouseCursorState == CursorState::Forwarded } else if (_mouseCursorState == CursorState::Forwarded
@ -722,7 +732,10 @@ void InnerWidget::addEvents(Direction direction, const QVector<MTPChannelAdminLo
} }
auto count = 0; auto count = 0;
const auto addOne = [&](OwnedItem item) { const auto addOne = [&](OwnedItem item, TimeId sentDate) {
if (sentDate) {
_itemDates.emplace(item->data(), sentDate);
}
_eventIds.emplace(id); _eventIds.emplace(id);
_itemsByData.emplace(item->data(), item.get()); _itemsByData.emplace(item->data(), item.get());
addToItems.push_back(std::move(item)); addToItems.push_back(std::move(item));

View file

@ -242,6 +242,7 @@ private:
std::vector<OwnedItem> _items; std::vector<OwnedItem> _items;
std::set<uint64> _eventIds; std::set<uint64> _eventIds;
std::map<not_null<const HistoryItem*>, not_null<Element*>> _itemsByData; std::map<not_null<const HistoryItem*>, not_null<Element*>> _itemsByData;
base::flat_map<not_null<const HistoryItem*>, TimeId> _itemDates;
base::flat_set<FullMsgId> _animatedStickersPlayed; base::flat_set<FullMsgId> _animatedStickersPlayed;
base::flat_map< base::flat_map<
not_null<PeerData*>, not_null<PeerData*>,

View file

@ -45,6 +45,16 @@ TextWithEntities PrepareText(const QString &value, const QString &emptyValue) {
return result; return result;
} }
TimeId ExtractSentDate(const MTPMessage &message) {
return message.match([&](const MTPDmessageEmpty &) {
return 0;
}, [&](const MTPDmessageService &data) {
return data.vdate().v;
}, [&](const MTPDmessage &data) {
return data.vdate().v;
});
}
MTPMessage PrepareLogMessage( MTPMessage PrepareLogMessage(
const MTPMessage &message, const MTPMessage &message,
MsgId newId, MsgId newId,
@ -380,7 +390,7 @@ void GenerateItems(
not_null<HistoryView::ElementDelegate*> delegate, not_null<HistoryView::ElementDelegate*> delegate,
not_null<History*> history, not_null<History*> history,
const MTPDchannelAdminLogEvent &event, const MTPDchannelAdminLogEvent &event,
Fn<void(OwnedItem item)> callback) { Fn<void(OwnedItem item, TimeId sentDate)> callback) {
Expects(history->peer->isChannel()); Expects(history->peer->isChannel());
const auto session = &history->session(); const auto session = &history->session();
@ -389,8 +399,10 @@ void GenerateItems(
const auto channel = history->peer->asChannel(); const auto channel = history->peer->asChannel();
const auto &action = event.vaction(); const auto &action = event.vaction();
const auto date = event.vdate().v; const auto date = event.vdate().v;
const auto addPart = [&](not_null<HistoryItem*> item) { const auto addPart = [&](
return callback(OwnedItem(delegate, item)); not_null<HistoryItem*> item,
TimeId sentDate = 0) {
return callback(OwnedItem(delegate, item), sentDate);
}; };
using Flag = MTPDmessage::Flag; using Flag = MTPDmessage::Flag;
@ -545,13 +557,15 @@ void GenerateItems(
addSimpleServiceMessage(text); addSimpleServiceMessage(text);
auto detachExistingItem = false; auto detachExistingItem = false;
addPart(history->createItem( addPart(
PrepareLogMessage( history->createItem(
action.vmessage(), PrepareLogMessage(
history->nextNonHistoryEntryId(), action.vmessage(),
date), history->nextNonHistoryEntryId(),
MTPDmessage_ClientFlag::f_admin_log_entry, date),
detachExistingItem)); MTPDmessage_ClientFlag::f_admin_log_entry,
detachExistingItem),
ExtractSentDate(action.vmessage()));
}, [&](const auto &) { }, [&](const auto &) {
auto text = tr::lng_admin_log_unpinned_message(tr::now, lt_from, fromLinkText); auto text = tr::lng_admin_log_unpinned_message(tr::now, lt_from, fromLinkText);
addSimpleServiceMessage(text); addSimpleServiceMessage(text);
@ -598,10 +612,15 @@ void GenerateItems(
addSimpleServiceMessage(text); addSimpleServiceMessage(text);
auto detachExistingItem = false; auto detachExistingItem = false;
addPart(history->createItem( addPart(
PrepareLogMessage(action.vmessage(), history->nextNonHistoryEntryId(), date), history->createItem(
MTPDmessage_ClientFlag::f_admin_log_entry, PrepareLogMessage(
detachExistingItem)); action.vmessage(),
history->nextNonHistoryEntryId(),
date),
MTPDmessage_ClientFlag::f_admin_log_entry,
detachExistingItem),
ExtractSentDate(action.vmessage()));
}; };
auto createParticipantJoin = [&]() { auto createParticipantJoin = [&]() {
@ -740,10 +759,15 @@ void GenerateItems(
addSimpleServiceMessage(text); addSimpleServiceMessage(text);
auto detachExistingItem = false; auto detachExistingItem = false;
addPart(history->createItem( addPart(
PrepareLogMessage(action.vmessage(), history->nextNonHistoryEntryId(), date), history->createItem(
MTPDmessage_ClientFlag::f_admin_log_entry, PrepareLogMessage(
detachExistingItem)); action.vmessage(),
history->nextNonHistoryEntryId(),
date),
MTPDmessage_ClientFlag::f_admin_log_entry,
detachExistingItem),
ExtractSentDate(action.vmessage()));
}; };
auto createChangeLinkedChat = [&](const MTPDchannelAdminLogEventActionChangeLinkedChat &action) { auto createChangeLinkedChat = [&](const MTPDchannelAdminLogEventActionChangeLinkedChat &action) {

View file

@ -22,7 +22,7 @@ void GenerateItems(
not_null<HistoryView::ElementDelegate*> delegate, not_null<HistoryView::ElementDelegate*> delegate,
not_null<History*> history, not_null<History*> history,
const MTPDchannelAdminLogEvent &event, const MTPDchannelAdminLogEvent &event,
Fn<void(OwnedItem item)> callback); Fn<void(OwnedItem item, TimeId sentDate)> callback);
// Smart pointer wrapper for HistoryItem* that destroys the owned item. // Smart pointer wrapper for HistoryItem* that destroys the owned item.
class OwnedItem { class OwnedItem {