Merge pull request #4060 from thelounge/xpaw/fix-323

Always use multi-prefix modes
This commit is contained in:
Pavel Djundik 2020-09-29 13:48:21 +03:00 committed by GitHub
commit d4bf0e365f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 38 additions and 19 deletions

View File

@ -32,7 +32,7 @@
:on-hover="hoverUser"
:active="user.original === activeUser"
:user="user.original"
v-html="user.original.mode + user.string"
v-html="user.string"
/>
</template>
<template v-else>
@ -98,18 +98,25 @@ export default {
const result = this.filteredUsers;
for (const user of result) {
if (!groups[user.original.mode]) {
groups[user.original.mode] = [];
const mode = user.original.modes[0] || "";
if (!groups[mode]) {
groups[mode] = [];
}
groups[user.original.mode].push(user);
// Prepend user mode to search result
user.string = mode + user.string;
groups[mode].push(user);
}
} else {
for (const user of this.channel.users) {
if (!groups[user.mode]) {
groups[user.mode] = [user];
const mode = user.modes[0] || "";
if (!groups[mode]) {
groups[mode] = [user];
} else {
groups[user.mode].push(user);
groups[mode].push(user);
}
}
}

View File

@ -82,7 +82,10 @@ export default {
this.$root,
channel,
network,
channel.users.find((u) => u.nick === data.user.nick) || {nick: data.user.nick}
channel.users.find((u) => u.nick === data.user.nick) || {
nick: data.user.nick,
modes: [],
}
);
this.open(data.event, items);
},

View File

@ -6,7 +6,7 @@
v-on="onHover ? {mouseenter: hover} : {}"
@click.prevent="openContextMenu"
@contextmenu.prevent="openContextMenu"
><slot>{{ user.mode }}{{ user.nick }}</slot></span
><slot>{{ mode }}{{ user.nick }}</slot></span
>
</template>
@ -22,6 +22,14 @@ export default {
onHover: Function,
},
computed: {
mode() {
// Message objects have a singular mode, but user objects have modes array
if (this.user.modes) {
return this.user.modes[0];
}
return this.user.mode;
},
nickColor() {
return colorClass(this.user.nick);
},

View File

@ -172,6 +172,7 @@ export function generateChannelContextMenu($root, channel, network) {
export function generateUserContextMenu($root, channel, network, user) {
const currentChannelUser = channel.users.find((u) => u.nick === network.nick) || {};
const currentChannelModes = currentChannelUser.modes || [];
const whois = () => {
const chan = $root.$store.getters.findChannelOnCurrentNetwork(user.nick);
@ -221,7 +222,7 @@ export function generateUserContextMenu($root, channel, network, user) {
},
];
if (currentChannelUser.mode === "@") {
if (currentChannelModes.includes("@")) {
items.push({
label: "Kick",
type: "item",
@ -234,7 +235,7 @@ export function generateUserContextMenu($root, channel, network, user) {
},
});
if (user.mode === "@") {
if (user.modes.includes("@")) {
items.push({
label: "Revoke operator (-o)",
type: "item",
@ -260,7 +261,7 @@ export function generateUserContextMenu($root, channel, network, user) {
});
}
if (user.mode === "+") {
if (user.modes.includes("+")) {
items.push({
label: "Revoke voice (-v)",
type: "item",

View File

@ -8,25 +8,28 @@ function User(attr, prefixLookup) {
_.defaults(this, attr, {
modes: [],
away: "",
mode: "",
nick: "",
lastMessage: 0,
});
Object.defineProperty(this, "mode", {
get() {
return this.modes[0] || "";
},
});
this.setModes(this.modes, prefixLookup);
}
User.prototype.setModes = function (modes, prefixLookup) {
// irc-framework sets character mode, but The Lounge works with symbols
this.modes = modes.map((mode) => prefixLookup[mode]);
this.mode = this.modes[0] || "";
};
User.prototype.toJSON = function () {
return {
nick: this.nick,
mode: this.mode,
modes: this.modes,
lastMessage: this.lastMessage,
};
};

View File

@ -117,9 +117,6 @@ module.exports = function (irc, network) {
return userModeSortPriority[a] - userModeSortPriority[b];
});
}
// TODO: remove in future
user.mode = (user.modes && user.modes[0]) || "";
});
if (!usersUpdated) {