mirror of
https://github.com/hack-chat/main.git
synced 2024-03-22 13:20:33 +08:00
Updated Whisper
This commit is contained in:
parent
866fa9bcff
commit
308130e2b0
|
@ -70,7 +70,7 @@ export async function run({
|
|||
// build invite
|
||||
const outgoingPayload = {
|
||||
cmd: 'invite',
|
||||
channel: socket.channel,
|
||||
channel: socket.channel, // @todo Multichannel
|
||||
from: socket.userid,
|
||||
to: targetUser.userid,
|
||||
inviteChannel: channel,
|
||||
|
|
|
@ -4,7 +4,16 @@
|
|||
and accept a `userid` rather than `nick`
|
||||
*/
|
||||
|
||||
import * as UAC from '../utility/UAC/_info';
|
||||
import {
|
||||
findUser,
|
||||
} from '../utility/_Channels';
|
||||
import {
|
||||
Errors,
|
||||
} from '../utility/_Constants';
|
||||
import {
|
||||
legacyWhisperOut,
|
||||
legacyWhisperReply,
|
||||
} from '../utility/_LegacyFunctions';
|
||||
|
||||
// module support functions
|
||||
|
||||
|
@ -26,7 +35,12 @@ const parseText = (text) => {
|
|||
|
||||
// module main
|
||||
export async function run({ server, socket, payload }) {
|
||||
// check user input
|
||||
// if this is a legacy client add missing params to payload
|
||||
if (socket.hcProtocol === 1) {
|
||||
payload.channel = socket.channel; // eslint-disable-line no-param-reassign
|
||||
}
|
||||
|
||||
// verify user input
|
||||
const text = parseText(payload.text);
|
||||
|
||||
if (!text) {
|
||||
|
@ -44,41 +58,37 @@ export async function run({ server, socket, payload }) {
|
|||
}, socket);
|
||||
}
|
||||
|
||||
const targetNick = payload.nick;
|
||||
if (!UAC.verifyNickname(targetNick)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// find target user
|
||||
let targetClient = server.findSockets({ channel: socket.channel, nick: targetNick });
|
||||
|
||||
if (targetClient.length === 0) {
|
||||
const targetUser = findUser(server, payload);
|
||||
if (!targetUser) {
|
||||
return server.reply({
|
||||
cmd: 'warn', // @todo Add numeric error code as `id`
|
||||
text: 'Could not find user in channel',
|
||||
cmd: 'warn',
|
||||
text: 'Could not find user in that channel',
|
||||
id: Errors.Global.UNKNOWN_USER,
|
||||
channel: socket.channel, // @todo Multichannel
|
||||
}, socket);
|
||||
}
|
||||
|
||||
[targetClient] = targetClient;
|
||||
|
||||
server.reply({
|
||||
cmd: 'info',
|
||||
type: 'whisper',
|
||||
from: socket.nick,
|
||||
trip: socket.trip || 'null',
|
||||
text: `${socket.nick} whispered: ${text}`,
|
||||
const outgoingPayload = {
|
||||
cmd: 'whisper',
|
||||
channel: socket.channel, // @todo Multichannel
|
||||
}, targetClient);
|
||||
from: socket.userid,
|
||||
to: targetUser.userid,
|
||||
text,
|
||||
};
|
||||
|
||||
targetClient.whisperReply = socket.nick;
|
||||
// send invite notice to target client
|
||||
if (targetUser.hcProtocol === 1) {
|
||||
server.reply(legacyWhisperOut(outgoingPayload, socket), targetUser);
|
||||
} else {
|
||||
server.reply(outgoingPayload, targetUser);
|
||||
}
|
||||
|
||||
server.reply({
|
||||
cmd: 'info',
|
||||
type: 'whisper',
|
||||
text: `You whispered to @${targetNick}: ${text}`,
|
||||
channel: socket.channel, // @todo Multichannel
|
||||
}, socket);
|
||||
// send invite notice to this client
|
||||
if (socket.hcProtocol === 1) {
|
||||
server.reply(legacyWhisperReply(outgoingPayload, targetUser.nick), socket);
|
||||
} else {
|
||||
server.reply(outgoingPayload, socket);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -120,6 +130,7 @@ export function whisperCheck({
|
|||
socket,
|
||||
payload: {
|
||||
cmd: 'whisper',
|
||||
channel: socket.channel, // @todo Multichannel
|
||||
nick: target,
|
||||
text: whisperText,
|
||||
},
|
||||
|
|
|
@ -59,7 +59,7 @@ export function legacyLevelToLabel(level) {
|
|||
* @param {string} nick Sender nick
|
||||
* @return {object}
|
||||
*/
|
||||
export function legacyInviteOut(payload, nick) {
|
||||
export function legacyInviteOut(payload, nick) {
|
||||
return {
|
||||
...payload,
|
||||
...{
|
||||
|
@ -90,3 +90,39 @@ export function legacyInviteReply(payload, nick) {
|
|||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Alter the outgoing payload to a `whisper` cmd and add/change missing props
|
||||
* @param {object} payload Original payload
|
||||
* @param {string} nick Sender nick
|
||||
* @return {object}
|
||||
*/
|
||||
export function legacyWhisperOut(payload, from) {
|
||||
return {
|
||||
...payload,
|
||||
...{
|
||||
cmd: 'info',
|
||||
type: 'whisper',
|
||||
from: from.nick,
|
||||
trip: from.trip || 'null',
|
||||
text: `${from.nick} whispered: ${payload.text}`,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Alter the outgoing payload to a `whisper` cmd and add/change missing props
|
||||
* @param {object} payload Original payload
|
||||
* @param {string} nick Receiver nick
|
||||
* @return {object}
|
||||
*/
|
||||
export function legacyWhisperReply(payload, nick) {
|
||||
return {
|
||||
...payload,
|
||||
...{
|
||||
cmd: 'info',
|
||||
type: 'whisper',
|
||||
text: `You whispered to @${nick}: ${payload.text}`,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user