tdlight/td/telegram/DeviceTokenManager.h

91 lines
2.3 KiB
C
Raw Normal View History

//
2022-12-31 22:28:08 +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
#include "td/telegram/net/NetQuery.h"
#include "td/telegram/td_api.h"
#include "td/telegram/UserId.h"
2021-09-18 23:47:05 +02:00
#include "td/actor/actor.h"
#include "td/utils/common.h"
2022-06-27 12:30:18 +02:00
#include "td/utils/Promise.h"
#include "td/utils/Slice.h"
#include "td/utils/StringBuilder.h"
#include <array>
#include <utility>
namespace td {
class DeviceTokenManager final : public NetQueryCallback {
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,
Promise<td_api::object_ptr<td_api::pushReceiverId>> promise);
void reregister_device();
vector<std::pair<int64, Slice>> get_encryption_keys() const;
private:
ActorShared<> parent_;
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
};
struct TokenInfo {
enum class State : int32 { Sync, Unregister, Register, Reregister };
State state = State::Sync;
string token;
uint64 net_query_id = 0;
2021-09-03 11:27:59 +02:00
vector<int64> other_user_ids;
bool is_app_sandbox = false;
bool encrypt = false;
string encryption_key;
int64 encryption_key_id = 0;
Promise<td_api::object_ptr<td_api::pushReceiverId>> promise;
template <class StorerT>
void store(StorerT &storer) const;
template <class ParserT>
void parse(ParserT &parser);
};
friend StringBuilder &operator<<(StringBuilder &string_builder, const TokenInfo::State &state);
friend StringBuilder &operator<<(StringBuilder &string_builder, const TokenInfo &token_info);
2021-07-05 18:17:26 +02:00
std::array<TokenInfo, TokenType::Size> tokens_;
int32 sync_cnt_{0};
2021-07-03 22:51:36 +02:00
void start_up() final;
static string get_database_key(int32 token_type);
void save_info(int32 token_type);
void dec_sync_cnt();
2021-07-03 22:51:36 +02:00
void loop() final;
void on_result(NetQueryPtr net_query) final;
};
} // namespace td