Made the channel event log code similar to the normal event handling code.

This commit is contained in:
flash 2024-05-24 13:11:21 +00:00
parent 5daad52aba
commit d426df91f0

View file

@ -262,19 +262,12 @@ namespace SharpChat {
public void HandleChannelEventLog(string channelName, Action<ISockChatS2CPacket> handler) {
foreach(ChatEventInfo info in EventStorage.GetChannelEventLog(channelName)) {
ISockChatS2CPacket? packet;
switch(info.Type) {
case "msg:add":
string maText = string.Empty;
bool maAction = false;
if(info.Data is not MessageAddEventData msgAdd)
break;
if(info.Data is MessageAddEventData messageAdd) {
maText = messageAdd.Text;
maAction = messageAdd.IsAction;
}
packet = new MessageAddLogS2CPacket(
handler(new MessageAddLogS2CPacket(
info.Id,
info.Created,
info.SenderId,
@ -282,54 +275,47 @@ namespace SharpChat {
info.SenderColour,
info.SenderRank,
info.SenderPerms,
maText,
maAction,
msgAdd.Text,
msgAdd.IsAction,
info.ChannelName.StartsWith('@'),
info.IsBroadcast,
false
);
));
break;
case "user:connect":
packet = new UserConnectLogS2CPacket(
handler(new UserConnectLogS2CPacket(
info.Id,
info.Created,
SockChatUtility.GetUserName(info)
);
));
break;
case "user:disconnect":
packet = new UserDisconnectLogS2CPacket(
handler(new UserDisconnectLogS2CPacket(
info.Id,
info.Created,
SockChatUtility.GetUserName(info),
info.Data is UserDisconnectEventData userDisconnect ? userDisconnect.Reason : UserDisconnectReason.Leave
);
));
break;
case "chan:join":
packet = new UserChannelJoinLogS2CPacket(
handler(new UserChannelJoinLogS2CPacket(
info.Id,
info.Created,
SockChatUtility.GetUserName(info)
);
));
break;
case "chan:leave":
packet = new UserChannelLeaveLogS2CPacket(
handler(new UserChannelLeaveLogS2CPacket(
info.Id,
info.Created,
SockChatUtility.GetUserName(info)
);
break;
default:
packet = null;
));
break;
}
if(packet != null)
handler(packet);
}
}