diff --git a/src/libs/InputHandler.js b/src/libs/InputHandler.js index f320d68bc..8a0b4610c 100644 --- a/src/libs/InputHandler.js +++ b/src/libs/InputHandler.js @@ -752,13 +752,18 @@ inputCommands.mode = function inputCommandMode(event, command, line) { // parts[0] = the mode(s) // parts[1] = optional mode arguments - // If we're asking for a ban list, show the response in the active channel - if (parts[0] === '+b' && !parts[1]) { - buffer.flags.requested_banlist = true; + // If we're asking for a ban or invite list, show the response in the active channel + if (['+b', '+I'].includes(parts[0]) && !parts[1]) { + let flagKey = (parts[0] === '+b') + ? 'requested_banlist' + : 'requested_invitelist'; + + buffer.flag(flagKey, true); + // An IRCd may fuck up and simply not reply to a MODE command. Give a few seconds // for it to reply and if not, ignore our request was sent setTimeout(() => { - buffer.flags.requested_banlist = false; + buffer.flag(flagKey, false); }, 4000); } diff --git a/src/libs/IrcClient.js b/src/libs/IrcClient.js index 4d99b5081..2e823d2fc 100644 --- a/src/libs/IrcClient.js +++ b/src/libs/IrcClient.js @@ -1258,31 +1258,73 @@ function clientMiddleware(state, network) { if (command === 'banlist') { let buffer = state.getBufferByName(networkid, event.channel); - if (buffer && buffer.flags.requested_banlist) { + let serverBuffer = network.serverBuffer(); + let targetBuffer = buffer || serverBuffer; + + if (!buffer || buffer.flags.requested_banlist) { + let banText = '\x02'; + + if (targetBuffer === serverBuffer) { + banText += event.channel + ' '; + } + banText += TextFormatting.t('banned') + ' [+b]\x02\n'; + if (!event.bans || event.bans.length === 0) { - state.addMessage(buffer, { - time: eventTime, - server_time: serverTime, - nick: '', - message: TextFormatting.t('bans_nobody'), - type: 'banlist', - }); + banText += TextFormatting.t('bans_nobody'); } else { - let banText = ''; _.each(event.bans, (ban) => { - let dateStr = (new Date(ban.banned_at * 1000)).toDateString(); - banText += `+b ${ban.banned} [by ${ban.banned_by}, ${dateStr}]\n`; + let dateStr = (new Date(ban.banned_at * 1000)).toLocaleDateString(); + banText += `${ban.banned} [\x1d${ban.banned_by}, ${dateStr}\x1d]\n`; }); + } - state.addMessage(buffer, { - time: eventTime, - server_time: serverTime, - nick: '*', - message: banText, - type: 'banlist', + state.addMessage(targetBuffer, { + time: eventTime, + server_time: serverTime, + nick: '', + message: banText, + type: 'banlist', + }); + + if (buffer) { + buffer.flag('requested_banlist', false); + } + } + } + + if (command === 'inviteList') { + let buffer = state.getBufferByName(networkid, event.channel); + let serverBuffer = network.serverBuffer(); + let targetBuffer = buffer || serverBuffer; + + if (!buffer || buffer.flags.requested_invitelist) { + let inviteText = '\x02'; + + if (targetBuffer === serverBuffer) { + inviteText += event.channel + ' '; + } + inviteText += TextFormatting.t('invited') + ' [+I]\x02\n'; + + if (!event.invites || event.invites.length === 0) { + inviteText += TextFormatting.t('invited_nobody'); + } else { + _.each(event.invites, (invite) => { + let dateStr = (new Date(invite.invited_at * 1000)).toLocaleDateString(); + inviteText += `${invite.invited} [\x1d${invite.invited_by}, ${dateStr}\x1d]\n`; }); } - buffer.flags.requested_banlist = false; + + state.addMessage(targetBuffer, { + time: eventTime, + server_time: serverTime, + nick: '', + message: inviteText, + type: 'invitelist', + }); + + if (buffer) { + buffer.flag('requested_invitelist', false); + } } } diff --git a/src/libs/state/BufferState.js b/src/libs/state/BufferState.js index 989d3ce15..15dd68ce6 100644 --- a/src/libs/state/BufferState.js +++ b/src/libs/state/BufferState.js @@ -29,6 +29,7 @@ export default class BufferState { chathistory_available: true, requested_modes: false, requested_banlist: false, + requested_invitelist: false, is_requesting_chathistory: false, }; this.settings = { };