- API 15
- Migrate config for API 15 - Migrate database for API 15 - Allow usage of new target source - Implement first tell target option
This commit is contained in:
+26
-69
@@ -10,74 +10,30 @@ using FFXIVClientStructs.FFXIV.Client.UI.Agent;
|
||||
|
||||
namespace ChatTwo;
|
||||
|
||||
internal class SortCode
|
||||
public partial class Message
|
||||
{
|
||||
internal ChatType Type { get; }
|
||||
internal ChatSource Source { get; }
|
||||
public Guid Id { get; } = Guid.NewGuid();
|
||||
public ulong Receiver { get; }
|
||||
public ulong ContentId { get; set; }
|
||||
public ulong AccountId { get; set; } // 0 if not set
|
||||
|
||||
public SortCode(ChatType type, ChatSource source)
|
||||
{
|
||||
Type = type;
|
||||
Source = source;
|
||||
}
|
||||
public DateTimeOffset Date { get; }
|
||||
public ChatCode Code { get; }
|
||||
public List<Chunk> Sender { get; }
|
||||
public List<Chunk> Content { get; private set; }
|
||||
|
||||
internal SortCode(uint raw)
|
||||
{
|
||||
Type = (ChatType)(raw >> 16);
|
||||
Source = (ChatSource)(raw & 0xFFFF);
|
||||
}
|
||||
public SeString SenderSource { get; }
|
||||
public SeString ContentSource { get; }
|
||||
|
||||
internal uint Encode()
|
||||
{
|
||||
return ((uint) Type << 16) | (uint) Source;
|
||||
}
|
||||
|
||||
private bool Equals(SortCode other)
|
||||
{
|
||||
return Type == other.Type && Source == other.Source;
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj))
|
||||
return false;
|
||||
|
||||
if (ReferenceEquals(this, obj))
|
||||
return true;
|
||||
|
||||
return obj.GetType() == GetType() && Equals((SortCode) obj);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked { return ((int) Type * 397) ^ (int) Source; }
|
||||
}
|
||||
}
|
||||
|
||||
internal partial class Message
|
||||
{
|
||||
internal Guid Id { get; } = Guid.NewGuid();
|
||||
internal ulong Receiver { get; }
|
||||
internal ulong ContentId { get; set; }
|
||||
internal ulong AccountId { get; set; } // 0 if not set
|
||||
|
||||
internal DateTimeOffset Date { get; }
|
||||
internal ChatCode Code { get; }
|
||||
internal List<Chunk> Sender { get; }
|
||||
internal List<Chunk> Content { get; private set; }
|
||||
|
||||
internal SeString SenderSource { get; }
|
||||
internal SeString ContentSource { get; }
|
||||
|
||||
internal SortCode SortCode { get; }
|
||||
internal Guid ExtraChatChannel { get; }
|
||||
public int SortCodeV2 { get; }
|
||||
public Guid ExtraChatChannel { get; }
|
||||
|
||||
// Not stored in the database:
|
||||
internal int Hash { get; }
|
||||
internal Dictionary<Guid, float?> Height { get; } = new();
|
||||
internal Dictionary<Guid, bool> IsVisible { get; } = new();
|
||||
public int Hash { get; }
|
||||
public Dictionary<Guid, float?> Height { get; } = new();
|
||||
public Dictionary<Guid, bool> IsVisible { get; } = new();
|
||||
|
||||
internal Message(ulong receiver, ulong contentId, ulong accountId, ChatCode code, List<Chunk> sender, List<Chunk> content, SeString senderSource, SeString contentSource)
|
||||
public Message(ulong receiver, ulong contentId, ulong accountId, ChatCode code, List<Chunk> sender, List<Chunk> content, SeString senderSource, SeString contentSource)
|
||||
{
|
||||
var extraChatChannel = ExtractExtraChatChannel(contentSource);
|
||||
Receiver = receiver;
|
||||
@@ -89,7 +45,7 @@ internal partial class Message
|
||||
Content = CheckMessageContent(content, extraChatChannel);
|
||||
SenderSource = senderSource;
|
||||
ContentSource = contentSource;
|
||||
SortCode = new SortCode(Code.Type, Code.Source);
|
||||
SortCodeV2 = Code.ToSortCodeV2();
|
||||
ExtraChatChannel = extraChatChannel;
|
||||
Hash = GenerateHash();
|
||||
|
||||
@@ -97,7 +53,7 @@ internal partial class Message
|
||||
chunk.Message = this;
|
||||
}
|
||||
|
||||
internal Message(Guid id, ulong receiver, ulong contentId, DateTimeOffset date, ChatCode code, List<Chunk> sender, List<Chunk> content, SeString senderSource, SeString contentSource, SortCode sortCode, Guid extraChatChannel)
|
||||
public Message(Guid id, ulong receiver, ulong contentId, DateTimeOffset date, ChatCode code, List<Chunk> sender, List<Chunk> content, SeString senderSource, SeString contentSource, Guid extraChatChannel)
|
||||
{
|
||||
Id = id;
|
||||
Receiver = receiver;
|
||||
@@ -110,7 +66,7 @@ internal partial class Message
|
||||
Content = content;
|
||||
SenderSource = senderSource;
|
||||
ContentSource = contentSource;
|
||||
SortCode = sortCode;
|
||||
SortCodeV2 = code.ToSortCodeV2();
|
||||
ExtraChatChannel = extraChatChannel;
|
||||
Hash = GenerateHash();
|
||||
|
||||
@@ -118,25 +74,26 @@ internal partial class Message
|
||||
chunk.Message = this;
|
||||
}
|
||||
|
||||
internal static Message FakeMessage(List<Chunk> content, ChatCode code)
|
||||
public static Message FakeMessage(List<Chunk> content, ChatCode code)
|
||||
{
|
||||
return new Message(0, 0, 0, code, [], content, new SeString(), new SeString());
|
||||
}
|
||||
|
||||
internal bool Matches(Dictionary<ChatType, ChatSource> channels, bool allExtraChatChannels, HashSet<Guid> extraChatChannels)
|
||||
public bool Matches(Dictionary<ChatType, (ChatSource Source, ChatSource Target)> channels, bool allExtraChatChannels, HashSet<Guid> extraChatChannels)
|
||||
{
|
||||
if (ExtraChatChannel != Guid.Empty)
|
||||
return allExtraChatChannels || extraChatChannels.Contains(ExtraChatChannel);
|
||||
|
||||
var source = (ChatSource)(1 << (int)Code.Source);
|
||||
var target = (ChatSource)(1 << (int)Code.Target);
|
||||
return Code.Type.IsGm()
|
||||
|| channels.TryGetValue(Code.Type, out var sources)
|
||||
&& (Code.Source is 0 or (ChatSource) 1
|
||||
|| sources.HasFlag(Code.Source));
|
||||
&& (Code.Source is 0 || sources.Source.HasFlag(source) || sources.Target.HasFlag(target));
|
||||
}
|
||||
|
||||
private int GenerateHash()
|
||||
{
|
||||
var hash = SortCode.GetHashCode()
|
||||
var hash = SortCodeV2.GetHashCode()
|
||||
^ ExtraChatChannel.GetHashCode()
|
||||
^ string.Join("", Sender.Select(c => c.StringValue())).GetHashCode()
|
||||
^ string.Join("", Content.Select(c => c.StringValue())).GetHashCode();
|
||||
|
||||
Reference in New Issue
Block a user