Fix client side generated changelogs display.

Also use message date if available in MediaView.
This commit is contained in:
John Preston 2018-09-27 23:31:48 +03:00
parent 352fc55234
commit a70613d929
17 changed files with 141 additions and 198 deletions

View file

@ -331,15 +331,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_settings_language" = "Language";
"lng_settings_default_scale" = "Default interface scale";
"lng_settings_edit_info" = "Edit information";
"lng_settings_connection_type" = "Connection type";
"lng_settings_downloading_update" = "Downloading update {progress}...";
"lng_settings_use_night_mode" = "Use night mode";
"lng_settings_privacy_title" = "Privacy";
"lng_settings_last_seen" = "Last seen";
"lng_settings_calls" = "Voice calls";
"lng_settings_groups_invite" = "Groups";
"lng_settings_group_privacy_about" = "Change who can add you to groups and channel.";
"lng_settings_group_privacy_about" = "Change who can add you to groups and channels.";
"lng_settings_sessions_about" = "Control your sessions on other devices.";
"lng_settings_passcode_disable" = "Disable passcode";
"lng_settings_password_disable" = "Disable cloud password";

View file

@ -610,11 +610,23 @@ void ApiWrap::requestDialogEntry(not_null<Data::Feed*> feed) {
// }).send();
//}
void ApiWrap::requestDialogEntry(not_null<History*> history) {
if (_dialogRequests.contains(history)) {
void ApiWrap::requestDialogEntry(
not_null<History*> history,
Fn<void()> callback) {
const auto[i, ok] = _dialogRequests.try_emplace(history);
if (callback) {
i->second.push_back(std::move(callback));
}
if (!ok) {
return;
}
_dialogRequests.emplace(history);
const auto finalize = [=] {
if (const auto callbacks = _dialogRequests.take(history)) {
for (const auto callback : *callbacks) {
callback();
}
}
};
auto peers = QVector<MTPInputDialogPeer>(
1,
MTP_inputDialogPeer(history->peer->input));
@ -623,9 +635,9 @@ void ApiWrap::requestDialogEntry(not_null<History*> history) {
)).done([=](const MTPmessages_PeerDialogs &result) {
applyPeerDialogs(result);
historyDialogEntryApplied(history);
_dialogRequests.remove(history);
finalize();
}).fail([=](const RPCError &error) {
_dialogRequests.remove(history);
finalize();
}).send();
}

View file

@ -84,7 +84,9 @@ public:
void requestContacts();
void requestDialogEntry(not_null<Data::Feed*> feed);
//void requestFeedDialogsEntries(not_null<Data::Feed*> feed);
void requestDialogEntry(not_null<History*> history);
void requestDialogEntry(
not_null<History*> history,
Fn<void()> callback = nullptr);
//void applyFeedSources(const MTPDchannels_feedSources &data); // #feed
//void setFeedChannels(
// not_null<Data::Feed*> feed,
@ -622,7 +624,9 @@ private:
mtpRequestId _contactsRequestId = 0;
mtpRequestId _contactsStatusesRequestId = 0;
base::flat_set<not_null<Data::Feed*>> _dialogFeedRequests;
base::flat_set<not_null<History*>> _dialogRequests;
base::flat_map<
not_null<History*>,
std::vector<Fn<void()>>> _dialogRequests;
base::flat_map<not_null<History*>, mtpRequestId> _unreadMentionsRequests;

View file

@ -66,3 +66,7 @@ inline constexpr void validate(bool condition, const char *message, const char *
#undef Unexpected
#endif // Unexpected
#define Unexpected(message) (::base::assertion::fail("Unexpected: " message, __FILE__, __LINE__))
#ifdef _DEBUG
#define AssertIsDebug(...)
#endif // _DEBUG

View file

@ -146,10 +146,9 @@ void Changelogs::addLocalLogs() {
void Changelogs::addLocalLog(const QString &text) {
auto textWithEntities = TextWithEntities{ text };
TextUtilities::ParseEntities(textWithEntities, TextParseLinks);
App::wnd()->serviceNotification(
_session->data().serviceNotification(
textWithEntities,
MTP_messageMediaEmpty(),
unixtime());
MTP_messageMediaEmpty());
_addedSomeLocal = true;
};

View file

@ -329,7 +329,7 @@ void Session::notifyItemIdChange(IdChange event) {
view->refreshDataId();
};
enumerateItemViews(event.item, refreshViewDataId);
if (const auto group = Auth().data().groups().find(event.item)) {
if (const auto group = groups().find(event.item)) {
const auto leader = group->items.back();
if (leader != event.item) {
enumerateItemViews(leader, refreshViewDataId);
@ -1922,6 +1922,77 @@ rpl::producer<> Session::defaultNotifyUpdates(
: defaultChatNotifyUpdates();
}
void Session::serviceNotification(
const TextWithEntities &message,
const MTPMessageMedia &media) {
const auto date = unixtime();
if (!App::userLoaded(ServiceUserId)) {
App::feedUsers(MTP_vector<MTPUser>(1, MTP_user(
MTP_flags(
MTPDuser::Flag::f_first_name
| MTPDuser::Flag::f_phone
| MTPDuser::Flag::f_status
| MTPDuser::Flag::f_verified),
MTP_int(ServiceUserId),
MTPlong(),
MTP_string("Telegram"),
MTPstring(),
MTPstring(),
MTP_string("42777"),
MTP_userProfilePhotoEmpty(),
MTP_userStatusRecently(),
MTPint(),
MTPstring(),
MTPstring(),
MTPstring())));
}
const auto history = App::history(peerFromUser(ServiceUserId));
if (!history->lastMessageKnown()) {
_session->api().requestDialogEntry(history, [=] {
insertCheckedServiceNotification(message, media, date);
});
} else {
insertCheckedServiceNotification(message, media, date);
}
}
void Session::insertCheckedServiceNotification(
const TextWithEntities &message,
const MTPMessageMedia &media,
TimeId date) {
const auto history = App::history(peerFromUser(ServiceUserId));
if (!history->isReadyFor(ShowAtUnreadMsgId)) {
history->setUnreadCount(0);
history->getReadyFor(ShowAtTheEndMsgId);
}
const auto flags = MTPDmessage::Flag::f_entities
| MTPDmessage::Flag::f_from_id
| MTPDmessage_ClientFlag::f_clientside_unread;
auto sending = TextWithEntities(), left = message;
while (TextUtilities::CutPart(sending, left, MaxMessageSize)) {
App::histories().addNewMessage(
MTP_message(
MTP_flags(flags),
MTP_int(clientMsgId()),
MTP_int(ServiceUserId),
MTP_peerUser(MTP_int(_session->userId())),
MTPnullFwdHeader,
MTPint(),
MTPint(),
MTP_int(date),
MTP_string(sending.text),
media,
MTPnullMarkup,
TextUtilities::EntitiesToMTP(sending.entities),
MTPint(),
MTPint(),
MTPstring(),
MTPlong()),
NewMessageUnread);
}
sendHistoryChangeNotifications();
}
void Session::forgetMedia() {
for (const auto &[id, photo] : _photos) {
photo->forget();

View file

@ -410,6 +410,10 @@ public:
rpl::producer<> defaultNotifyUpdates(
not_null<const PeerData*> peer) const;
void serviceNotification(
const TextWithEntities &message,
const MTPMessageMedia &media);
void forgetMedia();
void setMimeForwardIds(MessageIdsList &&list);
@ -521,6 +525,11 @@ private:
not_null<const HistoryItem*> item,
Method method);
void insertCheckedServiceNotification(
const TextWithEntities &message,
const MTPMessageMedia &media,
TimeId date);
not_null<AuthSession*> _session;
Storage::DatabasePointer _cache;

View file

@ -2176,8 +2176,13 @@ void History::markFullyLoaded() {
void History::setLastMessage(HistoryItem *item) {
if (item) {
if (_lastMessage && !*_lastMessage) {
Local::removeSavedPeer(peer);
if (_lastMessage) {
if (!*_lastMessage) {
Local::removeSavedPeer(peer);
} else if (!IsServerMsgId((*_lastMessage)->id)
&& (*_lastMessage)->date() > item->date()) {
return;
}
}
_lastMessage = item;
if (const auto feed = peer->feed()) {
@ -2280,12 +2285,25 @@ void History::applyDialog(const MTPDdialog &data) {
}
}
bool History::skipUnreadUpdateForClientSideUnread() const {
if (peer->id != peerFromUser(ServiceUserId)) {
return false;
} else if (!_unreadCount || !*_unreadCount) {
return false;
} else if (!_lastMessage || IsServerMsgId((*_lastMessage)->id)) {
return false;
}
return true;
}
void History::applyDialogFields(
int unreadCount,
MsgId maxInboxRead,
MsgId maxOutboxRead) {
setUnreadCount(unreadCount);
setInboxReadTill(maxInboxRead);
if (!skipUnreadUpdateForClientSideUnread()) {
setUnreadCount(unreadCount);
setInboxReadTill(maxInboxRead);
}
setOutboxReadTill(maxOutboxRead);
}

View file

@ -471,6 +471,7 @@ private:
void addItemsToLists(const std::vector<not_null<HistoryItem*>> &items);
void clearSendAction(not_null<UserData*> from);
bool skipUnreadUpdateForClientSideUnread() const;
HistoryItem *lastAvailableMessage() const;
void getNextFirstUnreadMessage();

View file

@ -1690,71 +1690,6 @@ void MainWidget::dialogsCancelled() {
_history->activate();
}
void MainWidget::insertCheckedServiceNotification(const TextWithEntities &message, const MTPMessageMedia &media, int32 date) {
auto flags = MTPDmessage::Flag::f_entities | MTPDmessage::Flag::f_from_id | MTPDmessage_ClientFlag::f_clientside_unread;
auto sending = TextWithEntities(), left = message;
HistoryItem *item = nullptr;
while (TextUtilities::CutPart(sending, left, MaxMessageSize)) {
auto localEntities = TextUtilities::EntitiesToMTP(sending.entities);
item = App::histories().addNewMessage(
MTP_message(
MTP_flags(flags),
MTP_int(clientMsgId()),
MTP_int(ServiceUserId),
MTP_peerUser(MTP_int(Auth().userId())),
MTPnullFwdHeader,
MTPint(),
MTPint(),
MTP_int(date),
MTP_string(sending.text),
media,
MTPnullMarkup,
localEntities,
MTPint(),
MTPint(),
MTPstring(),
MTPlong()),
NewMessageUnread);
}
Auth().data().sendHistoryChangeNotifications();
}
void MainWidget::serviceHistoryDone(const MTPmessages_Messages &msgs) {
auto handleResult = [&](auto &&result) {
App::feedUsers(result.vusers);
App::feedChats(result.vchats);
App::feedMsgs(result.vmessages, NewMessageLast);
};
switch (msgs.type()) {
case mtpc_messages_messages:
handleResult(msgs.c_messages_messages());
break;
case mtpc_messages_messagesSlice:
handleResult(msgs.c_messages_messagesSlice());
break;
case mtpc_messages_channelMessages:
LOG(("API Error: received messages.channelMessages! (MainWidget::serviceHistoryDone)"));
handleResult(msgs.c_messages_channelMessages());
break;
case mtpc_messages_messagesNotModified:
LOG(("API Error: received messages.messagesNotModified! (MainWidget::serviceHistoryDone)"));
break;
}
App::wnd()->showDelayedServiceMsgs();
}
bool MainWidget::serviceHistoryFail(const RPCError &error) {
if (MTP::isDefaultHandledError(error)) return false;
App::wnd()->showDelayedServiceMsgs();
return false;
}
bool MainWidget::isIdle() const {
return _isIdle;
}
@ -3664,7 +3599,6 @@ void MainWidget::start() {
update();
_started = true;
App::wnd()->sendServiceHistoryRequest();
Local::readInstalledStickers();
Local::readFeaturedStickers();
Local::readRecentStickers();
@ -4905,7 +4839,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
} else if (d.is_popup()) {
Ui::show(Box<InformBox>(text));
} else {
App::wnd()->serviceNotification(text, d.vmedia);
Auth().data().serviceNotification(text, d.vmedia);
emit App::wnd()->checkNewAuthorization();
}
} break;

View file

@ -239,10 +239,6 @@ public:
void checkLastUpdate(bool afterSleep);
void insertCheckedServiceNotification(const TextWithEntities &message, const MTPMessageMedia &media, int32 date);
void serviceHistoryDone(const MTPmessages_Messages &msgs);
bool serviceHistoryFail(const RPCError &error);
bool isIdle() const;
QPixmap cachedBackground(const QRect &forRect, int &x, int &y);

View file

@ -212,71 +212,6 @@ void MainWindow::setupIntro() {
}
fixOrder();
_delayedServiceMsgs.clear();
if (_serviceHistoryRequest) {
MTP::cancel(_serviceHistoryRequest);
_serviceHistoryRequest = 0;
}
}
void MainWindow::serviceNotification(const TextWithEntities &message, const MTPMessageMedia &media, int32 date, bool force) {
if (date <= 0) date = unixtime();
auto h = (_main && App::userLoaded(ServiceUserId)) ? App::history(ServiceUserId).get() : nullptr;
if (!h || (!force && h->isEmpty())) {
_delayedServiceMsgs.push_back(DelayedServiceMsg(message, media, date));
return sendServiceHistoryRequest();
}
_main->insertCheckedServiceNotification(message, media, date);
}
void MainWindow::showDelayedServiceMsgs() {
for (auto &delayed : base::take(_delayedServiceMsgs)) {
serviceNotification(delayed.message, delayed.media, delayed.date, true);
}
}
void MainWindow::sendServiceHistoryRequest() {
if (!_main || !_main->started() || _delayedServiceMsgs.isEmpty() || _serviceHistoryRequest) return;
auto user = App::userLoaded(ServiceUserId);
if (!user) {
auto userFlags = MTPDuser::Flag::f_first_name | MTPDuser::Flag::f_phone | MTPDuser::Flag::f_status | MTPDuser::Flag::f_verified;
user = App::feedUsers(MTP_vector<MTPUser>(1, MTP_user(
MTP_flags(userFlags),
MTP_int(ServiceUserId),
MTPlong(),
MTP_string("Telegram"),
MTPstring(),
MTPstring(),
MTP_string("42777"),
MTP_userProfilePhotoEmpty(),
MTP_userStatusRecently(),
MTPint(),
MTPstring(),
MTPstring(),
MTPstring())));
}
auto offsetId = 0;
auto offsetDate = 0;
auto addOffset = 0;
auto limit = 1;
auto maxId = 0;
auto minId = 0;
auto historyHash = 0;
_serviceHistoryRequest = MTP::send(
MTPmessages_GetHistory(
user->input,
MTP_int(offsetId),
MTP_int(offsetDate),
MTP_int(addOffset),
MTP_int(limit),
MTP_int(maxId),
MTP_int(minId),
MTP_int(historyHash)),
_main->rpcDone(&MainWidget::serviceHistoryDone),
_main->rpcFail(&MainWidget::serviceHistoryFail));
}
void MainWindow::setupMain() {

View file

@ -53,9 +53,6 @@ public:
void clearPasscodeLock();
void setupIntro();
void setupMain();
void serviceNotification(const TextWithEntities &message, const MTPMessageMedia &media = MTP_messageMediaEmpty(), int32 date = 0, bool force = false);
void sendServiceHistoryRequest();
void showDelayedServiceMsgs();
MainWidget *chatsWidget() {
return mainWidget();
@ -166,15 +163,6 @@ private:
void placeSmallCounter(QImage &img, int size, int count, style::color bg, const QPoint &shift, style::color color) override;
QImage icon16, icon32, icon64, iconbig16, iconbig32, iconbig64;
struct DelayedServiceMsg {
DelayedServiceMsg(const TextWithEntities &message, const MTPMessageMedia &media, int32 date) : message(message), media(media), date(date) {
}
TextWithEntities message;
MTPMessageMedia media;
int32 date;
};
QList<DelayedServiceMsg> _delayedServiceMsgs;
mtpRequestId _serviceHistoryRequest = 0;
TimeMs _lastTrayClickTime = 0;
object_ptr<Window::PasscodeLockWidget> _passcodeLock = { nullptr };

View file

@ -336,12 +336,12 @@ void MediaView::updateControls() {
const auto dNow = QDateTime::currentDateTime();
const auto d = [&] {
if (_photo) {
if (const auto item = App::histItemById(_msgid)) {
return ItemDateTime(item);
} else if (_photo) {
return ParseDateTime(_photo->date);
} else if (_doc) {
return ParseDateTime(_doc->date);
} else if (const auto item = App::histItemById(_msgid)) {
return ItemDateTime(item);
}
return dNow;
}();
@ -588,8 +588,8 @@ void MediaView::step_radial(TimeMs ms, bool timer) {
}
const auto wasAnimating = _radial.animating();
const auto updated = _radial.update(
radialProgress(),
!radialLoading(),
radialProgress(),
!radialLoading(),
ms + radialTimeShift());
if (timer && (wasAnimating || _radial.animating()) && (!anim::Disabled() || updated)) {
update(radialRect());

View file

@ -707,30 +707,6 @@ void SetupChatBackground(not_null<Ui::VerticalLayout*> container) {
}, adaptive->lifetime());
}
void SetupNightMode(not_null<Ui::VerticalLayout*> container) {
const auto calling = Ui::AttachAsChild(container, 0);
AddButton(
container,
lng_settings_use_night_mode,
st::settingsButton
)->toggleOn(
rpl::single(Window::Theme::IsNightMode())
)->toggledValue(
) | rpl::start_with_next([=](bool toggled) {
++*calling;
const auto change = [=] {
if (!--*calling && toggled != Window::Theme::IsNightMode()) {
Window::Theme::ToggleNightMode();
Window::Theme::KeepApplied();
}
};
App::CallDelayed(
st::settingsButton.toggle.duration,
container,
change);
}, container->lifetime());
}
void SetupUseDefaultTheme(not_null<Ui::VerticalLayout*> container) {
using Update = const Window::Theme::BackgroundUpdate;
container->add(
@ -940,7 +916,6 @@ void SetupThemeOptions(not_null<Ui::VerticalLayout*> container) {
AddSubsectionTitle(container, lng_settings_themes);
SetupDefaultThemes(container);
//SetupNightMode(container);
AddButton(
container,

View file

@ -12,7 +12,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Settings {
void SetupDataStorage(not_null<Ui::VerticalLayout*> container);
void SetupNightMode(not_null<Ui::VerticalLayout*> container);
void SetupUseDefaultTheme(not_null<Ui::VerticalLayout*> container);
void SetupDefaultThemes(not_null<Ui::VerticalLayout*> container);

View file

@ -169,7 +169,7 @@ void AddSubsectionTitle(
void FillMenu(Fn<void(Type)> showOther, MenuCallback addAction) {
addAction(
lang(lng_settings_edit_info),
lang(lng_settings_information),
[=] { showOther(Type::Information); });
addAction(
lang(lng_settings_logout),