mirror of
https://github.com/cadmium-im/zirconium-sharp.git
synced 2024-11-08 11:41:04 +00:00
Implement linking event to previous in chat room when saving event
This commit is contained in:
parent
2485612c87
commit
6ea903ebb9
@ -43,8 +43,23 @@ namespace ChatSubsystem.Storage
|
||||
await events.InsertOneAsync(e);
|
||||
return;
|
||||
}
|
||||
// TODO link to previous events in the room
|
||||
res.PrevID = res.Id;
|
||||
e.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);
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ namespace ChatSubsystem.Storage.Models
|
||||
public EntityID ChatId { get; set; }
|
||||
public string Type { get; set; }
|
||||
public long Timestamp { get; set; }
|
||||
public EntityID[] PrevEvents { get; set; }
|
||||
public EntityID PrevEvent { get; set; }
|
||||
public ObjectId PrevID { get; set; }
|
||||
public EntityID OriginServer { get; set; }
|
||||
public EventContent Content { get; set; }
|
||||
|
Loading…
Reference in New Issue
Block a user