Add reviewed AI drafts and durable staff-approved Gmail delivery

This commit is contained in:
wolf-demon
2026-09-10 09:26:40 +01:00
parent 41f8d805e8
commit b1548ed6e6
19 changed files with 456 additions and 22 deletions
+4
View File
@@ -20,9 +20,11 @@ public interface IStore
Task<bool> TryLease(string id, string owner);
Task ReleaseLease(string id, string owner);
Task Import(Conversation message);
Task<List<Conversation>> Deliveries();
}
public sealed class MongoStore : IStore
{
public Task<List<Conversation>> Deliveries() => Collection<Conversation>().Find(x => x.Delivery != null && (x.Delivery.State == "Pending" || x.Delivery.State == "Sending")).SortBy(x => x.Delivery!.UpdatedAt).Limit(100).ToListAsync();
private readonly IMongoDatabase db;
public MongoStore(IConfiguration config)
{
@@ -42,6 +44,7 @@ public sealed class MongoStore : IStore
await Collection<StaffUser>().Indexes.CreateOneAsync(new CreateIndexModel<StaffUser>(Builders<StaffUser>.IndexKeys.Ascending(x => x.Email), new() { Unique = true }));
await Collection<Conversation>().Indexes.CreateOneAsync(new CreateIndexModel<Conversation>(Builders<Conversation>.IndexKeys.Ascending(x => x.HotelId).Ascending(x => x.MailboxId).Ascending(x => x.ProviderMessageId), new() { Unique = true }));
await Collection<Conversation>().Indexes.CreateOneAsync(new CreateIndexModel<Conversation>(Builders<Conversation>.IndexKeys.Ascending(x => x.HotelId).Descending(x => x.ReceivedAt)));
await Collection<Conversation>().Indexes.CreateOneAsync(new CreateIndexModel<Conversation>(Builders<Conversation>.IndexKeys.Ascending("Delivery.State").Ascending("Delivery.UpdatedAt")));
await Collection<Mailbox>().Indexes.CreateOneAsync(new CreateIndexModel<Mailbox>(Builders<Mailbox>.IndexKeys.Ascending(x => x.Email), new() { Unique = true }));
await Collection<OAuthRequest>().Indexes.CreateOneAsync(new CreateIndexModel<OAuthRequest>(Builders<OAuthRequest>.IndexKeys.Ascending(x => x.ExpiresAt), new() { ExpireAfter = TimeSpan.Zero }));
}
@@ -95,6 +98,7 @@ public sealed class MongoStore : IStore
// Explicit Development-only preview store. Production never falls back to this.
public sealed class PreviewStore : IStore
{
public Task<List<Conversation>> Deliveries() => Task.FromResult(rows.Where(x => x.Key.StartsWith("Conversation:")).Select(x => Clone<Conversation>(x.Value)).Where(x => x.Delivery?.State is "Pending" or "Sending").ToList());
private readonly ConcurrentDictionary<string, string> rows = new();
private readonly object gate = new();
static string Key<T>(string id) => typeof(T).Name + ":" + id;