Implement linking event to previous in chat room when saving event

This commit is contained in:
ChronosX88 2021-03-07 23:12:25 +03:00
parent 2485612c87
commit 6ea903ebb9
Signed by: ChronosXYZ
GPG Key ID: 085A69A82C8C511A
2 changed files with 18 additions and 3 deletions

View File

@ -43,8 +43,23 @@ namespace ChatSubsystem.Storage
await events.InsertOneAsync(e); await events.InsertOneAsync(e);
return; return;
} }
// TODO link to previous events in the room e.PrevID = res.Id;
res.PrevID = res.Id;
connectToField = (FieldDefinition<Event, EntityID>)"PrevEvents";
var opts = new AggregateGraphLookupOptions<Event, Event, EventWithChildren>()
{
RestrictSearchWithMatch = "{ ChatId: "+e.ChatId+" }"
};
res = await events.Aggregate()
.GraphLookup(events, connectFromField, connectToField, startWith, @as, opts)
.Match("{ Children: { $size: 0 } }").FirstOrDefaultAsync();
if (res == null)
{
await events.InsertOneAsync(e);
return;
}
e.PrevEvent = res.EventID;
await events.InsertOneAsync(e); await events.InsertOneAsync(e);
} }

View File

@ -13,7 +13,7 @@ namespace ChatSubsystem.Storage.Models
public EntityID ChatId { get; set; } public EntityID ChatId { get; set; }
public string Type { get; set; } public string Type { get; set; }
public long Timestamp { get; set; } public long Timestamp { get; set; }
public EntityID[] PrevEvents { get; set; } public EntityID PrevEvent { get; set; }
public ObjectId PrevID { get; set; } public ObjectId PrevID { get; set; }
public EntityID OriginServer { get; set; } public EntityID OriginServer { get; set; }
public EventContent Content { get; set; } public EventContent Content { get; set; }