Skip to content

Commit

Permalink
Fix and improve MessageInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsOnlyBinary committed Aug 20, 2024
1 parent 580e775 commit 27a1fed
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 91 deletions.
6 changes: 6 additions & 0 deletions src/components/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
'kiwi-wrap--touch': $state.ui.is_touch,
}"
:data-activebuffer="buffer ? buffer.name.toLowerCase() : ''"
:data-theme="currentThemeName"
class="kiwi-wrap kiwi-theme-bg"
@click="emitDocumentClick"
@paste.capture="emitBufferPaste"
Expand Down Expand Up @@ -73,6 +74,7 @@ import ControlInput from '@/components/ControlInput';
import MediaViewer from '@/components/MediaViewer';
import AvatarCommon from '@/components/UserAvatarCommon';
import { State as SidebarState } from '@/components/Sidebar';
import ThemeManager from '@/libs/ThemeManager';
import * as Notifications from '@/libs/Notifications';
import * as bufferTools from '@/libs/bufferTools';
import Logger from '@/libs/Logger';
Expand Down Expand Up @@ -118,6 +120,10 @@ export default {
buffer() {
return this.$state.getActiveBuffer();
},
currentThemeName() {
const theme = ThemeManager.instance().currentTheme();
return theme ? theme.name.toLowerCase() : '';
},
},
created() {
this.listenForActiveComponents();
Expand Down
25 changes: 7 additions & 18 deletions src/components/MessageInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
class="kiwi-messageinfo-actions"
>
<a
v-if="!requestingInput && buffer.name !== message.nick && !isSelf()"
v-if="!requestingInput && message.nick && buffer.name !== message.nick && !isSelf()"
class="u-link kiwi-messageinfo-reply"
@click="openQuery"
>
{{ $t('reply_in_private') }}
</a>

<div v-if="areWeAnOp() && !isSelf()" class="kiwi-messageinfo-opbuttons">
<div v-if="message.user && areWeAnOp() && !isSelf()" class="kiwi-messageinfo-opbuttons">
<input-prompt
label="Kick reason:" @submit="onKick"
@cancel="requestingInput = false"
Expand Down Expand Up @@ -77,17 +77,13 @@ export default {
},
isSelf() {
let user = this.$state.getUser(this.buffer.getNetwork().id, this.message.nick);
return this.buffer.getNetwork().ircClient.user.nick === user.nick;
return user && this.buffer.getNetwork().ircClient.user.nick === user.nick;
},
onBan(reason) {
let network = this.buffer.getNetwork();
network.ircClient.mode(this.buffer.name, '+b', this.message.nick);
this.buffer.banKickUser(this.message.user, reason);
},
onKick(promptedReason) {
let network = this.buffer.getNetwork();
let defaultReason = this.$state.setting('buffers.default_kick_reason');
let reason = promptedReason || defaultReason;
network.ircClient.raw('KICK', this.buffer.name, this.message.nick, reason);
onKick(reason) {
this.buffer.kickUser(this.message.user, reason);
},
openQuery() {
let network = this.buffer.getNetwork();
Expand All @@ -103,6 +99,7 @@ export default {
display: block;
position: relative;
padding: 0;
margin-bottom: 10px;
}
.kiwi-messageinfo-urls {
Expand Down Expand Up @@ -173,10 +170,6 @@ export default {
border-radius: 4px;
}
.kiwi-messageinfo-opbuttons .u-input-prompt input {
margin-bottom: 5px;
}
@media screen and (max-width: 490px) {
.kiwi-messageinfo-actions {
text-align: center;
Expand All @@ -185,9 +178,5 @@ export default {
.kiwi-messageinfo-opbuttons {
margin: 0;
}
.kiwi-messageinfo-opbuttons .u-input-prompt a {
margin-top: 10px;
}
}
</style>
3 changes: 1 addition & 2 deletions src/components/MessageList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1037,8 +1037,7 @@ div.kiwi-messagelist-item.kiwi-messagelist-item--selected .kiwi-messagelist-mess
}
@media screen and (max-width: 700px) {
.kiwi-messagelist-message,
.kiwi-messageinfo {
.kiwi-messagelist-message {
margin: 0;
}
}
Expand Down
72 changes: 3 additions & 69 deletions src/components/UserBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
type="button"
class="u-button u-button-secondary
kiwi-userbox-opaction-kick kiwi-userbox-opaction"
@click="kickUser"
@click="buffer.kickUser(user)"
>
<i class="fa fa-sign-out" aria-hidden="true" />
{{ $t('user_kick') }}
Expand All @@ -171,7 +171,7 @@
type="button"
class="u-button u-button-secondary
kiwi-userbox-opaction-ban kiwi-userbox-opaction"
@click="banUser"
@click="buffer.banUser(user)"
>
<i class="fa fa-ban" aria-hidden="true" />
{{ $t('user_ban') }}
Expand All @@ -182,7 +182,7 @@
type="button"
class="u-button u-button-secondary
kiwi-userbox-opaction-kickban kiwi-userbox-opaction"
@click="kickbanUser"
@click="buffer.banKickUser(user)"
>
<i class="fa fa-exclamation-triangle" aria-hidden="true" />
{{ $t('user_kickban') }}
Expand Down Expand Up @@ -212,9 +212,7 @@
<script>
'kiwi public';
import * as ipRegex from 'ip-regex';
import * as TextFormatting from '@/helpers/TextFormatting';
import * as IrcdDiffs from '@/helpers/IrcdDiffs';
import * as Misc from '@/helpers/Misc';
import GlobalApi from '@/libs/GlobalApi';
import toHtml from '@/libs/renderers/Html';
Expand Down Expand Up @@ -384,70 +382,6 @@ export default {
this.whoisLoading = false;
});
},
kickUser() {
let reason = this.$state.setting('buffers.default_kick_reason');
this.network.ircClient.raw('KICK', this.buffer.name, this.user.nick, reason);
},
createBanMask() {
// try to ban via user account first
if (this.user.account) {
// if EXTBAN is supported use that
let extban = IrcdDiffs.extbanAccount(this.network);
if (extban) {
return extban + ':' + this.user.account;
}
// if the account name is in the host ban the host
// Eg. user@network/user/accountname
if (this.user.host.toLowerCase().indexOf(this.user.account.toLowerCase()) > -1) {
return '*!*@' + this.user.host;
}
}
// if an ip address is in the host and not the whole host ban the ip
// Eg. user@gateway/1.2.3.4
let ipTest = new RegExp('(' + ipRegex.v4().source + '|' + ipRegex.v6().source + ')');
if (ipTest.test(this.user.host)) {
let match = this.user.host.match(ipTest)[0];
if (match !== this.user.host) {
return '*!*@*' + match + '*';
}
}
// if an 8 char hex is the username ban by username. Commonly used in gateways
// Eg. [email protected]
let hexTest = /^([a-f0-9]{8})$/i;
if (hexTest.test(this.user.username)) {
let match = this.user.username.match(hexTest)[0];
return '*!' + match + '@*';
}
// fallback to default_ban_mask from config
let mask = this.$state.setting('buffers.default_ban_mask');
mask = mask.replace('%n', this.user.nick);
mask = mask.replace('%i', this.user.username);
mask = mask.replace('%h', this.user.host);
return mask;
},
banUser() {
if (!this.user.username || !this.user.host) {
return;
}
let banMask = this.createBanMask();
this.network.ircClient.raw('MODE', this.buffer.name, '+b', banMask);
},
kickbanUser() {
if (!this.user.username || !this.user.host) {
return;
}
let banMask = this.createBanMask();
let reason = this.$state.setting('buffers.default_kick_reason');
this.network.ircClient.raw('MODE', this.buffer.name, '+b', banMask);
this.network.ircClient.raw('KICK', this.buffer.name, this.user.nick, reason);
},
inviteUser() {
if (!this.inviteChan) {
return;
Expand Down
3 changes: 2 additions & 1 deletion src/libs/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,8 @@ function createNewState() {
let userObj = null;

if (!usersArr[user.nick.toUpperCase()]) {
userObj = usersArr[user.nick.toUpperCase()] = new UserState(user);
userObj = new UserState(network.id, user, state);
usersArr[user.nick.toUpperCase()] = userObj;
} else {
// Update the existing user object with any new info we have
userObj = state.getUser(network.id, user.nick, usersArr);
Expand Down
19 changes: 19 additions & 0 deletions src/libs/state/BufferState.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,25 @@ export default class BufferState {
return true;
}

banUser(user) {
if (!user.username || !user.host) {
return;
}

let banMask = user.createBanMask();
this.getNetwork().ircClient.raw('MODE', this.name, '+b', banMask);
}

kickUser(user, _reason) {
let reason = _reason || this.state.setting('buffers.default_kick_reason');
this.getNetwork().ircClient.raw('KICK', this.name, user.nick, reason);
}

banKickUser(user, reason) {
this.banUser(user);
this.kickUser(user, reason);
}

removeUser(nick) {
let userObj = this.state.getUser(this.networkid, nick);

Expand Down
54 changes: 53 additions & 1 deletion src/libs/state/UserState.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

import Vue from 'vue';
import getState from '@/libs/state';
import * as ipRegex from 'ip-regex';
import * as IrcdDiffs from '@/helpers/IrcdDiffs';
import * as TextFormatting from '@/helpers/TextFormatting';
import { def } from './common';

let nextId = 0;

export default class UserState {
constructor(user) {
constructor(networkid, user, state) {
this.id = ++nextId;
this.networkid = networkid;
this.key = user.nick.toUpperCase();
this.nick = user.nick;
this.host = user.host || '';
Expand All @@ -29,6 +32,8 @@ export default class UserState {

Vue.observable(this);

def(this, 'state', state, false);

// Whois details are non-enumerable properties (vues $watch won't cover these properties)
// watch hasWhois to know when this data is populated
def(this, 'whois', {
Expand Down Expand Up @@ -79,6 +84,10 @@ export default class UserState {
return this.colour === 'default' ? '' : this.colour;
}

getNetwork() {
return this.state.getNetwork(this.networkid);
}

isAway() {
return this.away && this.away !== 'offline';
}
Expand All @@ -87,6 +96,49 @@ export default class UserState {
return this.away === 'offline';
}

createBanMask() {
// try to ban via user account first
if (this.account) {
// if EXTBAN is supported use that
let extban = IrcdDiffs.extbanAccount(this.getNetwork());
if (extban) {
return extban + ':' + this.account;
}

// if the account name is in the host ban the host
// Eg. user@network/user/accountname
if (this.host.toLowerCase().indexOf(this.account.toLowerCase()) > -1) {
return '*!*@' + this.host;
}
}

// if an ip address is in the host and not the whole host ban the ip
// Eg. user@gateway/1.2.3.4
let ipTest = new RegExp('(' + ipRegex.v4().source + '|' + ipRegex.v6().source + ')');
if (ipTest.test(this.host)) {
let match = this.host.match(ipTest)[0];
if (match !== this.host) {
return '*!*@*' + match + '*';
}
}

// if an 8 char hex is the username ban by username. Commonly used in gateways
// Eg. [email protected]
let hexTest = /^([a-f0-9]{8})$/i;
if (hexTest.test(this.username)) {
let match = this.username.match(hexTest)[0];
return '*!' + match + '@*';
}

// fallback to default_ban_mask from config
let mask = this.state.setting('buffers.default_ban_mask');
mask = mask.replace('%n', this.nick);
mask = mask.replace('%i', this.username);
mask = mask.replace('%h', this.host);

return mask;
}

typingStatus(_target, status) {
let target = _target.toUpperCase();
if (!status) {
Expand Down

0 comments on commit 27a1fed

Please sign in to comment.