More cleanup
This commit is contained in:
+28
-20
@@ -8,7 +8,8 @@ namespace ChatTwo;
|
||||
[Union(0, typeof(TextChunk))]
|
||||
[Union(1, typeof(IconChunk))]
|
||||
[MessagePackObject]
|
||||
public abstract class Chunk {
|
||||
public abstract class Chunk
|
||||
{
|
||||
[IgnoreMember]
|
||||
[BsonIgnore] // used by LegacyMessageImporter
|
||||
internal Message? Message { get; set; }
|
||||
@@ -20,12 +21,14 @@ public abstract class Chunk {
|
||||
[MessagePackFormatter(typeof(PayloadMessagePackFormatter))]
|
||||
public Payload? Link { get; set; }
|
||||
|
||||
protected Chunk(ChunkSource source, Payload? link) {
|
||||
protected Chunk(ChunkSource source, Payload? link)
|
||||
{
|
||||
Source = source;
|
||||
Link = link;
|
||||
}
|
||||
|
||||
internal SeString? GetSeString() => Source switch {
|
||||
internal SeString? GetSeString() => Source switch
|
||||
{
|
||||
ChunkSource.None => null,
|
||||
ChunkSource.Sender => Message?.SenderSource,
|
||||
ChunkSource.Content => Message?.ContentSource,
|
||||
@@ -35,26 +38,27 @@ public abstract class Chunk {
|
||||
/// <summary>
|
||||
/// Get some basic text for use in generating hashes.
|
||||
/// </summary>
|
||||
internal string StringValue() {
|
||||
switch (this) {
|
||||
case TextChunk text:
|
||||
return text.Content;
|
||||
case IconChunk icon:
|
||||
return icon.Icon.ToString();
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
internal string StringValue()
|
||||
{
|
||||
return this switch
|
||||
{
|
||||
TextChunk text => text.Content,
|
||||
IconChunk icon => icon.Icon.ToString(),
|
||||
_ => ""
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public enum ChunkSource {
|
||||
public enum ChunkSource
|
||||
{
|
||||
None,
|
||||
Sender,
|
||||
Content,
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
public class TextChunk : Chunk {
|
||||
public class TextChunk : Chunk
|
||||
{
|
||||
[Key(2)]
|
||||
public ChatType? FallbackColour { get; set; }
|
||||
[Key(3)]
|
||||
@@ -66,13 +70,14 @@ public class TextChunk : Chunk {
|
||||
[Key(6)]
|
||||
public string Content { get; set; }
|
||||
|
||||
internal TextChunk(ChunkSource source, Payload? link, string content) : base(source, link) {
|
||||
internal TextChunk(ChunkSource source, Payload? link, string content) : base(source, link)
|
||||
{
|
||||
Content = content;
|
||||
}
|
||||
|
||||
// ReSharper disable once UnusedMember.Global // Used by MessagePack
|
||||
public TextChunk(ChunkSource source, Payload? link, ChatType? fallbackColour, uint? foreground, uint? glow,
|
||||
bool italic, string content) : base(source, link) {
|
||||
public TextChunk(ChunkSource source, Payload? link, ChatType? fallbackColour, uint? foreground, uint? glow, bool italic, string content) : base(source, link)
|
||||
{
|
||||
FallbackColour = fallbackColour;
|
||||
Foreground = foreground;
|
||||
Glow = glow;
|
||||
@@ -85,7 +90,8 @@ public class TextChunk : Chunk {
|
||||
/// </summary>
|
||||
public TextChunk NewWithStyle(ChunkSource source, Payload? link, string content)
|
||||
{
|
||||
return new TextChunk(source, link, content) {
|
||||
return new TextChunk(source, link, content)
|
||||
{
|
||||
FallbackColour = FallbackColour,
|
||||
Foreground = Foreground,
|
||||
Glow = Glow,
|
||||
@@ -95,11 +101,13 @@ public class TextChunk : Chunk {
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
public class IconChunk : Chunk {
|
||||
public class IconChunk : Chunk
|
||||
{
|
||||
[Key(2)]
|
||||
public BitmapFontIcon Icon { get; set; }
|
||||
|
||||
public IconChunk(ChunkSource source, Payload? link, BitmapFontIcon icon) : base(source, link) {
|
||||
public IconChunk(ChunkSource source, Payload? link, BitmapFontIcon icon) : base(source, link)
|
||||
{
|
||||
Icon = icon;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user