Add Notification.h.
GitOrigin-RevId: e102973d5585fdf346ac01b09bd2262f9c11fd2e
This commit is contained in:
parent
60e685bd7c
commit
bd531081ad
@ -535,6 +535,7 @@ set(TDLIB_SOURCE
|
||||
td/telegram/net/SessionProxy.h
|
||||
td/telegram/net/SessionMultiProxy.h
|
||||
td/telegram/net/TempAuthKeyWatchdog.h
|
||||
td/telegram/Notification.h
|
||||
td/telegram/NotificationGroupId.h
|
||||
td/telegram/NotificationId.h
|
||||
td/telegram/NotificationManager.h
|
||||
|
@ -5,11 +5,11 @@
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
#include "td/telegram/AuthManager.h"
|
||||
#include "td/telegram/AuthManager.hpp"
|
||||
|
||||
#include "td/telegram/td_api.h"
|
||||
#include "td/telegram/telegram_api.h"
|
||||
|
||||
#include "td/telegram/AuthManager.hpp"
|
||||
#include "td/telegram/ConfigManager.h"
|
||||
#include "td/telegram/ConfigShared.h"
|
||||
#include "td/telegram/ContactsManager.h"
|
||||
|
@ -5,6 +5,7 @@
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
#include "td/telegram/MessagesManager.h"
|
||||
|
||||
#include "td/telegram/AnimationsManager.h"
|
||||
#include "td/telegram/AuthManager.h"
|
||||
#include "td/telegram/ChatId.h"
|
||||
@ -17419,6 +17420,15 @@ NotificationGroupId MessagesManager::get_dialog_message_notification_group_id(Di
|
||||
return d->message_notification_group_id;
|
||||
}
|
||||
|
||||
MessagesManager::MessageNotificationGroup MessagesManager::get_message_notification_group_force(
|
||||
NotificationGroupId group_id) {
|
||||
MessageNotificationGroup result;
|
||||
if (G()->parameters().use_message_db) {
|
||||
// TODO load message notification group
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int32 MessagesManager::get_dialog_pending_notification_count(Dialog *d) {
|
||||
CHECK(d != nullptr);
|
||||
if (is_dialog_muted(d)) {
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "td/telegram/MessageId.h"
|
||||
#include "td/telegram/MessagesDb.h"
|
||||
#include "td/telegram/net/NetQuery.h"
|
||||
#include "td/telegram/Notification.h"
|
||||
#include "td/telegram/NotificationGroupId.h"
|
||||
#include "td/telegram/NotificationId.h"
|
||||
#include "td/telegram/NotificationSettings.h"
|
||||
@ -656,6 +657,13 @@ class MessagesManager : public Actor {
|
||||
vector<tl_object_ptr<telegram_api::User>> users,
|
||||
vector<tl_object_ptr<telegram_api::Chat>> chats);
|
||||
|
||||
struct MessageNotificationGroup {
|
||||
DialogId dialog_id;
|
||||
int32 total_count = 0;
|
||||
vector<Notification> notifications;
|
||||
};
|
||||
MessageNotificationGroup get_message_notification_group_force(NotificationGroupId group_id);
|
||||
|
||||
void on_binlog_events(vector<BinlogEvent> &&events);
|
||||
|
||||
void get_payment_form(FullMessageId full_message_id, Promise<tl_object_ptr<td_api::paymentForm>> &&promise);
|
||||
|
41
td/telegram/Notification.h
Normal file
41
td/telegram/Notification.h
Normal file
@ -0,0 +1,41 @@
|
||||
//
|
||||
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include "td/telegram/DialogId.h"
|
||||
#include "td/telegram/NotificationId.h"
|
||||
#include "td/telegram/NotificationType.h"
|
||||
#include "td/telegram/td_api.h"
|
||||
|
||||
#include "td/utils/common.h"
|
||||
#include "td/utils/StringBuilder.h"
|
||||
|
||||
namespace td {
|
||||
|
||||
class Notification {
|
||||
public:
|
||||
NotificationId notification_id;
|
||||
int32 date = 0;
|
||||
unique_ptr<NotificationType> type;
|
||||
|
||||
Notification(NotificationId notification_id, int32 date, unique_ptr<NotificationType> type)
|
||||
: notification_id(notification_id), date(date), type(std::move(type)) {
|
||||
}
|
||||
};
|
||||
|
||||
inline td_api::object_ptr<td_api::notification> get_notification_object(DialogId dialog_id,
|
||||
const Notification ¬ification) {
|
||||
return td_api::make_object<td_api::notification>(notification.notification_id.get(),
|
||||
notification.type->get_notification_type_object(dialog_id));
|
||||
}
|
||||
|
||||
inline StringBuilder &operator<<(StringBuilder &sb, const Notification notification) {
|
||||
return sb << "notification[" << notification.notification_id << ", " << notification.date << ", "
|
||||
<< *notification.type << ']';
|
||||
}
|
||||
|
||||
} // namespace td
|
@ -10,6 +10,7 @@
|
||||
#include "td/telegram/ConfigShared.h"
|
||||
#include "td/telegram/ContactsManager.h"
|
||||
#include "td/telegram/Global.h"
|
||||
#include "td/telegram/MessagesManager.h"
|
||||
#include "td/telegram/Td.h"
|
||||
#include "td/telegram/TdDb.h"
|
||||
|
||||
@ -85,7 +86,7 @@ void NotificationManager::start_up() {
|
||||
on_notification_cloud_delay_changed();
|
||||
on_notification_default_delay_changed();
|
||||
|
||||
// TODO load groups
|
||||
// TODO send updateActiveNotifications
|
||||
}
|
||||
|
||||
void NotificationManager::tear_down() {
|
||||
@ -102,6 +103,34 @@ NotificationManager::NotificationGroups::iterator NotificationManager::get_group
|
||||
return groups_.end();
|
||||
}
|
||||
|
||||
NotificationManager::NotificationGroups::iterator NotificationManager::get_group_force(NotificationGroupId group_id) {
|
||||
auto group_it = get_group(group_id);
|
||||
if (group_it != groups_.end()) {
|
||||
return group_it;
|
||||
}
|
||||
|
||||
auto message_group = td_->messages_manager_->get_message_notification_group_force(group_id);
|
||||
if (!message_group.dialog_id.is_valid()) {
|
||||
return groups_.end();
|
||||
}
|
||||
|
||||
NotificationGroupKey group_key;
|
||||
group_key.group_id = group_id;
|
||||
group_key.dialog_id = message_group.dialog_id;
|
||||
group_key.last_notification_date = 0;
|
||||
for (auto ¬ification : message_group.notifications) {
|
||||
if (notification.date >= group_key.last_notification_date) {
|
||||
group_key.last_notification_date = notification.date;
|
||||
}
|
||||
}
|
||||
|
||||
NotificationGroup group;
|
||||
group.total_count = message_group.total_count;
|
||||
group.notifications = std::move(message_group.notifications);
|
||||
|
||||
return groups_.emplace(std::move(group_key), std::move(group)).first;
|
||||
}
|
||||
|
||||
NotificationId NotificationManager::get_max_notification_id() const {
|
||||
return current_notification_id_;
|
||||
}
|
||||
@ -193,15 +222,13 @@ void NotificationManager::add_notification(NotificationGroupId group_id, DialogI
|
||||
<< " with settings from " << notification_settings_dialog_id
|
||||
<< (is_silent ? " silently" : " with sound") << ": " << *type;
|
||||
|
||||
auto group_it = get_group(group_id);
|
||||
auto group_it = get_group_force(group_id);
|
||||
if (group_it == groups_.end()) {
|
||||
NotificationGroupKey group_key;
|
||||
group_key.group_id = group_id;
|
||||
group_key.dialog_id = dialog_id;
|
||||
group_key.last_notification_date = 0;
|
||||
group_it = std::move(groups_.emplace(group_key, NotificationGroup()).first);
|
||||
|
||||
// TODO synchronously load old group notifications from the database
|
||||
}
|
||||
|
||||
PendingNotification notification;
|
||||
@ -223,12 +250,6 @@ void NotificationManager::add_notification(NotificationGroupId group_id, DialogI
|
||||
group.pending_notifications.push_back(std::move(notification));
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::notification> NotificationManager::get_notification_object(
|
||||
DialogId dialog_id, const Notification ¬ification) {
|
||||
return td_api::make_object<td_api::notification>(notification.notification_id.get(),
|
||||
notification.type->get_notification_type_object(dialog_id));
|
||||
}
|
||||
|
||||
struct NotificationUpdate {
|
||||
const td_api::Update *update;
|
||||
};
|
||||
@ -619,8 +640,8 @@ void NotificationManager::do_flush_pending_notifications(NotificationGroupKey &g
|
||||
vector<td_api::object_ptr<td_api::notification>> added_notifications;
|
||||
added_notifications.reserve(pending_notifications.size());
|
||||
for (auto &pending_notification : pending_notifications) {
|
||||
Notification notification{pending_notification.notification_id, pending_notification.date,
|
||||
std::move(pending_notification.type)};
|
||||
Notification notification(pending_notification.notification_id, pending_notification.date,
|
||||
std::move(pending_notification.type));
|
||||
added_notifications.push_back(get_notification_object(group_key.dialog_id, notification));
|
||||
if (added_notifications.back()->type_ == nullptr) {
|
||||
added_notifications.pop_back();
|
||||
@ -864,7 +885,8 @@ void NotificationManager::on_notifications_removed(
|
||||
|
||||
/*
|
||||
if (last_loaded_group_key_ < last_group_key) {
|
||||
// TODO load new groups from database
|
||||
TODO
|
||||
load_notification_groups_from_database();
|
||||
}
|
||||
*/
|
||||
}
|
||||
@ -929,9 +951,8 @@ void NotificationManager::remove_notification(NotificationGroupId group_id, Noti
|
||||
|
||||
// TODO remove notification from database by notification_id
|
||||
|
||||
auto group_it = get_group(group_id);
|
||||
auto group_it = get_group_force(group_id);
|
||||
if (group_it == groups_.end()) {
|
||||
// TODO synchronously load the group
|
||||
return promise.set_value(Unit());
|
||||
}
|
||||
|
||||
@ -1014,10 +1035,9 @@ void NotificationManager::remove_notification_group(NotificationGroupId group_id
|
||||
// TODO remove notifications from database by max_notification_id, save that they are removed
|
||||
}
|
||||
|
||||
auto group_it = get_group(group_id);
|
||||
auto group_it = get_group_force(group_id);
|
||||
if (group_it == groups_.end()) {
|
||||
VLOG(notifications) << "Can't find " << group_id;
|
||||
// TODO synchronously load the group
|
||||
return promise.set_value(Unit());
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
#include "td/telegram/DialogId.h"
|
||||
#include "td/telegram/MessageId.h"
|
||||
#include "td/telegram/Notification.h"
|
||||
#include "td/telegram/NotificationGroupId.h"
|
||||
#include "td/telegram/NotificationId.h"
|
||||
#include "td/telegram/NotificationType.h"
|
||||
@ -90,16 +91,6 @@ class NotificationManager : public Actor {
|
||||
static constexpr int32 MIN_UPDATE_DELAY_MS = 50;
|
||||
static constexpr int32 MAX_UPDATE_DELAY_MS = 60000;
|
||||
|
||||
struct Notification {
|
||||
NotificationId notification_id;
|
||||
int32 date = 0;
|
||||
unique_ptr<NotificationType> type;
|
||||
|
||||
Notification(NotificationId notification_id, int32 date, unique_ptr<NotificationType> type)
|
||||
: notification_id(notification_id), date(date), type(std::move(type)) {
|
||||
}
|
||||
};
|
||||
|
||||
struct PendingNotification {
|
||||
int32 date = 0;
|
||||
DialogId settings_dialog_id;
|
||||
@ -148,9 +139,6 @@ class NotificationManager : public Actor {
|
||||
void start_up() override;
|
||||
void tear_down() override;
|
||||
|
||||
static td_api::object_ptr<td_api::notification> get_notification_object(DialogId dialog_id,
|
||||
const Notification ¬ification);
|
||||
|
||||
void add_update(int32 group_id, td_api::object_ptr<td_api::Update> update);
|
||||
|
||||
void add_update_notification_group(td_api::object_ptr<td_api::updateNotificationGroup> update);
|
||||
@ -160,6 +148,8 @@ class NotificationManager : public Actor {
|
||||
|
||||
NotificationGroups::iterator get_group(NotificationGroupId group_id);
|
||||
|
||||
NotificationGroups::iterator get_group_force(NotificationGroupId group_id);
|
||||
|
||||
NotificationGroupKey get_last_updated_group_key() const;
|
||||
|
||||
void send_remove_group_update(const NotificationGroupKey &group_key, const NotificationGroup &group,
|
||||
|
Loading…
Reference in New Issue
Block a user