mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
feat: progress AyuSync implementation
This commit is contained in:
parent
0813121f58
commit
3286eacf75
7 changed files with 110 additions and 3 deletions
|
@ -123,6 +123,8 @@ PRIVATE
|
||||||
ayu/sync/utils/ayu_pipe_wrapper.cpp
|
ayu/sync/utils/ayu_pipe_wrapper.cpp
|
||||||
ayu/sync/utils/ayu_pipe_wrapper.h
|
ayu/sync/utils/ayu_pipe_wrapper.h
|
||||||
ayu/sync/utils/process_utils.hpp
|
ayu/sync/utils/process_utils.hpp
|
||||||
|
ayu/sync/utils/telegram_helpers.cpp
|
||||||
|
ayu/sync/utils/telegram_helpers.h
|
||||||
ayu/libs/pipe.hpp
|
ayu/libs/pipe.hpp
|
||||||
ayu/libs/json.hpp
|
ayu/libs/json.hpp
|
||||||
ayu/libs/json_ext.hpp
|
ayu/libs/json_ext.hpp
|
||||||
|
|
|
@ -42,10 +42,10 @@ void CustomLangPack::fetchCustomLangPack(const QString &langPackId, const QStrin
|
||||||
|
|
||||||
QUrl url;
|
QUrl url;
|
||||||
if (!finalLangPackId.isEmpty() && !langPackBaseId.isEmpty() && !needFallback) {
|
if (!finalLangPackId.isEmpty() && !langPackBaseId.isEmpty() && !needFallback) {
|
||||||
url.setUrl(qsl("https://raw.githubusercontent.com/AyuGram/Languages/main/values/langs/%1/Shared.json").arg(
|
url.setUrl(qsl("https://raw.githubusercontent.com/AyuGram/Languages/l10n_main/values/langs/%1/Shared.json").arg(
|
||||||
finalLangPackId));
|
finalLangPackId));
|
||||||
} else {
|
} else {
|
||||||
url.setUrl(qsl("https://raw.githubusercontent.com/AyuGram/Languages/main/values/langs/%1/Shared.json").arg(
|
url.setUrl(qsl("https://raw.githubusercontent.com/AyuGram/Languages/l10n_main/values/langs/%1/Shared.json").arg(
|
||||||
needFallback ? langPackBaseId : finalLangPackId));
|
needFallback ? langPackBaseId : finalLangPackId));
|
||||||
}
|
}
|
||||||
_chkReply = networkManager.get(QNetworkRequest(url));
|
_chkReply = networkManager.get(QNetworkRequest(url));
|
||||||
|
|
|
@ -8,6 +8,11 @@
|
||||||
#include "ayu_sync_controller.h"
|
#include "ayu_sync_controller.h"
|
||||||
#include "ayu/libs/process.hpp"
|
#include "ayu/libs/process.hpp"
|
||||||
#include "ayu/sync/utils/process_utils.hpp"
|
#include "ayu/sync/utils/process_utils.hpp"
|
||||||
|
#include "ayu/sync/models.h"
|
||||||
|
#include "data/data_session.h"
|
||||||
|
#include "history/history.h"
|
||||||
|
#include "ayu/sync/utils/telegram_helpers.h"
|
||||||
|
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
@ -73,6 +78,39 @@ namespace AyuSync {
|
||||||
auto userId = p["userId"].get<long>();
|
auto userId = p["userId"].get<long>();
|
||||||
auto type = p["type"].get<std::string>();
|
auto type = p["type"].get<std::string>();
|
||||||
|
|
||||||
LOG(("userId: %1, type: %1").arg(userId).arg(type.c_str()));
|
LOG(("userId: %1, type: %2").arg(userId).arg(type.c_str()));
|
||||||
|
|
||||||
|
// todo: check if account exists
|
||||||
|
|
||||||
|
if (type == "sync_force") {
|
||||||
|
auto ev = p.template get<SyncForce>();
|
||||||
|
onSyncForce(ev);
|
||||||
|
} else if (type == "sync_batch") {
|
||||||
|
onSyncBatch(p);
|
||||||
|
} else if (type == "sync_read") {
|
||||||
|
auto ev = p.template get<SyncRead>();
|
||||||
|
onSyncRead(ev);
|
||||||
|
} else {
|
||||||
|
LOG(("Unknown sync type: %1").arg(type.c_str()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ayu_sync_controller::onSyncForce(SyncForce ev) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void ayu_sync_controller::onSyncBatch(json ev) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void ayu_sync_controller::onSyncRead(SyncRead ev) {
|
||||||
|
auto session = getSession(ev.userId);
|
||||||
|
|
||||||
|
auto peer = PeerId(abs(ev.args.dialogId));
|
||||||
|
|
||||||
|
auto history = session->data().history(peer);
|
||||||
|
if (history) {
|
||||||
|
history->inboxRead(ev.args.untilId, ev.args.unread);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -8,6 +8,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ayu/libs/json.hpp"
|
#include "ayu/libs/json.hpp"
|
||||||
|
#include "models.h"
|
||||||
#include "utils/ayu_pipe_wrapper.h"
|
#include "utils/ayu_pipe_wrapper.h"
|
||||||
|
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
|
@ -26,6 +27,10 @@ namespace AyuSync {
|
||||||
public:
|
public:
|
||||||
void initializeAgent();
|
void initializeAgent();
|
||||||
|
|
||||||
|
void onSyncForce(SyncForce ev);
|
||||||
|
void onSyncBatch(json ev);
|
||||||
|
void onSyncRead(SyncRead ev);
|
||||||
|
|
||||||
void invokeHandler(json p);
|
void invokeHandler(json p);
|
||||||
private:
|
private:
|
||||||
void receiver();
|
void receiver();
|
||||||
|
|
|
@ -4,15 +4,18 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class SyncEvent {
|
class SyncEvent {
|
||||||
|
public:
|
||||||
std::string type = "sync_unspecified";
|
std::string type = "sync_unspecified";
|
||||||
long userId = 0;
|
long userId = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SyncBatch : public SyncEvent {
|
class SyncBatch : public SyncEvent {
|
||||||
|
public:
|
||||||
std::string type = "sync_batch";
|
std::string type = "sync_batch";
|
||||||
long userId;
|
long userId;
|
||||||
|
|
||||||
class SyncBatchArgs {
|
class SyncBatchArgs {
|
||||||
|
public:
|
||||||
std::vector<SyncEvent> events;
|
std::vector<SyncEvent> events;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -20,10 +23,12 @@ class SyncBatch : public SyncEvent {
|
||||||
};
|
};
|
||||||
|
|
||||||
class SyncRead : public SyncEvent {
|
class SyncRead : public SyncEvent {
|
||||||
|
public:
|
||||||
std::string type = "sync_read";
|
std::string type = "sync_read";
|
||||||
long userId;
|
long userId;
|
||||||
|
|
||||||
class SyncReadArgs {
|
class SyncReadArgs {
|
||||||
|
public:
|
||||||
long dialogId;
|
long dialogId;
|
||||||
int untilId;
|
int untilId;
|
||||||
int unread;
|
int unread;
|
||||||
|
@ -33,10 +38,12 @@ class SyncRead : public SyncEvent {
|
||||||
};
|
};
|
||||||
|
|
||||||
class SyncForce : public SyncEvent {
|
class SyncForce : public SyncEvent {
|
||||||
|
public:
|
||||||
std::string type = "sync_force";
|
std::string type = "sync_force";
|
||||||
long userId;
|
long userId;
|
||||||
|
|
||||||
class SyncForceArgs {
|
class SyncForceArgs {
|
||||||
|
public:
|
||||||
int fromDate;
|
int fromDate;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -44,12 +51,26 @@ class SyncForce : public SyncEvent {
|
||||||
};
|
};
|
||||||
|
|
||||||
class SyncForceFinish : public SyncEvent {
|
class SyncForceFinish : public SyncEvent {
|
||||||
|
public:
|
||||||
std::string type = "sync_force_finish";
|
std::string type = "sync_force_finish";
|
||||||
long userId;
|
long userId;
|
||||||
|
|
||||||
class SyncForceFinishArgs {
|
class SyncForceFinishArgs {
|
||||||
|
public:
|
||||||
|
short dummy; // required to be JSON serializable
|
||||||
};
|
};
|
||||||
|
|
||||||
SyncForceFinishArgs args;
|
SyncForceFinishArgs args;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SyncEvent, type, userId)
|
||||||
|
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SyncBatch::SyncBatchArgs, events)
|
||||||
|
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SyncBatch, type, userId, args)
|
||||||
|
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SyncRead::SyncReadArgs, dialogId, untilId, unread)
|
||||||
|
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SyncRead, type, userId, args)
|
||||||
|
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SyncForce::SyncForceArgs, fromDate)
|
||||||
|
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SyncForce, type, userId, args)
|
||||||
|
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SyncForceFinish::SyncForceFinishArgs, dummy)
|
||||||
|
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SyncForceFinish, type, userId, args)
|
||||||
|
|
||||||
|
|
26
Telegram/SourceFiles/ayu/sync/utils/telegram_helpers.cpp
Normal file
26
Telegram/SourceFiles/ayu/sync/utils/telegram_helpers.cpp
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
// This is the source code of AyuGram for Desktop.
|
||||||
|
//
|
||||||
|
// We do not and cannot prevent the use of our code,
|
||||||
|
// but be respectful and credit the original author.
|
||||||
|
//
|
||||||
|
// Copyright @Radolyn, 2023
|
||||||
|
|
||||||
|
#include "telegram_helpers.h"
|
||||||
|
#include "data/data_peer_id.h"
|
||||||
|
|
||||||
|
Main::Session* getSession(long userId) {
|
||||||
|
for (auto &[index, account] : Core::App().domain().accounts()) {
|
||||||
|
if (const auto session = account->maybeSession()) {
|
||||||
|
if (session->userId().bare == userId) {
|
||||||
|
return session;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
PeerId dialogIdToPeerId(long dialogId) {
|
||||||
|
auto peerId = PeerId();
|
||||||
|
return peerId;
|
||||||
|
}
|
15
Telegram/SourceFiles/ayu/sync/utils/telegram_helpers.h
Normal file
15
Telegram/SourceFiles/ayu/sync/utils/telegram_helpers.h
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
// This is the source code of AyuGram for Desktop.
|
||||||
|
//
|
||||||
|
// We do not and cannot prevent the use of our code,
|
||||||
|
// but be respectful and credit the original author.
|
||||||
|
//
|
||||||
|
// Copyright @Radolyn, 2023
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "core/application.h"
|
||||||
|
#include "main/main_account.h"
|
||||||
|
#include "main/main_session.h"
|
||||||
|
#include "main/main_domain.h"
|
||||||
|
|
||||||
|
Main::Session* getSession(long userId);
|
Loading…
Add table
Reference in a new issue