From 125c1caeeb7ae42bcdfc642fa7de5cc8ddc0f170 Mon Sep 17 00:00:00 2001 From: Wizou <11647984+wiz0u@users.noreply.github.com> Date: Sun, 18 Feb 2024 17:41:30 +0100 Subject: [PATCH] Alternate simpler byte[] callback session store --- src/Client.cs | 3 +++ src/Session.cs | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/src/Client.cs b/src/Client.cs index af22c38..922925e 100644 --- a/src/Client.cs +++ b/src/Client.cs @@ -94,6 +94,9 @@ namespace WTelegram }) { } + public Client(Func configProvider, byte[] startSession, Action saveSession) + : this(configProvider, new ActionStore(startSession, saveSession)) { } + /// Welcome to WTelegramClient! 🙂 /// Config callback, is queried for: api_id, api_hash, session_pathname /// if specified, must support initial Length & Read() of a session, then calls to Write() the updated session. Other calls can be ignored diff --git a/src/Session.cs b/src/Session.cs index b76ecbc..54c354c 100644 --- a/src/Session.cs +++ b/src/Session.cs @@ -192,4 +192,11 @@ namespace WTelegram base.Write(_header, 0, 8); } } + + // QWxp couldn't be bothered to write such a simple SessionStore, so here it is: + internal class ActionStore(byte[] startSession, Action saveSession) : MemoryStream(startSession ?? Array.Empty()) + { + public override void Write(byte[] buffer, int offset, int count) => saveSession(buffer[offset..(offset + count)]); + public override void SetLength(long value) { } + } } \ No newline at end of file