XSOverlay: Adjust message length timeout (#2445)

main
nyan 6 months ago committed by GitHub
parent bbec51fd19
commit 5c7fa5578c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -68,7 +68,6 @@ interface Call {
ringing: string[]; ringing: string[];
} }
const MuteStore = findByPropsLazy("isSuppressEveryoneEnabled");
const Notifs = findByPropsLazy("makeTextChatNotification"); const Notifs = findByPropsLazy("makeTextChatNotification");
const XSLog = new Logger("XSOverlay"); const XSLog = new Logger("XSOverlay");
@ -115,13 +114,13 @@ const settings = definePluginSettings({
}, },
timeout: { timeout: {
type: OptionType.NUMBER, type: OptionType.NUMBER,
description: "Notif duration (secs)", description: "Notification duration (secs)",
default: 1.0, default: 3,
}, },
timeoutPerCharacter: { lengthBasedTimeout: {
type: OptionType.NUMBER, type: OptionType.BOOLEAN,
description: "Duration multiplier per character", description: "Extend duration with message length",
default: 0.5 default: true
}, },
opacity: { opacity: {
type: OptionType.SLIDER, type: OptionType.SLIDER,
@ -262,12 +261,11 @@ function shouldIgnoreForChannelType(channel: Channel) {
} }
function sendMsgNotif(titleString: string, content: string, message: Message) { function sendMsgNotif(titleString: string, content: string, message: Message) {
const timeout = Math.max(settings.store.timeout, content.length * settings.store.timeoutPerCharacter);
fetch(`https://cdn.discordapp.com/avatars/${message.author.id}/${message.author.avatar}.png?size=128`).then(response => response.arrayBuffer()).then(result => { fetch(`https://cdn.discordapp.com/avatars/${message.author.id}/${message.author.avatar}.png?size=128`).then(response => response.arrayBuffer()).then(result => {
const msgData = { const msgData = {
messageType: 1, messageType: 1,
index: 0, index: 0,
timeout, timeout: settings.store.lengthBasedTimeout ? calculateTimeout(content) : settings.store.timeout,
height: calculateHeight(content), height: calculateHeight(content),
opacity: settings.store.opacity, opacity: settings.store.opacity,
volume: settings.store.volume, volume: settings.store.volume,
@ -286,7 +284,7 @@ function sendOtherNotif(content: string, titleString: string) {
const msgData = { const msgData = {
messageType: 1, messageType: 1,
index: 0, index: 0,
timeout: settings.store.timeout, timeout: settings.store.lengthBasedTimeout ? calculateTimeout(content) : settings.store.timeout,
height: calculateHeight(content), height: calculateHeight(content),
opacity: settings.store.opacity, opacity: settings.store.opacity,
volume: settings.store.volume, volume: settings.store.volume,
@ -313,3 +311,10 @@ function calculateHeight(content: string) {
if (content.length <= 300) return 200; if (content.length <= 300) return 200;
return 250; return 250;
} }
function calculateTimeout(content: string) {
if (content.length <= 100) return 3;
if (content.length <= 200) return 4;
if (content.length <= 300) return 5;
return 6;
}

Loading…
Cancel
Save