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
7323233b8d
commit
52b78be450
5 changed files with 31 additions and 10 deletions
|
@ -95,7 +95,11 @@ namespace AyuSync
|
||||||
|
|
||||||
LOG(("userId: %1, type: %2").arg(userId).arg(type.c_str()));
|
LOG(("userId: %1, type: %2").arg(userId).arg(type.c_str()));
|
||||||
|
|
||||||
// todo: check if account exists
|
if (!accountExists(userId))
|
||||||
|
{
|
||||||
|
LOG(("Sync for unknown account: %1").arg(userId));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (type == "sync_force")
|
if (type == "sync_force")
|
||||||
{
|
{
|
||||||
|
@ -117,15 +121,19 @@ namespace AyuSync
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DECLSPEC_NOINLINE void ayu_sync_controller::onSyncForce(SyncForce ev)
|
void ayu_sync_controller::onSyncForce(SyncForce ev)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
DECLSPEC_NOINLINE void ayu_sync_controller::onSyncBatch(json ev)
|
void ayu_sync_controller::onSyncBatch(json ev)
|
||||||
{
|
{
|
||||||
|
for (auto& item : ev["args"]["events"])
|
||||||
|
{
|
||||||
|
invokeHandler(item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DECLSPEC_NOINLINE void ayu_sync_controller::onSyncRead(SyncRead ev)
|
void ayu_sync_controller::onSyncRead(SyncRead ev)
|
||||||
{
|
{
|
||||||
dispatchToMainThread([=]
|
dispatchToMainThread([=]
|
||||||
{
|
{
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include "ayu/libs/bit_converter.hpp"
|
#include "ayu/libs/bit_converter.hpp"
|
||||||
|
|
||||||
|
using stringbuf = std::basic_stringbuf<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char>>;
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void ayu_pipe_wrapper::send(T obj)
|
void ayu_pipe_wrapper::send(T obj)
|
||||||
{
|
{
|
||||||
|
@ -30,25 +32,30 @@ std::optional<json> ayu_pipe_wrapper::receive()
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
char lengthBuff[4];
|
unsigned char lengthBuff[4];
|
||||||
is.read(lengthBuff, 4);
|
is.read(lengthBuff, 4);
|
||||||
|
|
||||||
auto length = bit_converter::bytes_to_i32(lengthBuff, false);
|
auto length = bit_converter::bytes_to_i32(lengthBuff, false);
|
||||||
|
|
||||||
|
LOG(("ayu_pipe_wrapper::receive() length: %1").arg(length));
|
||||||
|
|
||||||
if (length <= 0)
|
if (length <= 0)
|
||||||
{
|
{
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto sb = std::stringbuf();
|
auto sb = stringbuf();
|
||||||
char buff[4096];
|
unsigned char buff[4096];
|
||||||
|
|
||||||
while (length > 0)
|
while (length > 0)
|
||||||
{
|
{
|
||||||
auto readSize = std::min(length, static_cast<int>(sizeof(buff)));
|
auto readSize = std::min(length, static_cast<int>(sizeof(buff)));
|
||||||
is.read(buff, readSize);
|
is.read(buff, readSize);
|
||||||
sb.sputn(buff, readSize);
|
|
||||||
length -= readSize;
|
auto reallyRead = is.gcount();
|
||||||
|
|
||||||
|
sb.sputn(buff, reallyRead);
|
||||||
|
length -= reallyRead;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto p = json::parse(sb.str());
|
auto p = json::parse(sb.str());
|
||||||
|
|
|
@ -22,5 +22,5 @@ public:
|
||||||
std::optional<json> receive();
|
std::optional<json> receive();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
nes::pipe_istream is{"AyuSync"};
|
nes::basic_pipe_istream<unsigned char> is{"AyuSync"};
|
||||||
};
|
};
|
||||||
|
|
|
@ -32,6 +32,11 @@ Main::Session* getSession(ID userId)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool accountExists(ID userId)
|
||||||
|
{
|
||||||
|
return userId == 0 || getSession(userId) != nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
void dispatchToMainThread(std::function<void()> callback)
|
void dispatchToMainThread(std::function<void()> callback)
|
||||||
{
|
{
|
||||||
auto timer = new QTimer();
|
auto timer = new QTimer();
|
||||||
|
|
|
@ -15,5 +15,6 @@
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
|
|
||||||
Main::Session* getSession(ID userId);
|
Main::Session* getSession(ID userId);
|
||||||
|
bool accountExists(ID userId);
|
||||||
void dispatchToMainThread(std::function<void()> callback);
|
void dispatchToMainThread(std::function<void()> callback);
|
||||||
not_null<History*> getHistoryFromDialogId(ID dialogId, Main::Session* session);
|
not_null<History*> getHistoryFromDialogId(ID dialogId, Main::Session* session);
|
||||||
|
|
Loading…
Add table
Reference in a new issue