summary refs log tree commit diff
path: root/MxApiExtensions/Classes
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2023-11-05 17:59:38 +0100
committerTheArcaneBrony <myrainbowdash949@gmail.com>2023-11-05 17:59:38 +0100
commit2abb132234546e61bb0aff3897dc49e72ea84f5d (patch)
treec885c03d35e7a0a6b8fc21bd0b259216c61c877c /MxApiExtensions/Classes
parentUpdate (diff)
downloadMxApiExtensions-2abb132234546e61bb0aff3897dc49e72ea84f5d.tar.xz
Working sync proxy
Diffstat (limited to 'MxApiExtensions/Classes')
-rw-r--r--MxApiExtensions/Classes/SyncState.cs80
1 files changed, 78 insertions, 2 deletions
diff --git a/MxApiExtensions/Classes/SyncState.cs b/MxApiExtensions/Classes/SyncState.cs

index 6950954..e44d35c 100644 --- a/MxApiExtensions/Classes/SyncState.cs +++ b/MxApiExtensions/Classes/SyncState.cs
@@ -1,15 +1,91 @@ using System.Collections.Concurrent; +using System.Text.Json.Serialization; +using LibMatrix; +using LibMatrix.EventTypes.Spec.State; using LibMatrix.Helpers; using LibMatrix.Homeservers; using LibMatrix.Responses; +using Microsoft.OpenApi.Extensions; namespace MxApiExtensions.Classes; public class SyncState { + private Task? _nextSyncResponse; public string? NextBatch { get; set; } public ConcurrentQueue<SyncResponse> SyncQueue { get; set; } = new(); public bool IsInitialSync { get; set; } - public Task? NextSyncResponse { get; set; } + + [JsonIgnore] + public Task? NextSyncResponse { + get => _nextSyncResponse; + set { + _nextSyncResponse = value; + NextSyncResponseStartedAt = DateTime.Now; + } + } + public DateTime NextSyncResponseStartedAt { get; set; } = DateTime.Now; + + [JsonIgnore] public AuthenticatedHomeserverGeneric Homeserver { get; set; } -} + +#region Debug stuff + + public object NextSyncResponseTaskInfo => new { + NextSyncResponse?.Id, + NextSyncResponse?.IsCompleted, + NextSyncResponse?.IsCompletedSuccessfully, + NextSyncResponse?.IsCanceled, + NextSyncResponse?.IsFaulted, + Status = NextSyncResponse?.Status.GetDisplayName() + }; + + +#endregion + + public void SendEphemeralTimelineEventInRoom(string roomId, StateEventResponse @event) { + SyncQueue.Enqueue(new() { + NextBatch = NextBatch ?? "null", + Rooms = new() { + Join = new() { + { + roomId, + new() { + Timeline = new() { + Events = new() { + @event + } + } + } + } + } + } + }); + } + + public void SendStatusMessage(string text) { + SyncQueue.Enqueue(new() { + NextBatch = NextBatch ?? "null", + Presence = new() { + Events = new() { + new StateEventResponse { + TypedContent = new PresenceEventContent { + DisplayName = "MxApiExtensions", + Presence = "online", + StatusMessage = text, + // AvatarUrl = (await syncState.Homeserver.GetProfile(syncState.Homeserver.WhoAmI.UserId)).AvatarUrl + AvatarUrl = "", + LastActiveAgo = 15, + CurrentlyActive = true + }, + Type = "m.presence", + StateKey = Homeserver.WhoAmI.UserId, + Sender = Homeserver.WhoAmI.UserId, + EventId = Guid.NewGuid().ToString(), + OriginServerTs = 0 + } + } + } + }); + } +} \ No newline at end of file