-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from DevTown/main
Functions from @SlimeQ and more
- Loading branch information
Showing
44 changed files
with
884 additions
and
250 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,31 @@ | ||
namespace Matrix.Sdk.Core.Domain.MatrixRoom | ||
namespace Matrix.Sdk.Core.Domain.Room | ||
{ | ||
using System.Collections.Generic; | ||
using Infrastructure.Dto.Sync; | ||
using Infrastructure.Dto.Sync.Event.Room; | ||
using RoomEvent; | ||
|
||
public record MatrixRoom | ||
public record MatrixRoom(string Id, MatrixRoomStatus Status, List<string> JoinedUserIds) | ||
{ | ||
public MatrixRoom(string id, MatrixRoomStatus status, List<string> joinedUserIds) | ||
public static MatrixRoom Create(string roomId, RoomResponse joinedRoom, MatrixRoomStatus status) | ||
{ | ||
Id = id; | ||
Status = status; | ||
JoinedUserIds = joinedUserIds; | ||
} | ||
var joinedUserIds = new List<string>(); | ||
foreach (RoomEventResponse timelineEvent in joinedRoom.Timeline.Events) | ||
if (JoinRoomEvent.Factory.TryCreateFrom(timelineEvent, roomId, out JoinRoomEvent joinRoomEvent)) | ||
joinedUserIds.Add(joinRoomEvent!.SenderUserId); | ||
|
||
public MatrixRoom(string id, MatrixRoomStatus status) | ||
{ | ||
Id = id; | ||
Status = status; | ||
JoinedUserIds = new List<string>(); | ||
return new MatrixRoom(roomId, status, joinedUserIds); | ||
} | ||
|
||
public string Id { get; } | ||
|
||
public MatrixRoomStatus Status { get; } | ||
public static MatrixRoom CreateInvite(string roomId, InvitedRoom invitedRoom) | ||
{ | ||
var joinedUserIds = new List<string>(); | ||
foreach (RoomStrippedState timelineEvent in invitedRoom.InviteState.Events) | ||
if (JoinRoomEvent.Factory.TryCreateFromStrippedState(timelineEvent, roomId, | ||
out JoinRoomEvent joinRoomEvent)) | ||
joinedUserIds.Add(joinRoomEvent!.SenderUserId); | ||
|
||
public List<string> JoinedUserIds { get; } | ||
return new MatrixRoom(roomId, MatrixRoomStatus.Invited, joinedUserIds); | ||
} | ||
} | ||
} |
71 changes: 0 additions & 71 deletions
71
Matrix.Sdk/Core/Domain/MatrixRoom/MatrixRoomEventFactory.cs
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,62 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Matrix.Sdk.Core.Infrastructure.Dto.Sync; | ||
using Matrix.Sdk.Core.Infrastructure.Dto.Sync.Event.Room; | ||
|
||
namespace Matrix.Sdk.Core.Domain.RoomEvent | ||
{ | ||
public abstract record BaseRoomEvent(string RoomId, string SenderUserId); | ||
public abstract record BaseRoomEvent(string EventId, string RoomId, string SenderUserId, DateTimeOffset Timestamp) | ||
{ | ||
public static List<BaseRoomEvent> Create(string roomId, RoomResponse joinedRoom) | ||
{ | ||
var roomEvents = new List<BaseRoomEvent>(); | ||
|
||
foreach (RoomEventResponse timelineEvent in joinedRoom.Timeline.Events) | ||
{ | ||
var e = Create(roomId, timelineEvent); | ||
if (e != null) roomEvents.Add(e); | ||
|
||
} | ||
return roomEvents; | ||
} | ||
|
||
public static BaseRoomEvent Create(string roomId, RoomEventResponse timelineEvent) | ||
{ | ||
if (JoinRoomEvent.Factory.TryCreateFrom(timelineEvent, roomId, out JoinRoomEvent joinRoomEvent)) return joinRoomEvent; | ||
if (CreateRoomEvent.Factory.TryCreateFrom(timelineEvent, roomId, out var createRoomEvent)) return createRoomEvent; | ||
if (InviteToRoomEvent.Factory.TryCreateFrom(timelineEvent, roomId, out var inviteToRoomEvent)) return inviteToRoomEvent; | ||
if (TextMessageEvent.Factory.TryCreateFrom(timelineEvent, roomId, out var textMessageEvent)) return textMessageEvent; | ||
if (ImageMessageEvent.Factory.TryCreateFrom(timelineEvent, roomId, out var imageMessageEvent)) return imageMessageEvent; | ||
if (RedactionEvent.Factory.TryCreateFrom(timelineEvent, roomId, out var redactionEvent)) return redactionEvent; | ||
if (ReactionEvent.Factory.TryCreateFrom(timelineEvent, roomId, out var reactionEvent)) return reactionEvent; | ||
return null; | ||
} | ||
|
||
public static List<BaseRoomEvent> CreateFromInvited(string roomId, InvitedRoom invitedRoom) | ||
{ | ||
var roomEvents = new List<BaseRoomEvent>(); | ||
|
||
foreach (RoomStrippedState inviteStateEvent in invitedRoom.InviteState.Events) | ||
{ | ||
var e = CreateFromInvited(roomId, inviteStateEvent); | ||
if (e != null) | ||
{ | ||
roomEvents.Add(e); | ||
} | ||
} | ||
return roomEvents; | ||
} | ||
|
||
public static BaseRoomEvent CreateFromInvited(string roomId, RoomStrippedState inviteStateEvent) | ||
{ | ||
if (JoinRoomEvent.Factory.TryCreateFromStrippedState(inviteStateEvent, roomId, out var joinRoomEvent)) return joinRoomEvent; | ||
if (CreateRoomEvent.Factory.TryCreateFromStrippedState(inviteStateEvent, roomId, out var createRoomEvent)) return createRoomEvent; | ||
if (InviteToRoomEvent.Factory.TryCreateFromStrippedState(inviteStateEvent, roomId, out var inviteToRoomEvent)) return inviteToRoomEvent; | ||
if (TextMessageEvent.Factory.TryCreateFromStrippedState(inviteStateEvent, roomId, out var textMessageEvent)) return textMessageEvent; | ||
if (ImageMessageEvent.Factory.TryCreateFromStrippedState(inviteStateEvent, roomId, out var imageMessageEvent)) return imageMessageEvent; | ||
if (RedactionEvent.Factory.TryCreateFromStrippedState(inviteStateEvent, roomId, out var redactionEvent)) return redactionEvent; | ||
if (ReactionEvent.Factory.TryCreateFromStrippedState(inviteStateEvent, roomId, out var reactionEvent)) return reactionEvent; | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Matrix.Sdk.Core.Infrastructure.Dto.Event; | ||
using Newtonsoft.Json; | ||
|
||
namespace Matrix.Sdk.Core.Domain.RoomEvent | ||
{ | ||
public record EditEvent(MessageType MessageType, string Message, string EventId) | ||
{ | ||
public string body = $"* {Message}"; | ||
public MessageType msgtype { get; } = MessageType; | ||
|
||
[JsonProperty("m.new_content")] | ||
public MessageEvent newContent = new MessageEvent(MessageType, Message); | ||
|
||
[JsonProperty("m.relates_to")] | ||
public RelatesTo mRelatesTo = new RelatesTo(EventId); | ||
|
||
public record RelatesTo(string evntid) | ||
{ | ||
public string event_id = evntid; | ||
public string rel_type = "m.replace"; | ||
} | ||
} | ||
} |
Oops, something went wrong.