Files
duplicati/proprietary/Office365/SourceItems/GroupConversationThread.cs
T

56 lines
2.9 KiB
C#
Raw Normal View History

2026-01-14 10:23:49 +01:00
// Copyright (c) 2026 Duplicati Inc. All rights reserved.
2026-01-22 17:01:13 +01:00
using System.Globalization;
2026-01-14 10:23:49 +01:00
using System.Runtime.CompilerServices;
using Duplicati.Library.Common.IO;
using Duplicati.Library.Interface;
using Duplicati.Library.Utility;
namespace Duplicati.Proprietary.Office365.SourceItems;
internal class GroupConversationThreadSourceEntry(SourceProvider provider, string path, GraphGroup group, GraphConversationThread thread)
: MetaEntryBase(Util.AppendDirSeparator(SystemIO.IO_OS.PathCombine(path, thread.Id)), null, thread.LastDeliveredDateTime.FromGraphDateTime())
{
public override async IAsyncEnumerable<ISourceProviderEntry> Enumerate([EnumeratorCancellation] CancellationToken cancellationToken)
{
await foreach (var post in provider.GroupConversationApi.ListThreadPostsAsync(group.Id, thread.Id, cancellationToken))
{
if (cancellationToken.IsCancellationRequested)
yield break;
yield return new StreamResourceEntryFunction(
SystemIO.IO_OS.PathCombine(this.Path, post.Id + ".json"),
createdUtc: post.CreatedDateTime.FromGraphDateTime(),
lastModificationUtc: post.LastModifiedDateTime.FromGraphDateTime(),
size: -1,
streamFactory: (ct) => provider.GroupConversationApi.GetThreadPostStreamAsync(group.Id, thread.Id, post.Id, ct),
minorMetadataFactory: (ct) => Task.FromResult(new Dictionary<string, string?>
{
{ "o365:v", "1" },
{ "o365:Id", post.Id },
{ "o365:Type", SourceItemType.GroupConversationThreadPost.ToString() },
{ "o365:Name", $"{post.From?.EmailAddress?.Name} - {post.CreatedDateTime.FromGraphDateTime()}" },
{ "o365:From", post.From?.ToString() },
2026-01-22 17:01:13 +01:00
{ "o365:CreatedDateTime", post.CreatedDateTime.FromGraphDateTime().ToString("o", CultureInfo.InvariantCulture) },
{ "o365:LastModifiedDateTime", post.LastModifiedDateTime.FromGraphDateTime().ToString("o", CultureInfo.InvariantCulture) }
2026-01-14 10:23:49 +01:00
}
.WhereNotNull()
.ToDictionary(kvp => kvp.Key, kvp => kvp.Value))
);
}
}
public override Task<Dictionary<string, string?>> GetMinorMetadata(CancellationToken cancellationToken)
=> Task.FromResult(new Dictionary<string, string?>
{
{ "o365:v", "1" },
{ "o365:Id", thread.Id },
{ "o365:Type", SourceItemType.GroupConversationThread.ToString() },
{ "o365:Name", $"Thread: {thread.Topic ?? ""}" },
{ "o365:Topic", thread.Topic },
2026-01-22 17:01:13 +01:00
{ "o365:LastDeliveredDateTime", thread.LastDeliveredDateTime.FromGraphDateTime().ToString("o", CultureInfo.InvariantCulture) }
2026-01-14 10:23:49 +01:00
}
.WhereNotNull()
.ToDictionary(kvp => kvp.Key, kvp => kvp.Value));
}