mirror of
https://github.com/thelounge/thelounge.git
synced 2026-03-14 14:35:50 +01:00
Merge 80db482aac into b2e3112806
This commit is contained in:
commit
1f9b70181a
7 changed files with 78 additions and 13 deletions
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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});
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -145,6 +145,12 @@ const defaultConfig = {
|
|||
searchEnabled: {
|
||||
default: false,
|
||||
},
|
||||
notifications: {
|
||||
default: {
|
||||
hideMessagePreview: false,
|
||||
},
|
||||
sync: "always",
|
||||
},
|
||||
};
|
||||
|
||||
export const config = normalizeConfig(defaultConfig);
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue