迁移聊天室静音偏好工具
This commit is contained in:
@@ -1047,6 +1047,10 @@
|
||||
* @returns {string[]}
|
||||
*/
|
||||
function loadBlockedSystemSenders() {
|
||||
if (window.ChatRoomTools?.loadBlockedSystemSenders) {
|
||||
return window.ChatRoomTools.loadBlockedSystemSenders(BLOCKABLE_SYSTEM_SENDERS);
|
||||
}
|
||||
|
||||
try {
|
||||
const saved = JSON.parse(localStorage.getItem(BLOCKED_SYSTEM_SENDERS_STORAGE_KEY) || '[]');
|
||||
if (!Array.isArray(saved)) {
|
||||
@@ -1064,6 +1068,11 @@
|
||||
* 将当前屏蔽配置持久化到 localStorage。
|
||||
*/
|
||||
function persistBlockedSystemSenders() {
|
||||
if (window.ChatRoomTools?.persistBlockedSystemSenders) {
|
||||
window.ChatRoomTools.persistBlockedSystemSenders(blockedSystemSenders);
|
||||
return;
|
||||
}
|
||||
|
||||
localStorage.setItem(
|
||||
BLOCKED_SYSTEM_SENDERS_STORAGE_KEY,
|
||||
JSON.stringify(Array.from(blockedSystemSenders))
|
||||
@@ -1076,6 +1085,10 @@
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function isSoundMuted() {
|
||||
if (window.ChatRoomTools?.isSoundMuted) {
|
||||
return window.ChatRoomTools.isSoundMuted();
|
||||
}
|
||||
|
||||
const muteCheckbox = document.getElementById('sound_muted');
|
||||
|
||||
if (muteCheckbox) {
|
||||
@@ -1102,6 +1115,11 @@
|
||||
*/
|
||||
function persistChatPreferencesToLocal() {
|
||||
persistBlockedSystemSenders();
|
||||
if (window.ChatRoomTools?.setSoundMuted) {
|
||||
window.ChatRoomTools.setSoundMuted(isSoundMuted());
|
||||
return;
|
||||
}
|
||||
|
||||
localStorage.setItem(CHAT_SOUND_MUTED_STORAGE_KEY, isSoundMuted() ? '1' : '0');
|
||||
}
|
||||
|
||||
@@ -3264,9 +3282,10 @@
|
||||
|
||||
const storedBlockedSystemSenders = loadBlockedSystemSenders();
|
||||
const mutedFromLocal = localStorage.getItem(CHAT_SOUND_MUTED_STORAGE_KEY) === '1';
|
||||
const hasServerPreferences = initialChatPreferences.blocked_system_senders.length > 0 || initialChatPreferences.sound_muted;
|
||||
const shouldMigrateLocalPreferences = !hasServerPreferences
|
||||
&& (storedBlockedSystemSenders.length > 0 || mutedFromLocal);
|
||||
const shouldMigrateLocalPreferences = window.ChatRoomTools?.shouldMigrateLocalChatPreferences
|
||||
? window.ChatRoomTools.shouldMigrateLocalChatPreferences(initialChatPreferences, storedBlockedSystemSenders, mutedFromLocal)
|
||||
: !(initialChatPreferences.blocked_system_senders.length > 0 || initialChatPreferences.sound_muted)
|
||||
&& (storedBlockedSystemSenders.length > 0 || mutedFromLocal);
|
||||
|
||||
if (shouldMigrateLocalPreferences) {
|
||||
blockedSystemSenders = new Set(storedBlockedSystemSenders);
|
||||
@@ -3274,8 +3293,12 @@
|
||||
|
||||
// 恢复禁音复选框状态;默认一律为未禁音。
|
||||
const muted = shouldMigrateLocalPreferences ? mutedFromLocal : initialChatPreferences.sound_muted;
|
||||
const muteChk = document.getElementById('sound_muted');
|
||||
if (muteChk) muteChk.checked = muted;
|
||||
if (window.ChatRoomTools?.setSoundMuted) {
|
||||
window.ChatRoomTools.setSoundMuted(muted);
|
||||
} else {
|
||||
const muteChk = document.getElementById('sound_muted');
|
||||
if (muteChk) muteChk.checked = muted;
|
||||
}
|
||||
syncBlockedSystemSenderCheckboxes();
|
||||
|
||||
if (shouldMigrateLocalPreferences) {
|
||||
@@ -3293,7 +3316,11 @@
|
||||
* @param {boolean} muted true = 禁音,false = 开启声音
|
||||
*/
|
||||
function toggleSoundMute(muted) {
|
||||
localStorage.setItem(CHAT_SOUND_MUTED_STORAGE_KEY, muted ? '1' : '0');
|
||||
if (window.ChatRoomTools?.setSoundMuted) {
|
||||
window.ChatRoomTools.setSoundMuted(muted);
|
||||
} else {
|
||||
localStorage.setItem(CHAT_SOUND_MUTED_STORAGE_KEY, muted ? '1' : '0');
|
||||
}
|
||||
if (muted && typeof EffectSounds !== 'undefined') {
|
||||
EffectSounds.stop(); // 立即停止当前音效
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user