2024-01-04 16:02:36 +01:00
|
|
|
//
|
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
|
2024-01-04 16:30:12 +01:00
|
|
|
#include "td/telegram/DialogId.h"
|
|
|
|
#include "td/telegram/td_api.h"
|
|
|
|
|
2024-01-04 16:02:36 +01:00
|
|
|
#include "td/actor/actor.h"
|
2024-01-04 16:30:12 +01:00
|
|
|
#include "td/actor/MultiTimeout.h"
|
2024-01-04 16:02:36 +01:00
|
|
|
|
|
|
|
#include "td/utils/common.h"
|
2024-01-04 16:30:12 +01:00
|
|
|
#include "td/utils/FlatHashMap.h"
|
2024-01-04 16:02:36 +01:00
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
|
|
|
class Td;
|
|
|
|
|
|
|
|
class DialogOnlineMemberManager final : public Actor {
|
|
|
|
public:
|
|
|
|
DialogOnlineMemberManager(Td *td, ActorShared<> parent);
|
|
|
|
|
2024-01-04 16:30:12 +01:00
|
|
|
static constexpr int32 ONLINE_MEMBER_COUNT_CACHE_EXPIRE_TIME = 30 * 60;
|
|
|
|
|
|
|
|
void on_update_dialog_online_member_count(DialogId dialog_id, int32 online_member_count, bool is_from_server);
|
|
|
|
|
|
|
|
void on_dialog_opened(DialogId dialog_id);
|
|
|
|
|
|
|
|
void on_dialog_closed(DialogId dialog_id);
|
|
|
|
|
|
|
|
void get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const;
|
|
|
|
|
2024-01-04 16:02:36 +01:00
|
|
|
private:
|
|
|
|
void tear_down() final;
|
|
|
|
|
2024-01-04 16:30:12 +01:00
|
|
|
static constexpr int32 ONLINE_MEMBER_COUNT_UPDATE_TIME = 5 * 60;
|
|
|
|
|
|
|
|
static void on_update_dialog_online_member_count_timeout_callback(void *messages_manager_ptr, int64 dialog_id_int);
|
|
|
|
|
|
|
|
void set_dialog_online_member_count(DialogId dialog_id, int32 online_member_count, bool is_from_server,
|
|
|
|
const char *source);
|
|
|
|
|
|
|
|
void on_update_dialog_online_member_count_timeout(DialogId dialog_id);
|
|
|
|
|
|
|
|
void send_update_chat_online_member_count(DialogId dialog_id, int32 online_member_count) const;
|
|
|
|
|
|
|
|
struct OnlineMemberCountInfo {
|
|
|
|
int32 online_member_count = 0;
|
|
|
|
double update_time = 0;
|
|
|
|
bool is_update_sent = false;
|
|
|
|
};
|
|
|
|
FlatHashMap<DialogId, OnlineMemberCountInfo, DialogIdHash> dialog_online_member_counts_;
|
|
|
|
|
|
|
|
MultiTimeout update_dialog_online_member_count_timeout_{"UpdateDialogOnlineMemberCountTimeout"};
|
|
|
|
|
2024-01-04 16:02:36 +01:00
|
|
|
Td *td_;
|
|
|
|
ActorShared<> parent_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace td
|