From 355b8cb8cfdfd036622d7311b3f405f4f2eb07eb Mon Sep 17 00:00:00 2001 From: Ahmed Massoud Date: Sat, 22 Aug 2020 22:14:13 +0300 Subject: [PATCH] Add call time for call status messages (#365) --- DiscordChatExporter.Domain/Discord/Models/Message.cs | 12 ++++++++++-- .../Exporting/Writers/CsvMessageWriter.cs | 1 - .../Exporting/Writers/JsonMessageWriter.cs | 1 + 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/DiscordChatExporter.Domain/Discord/Models/Message.cs b/DiscordChatExporter.Domain/Discord/Models/Message.cs index 7a257e4..120bdf5 100644 --- a/DiscordChatExporter.Domain/Discord/Models/Message.cs +++ b/DiscordChatExporter.Domain/Discord/Models/Message.cs @@ -32,10 +32,12 @@ namespace DiscordChatExporter.Domain.Discord.Models public DateTimeOffset Timestamp { get; } public DateTimeOffset? EditedTimestamp { get; } + public DateTimeOffset? CallEndedTimestamp { get; } public bool IsPinned { get; } public string Content { get; } + public IReadOnlyList Attachments { get; } @@ -51,6 +53,7 @@ namespace DiscordChatExporter.Domain.Discord.Models User author, DateTimeOffset timestamp, DateTimeOffset? editedTimestamp, + DateTimeOffset? callEndedTimestamp, bool isPinned, string content, IReadOnlyList attachments, @@ -63,6 +66,7 @@ namespace DiscordChatExporter.Domain.Discord.Models Author = author; Timestamp = timestamp; EditedTimestamp = editedTimestamp; + CallEndedTimestamp = callEndedTimestamp; IsPinned = isPinned; Content = content; Attachments = attachments; @@ -82,14 +86,16 @@ namespace DiscordChatExporter.Domain.Discord.Models var author = json.GetProperty("author").Pipe(User.Parse); var timestamp = json.GetProperty("timestamp").GetDateTimeOffset(); var editedTimestamp = json.GetPropertyOrNull("edited_timestamp")?.GetDateTimeOffset(); + var callEndedTimestamp = json.GetPropertyOrNull("call")?.GetPropertyOrNull("ended_timestamp")?.GetDateTimeOffset(); var type = (MessageType) json.GetProperty("type").GetInt32(); var isPinned = json.GetPropertyOrNull("pinned")?.GetBoolean() ?? false; + var content = type switch { MessageType.RecipientAdd => "Added a recipient.", MessageType.RecipientRemove => "Removed a recipient.", - MessageType.Call => "Started a call.", + MessageType.Call => $"Started a call that lasted {callEndedTimestamp?.Pipe(t => t - timestamp).Pipe(t => (int) t.TotalMinutes) ?? 0} minutes.", MessageType.ChannelNameChange => "Changed the channel name.", MessageType.ChannelIconChange => "Changed the channel icon.", MessageType.ChannelPinnedMessage => "Pinned a message.", @@ -119,13 +125,15 @@ namespace DiscordChatExporter.Domain.Discord.Models author, timestamp, editedTimestamp, + callEndedTimestamp, isPinned, content, attachments, embeds, reactions, mentionedUsers + ); } } -} \ No newline at end of file +} diff --git a/DiscordChatExporter.Domain/Exporting/Writers/CsvMessageWriter.cs b/DiscordChatExporter.Domain/Exporting/Writers/CsvMessageWriter.cs index c4f33fc..3d4c56b 100644 --- a/DiscordChatExporter.Domain/Exporting/Writers/CsvMessageWriter.cs +++ b/DiscordChatExporter.Domain/Exporting/Writers/CsvMessageWriter.cs @@ -55,7 +55,6 @@ namespace DiscordChatExporter.Domain.Exporting.Writers await _writer.WriteAsync(CsvEncode(buffer.ToString())); } - public override async ValueTask WriteMessageAsync(Message message) { // Author ID diff --git a/DiscordChatExporter.Domain/Exporting/Writers/JsonMessageWriter.cs b/DiscordChatExporter.Domain/Exporting/Writers/JsonMessageWriter.cs index 8fc6928..c3b1570 100644 --- a/DiscordChatExporter.Domain/Exporting/Writers/JsonMessageWriter.cs +++ b/DiscordChatExporter.Domain/Exporting/Writers/JsonMessageWriter.cs @@ -197,6 +197,7 @@ namespace DiscordChatExporter.Domain.Exporting.Writers _writer.WriteString("type", message.Type.ToString()); _writer.WriteString("timestamp", message.Timestamp); _writer.WriteString("timestampEdited", message.EditedTimestamp); + _writer.WriteString("callEndedTimestamp", message.CallEndedTimestamp); _writer.WriteBoolean("isPinned", message.IsPinned); // Content