Skip to content

Commit

Permalink
Show ban and invite lists in server buffer if the channel buffer does…
Browse files Browse the repository at this point in the history
… not exist
  • Loading branch information
ItsOnlyBinary committed Sep 13, 2023
1 parent 8b3c5e5 commit 78116ee
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 22 deletions.
13 changes: 9 additions & 4 deletions src/libs/InputHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
78 changes: 60 additions & 18 deletions src/libs/IrcClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/libs/state/BufferState.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = { };
Expand Down

0 comments on commit 78116ee

Please sign in to comment.