From 3054b456dcb54f069a5d8aaa615c1dfe060eef9b Mon Sep 17 00:00:00 2001 From: Rory& Date: Thu, 25 Apr 2024 06:31:52 +0200 Subject: Add projects logic, start of issues --- BugMine.Sdk/BugMineProject.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'BugMine.Sdk/BugMineProject.cs') diff --git a/BugMine.Sdk/BugMineProject.cs b/BugMine.Sdk/BugMineProject.cs index c90ba6e..babb680 100644 --- a/BugMine.Sdk/BugMineProject.cs +++ b/BugMine.Sdk/BugMineProject.cs @@ -1,4 +1,5 @@ using System.Text.Json.Nodes; +using LibMatrix.EventTypes.Spec.State; using LibMatrix.Homeservers; using LibMatrix.RoomTypes; @@ -13,27 +14,34 @@ public class BugMineProject(GenericRoom room) { public async Task InitializeAsync() { Info = (await Room.GetStateAsync(ProjectInfo.EventId))!; var alias = await room.GetCanonicalAliasAsync(); - + if (alias != null) ProjectSlug = alias.Alias?[1..] ?? room.RoomId; else ProjectSlug = room.RoomId; - + return this; } public async Task CreateIssue(BugMineIssueData issue) { // add relation to room creation event issue.RelatesTo = new() { - EventId = (await Room.GetStateEventAsync("m.room.create")).EventId, + EventId = await room.GetStateEventIdAsync(RoomCreateEventContent.EventId), RelationType = "gay.rory.bugmine.issue" }; var eventId = await Room.SendTimelineEventAsync(BugMineIssueData.EventId, issue); - + // return new BugMineIssueAccessor(Room, await Room.GetEventAsync<>(eventId)); var evt = await room.GetEventAsync(eventId.EventId); Console.WriteLine(evt); return new BugMineIssue(Room, evt); } + + public async IAsyncEnumerable GetIssues() { + var creationEventId = await room.GetStateEventIdAsync(RoomCreateEventContent.EventId); + await foreach (var evt in room.GetRelatedEventsAsync(creationEventId, "gay.rory.bugmine.issue", BugMineIssueData.EventId)) { + yield return new BugMineIssue(Room, evt); + } + } } public static class ProjectRoomExtensions { -- cgit 1.5.1