Use virtual channel name for DMs.

This commit is contained in:
flash 2023-02-16 23:56:50 +01:00
parent a5089f14b8
commit 1466562c54
3 changed files with 13 additions and 8 deletions

View file

@ -139,5 +139,11 @@ namespace SharpChat {
|| string.Equals(name, Nickname, StringComparison.InvariantCultureIgnoreCase)
|| string.Equals(name, DisplayName, StringComparison.InvariantCultureIgnoreCase);
}
public static string GetDMChannelName(ChatUser user1, ChatUser user2) {
return user1.UserId < user2.UserId
? $"@{user1.UserId}-{user2.UserId}"
: $"@{user2.UserId}-{user1.UserId}";
}
}
}

View file

@ -29,17 +29,19 @@ namespace SharpChat.Commands {
return;
string whisperStr = string.Join(' ', ctx.Args.Skip(1));
string whisperChan = ChatUser.GetDMChannelName(ctx.User, whisperUser);
DateTimeOffset dateTime = DateTimeOffset.Now;
ctx.Chat.SendTo(whisperUser, new ChatMessageAddPacket(new ChatMessage {
DateTime = DateTimeOffset.Now,
ChannelName = string.Empty,
DateTime = dateTime,
ChannelName = whisperChan,
Sender = ctx.User,
Text = whisperStr,
Flags = ChatMessageFlags.Private,
}));
ctx.Chat.SendTo(ctx.User, new ChatMessageAddPacket(new ChatMessage {
DateTime = DateTimeOffset.Now,
ChannelName = string.Empty,
DateTime = dateTime,
ChannelName = whisperChan,
Sender = ctx.User,
Text = $"{whisperUser.DisplayName} {whisperStr}",
Flags = ChatMessageFlags.Private,

View file

@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Threading;
namespace SharpChat {
public interface IServerPacket {
@ -8,13 +7,11 @@ namespace SharpChat {
}
public abstract class ServerPacket : IServerPacket {
private static long SequenceIdCounter = 0;
public long SequenceId { get; }
public ServerPacket(long sequenceId = 0) {
// Allow sequence id to be manually set for potential message repeats
SequenceId = sequenceId > 0 ? sequenceId : Interlocked.Increment(ref SequenceIdCounter);
SequenceId = sequenceId > 0 ? sequenceId : SharpId.Next();
}
public abstract IEnumerable<string> Pack();