Files
duplicati/proprietary/GoogleWorkspace/SourceItems/ChatSourceEntry.cs
T

49 lines
1.8 KiB
C#

// 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<ISourceProviderEntry> 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<Dictionary<string, string?>> GetMinorMetadata(CancellationToken cancellationToken)
{
return Task.FromResult(new Dictionary<string, string?>
{
{ "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));
}
}