2018-12-31 20:04:05 +01:00
|
|
|
//
|
2022-12-31 22:28:08 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
|
2018-12-31 20:04:05 +01:00
|
|
|
//
|
|
|
|
// 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/net/NetQuery.h"
|
|
|
|
#include "td/telegram/td_api.h"
|
2021-03-28 23:50:15 +02:00
|
|
|
#include "td/telegram/UserId.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2021-09-18 23:47:05 +02:00
|
|
|
#include "td/actor/actor.h"
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/common.h"
|
2022-06-27 12:30:18 +02:00
|
|
|
#include "td/utils/Promise.h"
|
2018-12-24 16:33:39 +01:00
|
|
|
#include "td/utils/Slice.h"
|
2018-01-19 16:04:16 +01:00
|
|
|
#include "td/utils/StringBuilder.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
#include <array>
|
2018-12-28 23:48:32 +01:00
|
|
|
#include <utility>
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
namespace td {
|
2018-01-10 01:18:03 +01:00
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class DeviceTokenManager final : public NetQueryCallback {
|
2018-12-31 20:04:05 +01:00
|
|
|
public:
|
|
|
|
explicit DeviceTokenManager(ActorShared<> parent) : parent_(std::move(parent)) {
|
|
|
|
}
|
2021-10-19 17:11:16 +02:00
|
|
|
void register_device(tl_object_ptr<td_api::DeviceToken> device_token_ptr, const vector<UserId> &other_user_ids,
|
2018-12-28 23:48:32 +01:00
|
|
|
Promise<td_api::object_ptr<td_api::pushReceiverId>> promise);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2019-11-17 20:43:10 +01:00
|
|
|
void reregister_device();
|
|
|
|
|
2018-12-28 23:48:32 +01:00
|
|
|
vector<std::pair<int64, Slice>> get_encryption_keys() const;
|
2018-12-24 16:33:39 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
private:
|
|
|
|
ActorShared<> parent_;
|
2018-01-19 16:04:16 +01:00
|
|
|
enum TokenType : int32 {
|
2021-07-05 18:17:26 +02:00
|
|
|
Apns = 1,
|
|
|
|
Fcm = 2,
|
|
|
|
Mpns = 3,
|
|
|
|
SimplePush = 4,
|
|
|
|
UbuntuPhone = 5,
|
|
|
|
BlackBerry = 6,
|
|
|
|
Unused = 7,
|
|
|
|
Wns = 8,
|
|
|
|
ApnsVoip = 9,
|
|
|
|
WebPush = 10,
|
|
|
|
MpnsVoip = 11,
|
|
|
|
Tizen = 12,
|
|
|
|
Size
|
2018-01-19 16:04:16 +01:00
|
|
|
};
|
2018-12-31 20:04:05 +01:00
|
|
|
struct TokenInfo {
|
2020-01-01 17:38:54 +01:00
|
|
|
enum class State : int32 { Sync, Unregister, Register, Reregister };
|
2018-12-31 20:04:05 +01:00
|
|
|
State state = State::Sync;
|
|
|
|
string token;
|
|
|
|
uint64 net_query_id = 0;
|
2021-09-03 11:27:59 +02:00
|
|
|
vector<int64> other_user_ids;
|
2018-01-10 13:11:35 +01:00
|
|
|
bool is_app_sandbox = false;
|
2018-12-24 16:33:39 +01:00
|
|
|
bool encrypt = false;
|
|
|
|
string encryption_key;
|
2018-12-28 23:48:32 +01:00
|
|
|
int64 encryption_key_id = 0;
|
|
|
|
Promise<td_api::object_ptr<td_api::pushReceiverId>> promise;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2018-01-10 01:18:03 +01:00
|
|
|
template <class StorerT>
|
|
|
|
void store(StorerT &storer) const;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2018-01-10 01:18:03 +01:00
|
|
|
template <class ParserT>
|
|
|
|
void parse(ParserT &parser);
|
2018-12-31 20:04:05 +01:00
|
|
|
};
|
|
|
|
|
2020-01-01 17:38:54 +01:00
|
|
|
friend StringBuilder &operator<<(StringBuilder &string_builder, const TokenInfo::State &state);
|
|
|
|
|
2018-01-10 01:18:03 +01:00
|
|
|
friend StringBuilder &operator<<(StringBuilder &string_builder, const TokenInfo &token_info);
|
|
|
|
|
2021-07-05 18:17:26 +02:00
|
|
|
std::array<TokenInfo, TokenType::Size> tokens_;
|
2018-12-31 20:04:05 +01:00
|
|
|
int32 sync_cnt_{0};
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
void start_up() final;
|
2018-01-10 01:18:03 +01:00
|
|
|
|
|
|
|
static string get_database_key(int32 token_type);
|
2018-12-31 20:04:05 +01:00
|
|
|
void save_info(int32 token_type);
|
2018-01-10 01:18:03 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
void dec_sync_cnt();
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
void loop() final;
|
|
|
|
void on_result(NetQueryPtr net_query) final;
|
2018-12-31 20:04:05 +01:00
|
|
|
};
|
2018-01-10 01:18:03 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
} // namespace td
|