public async Task <CollectionObject> Get(ActivityStreamFilter filter) { var ret = new List <BaseObject>(); var pipe = this.ctx.GetPipe(); var ctx = new ActivityDeliveryContext { IsReading = true, context = this.ctx, box = this, Filter = filter }; var tryCount = 0; using (var reader = await OpenReader(filter)) { while (true) { var item = await reader.Read(); if (item == null) { if (tryCount == 0) { return(null); } break; } else if (item is Error err) { ret.Add(item); } else if (item is ActivityObject activity) { if (filter.IsMatch(activity)) { ctx.item = activity; var res = await pipe.Pipe(ctx) ?? ctx.item; if (res != null) { ret.Add(res); } } } else { throw new Exception($"Invalid type {item.type}"); } tryCount++; } } if (ctx.Undos.Count > 0) { ret = ret.Where(r => !ctx.Undos.Contains(r.id)).ToList(); } return(ret.ToCollection()); }
public override Task Write(BaseObject item) { if (_filter.IsMatch(item)) { return(base.Write(item)); } else { return(Task.CompletedTask); } }