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
|
// build invite
|
||||||
const outgoingPayload = {
|
const outgoingPayload = {
|
||||||
cmd: 'invite',
|
cmd: 'invite',
|
||||||
channel: socket.channel,
|
channel: socket.channel, // @todo Multichannel
|
||||||
from: socket.userid,
|
from: socket.userid,
|
||||||
to: targetUser.userid,
|
to: targetUser.userid,
|
||||||
inviteChannel: channel,
|
inviteChannel: channel,
|
||||||
|
|
|
@ -4,7 +4,16 @@
|
||||||
and accept a `userid` rather than `nick`
|
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
|
// module support functions
|
||||||
|
|
||||||
|
@ -26,7 +35,12 @@ const parseText = (text) => {
|
||||||
|
|
||||||
// module main
|
// module main
|
||||||
export async function run({ server, socket, payload }) {
|
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);
|
const text = parseText(payload.text);
|
||||||
|
|
||||||
if (!text) {
|
if (!text) {
|
||||||
|
@ -44,41 +58,37 @@ export async function run({ server, socket, payload }) {
|
||||||
}, socket);
|
}, socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
const targetNick = payload.nick;
|
const targetUser = findUser(server, payload);
|
||||||
if (!UAC.verifyNickname(targetNick)) {
|
if (!targetUser) {
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// find target user
|
|
||||||
let targetClient = server.findSockets({ channel: socket.channel, nick: targetNick });
|
|
||||||
|
|
||||||
if (targetClient.length === 0) {
|
|
||||||
return server.reply({
|
return server.reply({
|
||||||
cmd: 'warn', // @todo Add numeric error code as `id`
|
cmd: 'warn',
|
||||||
text: 'Could not find user in channel',
|
text: 'Could not find user in that channel',
|
||||||
|
id: Errors.Global.UNKNOWN_USER,
|
||||||
channel: socket.channel, // @todo Multichannel
|
channel: socket.channel, // @todo Multichannel
|
||||||
}, socket);
|
}, socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
[targetClient] = targetClient;
|
const outgoingPayload = {
|
||||||
|
cmd: 'whisper',
|
||||||
server.reply({
|
|
||||||
cmd: 'info',
|
|
||||||
type: 'whisper',
|
|
||||||
from: socket.nick,
|
|
||||||
trip: socket.trip || 'null',
|
|
||||||
text: `${socket.nick} whispered: ${text}`,
|
|
||||||
channel: socket.channel, // @todo Multichannel
|
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({
|
// send invite notice to this client
|
||||||
cmd: 'info',
|
if (socket.hcProtocol === 1) {
|
||||||
type: 'whisper',
|
server.reply(legacyWhisperReply(outgoingPayload, targetUser.nick), socket);
|
||||||
text: `You whispered to @${targetNick}: ${text}`,
|
} else {
|
||||||
channel: socket.channel, // @todo Multichannel
|
server.reply(outgoingPayload, socket);
|
||||||
}, socket);
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -120,6 +130,7 @@ export function whisperCheck({
|
||||||
socket,
|
socket,
|
||||||
payload: {
|
payload: {
|
||||||
cmd: 'whisper',
|
cmd: 'whisper',
|
||||||
|
channel: socket.channel, // @todo Multichannel
|
||||||
nick: target,
|
nick: target,
|
||||||
text: whisperText,
|
text: whisperText,
|
||||||
},
|
},
|
||||||
|
|
|
@ -59,7 +59,7 @@ export function legacyLevelToLabel(level) {
|
||||||
* @param {string} nick Sender nick
|
* @param {string} nick Sender nick
|
||||||
* @return {object}
|
* @return {object}
|
||||||
*/
|
*/
|
||||||
export function legacyInviteOut(payload, nick) {
|
export function legacyInviteOut(payload, nick) {
|
||||||
return {
|
return {
|
||||||
...payload,
|
...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