Authorize data sync on connected agent registration
This commit is contained in:
@@ -47,11 +47,14 @@ public sealed class DatabaseMessageSyncCollector : IRemoteDataCollector
|
||||
var cursors = string.Equals(checkpoint.SourceGeneration, sourceGeneration, StringComparison.Ordinal)
|
||||
? checkpoint.ConfirmedCursors
|
||||
: new Dictionary<string, long>(StringComparer.Ordinal);
|
||||
var chatScopes = scopes.DistinctBy(scope => $"{scope.ChatType}:{scope.ChatId}").ToArray();
|
||||
var requestedScopes = scopes.DistinctBy(scope => $"{scope.ChatType}:{scope.ChatId}").ToArray();
|
||||
var directory = await WechatSessionDbReader.ReadAuthorizedAsync(account, requestedScopes, cancellationToken).ConfigureAwait(false);
|
||||
var chatScopes = requestedScopes.Any(scope => scope.ChatId == "*")
|
||||
? directory.Conversations.Select(entry => new RemoteReportingScope(entry.ChatId, entry.ChatType)).ToArray()
|
||||
: requestedScopes;
|
||||
var chatIds = chatScopes.Select(scope => scope.ChatId).Distinct(StringComparer.Ordinal).ToArray();
|
||||
var page = await WechatMessageDbReader.ReadIncrementalAsync(
|
||||
account.AccountRootPath, account.Databases, chatIds, cursors, perChatLimit, cancellationToken, overlapRows).ConfigureAwait(false);
|
||||
var directory = await WechatSessionDbReader.ReadAuthorizedAsync(account, chatScopes, cancellationToken).ConfigureAwait(false);
|
||||
var scopeByChat = chatScopes
|
||||
.GroupBy(scope => scope.ChatId, StringComparer.Ordinal)
|
||||
.ToDictionary(group => group.Key, group => group.First(), StringComparer.Ordinal);
|
||||
|
||||
@@ -56,9 +56,15 @@ public static class WechatSessionDbReader
|
||||
.Where(scope => !string.IsNullOrWhiteSpace(scope.ChatId))
|
||||
.DistinctBy(scope => $"{scope.ChatType}:{scope.ChatId}")
|
||||
.ToArray();
|
||||
var allChats = authorized.Any(scope => scope.ChatId == "*");
|
||||
var allowed = authorized
|
||||
.Where(scope => scope.ChatId != "*")
|
||||
.Select(scope => (scope.ChatId, scope.ChatType))
|
||||
.ToHashSet();
|
||||
var allowedTypes = authorized
|
||||
.Where(scope => scope.ChatId == "*")
|
||||
.Select(scope => scope.ChatType)
|
||||
.ToHashSet();
|
||||
var directoryRows = rows
|
||||
.Select(row =>
|
||||
{
|
||||
@@ -75,7 +81,9 @@ public static class WechatSessionDbReader
|
||||
LastActivityAt = timestamp > 0 ? DateTimeOffset.FromUnixTimeSeconds(timestamp) : (DateTimeOffset?)null
|
||||
};
|
||||
})
|
||||
.Where(row => allowed.Contains((row.ChatId, row.ChatType)))
|
||||
.Where(row => allChats
|
||||
? allowedTypes.Contains(row.ChatType)
|
||||
: allowed.Contains((row.ChatId, row.ChatType)))
|
||||
.ToArray();
|
||||
|
||||
IReadOnlyDictionary<string, string> names;
|
||||
|
||||
Reference in New Issue
Block a user