2023-10-06 11:19:08 +01:00
|
|
|
import MessageData from "../interfaces/packetTypes/MessageData";
|
2023-09-10 12:59:22 +01:00
|
|
|
import Shared from "../objects/Shared";
|
|
|
|
import PrivateChannel from "../objects/PrivateChannel";
|
|
|
|
import User from "../objects/User";
|
2023-08-20 13:03:01 +01:00
|
|
|
|
2023-09-10 12:59:22 +01:00
|
|
|
export default function PrivateMessage(user:User, message:MessageData) {
|
2023-08-20 13:03:01 +01:00
|
|
|
const shared:Shared = user.shared;
|
|
|
|
const sendingTo = shared.users.getByUsername(message.target);
|
|
|
|
if (!(sendingTo instanceof User)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let channel = shared.privateChatManager.GetChannelByName(`${user.username}${sendingTo.username}`);
|
|
|
|
if (!(channel instanceof PrivateChannel)) {
|
|
|
|
// Try it the other way around
|
|
|
|
channel = shared.privateChatManager.GetChannelByName(`${sendingTo.username}${user.username}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(channel instanceof PrivateChannel)) {
|
|
|
|
channel = shared.privateChatManager.AddChannel(user, sendingTo);
|
|
|
|
}
|
|
|
|
|
|
|
|
channel.SendMessage(user, message.message);
|
|
|
|
}
|