// Copyright (c) 2026 Duplicati Inc. All rights reserved. using Duplicati.Library.Common.IO; using Duplicati.Library.Interface; using System.Runtime.CompilerServices; namespace Duplicati.Proprietary.GoogleWorkspace.SourceItems; internal class ChatSourceEntry(SourceProvider provider, string parentPath) : MetaEntryBase(Util.AppendDirSeparator(SystemIO.IO_OS.PathCombine(parentPath, "Chat")), null, null) { public override async IAsyncEnumerable Enumerate([EnumeratorCancellation] CancellationToken cancellationToken) { var service = provider.ApiHelper.GetChatService(); var request = service.Spaces.List(); string? nextPageToken = null; do { if (cancellationToken.IsCancellationRequested) yield break; request.PageToken = nextPageToken; var spaces = await request.ExecuteAsync(cancellationToken); if (spaces.Spaces != null) { foreach (var space in spaces.Spaces) { if (cancellationToken.IsCancellationRequested) yield break; yield return new ChatSpaceSourceEntry(provider, this.Path, space); } } nextPageToken = spaces.NextPageToken; } while (!string.IsNullOrEmpty(nextPageToken)); } public override Task> GetMinorMetadata(CancellationToken cancellationToken) { return Task.FromResult(new Dictionary { { "gsuite:v", "1" }, { "gsuite:Type", SourceItemType.UserChat.ToString() }, { "gsuite:Name", "Chat" }, { "gsuite:Id", "Chat" } } .Where(kv => !string.IsNullOrEmpty(kv.Value)) .ToDictionary(kv => kv.Key, kv => kv.Value)); } }