This commit is contained in:
xpmb 2026-01-12 18:14:03 -05:00 committed by GitHub
commit 1f9b70181a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 78 additions and 13 deletions

View file

@ -1,5 +1,17 @@
<template>
<div>
<h2>General</h2>
<div>
<label class="opt">
<input
:checked="store.state.settings.notifications.hideMessagePreview"
type="checkbox"
name="notifications.hideMessagePreview"
/>
Hide message preview in all notifications
</label>
</div>
<template v-if="!store.state.serverConfiguration?.public">
<h2>Push Notifications</h2>
<div>

View file

@ -45,6 +45,25 @@ export default defineComponent({
value = (event.target as HTMLInputElement).value;
}
// Handle nested settings
if (name.includes(".")) {
const [parentKey, childKey] = name.split(".");
const currentParentValue = store.state.settings[parentKey];
if (typeof currentParentValue === "object" && currentParentValue !== null) {
const newParentValue = {
...currentParentValue,
[childKey]: value,
};
void store.dispatch("settings/update", {
name: parentKey,
value: newParentValue,
sync: true,
});
return;
}
}
void store.dispatch("settings/update", {name, value, sync: true});
};

View file

@ -145,6 +145,12 @@ const defaultConfig = {
searchEnabled: {
default: false,
},
notifications: {
default: {
hideMessagePreview: false,
},
sync: "always",
},
};
export const config = normalizeConfig(defaultConfig);

View file

@ -134,11 +134,22 @@ function notifyMessage(
let title: string;
let body: string;
// TODO: fix msg type and get rid of that conditional
const nick = msg.from && msg.from.nick ? msg.from.nick : "unkonown";
const nick = msg.from && msg.from.nick ? msg.from.nick : "unknown";
// Check if user has disabled message previews
if (store.state.settings.notifications.hideMessagePreview) {
body = "You have a new message";
} else {
// TODO: fix msg type and get rid of that conditional
body = cleanIrcMessage(msg.text ? msg.text : "");
}
if (msg.type === MessageType.INVITE) {
title = "New channel invite:";
body = nick + " invited you to " + msg.channel;
if (!store.state.settings.notifications.hideMessagePreview) {
body = nick + " invited you to " + msg.channel;
}
} else {
title = nick;
@ -149,9 +160,6 @@ function notifyMessage(
if (msg.type === MessageType.MESSAGE) {
title += " says:";
}
// TODO: fix msg type and get rid of that conditional
body = cleanIrcMessage(msg.text ? msg.text : "");
}
const timestamp = Date.parse(String(msg.time));

View file

@ -110,7 +110,19 @@ function assignStoredSettings(
typeof storedSettings[key] !== "undefined" &&
typeof defaultSettings[key] === typeof storedSettings[key]
) {
newSettings[key] = storedSettings[key];
// Handle nested objects by merging them
if (
typeof defaultSettings[key] === "object" &&
defaultSettings[key] !== null &&
!Array.isArray(defaultSettings[key])
) {
newSettings[key] = {
...defaultSettings[key],
...storedSettings[key],
};
} else {
newSettings[key] = storedSettings[key];
}
}
}

View file

@ -179,7 +179,14 @@ export default <IrcEventHandler>function (irc, network) {
// Do not send notifications if the channel is muted or for messages older than 15 minutes (znc buffer for example)
if (!chan.muted && msg.highlight && (!data.time || data.time > Date.now() - 900000)) {
let title = chan.name;
let body = cleanMessage;
let body: string;
// Check if user has disabled message previews
if (client.config.clientSettings?.notifications?.hideMessagePreview) {
body = "sent you a message";
} else {
body = cleanMessage;
}
if (msg.type === MessageType.ACTION) {
// For actions, do not include colon in the message

View file

@ -718,16 +718,17 @@ function initializeClient(
return;
}
if (
typeof newSetting.value === "object" ||
typeof newSetting.name !== "string" ||
newSetting.name[0] === "_"
) {
if (typeof newSetting.name !== "string" || newSetting.name[0] === "_") {
return;
}
// Allow plain objects for nested settings, but reject arrays and null
if (typeof newSetting.value === "object" && !_.isPlainObject(newSetting.value)) {
return;
}
// We do not need to do write operations and emit events if nothing changed.
if (client.config.clientSettings[newSetting.name] !== newSetting.value) {
if (!_.isEqual(client.config.clientSettings[newSetting.name], newSetting.value)) {
client.config.clientSettings[newSetting.name] = newSetting.value;
// Pass the setting to all clients.