2018-01-04 09:40:58 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#include "data/data_feed.h"
|
|
|
|
|
2018-01-23 16:51:12 +00:00
|
|
|
#include "data/data_session.h"
|
2018-01-05 15:57:18 +00:00
|
|
|
#include "dialogs/dialogs_key.h"
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "history/history.h"
|
2018-01-11 19:33:26 +00:00
|
|
|
#include "history/history_item.h"
|
2018-01-22 09:33:09 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2018-01-23 16:51:12 +00:00
|
|
|
#include "storage/storage_facade.h"
|
|
|
|
#include "storage/storage_feed_messages.h"
|
|
|
|
#include "auth_session.h"
|
2018-01-29 17:13:24 +00:00
|
|
|
#include "apiwrap.h"
|
|
|
|
#include "mainwidget.h"
|
2018-01-05 15:57:18 +00:00
|
|
|
|
2018-01-04 09:40:58 +00:00
|
|
|
namespace Data {
|
|
|
|
|
2018-03-06 17:07:42 +00:00
|
|
|
// #feed
|
|
|
|
//MessagePosition FeedPositionFromMTP(const MTPFeedPosition &position) {
|
|
|
|
// Expects(position.type() == mtpc_feedPosition);
|
|
|
|
//
|
|
|
|
// const auto &data = position.c_feedPosition();
|
|
|
|
// return MessagePosition(data.vdate.v, FullMsgId(
|
|
|
|
// peerToChannel(peerFromMTP(data.vpeer)),
|
|
|
|
// data.vid.v));
|
|
|
|
//}
|
2018-01-05 15:57:18 +00:00
|
|
|
|
2018-01-23 16:51:12 +00:00
|
|
|
Feed::Feed(FeedId id, not_null<Data::Session*> parent)
|
2018-01-05 15:57:18 +00:00
|
|
|
: Entry(this)
|
2018-01-22 09:33:09 +00:00
|
|
|
, _id(id)
|
2018-01-23 16:51:12 +00:00
|
|
|
, _parent(parent)
|
2018-01-22 09:33:09 +00:00
|
|
|
, _name(lang(lng_feed_name)) {
|
|
|
|
indexNameParts();
|
|
|
|
}
|
|
|
|
|
2018-01-23 16:51:12 +00:00
|
|
|
FeedId Feed::id() const {
|
|
|
|
return _id;
|
|
|
|
}
|
|
|
|
|
2018-01-22 09:33:09 +00:00
|
|
|
void Feed::indexNameParts() {
|
|
|
|
_nameWords.clear();
|
|
|
|
_nameFirstLetters.clear();
|
|
|
|
auto toIndexList = QStringList();
|
|
|
|
auto appendToIndex = [&](const QString &value) {
|
|
|
|
if (!value.isEmpty()) {
|
|
|
|
toIndexList.push_back(TextUtilities::RemoveAccents(value));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
appendToIndex(_name);
|
|
|
|
const auto appendTranslit = !toIndexList.isEmpty()
|
|
|
|
&& cRussianLetters().match(toIndexList.front()).hasMatch();
|
|
|
|
if (appendTranslit) {
|
|
|
|
appendToIndex(translitRusEng(toIndexList.front()));
|
|
|
|
}
|
|
|
|
auto toIndex = toIndexList.join(' ');
|
|
|
|
toIndex += ' ' + rusKeyboardLayoutSwitch(toIndex);
|
|
|
|
|
|
|
|
const auto namesList = TextUtilities::PrepareSearchWords(toIndex);
|
|
|
|
for (const auto &name : namesList) {
|
|
|
|
_nameWords.insert(name);
|
|
|
|
_nameFirstLetters.insert(name[0]);
|
|
|
|
}
|
2018-01-04 09:40:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Feed::registerOne(not_null<ChannelData*> channel) {
|
2018-01-05 15:57:18 +00:00
|
|
|
const auto history = App::history(channel);
|
|
|
|
if (!base::contains(_channels, history)) {
|
2018-01-23 16:51:12 +00:00
|
|
|
const auto invisible = (_channels.size() < 2);
|
2018-01-05 15:57:18 +00:00
|
|
|
_channels.push_back(history);
|
2018-02-05 14:37:22 +00:00
|
|
|
_parent->session().storage().invalidate(
|
|
|
|
Storage::FeedMessagesInvalidate(_id));
|
|
|
|
|
2018-01-31 17:10:29 +00:00
|
|
|
if (history->lastMessageKnown()) {
|
2018-02-05 14:37:22 +00:00
|
|
|
if (const auto last = history->lastMessage()) {
|
|
|
|
if (justUpdateLastMessage(last)) {
|
|
|
|
updateChatListEntry();
|
|
|
|
}
|
|
|
|
}
|
2018-02-03 19:52:35 +00:00
|
|
|
} else if (lastMessageKnown()) {
|
2018-01-31 17:10:29 +00:00
|
|
|
_parent->session().api().requestDialogEntry(history);
|
2018-01-05 15:57:18 +00:00
|
|
|
}
|
2018-02-08 09:20:14 +00:00
|
|
|
if (unreadCountKnown()) {
|
|
|
|
if (history->unreadCountKnown()) {
|
|
|
|
// If history unreadCount is known that means that we've
|
|
|
|
// already had the channel information and if it was in the
|
|
|
|
// feed already (not yet known) it wouldn't get here.
|
|
|
|
// That means here we get if we add a new channel to feed.
|
|
|
|
if (const auto count = history->unreadCount()) {
|
|
|
|
unreadCountChanged(count, history->mute() ? count : 0);
|
|
|
|
}
|
|
|
|
} else if (!_settingChannels) {
|
|
|
|
_parent->session().api().requestDialogEntry(this);
|
|
|
|
}
|
|
|
|
}
|
2018-01-23 16:51:12 +00:00
|
|
|
if (invisible && _channels.size() > 1) {
|
|
|
|
updateChatListExistence();
|
2018-01-29 13:52:09 +00:00
|
|
|
for (const auto history : _channels) {
|
|
|
|
history->updateChatListExistence();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
history->updateChatListExistence();
|
2018-01-23 16:51:12 +00:00
|
|
|
}
|
2018-01-29 13:52:09 +00:00
|
|
|
_parent->notifyFeedUpdated(this, FeedUpdateFlag::Channels);
|
2018-01-05 15:57:18 +00:00
|
|
|
}
|
2018-01-04 09:40:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Feed::unregisterOne(not_null<ChannelData*> channel) {
|
2018-01-05 15:57:18 +00:00
|
|
|
const auto history = App::history(channel);
|
2018-01-23 16:51:12 +00:00
|
|
|
const auto i = ranges::remove(_channels, history);
|
|
|
|
if (i != end(_channels)) {
|
|
|
|
const auto visible = (_channels.size() > 1);
|
|
|
|
_channels.erase(i, end(_channels));
|
2018-02-05 14:37:22 +00:00
|
|
|
_parent->session().storage().remove(
|
|
|
|
Storage::FeedMessagesRemoveAll(_id, channel->bareId()));
|
|
|
|
|
2018-02-08 09:20:14 +00:00
|
|
|
if (lastMessageKnown()) {
|
|
|
|
if (const auto last = lastMessage()) {
|
|
|
|
if (last->history() == history) {
|
|
|
|
recountLastMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (unreadCountKnown()) {
|
|
|
|
if (history->unreadCountKnown()) {
|
|
|
|
if (const auto delta = -history->unreadCount()) {
|
|
|
|
unreadCountChanged(delta, history->mute() ? delta : 0);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_parent->session().api().requestDialogEntry(this);
|
2018-01-31 17:10:29 +00:00
|
|
|
}
|
2018-01-23 16:51:12 +00:00
|
|
|
}
|
|
|
|
if (visible && _channels.size() < 2) {
|
|
|
|
updateChatListExistence();
|
2018-01-29 13:52:09 +00:00
|
|
|
for (const auto history : _channels) {
|
|
|
|
history->updateChatListExistence();
|
|
|
|
}
|
2018-01-29 17:13:24 +00:00
|
|
|
} else {
|
|
|
|
history->updateChatListExistence();
|
2018-01-23 16:51:12 +00:00
|
|
|
}
|
2018-01-29 13:52:09 +00:00
|
|
|
_parent->notifyFeedUpdated(this, FeedUpdateFlag::Channels);
|
2018-01-05 15:57:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Feed::updateLastMessage(not_null<HistoryItem*> item) {
|
2018-01-31 17:10:29 +00:00
|
|
|
if (justUpdateLastMessage(item)) {
|
|
|
|
if (_lastMessage && *_lastMessage) {
|
2018-02-03 19:52:35 +00:00
|
|
|
setChatsListDate(ItemDateTime(*_lastMessage));
|
2018-01-31 17:10:29 +00:00
|
|
|
}
|
2018-01-05 15:57:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Feed::loadUserpic() {
|
|
|
|
constexpr auto kPaintUserpicsCount = 4;
|
|
|
|
auto load = kPaintUserpicsCount;
|
|
|
|
for (const auto channel : _channels) {
|
|
|
|
channel->peer->loadUserpic();
|
|
|
|
if (!--load) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Feed::paintUserpic(
|
|
|
|
Painter &p,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int size) const {
|
|
|
|
const auto small = (size - st::lineWidth) / 2;
|
|
|
|
const auto delta = size - small;
|
|
|
|
auto index = 0;
|
|
|
|
for (const auto channel : _channels) {
|
|
|
|
channel->peer->paintUserpic(p, x, y, small);
|
|
|
|
switch (++index) {
|
|
|
|
case 1:
|
|
|
|
case 3: x += delta; break;
|
|
|
|
case 2: x -= delta; y += delta; break;
|
2018-01-23 16:51:12 +00:00
|
|
|
case 4: return;
|
2018-01-05 15:57:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-29 13:52:09 +00:00
|
|
|
const std::vector<not_null<History*>> &Feed::channels() const {
|
|
|
|
return _channels;
|
|
|
|
}
|
|
|
|
|
2018-01-29 17:13:24 +00:00
|
|
|
int32 Feed::channelsHash() const {
|
2018-02-07 16:37:05 +00:00
|
|
|
const auto ordered = ranges::view::all(
|
2018-01-29 17:13:24 +00:00
|
|
|
_channels
|
|
|
|
) | ranges::view::transform([](not_null<History*> history) {
|
|
|
|
return history->peer->bareId();
|
2018-02-07 16:37:05 +00:00
|
|
|
}) | ranges::to_vector | ranges::action::sort;
|
|
|
|
return Api::CountHash(ordered);
|
2018-01-29 17:13:24 +00:00
|
|
|
}
|
|
|
|
|
2018-01-30 12:13:46 +00:00
|
|
|
bool Feed::channelsLoaded() const {
|
|
|
|
return _channelsLoaded;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Feed::setChannelsLoaded(bool loaded) {
|
2018-02-07 16:37:05 +00:00
|
|
|
if (_channelsLoaded != loaded) {
|
|
|
|
_channelsLoaded = loaded;
|
|
|
|
_parent->notifyFeedUpdated(this, FeedUpdateFlag::Channels);
|
|
|
|
}
|
2018-01-30 12:13:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Feed::setChannels(std::vector<not_null<ChannelData*>> channels) {
|
|
|
|
const auto remove = ranges::view::all(
|
|
|
|
_channels
|
|
|
|
) | ranges::view::transform([](not_null<History*> history) {
|
2018-02-08 09:20:14 +00:00
|
|
|
return not_null<ChannelData*>(history->peer->asChannel());
|
2018-01-30 12:13:46 +00:00
|
|
|
}) | ranges::view::filter([&](not_null<ChannelData*> channel) {
|
|
|
|
return !base::contains(channels, channel);
|
|
|
|
}) | ranges::to_vector;
|
|
|
|
|
|
|
|
const auto add = ranges::view::all(
|
|
|
|
channels
|
|
|
|
) | ranges::view::filter([&](not_null<ChannelData*> channel) {
|
|
|
|
return ranges::find(
|
|
|
|
_channels,
|
|
|
|
channel.get(),
|
|
|
|
[](auto history) { return history->peer->asChannel(); }
|
2018-02-03 19:52:35 +00:00
|
|
|
) == end(_channels);
|
2018-02-08 09:20:14 +00:00
|
|
|
}) | ranges::view::transform([](ChannelData *channel) {
|
|
|
|
return not_null<ChannelData*>(channel);
|
2018-01-30 12:13:46 +00:00
|
|
|
}) | ranges::to_vector;
|
|
|
|
|
2018-02-08 09:20:14 +00:00
|
|
|
changeChannelsList(add, remove);
|
|
|
|
|
|
|
|
setChannelsLoaded(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Feed::changeChannelsList(
|
|
|
|
const std::vector<not_null<ChannelData*>> &add,
|
|
|
|
const std::vector<not_null<ChannelData*>> &remove) {
|
|
|
|
_settingChannels = true;
|
|
|
|
const auto restore = gsl::finally([&] { _settingChannels = false; });
|
|
|
|
|
2018-01-30 12:13:46 +00:00
|
|
|
for (const auto channel : remove) {
|
|
|
|
channel->clearFeed();
|
|
|
|
}
|
2018-02-03 19:52:35 +00:00
|
|
|
|
|
|
|
// We assume the last message was correct before requesting the list.
|
|
|
|
// So we save it and don't allow channels from the list to change it.
|
|
|
|
// After that we restore it.
|
|
|
|
const auto oldLastMessage = base::take(_lastMessage);
|
2018-01-30 12:13:46 +00:00
|
|
|
for (const auto channel : add) {
|
2018-02-03 19:52:35 +00:00
|
|
|
_lastMessage = base::none;
|
2018-01-30 12:13:46 +00:00
|
|
|
channel->setFeed(this);
|
|
|
|
}
|
2018-02-03 19:52:35 +00:00
|
|
|
_lastMessage = oldLastMessage;
|
2018-01-30 12:13:46 +00:00
|
|
|
}
|
|
|
|
|
2018-01-31 17:10:29 +00:00
|
|
|
bool Feed::justUpdateLastMessage(not_null<HistoryItem*> item) {
|
|
|
|
if (!_lastMessage) {
|
|
|
|
return false;
|
|
|
|
} else if (*_lastMessage
|
|
|
|
&& item->position() <= (*_lastMessage)->position()) {
|
2018-01-05 15:57:18 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
_lastMessage = item;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Feed::messageRemoved(not_null<HistoryItem*> item) {
|
2018-01-31 17:10:29 +00:00
|
|
|
if (lastMessage() == item) {
|
2018-01-05 15:57:18 +00:00
|
|
|
recountLastMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Feed::historyCleared(not_null<History*> history) {
|
2018-01-31 17:10:29 +00:00
|
|
|
if (const auto last = lastMessage()) {
|
|
|
|
if (last->history() == history) {
|
|
|
|
messageRemoved(last);
|
|
|
|
}
|
2018-01-05 15:57:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Feed::recountLastMessage() {
|
2018-02-05 14:37:22 +00:00
|
|
|
_lastMessage = base::none;
|
2018-01-31 17:10:29 +00:00
|
|
|
for (const auto history : _channels) {
|
|
|
|
if (!history->lastMessageKnown()) {
|
2018-02-05 14:37:22 +00:00
|
|
|
_parent->session().api().requestDialogEntry(this);
|
2018-01-31 17:10:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2018-02-05 14:37:22 +00:00
|
|
|
setLastMessageFromChannels();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Feed::setLastMessageFromChannels() {
|
2018-01-05 15:57:18 +00:00
|
|
|
_lastMessage = nullptr;
|
|
|
|
for (const auto history : _channels) {
|
2018-01-31 17:10:29 +00:00
|
|
|
if (const auto last = history->lastMessage()) {
|
|
|
|
justUpdateLastMessage(last);
|
2018-01-05 15:57:18 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-31 17:10:29 +00:00
|
|
|
updateChatsListDate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Feed::updateChatsListDate() {
|
|
|
|
if (_lastMessage && *_lastMessage) {
|
2018-02-03 19:52:35 +00:00
|
|
|
setChatsListDate(ItemDateTime(*_lastMessage));
|
2018-01-05 15:57:18 +00:00
|
|
|
}
|
2018-01-04 09:40:58 +00:00
|
|
|
}
|
|
|
|
|
2018-01-31 17:10:29 +00:00
|
|
|
HistoryItem *Feed::lastMessage() const {
|
|
|
|
return _lastMessage ? *_lastMessage : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Feed::lastMessageKnown() const {
|
|
|
|
return !!_lastMessage;
|
|
|
|
}
|
|
|
|
|
2018-02-03 19:52:35 +00:00
|
|
|
int Feed::unreadCount() const {
|
|
|
|
return _unreadCount ? *_unreadCount : 0;
|
|
|
|
}
|
|
|
|
|
2018-02-04 19:57:03 +00:00
|
|
|
rpl::producer<int> Feed::unreadCountValue() const {
|
|
|
|
return rpl::single(
|
|
|
|
unreadCount()
|
|
|
|
) | rpl::then(_unreadCountChanges.events());
|
|
|
|
}
|
|
|
|
|
2018-02-03 19:52:35 +00:00
|
|
|
bool Feed::unreadCountKnown() const {
|
|
|
|
return !!_unreadCount;
|
|
|
|
}
|
2018-03-06 17:07:42 +00:00
|
|
|
// #feed
|
|
|
|
//void Feed::applyDialog(const MTPDdialogFeed &data) {
|
|
|
|
// const auto addChannel = [&](ChannelId channelId) {
|
|
|
|
// if (const auto channel = App::channelLoaded(channelId)) {
|
|
|
|
// channel->setFeed(this);
|
|
|
|
// }
|
|
|
|
// };
|
|
|
|
// for (const auto &channelId : data.vfeed_other_channels.v) {
|
|
|
|
// addChannel(channelId.v);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// _lastMessage = nullptr;
|
|
|
|
// if (const auto peerId = peerFromMTP(data.vpeer)) {
|
|
|
|
// if (const auto channelId = peerToChannel(peerId)) {
|
|
|
|
// addChannel(channelId);
|
|
|
|
// const auto fullId = FullMsgId(channelId, data.vtop_message.v);
|
|
|
|
// if (const auto item = App::histItemById(fullId)) {
|
|
|
|
// justUpdateLastMessage(item);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// updateChatsListDate();
|
|
|
|
//
|
|
|
|
// setUnreadCounts(
|
|
|
|
// data.vunread_count.v,
|
|
|
|
// data.vunread_muted_count.v);
|
|
|
|
// if (data.has_read_max_position()) {
|
|
|
|
// setUnreadPosition(FeedPositionFromMTP(data.vread_max_position));
|
|
|
|
// }
|
|
|
|
//}
|
2018-01-31 17:10:29 +00:00
|
|
|
|
2018-02-20 17:53:55 +00:00
|
|
|
void Feed::changedInChatListHook(Dialogs::Mode list, bool added) {
|
|
|
|
if (list == Dialogs::Mode::All && unreadCount()) {
|
|
|
|
const auto mutedCount = _unreadMutedCount;
|
|
|
|
const auto nonMutedCount = unreadCount() - mutedCount;
|
|
|
|
const auto mutedDelta = added ? mutedCount : -mutedCount;
|
|
|
|
const auto nonMutedDelta = added ? nonMutedCount : -nonMutedCount;
|
|
|
|
App::histories().unreadIncrement(nonMutedDelta, false);
|
|
|
|
App::histories().unreadIncrement(mutedDelta, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-31 17:10:29 +00:00
|
|
|
void Feed::setUnreadCounts(int unreadNonMutedCount, int unreadMutedCount) {
|
2018-02-03 19:52:35 +00:00
|
|
|
if (unreadCountKnown()
|
|
|
|
&& (*_unreadCount == unreadNonMutedCount + unreadMutedCount)
|
|
|
|
&& (_unreadMutedCount == unreadMutedCount)) {
|
|
|
|
return;
|
|
|
|
}
|
2018-02-20 17:53:55 +00:00
|
|
|
const auto unreadNonMutedCountDelta = _unreadCount | [&](int count) {
|
|
|
|
return unreadNonMutedCount - (count - _unreadMutedCount);
|
|
|
|
};
|
|
|
|
const auto unreadMutedCountDelta = _unreadCount | [&](int count) {
|
|
|
|
return unreadMutedCount - _unreadMutedCount;
|
|
|
|
};
|
2018-01-31 17:10:29 +00:00
|
|
|
_unreadCount = unreadNonMutedCount + unreadMutedCount;
|
2018-01-04 09:40:58 +00:00
|
|
|
_unreadMutedCount = unreadMutedCount;
|
2018-02-04 19:57:03 +00:00
|
|
|
|
|
|
|
_unreadCountChanges.fire(unreadCount());
|
2018-02-03 19:52:35 +00:00
|
|
|
updateChatListEntry();
|
2018-02-20 17:53:55 +00:00
|
|
|
|
|
|
|
if (inChatList(Dialogs::Mode::All)) {
|
|
|
|
App::histories().unreadIncrement(
|
|
|
|
unreadNonMutedCountDelta ? *unreadNonMutedCountDelta : unreadNonMutedCount,
|
|
|
|
false);
|
|
|
|
App::histories().unreadIncrement(
|
|
|
|
unreadMutedCountDelta ? *unreadMutedCountDelta : unreadMutedCount,
|
|
|
|
true);
|
|
|
|
}
|
2018-01-04 09:40:58 +00:00
|
|
|
}
|
|
|
|
|
2018-01-23 16:51:12 +00:00
|
|
|
void Feed::setUnreadPosition(const MessagePosition &position) {
|
2018-01-31 17:10:29 +00:00
|
|
|
if (_unreadPosition.current() < position) {
|
|
|
|
_unreadPosition = position;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Feed::unreadCountChanged(
|
2018-02-12 11:10:40 +00:00
|
|
|
int unreadCountDelta,
|
2018-01-31 17:10:29 +00:00
|
|
|
int mutedCountDelta) {
|
2018-02-12 11:10:40 +00:00
|
|
|
if (!unreadCountKnown()) {
|
2018-01-31 17:10:29 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-02-20 17:53:55 +00:00
|
|
|
accumulate_max(unreadCountDelta, -*_unreadCount);
|
|
|
|
*_unreadCount += unreadCountDelta;
|
|
|
|
|
|
|
|
mutedCountDelta = snap(
|
|
|
|
mutedCountDelta,
|
|
|
|
-_unreadMutedCount,
|
|
|
|
*_unreadCount - _unreadMutedCount);
|
|
|
|
_unreadMutedCount += mutedCountDelta;
|
2018-02-12 11:10:40 +00:00
|
|
|
|
|
|
|
_unreadCountChanges.fire(unreadCount());
|
|
|
|
updateChatListEntry();
|
2018-02-20 17:53:55 +00:00
|
|
|
|
|
|
|
if (inChatList(Dialogs::Mode::All)) {
|
|
|
|
App::histories().unreadIncrement(
|
|
|
|
unreadCountDelta,
|
|
|
|
false);
|
|
|
|
App::histories().unreadMuteChanged(mutedCountDelta, true);
|
|
|
|
}
|
2018-01-23 16:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MessagePosition Feed::unreadPosition() const {
|
|
|
|
return _unreadPosition.current();
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<MessagePosition> Feed::unreadPositionChanges() const {
|
|
|
|
return _unreadPosition.changes();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Feed::toImportant() const {
|
|
|
|
return false; // TODO feeds workmode
|
|
|
|
}
|
|
|
|
|
2018-05-11 14:03:53 +00:00
|
|
|
bool Feed::useProxyPromotion() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-01-23 16:51:12 +00:00
|
|
|
bool Feed::shouldBeInChatList() const {
|
|
|
|
return _channels.size() > 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Feed::chatListUnreadCount() const {
|
2018-02-03 19:52:35 +00:00
|
|
|
return unreadCount();
|
2018-01-23 16:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Feed::chatListMutedBadge() const {
|
2018-01-31 17:10:29 +00:00
|
|
|
return _unreadCount ? (*_unreadCount <= _unreadMutedCount) : false;
|
2018-01-23 16:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
HistoryItem *Feed::chatsListItem() const {
|
2018-01-31 17:10:29 +00:00
|
|
|
return lastMessage();
|
2018-01-23 16:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const QString &Feed::chatsListName() const {
|
|
|
|
return _name;
|
|
|
|
}
|
|
|
|
|
|
|
|
const base::flat_set<QString> &Feed::chatsListNameWords() const {
|
|
|
|
return _nameWords;
|
|
|
|
}
|
|
|
|
|
|
|
|
const base::flat_set<QChar> &Feed::chatsListFirstLetters() const {
|
|
|
|
return _nameFirstLetters;
|
|
|
|
}
|
|
|
|
|
2018-01-04 09:40:58 +00:00
|
|
|
} // namespace Data
|