Improve reactions

This commit is contained in:
Alexey Golub 2018-06-26 01:09:23 +03:00
parent e8436faf66
commit f0cd2dce1b
6 changed files with 43 additions and 33 deletions

View file

@ -1,26 +1,20 @@
using System; namespace DiscordChatExporter.Core.Models
namespace DiscordChatExporter.Core.Models
{ {
// https://discordapp.com/developers/docs/resources/channel#reaction-object
public class Reaction public class Reaction
{ {
public int Count { get; } public int Count { get; }
public bool Me { get; } public string EmojiId { get; }
public string Id { get; } public string EmojiName { get; }
public string Name { get; } public Reaction(int count, string emojiId, string emojiName)
public string Emoji { get; }
public Reaction(int count, bool me, string id, string name)
{ {
Count = count; Count = count;
Me = me; EmojiId = emojiId;
Id = id; EmojiName = emojiName;
Name = name;
Emoji = (id == "" ? name : $"<:{name}:{id}>");
} }
} }
} }

View file

@ -184,10 +184,16 @@
{{~ # Reactions }} {{~ # Reactions }}
<div class="chatlog__reactions"> <div class="chatlog__reactions">
{{ for reaction in message.Reactions}} {{ for reaction in message.Reactions }}
<div class="chatlog__reaction"> <div class="chatlog__reaction">
<div class="chatlog__reaction-emoji">{{ reaction.Emoji | FormatContent }}</div> <span class="chatlog__reaction-emoji">
<div class="chatlog__reaction-count">{{ reaction.Count }}</div> {{ if reaction.EmojiId }}
<img class="emoji emoji--small" title="{{ reaction.EmojiName }}" src="https://cdn.discordapp.com/emojis/{{ reaction.EmojiId }}.png" />
{{ else }}
{{ reaction.EmojiName }}
{{ end }}
</span>
<span class="chatlog__reaction-count">{{ reaction.Count }}</span>
</div> </div>
{{ end }} {{ end }}
</div> </div>

View file

@ -90,5 +90,9 @@ a {
} }
.chatlog__reaction { .chatlog__reaction {
background-color: rgba(255, 255, 255, 0.0392157); background-color: #ffffff0a;
}
.chatlog__reaction-count {
color: #ffffff4d;
} }

View file

@ -51,5 +51,9 @@ a {
} }
.chatlog__reaction { .chatlog__reaction {
background-color: rgba(79, 84, 92, 0.0588235); background-color: #4f545c0f;
}
.chatlog__reaction-count {
color: #99aab5;
} }

View file

@ -38,10 +38,15 @@ img {
margin-right: 1px; margin-right: 1px;
width: 24px; width: 24px;
height: 24px; height: 24px;
vertical-align: -.4em; vertical-align: middle;
} }
.emoji-jumboable { .emoji--small {
width: 16px;
height: 16px;
}
.emoji--large {
width: 32px; width: 32px;
height: 32px; height: 32px;
} }
@ -286,23 +291,21 @@ img {
} }
.chatlog__reactions { .chatlog__reactions {
display: flex; display: flex;
} }
.chatlog__reaction { .chatlog__reaction {
margin: 2px; margin: 6px 2px 2px 2px;
padding: 2px 6px 2px 2px;
border-radius: 3px; border-radius: 3px;
display: block;
padding-right: 6px;
} }
.chatlog__reaction-emoji { .chatlog__reaction-emoji {
display: inline;
margin-left: 3px; margin-left: 3px;
padding-right: 3px; vertical-align: middle;
font-size: large;
} }
.chatlog__reaction-count { .chatlog__reaction-count {
display: inline; font-size: .875em;
vertical-align: middle;
} }

View file

@ -141,11 +141,10 @@ namespace DiscordChatExporter.Core.Services
private Reaction ParseReaction(JToken json) private Reaction ParseReaction(JToken json)
{ {
var count = json["count"].Value<int>(); var count = json["count"].Value<int>();
var me = json["me"].Value<bool>(); var emojiId = json["emoji"]["id"]?.Value<string>();
var id = json["emoji"]["id"]?.ToString(); var emojiName = json["emoji"]["name"].Value<string>();
var name = json["emoji"]["name"].ToString();
return new Reaction(count, me, id, name); return new Reaction(count, emojiId, emojiName);
} }
private Message ParseMessage(JToken json) private Message ParseMessage(JToken json)