2018-12-31 20:04:05 +01:00
|
|
|
//
|
2018-12-31 23:02:34 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2019
|
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/actor/actor.h"
|
|
|
|
#include "td/actor/PromiseFuture.h"
|
|
|
|
|
|
|
|
#include "td/telegram/net/NetQuery.h"
|
|
|
|
|
|
|
|
#include "td/telegram/td_api.h"
|
|
|
|
|
|
|
|
#include "td/utils/common.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
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
class DeviceTokenManager : public NetQueryCallback {
|
|
|
|
public:
|
|
|
|
explicit DeviceTokenManager(ActorShared<> parent) : parent_(std::move(parent)) {
|
|
|
|
}
|
2018-01-10 01:18:03 +01:00
|
|
|
void register_device(tl_object_ptr<td_api::DeviceToken> device_token_ptr, vector<int32> 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
|
|
|
|
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:
|
2018-01-10 01:18:03 +01:00
|
|
|
static constexpr size_t MAX_OTHER_USER_IDS = 100;
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
ActorShared<> parent_;
|
2018-01-19 16:04:16 +01:00
|
|
|
enum TokenType : int32 {
|
|
|
|
APNS = 1,
|
2019-04-18 01:23:02 +02:00
|
|
|
FCM = 2,
|
2018-01-19 16:04:16 +01:00
|
|
|
MPNS = 3,
|
|
|
|
SIMPLE_PUSH = 4,
|
|
|
|
UBUNTU_PHONE = 5,
|
|
|
|
BLACKBERRY = 6,
|
|
|
|
UNUSED = 7,
|
|
|
|
WNS = 8,
|
|
|
|
APNS_VOIP = 9,
|
|
|
|
WEB_PUSH = 10,
|
|
|
|
MPNS_VOIP = 11,
|
|
|
|
TIZEN = 12,
|
|
|
|
SIZE
|
|
|
|
};
|
2018-12-31 20:04:05 +01:00
|
|
|
struct TokenInfo {
|
2018-04-19 15:08:30 +02:00
|
|
|
enum class State : int32 { Sync, Unregister, Register };
|
2018-12-31 20:04:05 +01:00
|
|
|
State state = State::Sync;
|
|
|
|
string token;
|
|
|
|
uint64 net_query_id = 0;
|
2018-01-10 01:18:03 +01:00
|
|
|
vector<int32> 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
|
|
|
};
|
|
|
|
|
2018-01-10 01:18:03 +01:00
|
|
|
friend StringBuilder &operator<<(StringBuilder &string_builder, const TokenInfo &token_info);
|
|
|
|
|
2018-01-19 16:04:16 +01:00
|
|
|
std::array<TokenInfo, TokenType::SIZE> tokens_;
|
2018-12-31 20:04:05 +01:00
|
|
|
int32 sync_cnt_{0};
|
|
|
|
|
|
|
|
void start_up() override;
|
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();
|
|
|
|
|
|
|
|
void loop() override;
|
|
|
|
void on_result(NetQueryPtr net_query) override;
|
|
|
|
};
|
2018-01-10 01:18:03 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
} // namespace td
|