about summary refs log tree commit diff
path: root/BugMine.Sdk/BugMineProject.cs
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2024-04-20 23:48:43 +0200
committerRory& <root@rory.gay>2024-04-20 23:48:43 +0200
commit68fe1a2284045908d92ef06c1c26cd937ded784e (patch)
tree71144f404f060888dcc5e4036e038abe857adc4e /BugMine.Sdk/BugMineProject.cs
parentStart adding pages (diff)
downloadBugMine-68fe1a2284045908d92ef06c1c26cd937ded784e.tar.xz
Add basic project management
Diffstat (limited to 'BugMine.Sdk/BugMineProject.cs')
-rw-r--r--BugMine.Sdk/BugMineProject.cs43
1 files changed, 43 insertions, 0 deletions
diff --git a/BugMine.Sdk/BugMineProject.cs b/BugMine.Sdk/BugMineProject.cs
new file mode 100644

index 0000000..c90ba6e --- /dev/null +++ b/BugMine.Sdk/BugMineProject.cs
@@ -0,0 +1,43 @@ +using System.Text.Json.Nodes; +using LibMatrix.Homeservers; +using LibMatrix.RoomTypes; + +namespace BugMine.Web.Classes; + +public class BugMineProject(GenericRoom room) { + public const string RoomType = "gay.rory.bugmine.project"; + public GenericRoom Room { get; } = room; + public ProjectInfo Info { get; set; } + public string ProjectSlug { get; set; } + + public async Task<BugMineProject> InitializeAsync() { + Info = (await Room.GetStateAsync<ProjectInfo>(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<BugMineIssue> CreateIssue(BugMineIssueData issue) { + // add relation to room creation event + issue.RelatesTo = new() { + EventId = (await Room.GetStateEventAsync("m.room.create")).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 static class ProjectRoomExtensions { + public static async Task<BugMineProject> AsBugMineProject(this GenericRoom room) { + return await new BugMineProject(room).InitializeAsync(); + } +} \ No newline at end of file