2024-02-10 17:23:47 +00:00
|
|
|
window.Umi = { UI: {}, Protocol: { SockChat: { Protocol: {} } } };
|
2024-01-18 19:50:37 +00:00
|
|
|
|
|
|
|
#include animate.js
|
2024-02-24 01:10:30 +00:00
|
|
|
#include channel.js
|
|
|
|
#include channels.js
|
2024-01-18 19:50:37 +00:00
|
|
|
#include common.js
|
2024-02-29 23:57:36 +00:00
|
|
|
#include compat.js
|
2024-01-18 19:50:37 +00:00
|
|
|
#include context.js
|
|
|
|
#include emotes.js
|
2024-02-24 01:10:30 +00:00
|
|
|
#include message.js
|
2024-01-18 19:50:37 +00:00
|
|
|
#include messages.js
|
|
|
|
#include mszauth.js
|
2024-02-24 01:10:30 +00:00
|
|
|
#include parsing.js
|
2024-02-29 23:57:36 +00:00
|
|
|
#include sockchat_old.js
|
2024-02-10 17:23:47 +00:00
|
|
|
#include txtrigs.js
|
2024-02-24 01:10:30 +00:00
|
|
|
#include user.js
|
|
|
|
#include users.js
|
2024-01-18 19:50:37 +00:00
|
|
|
#include utility.js
|
2024-01-22 21:45:39 +00:00
|
|
|
#include weeb.js
|
2024-02-09 22:38:57 +00:00
|
|
|
#include audio/autoplay.js
|
2024-01-22 21:45:39 +00:00
|
|
|
#include audio/context.js
|
2024-02-10 17:23:47 +00:00
|
|
|
#include controls/views.js
|
2024-01-22 21:45:39 +00:00
|
|
|
#include eeprom/eeprom.js
|
|
|
|
#include settings/backup.js
|
|
|
|
#include settings/settings.js
|
2024-02-10 17:23:47 +00:00
|
|
|
#include sound/context.js
|
2024-01-22 21:45:39 +00:00
|
|
|
#include sound/osukeys.js
|
|
|
|
#include sound/umisound.js
|
2024-02-24 20:26:40 +00:00
|
|
|
#include ui/baka.jsx
|
2024-01-18 19:50:37 +00:00
|
|
|
#include ui/chat-layout.js
|
|
|
|
#include ui/hooks.js
|
2024-02-24 01:10:30 +00:00
|
|
|
#include ui/emotes.js
|
2024-01-18 19:50:37 +00:00
|
|
|
#include ui/input-menus.js
|
|
|
|
#include ui/loading-overlay.jsx
|
|
|
|
#include ui/markup.js
|
|
|
|
#include ui/menus.js
|
2024-02-24 01:10:30 +00:00
|
|
|
#include ui/messages.jsx
|
2024-01-18 19:50:37 +00:00
|
|
|
#include ui/view.js
|
2024-02-29 21:43:00 +00:00
|
|
|
#include ui/ping.jsx
|
2024-01-22 21:45:39 +00:00
|
|
|
#include ui/settings.jsx
|
2024-01-18 19:50:37 +00:00
|
|
|
#include ui/toggles.js
|
|
|
|
#include ui/uploads.js
|
|
|
|
|
|
|
|
(async () => {
|
2024-02-10 17:23:47 +00:00
|
|
|
const views = new MamiViewsControl({ body: document.body });
|
|
|
|
const loadingOverlay = new Umi.UI.LoadingOverlay('spinner', 'Loading...');
|
|
|
|
await views.push(loadingOverlay);
|
2024-01-18 19:50:37 +00:00
|
|
|
|
2024-02-10 17:23:47 +00:00
|
|
|
loadingOverlay.setMessage('Loading environment...');
|
2024-01-18 19:50:37 +00:00
|
|
|
try {
|
|
|
|
window.futami = await FutamiCommon.load();
|
|
|
|
} catch(ex) {
|
2024-02-10 04:24:25 +00:00
|
|
|
console.error(ex);
|
2024-02-10 17:23:47 +00:00
|
|
|
loadingOverlay.setIcon('cross');
|
|
|
|
loadingOverlay.setHeader('Failed!');
|
|
|
|
loadingOverlay.setMessage('Failed to load common settings!');
|
2024-02-10 04:24:25 +00:00
|
|
|
return;
|
2024-01-18 19:50:37 +00:00
|
|
|
}
|
|
|
|
|
2024-02-10 17:23:47 +00:00
|
|
|
loadingOverlay.setMessage('Fetching credentials...');
|
2024-01-18 19:50:37 +00:00
|
|
|
try {
|
|
|
|
const auth = await MamiMisuzuAuth.update();
|
|
|
|
if(!auth.ok)
|
|
|
|
throw 'Authentication failed.';
|
|
|
|
} catch(ex) {
|
|
|
|
console.error(ex);
|
|
|
|
location.assign(futami.get('login'));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
setInterval(() => {
|
|
|
|
MamiMisuzuAuth.update()
|
|
|
|
.then(auth => {
|
|
|
|
if(!auth.ok)
|
|
|
|
location.assign(futami.get('login'));
|
|
|
|
})
|
|
|
|
}, 600000);
|
|
|
|
|
|
|
|
|
2024-02-10 17:23:47 +00:00
|
|
|
loadingOverlay.setMessage('Loading settings...');
|
2024-01-22 21:45:39 +00:00
|
|
|
|
|
|
|
const settings = new MamiSettings('umi-');
|
|
|
|
|
|
|
|
settings.define('style', 'string', 'dark');
|
|
|
|
settings.define('compactView', 'boolean', false);
|
|
|
|
settings.define('autoScroll', 'boolean', true);
|
|
|
|
settings.define('closeTabConfirm', 'boolean', false);
|
|
|
|
settings.define('showChannelList', 'boolean', false);
|
|
|
|
settings.define('fancyInfo', 'boolean', true);
|
|
|
|
settings.define('autoCloseUserContext', 'boolean', true);
|
|
|
|
settings.define('enableParser', 'boolean', true);
|
|
|
|
settings.define('enableEmoticons', 'boolean', true);
|
|
|
|
settings.define('autoParseUrls', 'boolean', true);
|
|
|
|
settings.define('preventOverflow', 'boolean', false);
|
|
|
|
settings.define('expandTextBox', 'boolean', false);
|
|
|
|
settings.define('eepromAutoInsert', 'boolean', true);
|
|
|
|
settings.define('autoEmbedV1', 'boolean', false);
|
|
|
|
settings.define('soundEnable', 'boolean', true, false, true);
|
|
|
|
settings.define('soundPack', 'string', 'ajax-chat');
|
|
|
|
settings.define('soundVolume', 'number', 80);
|
|
|
|
settings.define('soundEnableJoin', 'boolean', true);
|
|
|
|
settings.define('soundEnableLeave', 'boolean', true);
|
|
|
|
settings.define('soundEnableError', 'boolean', true);
|
|
|
|
settings.define('soundEnableServer', 'boolean', true);
|
|
|
|
settings.define('soundEnableIncoming', 'boolean', true);
|
2024-01-23 01:23:33 +00:00
|
|
|
settings.define('onlySoundOnMention', 'boolean', false);
|
|
|
|
settings.define('soundEnableOutgoing', 'boolean', true);
|
2024-01-22 21:45:39 +00:00
|
|
|
settings.define('soundEnablePrivate', 'boolean', true);
|
|
|
|
settings.define('soundEnableForceLeave', 'boolean', true);
|
|
|
|
settings.define('minecraft', ['no', 'yes', 'old'], 'no');
|
|
|
|
settings.define('windowsLiveMessenger', 'boolean', false);
|
|
|
|
settings.define('seinfeld', 'boolean', false);
|
|
|
|
settings.define('flashTitle', 'boolean', true);
|
|
|
|
settings.define('showServerMsgInTitle', 'boolean', true);
|
|
|
|
settings.define('playJokeSounds', 'boolean', true);
|
|
|
|
settings.define('weeaboo', 'boolean', false);
|
|
|
|
settings.define('motivationalImages', 'boolean', false);
|
|
|
|
settings.define('motivationalVideos', 'boolean', false);
|
|
|
|
settings.define('osuKeys', 'boolean', false);
|
|
|
|
settings.define('osuKeysV2', ['no', 'yes', 'rng'], 'no');
|
|
|
|
settings.define('explosionRadius', 'number', 20);
|
|
|
|
settings.define('dumpPackets', 'boolean', FUTAMI_DEBUG);
|
2024-02-24 01:10:30 +00:00
|
|
|
settings.define('dumpEvents', 'boolean', FUTAMI_DEBUG);
|
2024-01-22 21:45:39 +00:00
|
|
|
settings.define('neverUseWorker', 'boolean', false, false, true);
|
|
|
|
settings.define('forceUseWorker', 'boolean', false, false, true);
|
|
|
|
settings.define('marqueeAllNames', 'boolean', false);
|
|
|
|
settings.define('tmpDisableOldThemeSys', 'boolean', false, false, true);
|
|
|
|
|
|
|
|
const noNotifSupport = !('Notification' in window);
|
|
|
|
settings.define('enableNotifications', 'boolean', false, noNotifSupport, true);
|
|
|
|
settings.define('notificationShowMessage', 'boolean', false, noNotifSupport);
|
|
|
|
settings.define('notificationTriggers', 'string', '', noNotifSupport);
|
|
|
|
|
|
|
|
|
2024-02-10 17:23:47 +00:00
|
|
|
loadingOverlay.setMessage('Loading sounds...');
|
|
|
|
const soundCtx = new MamiSoundContext;
|
|
|
|
|
2024-01-18 19:50:37 +00:00
|
|
|
try {
|
|
|
|
const sounds = await futami.getJson('sounds2');
|
|
|
|
if(Array.isArray(sounds.library))
|
2024-02-10 17:23:47 +00:00
|
|
|
soundCtx.library.register(sounds.library, true);
|
2024-01-18 19:50:37 +00:00
|
|
|
if(Array.isArray(sounds.packs))
|
2024-02-10 17:23:47 +00:00
|
|
|
soundCtx.packs.register(sounds.packs, true);
|
2024-01-18 19:50:37 +00:00
|
|
|
} catch(ex) {
|
|
|
|
console.error(ex);
|
|
|
|
}
|
|
|
|
|
2024-01-22 21:45:39 +00:00
|
|
|
if(!await MamiDetectAutoPlay()) {
|
|
|
|
settings.set('soundEnable', false);
|
|
|
|
settings.virtualise('soundEnable');
|
|
|
|
}
|
|
|
|
|
2024-03-01 19:07:17 +00:00
|
|
|
settings.watch('soundEnable', ev => {
|
|
|
|
console.log(ev);
|
|
|
|
if(ev.detail.value) {
|
2024-02-10 17:23:47 +00:00
|
|
|
if(!soundCtx.ready)
|
|
|
|
soundCtx.reset();
|
2024-01-22 21:45:39 +00:00
|
|
|
|
|
|
|
settings.touch('soundVolume');
|
|
|
|
settings.touch('soundPack');
|
|
|
|
|
2024-02-16 00:41:13 +00:00
|
|
|
soundCtx.library.play(soundCtx.pack.getEventSound('server'));
|
2024-01-22 21:45:39 +00:00
|
|
|
}
|
|
|
|
|
2024-03-01 19:07:17 +00:00
|
|
|
soundCtx.muted = !ev.detail.value;
|
2024-01-22 21:45:39 +00:00
|
|
|
});
|
|
|
|
|
2024-03-01 19:07:17 +00:00
|
|
|
settings.watch('soundPack', ev => {
|
2024-02-10 17:23:47 +00:00
|
|
|
const packs = soundCtx.packs;
|
2024-03-01 19:07:17 +00:00
|
|
|
if(!packs.has(ev.detail.value)) {
|
|
|
|
settings.delete(ev.detail.name);
|
2024-01-22 21:45:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-01 19:07:17 +00:00
|
|
|
soundCtx.pack = packs.get(ev.detail.value);
|
|
|
|
if(!ev.detail.initial) soundCtx.library.play(soundCtx.pack.getEventSound('server'));
|
2024-01-22 21:45:39 +00:00
|
|
|
});
|
|
|
|
|
2024-03-01 19:07:17 +00:00
|
|
|
settings.watch('soundVolume', ev => {
|
|
|
|
soundCtx.volume = ev.detail.value / 100;
|
2024-01-22 21:45:39 +00:00
|
|
|
})
|
|
|
|
|
2024-01-18 19:50:37 +00:00
|
|
|
|
2024-02-10 17:23:47 +00:00
|
|
|
loadingOverlay.setMessage('Loading emoticons...');
|
2024-01-18 19:50:37 +00:00
|
|
|
try {
|
|
|
|
const emotes = await futami.getJson('emotes');
|
|
|
|
MamiEmotes.loadLegacy(emotes);
|
|
|
|
} catch(ex) {
|
|
|
|
console.error(ex);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const onHashChange = () => {
|
|
|
|
if(location.hash === '#reset') {
|
2024-01-22 21:45:39 +00:00
|
|
|
settings.clear(true);
|
2024-01-18 19:50:37 +00:00
|
|
|
location.assign('/');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
window.addEventListener('hashchange', onHashChange);
|
|
|
|
onHashChange();
|
|
|
|
|
|
|
|
window.addEventListener('keydown', ev => {
|
2024-02-29 23:57:36 +00:00
|
|
|
if(ev.altKey && ev.shiftKey && (ev.key === 'R' || ev.key === 'r'))
|
2024-01-18 19:50:37 +00:00
|
|
|
location.hash = 'reset';
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2024-02-10 17:23:47 +00:00
|
|
|
let eeprom;
|
|
|
|
|
|
|
|
loadingOverlay.setMessage('Loading EEPROM...');
|
|
|
|
try {
|
|
|
|
await MamiEEPROM.init();
|
|
|
|
eeprom = new EEPROM('1', futami.get('eeprom2'), MamiMisuzuAuth.getLine);
|
|
|
|
} catch(ex) {
|
|
|
|
console.error(ex);
|
|
|
|
eeprom = undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
loadingOverlay.setMessage('Preparing UI...');
|
|
|
|
|
|
|
|
const textTriggers = new MamiTextTriggers;
|
|
|
|
|
|
|
|
// define this as late as possible'
|
|
|
|
const ctx = new MamiContext({
|
|
|
|
settings: settings,
|
|
|
|
views: views,
|
|
|
|
sound: soundCtx,
|
|
|
|
textTriggers: textTriggers,
|
|
|
|
eeprom: eeprom,
|
|
|
|
});
|
|
|
|
Object.defineProperty(window, 'mami', { enumerable: true, value: ctx });
|
2024-01-18 19:50:37 +00:00
|
|
|
|
2024-02-09 00:56:27 +00:00
|
|
|
// should be dynamic when possible
|
|
|
|
const layout = new Umi.UI.ChatLayout;
|
|
|
|
await views.unshift(layout);
|
|
|
|
|
2024-01-18 19:50:37 +00:00
|
|
|
Umi.UI.View.AccentReload();
|
2024-02-09 00:56:27 +00:00
|
|
|
Umi.UI.Hooks.AddHooks();
|
2024-01-18 19:50:37 +00:00
|
|
|
|
2024-03-01 19:07:17 +00:00
|
|
|
settings.watch('style', ev => { if(!ev.detail.initial) Umi.UI.View.AccentReload(); });
|
|
|
|
settings.watch('compactView', ev => { if(!ev.detail.initial) Umi.UI.View.AccentReload(); });
|
|
|
|
settings.watch('preventOverflow', ev => document.body.classList.toggle('prevent-overflow', ev.detail.value));
|
|
|
|
settings.watch('tmpDisableOldThemeSys', ev => { if(!ev.detail.initial) Umi.UI.View.AccentReload(); });
|
2024-01-22 21:45:39 +00:00
|
|
|
|
2024-03-01 19:07:17 +00:00
|
|
|
settings.watch('minecraft', ev => {
|
|
|
|
if(ev.detail.initial && ev.detail.value === 'no')
|
2024-02-16 00:41:13 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
soundCtx.library.play((() => {
|
2024-02-10 02:26:38 +00:00
|
|
|
if(i)
|
2024-02-16 00:41:13 +00:00
|
|
|
return 'minecraft:nether:enter';
|
2024-03-01 19:07:17 +00:00
|
|
|
if(ev.detail.value === 'yes')
|
2024-02-16 00:41:13 +00:00
|
|
|
return 'minecraft:door:open';
|
2024-03-01 19:07:17 +00:00
|
|
|
if(ev.detail.value === 'old')
|
2024-02-16 00:41:13 +00:00
|
|
|
return 'minecraft:door:open-old';
|
2024-02-24 01:10:30 +00:00
|
|
|
return soundCtx.pack.getEventSound('join');
|
2024-02-16 00:41:13 +00:00
|
|
|
})());
|
2024-01-22 21:45:39 +00:00
|
|
|
});
|
|
|
|
|
2024-03-01 19:07:17 +00:00
|
|
|
settings.watch('enableNotifications', ev => {
|
|
|
|
if(!ev.detail.value || !('Notification' in window)
|
2024-01-22 21:45:39 +00:00
|
|
|
|| (Notification.permission === 'granted' && Notification.permission !== 'denied'))
|
|
|
|
return;
|
|
|
|
|
|
|
|
Notification.requestPermission()
|
|
|
|
.then(perm => {
|
|
|
|
if(perm !== 'granted')
|
|
|
|
settings.set('enableNotifications', false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2024-03-01 19:07:17 +00:00
|
|
|
settings.watch('playJokeSounds', ev => {
|
|
|
|
if(!ev.detail.value) return;
|
2024-01-22 21:45:39 +00:00
|
|
|
|
2024-02-10 17:23:47 +00:00
|
|
|
if(!textTriggers.hasTriggers())
|
|
|
|
futami.getJson('texttriggers').then(trigInfos => textTriggers.addTriggers(trigInfos));
|
2024-01-22 21:45:39 +00:00
|
|
|
});
|
|
|
|
|
2024-03-01 19:07:17 +00:00
|
|
|
settings.watch('weeaboo', ev => {
|
|
|
|
if(ev.detail.value) Weeaboo.init();
|
2024-01-22 21:45:39 +00:00
|
|
|
});
|
|
|
|
|
2024-03-01 19:07:17 +00:00
|
|
|
settings.watch('osuKeysV2', ev => {
|
2024-01-22 21:45:39 +00:00
|
|
|
// migrate old value
|
2024-03-01 19:07:17 +00:00
|
|
|
if(ev.detail.initial) {
|
2024-01-22 21:45:39 +00:00
|
|
|
if(settings.has('osuKeys')) {
|
|
|
|
settings.set('osuKeysV2', settings.get('osuKeys') ? 'yes' : 'no');
|
|
|
|
settings.delete('osuKeys');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-01 19:07:17 +00:00
|
|
|
OsuKeys.setEnable(ev.detail.value !== 'no');
|
|
|
|
OsuKeys.setRandomRate(ev.detail.value === 'rng');
|
2024-01-22 21:45:39 +00:00
|
|
|
});
|
|
|
|
|
2024-01-18 19:50:37 +00:00
|
|
|
|
2024-02-10 17:23:47 +00:00
|
|
|
loadingOverlay.setMessage('Building menus...');
|
2024-01-18 19:50:37 +00:00
|
|
|
|
2024-02-29 23:57:36 +00:00
|
|
|
MamiCompat('Umi.Parser.SockChatBBcode.EmbedStub', { value: () => {} }); // intentionally a no-op
|
|
|
|
MamiCompat('Umi.UI.View.SetText', { value: text => console.log(`Umi.UI.View.SetText(text: ${text})`) });
|
|
|
|
MamiCompat('Umi.UI.Menus.Add', { value: (baseId, title, initiallyHidden) => console.log(`Umi.UI.Menus.Add(baseId: ${baseId}, title: ${title}, initiallyHidden: ${initiallyHidden})`) });
|
|
|
|
MamiCompat('Umi.UI.Menus.Get', { value: (baseId, icon) => console.log(`Umi.UI.Menus.Get(baseId: ${baseId}, icon: ${icon})`) });
|
|
|
|
|
2024-01-18 19:50:37 +00:00
|
|
|
Umi.UI.Menus.Add('users', 'Users');
|
2024-01-22 21:45:39 +00:00
|
|
|
Umi.UI.Menus.Add('channels', 'Channels', !settings.get('showChannelList'));
|
2024-01-18 19:50:37 +00:00
|
|
|
Umi.UI.Menus.Add('settings', 'Settings');
|
|
|
|
|
|
|
|
let sidebarAnimation = null;
|
|
|
|
|
|
|
|
Umi.UI.Settings.Init();
|
|
|
|
Umi.UI.Toggles.Add('menu-toggle', {
|
|
|
|
'click': function() {
|
|
|
|
const sidebar = $c('sidebar')[0],
|
|
|
|
toggle = Umi.UI.Toggles.Get('menu-toggle'),
|
|
|
|
toggleOpened = 'sidebar__selector-mode--menu-toggle-opened',
|
|
|
|
toggleClosed = 'sidebar__selector-mode--menu-toggle-closed',
|
|
|
|
isClosed = toggle.classList.contains(toggleClosed);
|
|
|
|
|
|
|
|
if(sidebarAnimation !== null) {
|
|
|
|
sidebarAnimation.cancel();
|
|
|
|
sidebarAnimation = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(isClosed) {
|
|
|
|
toggle.classList.add(toggleOpened);
|
|
|
|
toggle.classList.remove(toggleClosed);
|
|
|
|
} else {
|
|
|
|
toggle.classList.add(toggleClosed);
|
|
|
|
toggle.classList.remove(toggleOpened);
|
|
|
|
}
|
|
|
|
|
|
|
|
let update;
|
|
|
|
if(isClosed)
|
|
|
|
update = function(t) {
|
|
|
|
sidebar.style.width = (40 + (220 * t)).toString() + 'px';
|
|
|
|
};
|
|
|
|
else
|
|
|
|
update = function(t) {
|
|
|
|
sidebar.style.width = (260 - (220 * t)).toString() + 'px';
|
|
|
|
};
|
|
|
|
|
|
|
|
sidebarAnimation = MamiAnimate({
|
|
|
|
duration: 500,
|
2024-01-23 01:23:33 +00:00
|
|
|
easing: 'outExpo',
|
2024-01-18 19:50:37 +00:00
|
|
|
update: update,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, 'Toggle Sidebar');
|
|
|
|
|
|
|
|
Umi.UI.Toggles.Get('menu-toggle').classList.add('sidebar__selector-mode--menu-toggle-opened');
|
|
|
|
|
|
|
|
Umi.UI.Toggles.Add('scroll', {
|
|
|
|
'click': function() {
|
2024-01-22 21:45:39 +00:00
|
|
|
settings.toggle('autoScroll');
|
2024-01-18 19:50:37 +00:00
|
|
|
}
|
|
|
|
}, 'Autoscroll');
|
2024-03-01 19:07:17 +00:00
|
|
|
settings.watch('autoScroll', ev => {
|
|
|
|
Umi.UI.Toggles.Get('scroll').classList.toggle('sidebar__selector-mode--scroll-off', !ev.detail.value);
|
2024-01-18 19:50:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
if(window.innerWidth < 768)
|
|
|
|
Umi.UI.Toggles.Get('menu-toggle').click();
|
|
|
|
|
|
|
|
Umi.UI.Toggles.Add('audio', {
|
|
|
|
'click': function() {
|
2024-01-22 21:45:39 +00:00
|
|
|
settings.toggle('soundEnable');
|
2024-01-18 19:50:37 +00:00
|
|
|
}
|
|
|
|
}, 'Sounds');
|
2024-03-01 19:07:17 +00:00
|
|
|
settings.watch('soundEnable', ev => {
|
|
|
|
Umi.UI.Toggles.Get('audio').classList.toggle('sidebar__selector-mode--audio-off', !ev.detail.value);
|
2024-01-18 19:50:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
Umi.UI.Toggles.Add('unembed', {
|
|
|
|
'click': function() {
|
|
|
|
const buttons = $qa('[data-embed="1"]');
|
|
|
|
for(const button of buttons)
|
|
|
|
button.click();
|
|
|
|
}
|
|
|
|
}, 'Unembed any embedded media');
|
|
|
|
|
|
|
|
Umi.UI.Toggles.Add('clear', {
|
|
|
|
'click': function() {
|
|
|
|
if(confirm('ARE YOU SURE ABOUT THAT???')) {
|
2024-01-22 21:45:39 +00:00
|
|
|
const limit = settings.get('explosionRadius');
|
2024-01-18 19:50:37 +00:00
|
|
|
const explode = $e({
|
|
|
|
tag: 'img',
|
|
|
|
attrs: {
|
|
|
|
src: '//static.flash.moe/images/explode.gif',
|
|
|
|
alt: '',
|
|
|
|
style: {
|
|
|
|
position: 'absolute',
|
|
|
|
zIndex: 9001,
|
|
|
|
bottom: 0,
|
|
|
|
right: 0,
|
|
|
|
pointerEvents: 'none',
|
|
|
|
},
|
|
|
|
onLoad: function() {
|
|
|
|
setTimeout(function(){
|
|
|
|
$r(explode);
|
|
|
|
}, 1700);
|
|
|
|
|
2024-02-10 17:23:47 +00:00
|
|
|
soundCtx.library.play('misc:explode');
|
2024-01-18 19:50:37 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
document.body.appendChild(explode);
|
|
|
|
|
|
|
|
let backLog = Umi.Messages.All();
|
|
|
|
backLog = backLog.slice(Math.max(backLog.length - limit, 0));
|
|
|
|
|
|
|
|
Umi.Messages.Clear();
|
|
|
|
|
|
|
|
for(const blMsg of backLog)
|
|
|
|
Umi.Messages.Add(blMsg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 'Clear Logs');
|
|
|
|
|
2024-02-29 21:43:00 +00:00
|
|
|
const pingIndicator = new MamiPingIndicator;
|
2024-02-29 21:55:29 +00:00
|
|
|
const pingToggle = Umi.UI.Toggles.Add('ping', {
|
|
|
|
click: () => alert(pingToggle.title),
|
2024-02-29 21:58:01 +00:00
|
|
|
}, 'Ready~');
|
2024-02-29 21:43:00 +00:00
|
|
|
pingToggle.appendChild(pingIndicator.getElement());
|
|
|
|
|
2024-01-18 19:50:37 +00:00
|
|
|
|
2024-02-10 17:23:47 +00:00
|
|
|
if(eeprom !== undefined) {
|
2024-01-18 19:50:37 +00:00
|
|
|
Umi.UI.Menus.Add('uploads', 'Upload History', !FUTAMI_DEBUG);
|
|
|
|
|
2024-02-02 21:02:29 +00:00
|
|
|
const doUpload = async file => {
|
|
|
|
const uploadEntry = Umi.UI.Uploads.create(file.name);
|
2024-02-10 17:23:47 +00:00
|
|
|
const uploadTask = eeprom.create(file);
|
2024-01-18 19:50:37 +00:00
|
|
|
|
2024-02-02 21:02:29 +00:00
|
|
|
uploadTask.onProgress(prog => uploadEntry.setProgress(prog.progress));
|
|
|
|
uploadEntry.addOption('Cancel', () => uploadTask.abort());
|
|
|
|
|
|
|
|
try {
|
|
|
|
const fileInfo = await uploadTask.start();
|
2024-01-18 19:50:37 +00:00
|
|
|
|
|
|
|
uploadEntry.hideOptions();
|
|
|
|
uploadEntry.clearOptions();
|
|
|
|
uploadEntry.removeProgress();
|
|
|
|
|
|
|
|
uploadEntry.addOption('Open', fileInfo.url);
|
2024-02-02 21:02:29 +00:00
|
|
|
uploadEntry.addOption('Insert', () => Umi.UI.Markup.InsertRaw(insertText, ''));
|
|
|
|
uploadEntry.addOption('Delete', () => {
|
2024-02-10 17:23:47 +00:00
|
|
|
eeprom.delete(fileInfo)
|
2024-02-02 21:02:29 +00:00
|
|
|
.then(() => uploadEntry.remove())
|
|
|
|
.catch(ex => {
|
|
|
|
console.error(ex);
|
|
|
|
alert(ex);
|
|
|
|
});
|
2024-01-18 19:50:37 +00:00
|
|
|
});
|
|
|
|
|
2024-02-02 21:02:29 +00:00
|
|
|
let insertText;
|
2024-01-18 19:50:37 +00:00
|
|
|
|
|
|
|
if(fileInfo.isImage()) {
|
2024-02-02 21:02:29 +00:00
|
|
|
insertText = `[img]${fileInfo.url}[/img]`;
|
2024-01-18 19:50:37 +00:00
|
|
|
uploadEntry.setThumbnail(fileInfo.thumb);
|
2024-02-02 21:02:29 +00:00
|
|
|
} else if(fileInfo.isAudio()) {
|
|
|
|
insertText = `[audio]${fileInfo.url}[/audio]`;
|
2024-01-18 19:50:37 +00:00
|
|
|
uploadEntry.setThumbnail(fileInfo.thumb);
|
|
|
|
} else if(fileInfo.isVideo()) {
|
2024-02-02 21:02:29 +00:00
|
|
|
insertText = `[video]${fileInfo.url}[/video]`;
|
2024-01-18 19:50:37 +00:00
|
|
|
uploadEntry.setThumbnail(fileInfo.thumb);
|
2024-02-02 21:02:29 +00:00
|
|
|
} else
|
2024-02-24 02:42:35 +00:00
|
|
|
insertText = location.protocol + fileInfo.url;
|
2024-01-18 19:50:37 +00:00
|
|
|
|
2024-01-22 21:45:39 +00:00
|
|
|
if(settings.get('eepromAutoInsert'))
|
2024-01-18 19:50:37 +00:00
|
|
|
Umi.UI.Markup.InsertRaw(insertText, '');
|
2024-02-02 21:02:29 +00:00
|
|
|
} catch(ex) {
|
|
|
|
if(!ex.aborted) {
|
|
|
|
console.error(ex);
|
|
|
|
alert(ex);
|
|
|
|
}
|
2024-01-18 19:50:37 +00:00
|
|
|
|
2024-02-02 21:02:29 +00:00
|
|
|
uploadEntry.remove();
|
|
|
|
}
|
2024-01-18 19:50:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const uploadForm = $e({
|
|
|
|
tag: 'input',
|
|
|
|
attrs: {
|
|
|
|
type: 'file',
|
|
|
|
multiple: true,
|
2024-02-02 21:02:29 +00:00
|
|
|
style: { display: 'none' },
|
|
|
|
onchange: ev => {
|
|
|
|
for(const file of ev.target.files)
|
|
|
|
doUpload(file);
|
2024-01-18 19:50:37 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
document.body.appendChild(uploadForm);
|
|
|
|
|
2024-02-02 21:02:29 +00:00
|
|
|
Umi.UI.InputMenus.AddButton('upload', 'Upload', () => uploadForm.click());
|
2024-01-18 19:50:37 +00:00
|
|
|
|
2024-02-09 00:56:27 +00:00
|
|
|
$i('umi-msg-text').onpaste = ev => {
|
2024-01-18 19:50:37 +00:00
|
|
|
if(ev.clipboardData && ev.clipboardData.files.length > 0)
|
|
|
|
for(const file of ev.clipboardData.files)
|
|
|
|
doUpload(file);
|
|
|
|
};
|
|
|
|
|
2024-02-02 21:02:29 +00:00
|
|
|
document.body.ondragenter = ev => {
|
2024-01-18 19:50:37 +00:00
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
|
|
|
};
|
2024-02-02 21:02:29 +00:00
|
|
|
document.body.ondragover = ev => {
|
2024-01-18 19:50:37 +00:00
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
|
|
|
};
|
2024-02-02 21:02:29 +00:00
|
|
|
document.body.ondragleave = ev => {
|
2024-01-18 19:50:37 +00:00
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
|
|
|
};
|
2024-02-02 21:02:29 +00:00
|
|
|
document.body.ondrop = ev => {
|
2024-01-18 19:50:37 +00:00
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
2024-02-02 21:02:29 +00:00
|
|
|
|
2024-01-18 19:50:37 +00:00
|
|
|
if(ev.dataTransfer && ev.dataTransfer.files.length > 0)
|
|
|
|
for(const file of ev.dataTransfer.files) {
|
|
|
|
if(file.name.slice(-5) === '.mami'
|
2024-01-22 21:45:39 +00:00
|
|
|
&& confirm('This file appears to be a settings export. Do you want to import it? This will overwrite your existing settings!')) {
|
|
|
|
(new MamiSettingsBackup(settings)).importFile(file);
|
2024-01-18 19:50:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
doUpload(file);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
Umi.UI.InputMenus.Add('markup', 'BB Code');
|
|
|
|
Umi.UI.InputMenus.Add('emotes', 'Emoticons');
|
|
|
|
|
|
|
|
window.addEventListener('beforeunload', function(ev) {
|
2024-01-22 21:45:39 +00:00
|
|
|
if(settings.get('closeTabConfirm')) {
|
2024-01-18 19:50:37 +00:00
|
|
|
ev.preventDefault();
|
|
|
|
return ev.returnValue = 'Are you sure you want to close the tab?';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2024-02-24 01:10:30 +00:00
|
|
|
// really not sure about all the watchers for the protocol just kinda being Listed here but we'll see i guess
|
2024-02-10 17:23:47 +00:00
|
|
|
loadingOverlay.setMessage('Connecting...');
|
2024-02-24 01:10:30 +00:00
|
|
|
|
|
|
|
const getLoadingOverlay = async (icon, header, message) => {
|
|
|
|
const currentView = views.current();
|
|
|
|
|
|
|
|
if('setIcon' in currentView) {
|
|
|
|
currentView.setIcon(icon);
|
|
|
|
currentView.setHeader(header);
|
|
|
|
currentView.setMessage(message);
|
|
|
|
return currentView;
|
|
|
|
}
|
|
|
|
|
|
|
|
const loading = new Umi.UI.LoadingOverlay(icon, header, message);
|
|
|
|
await views.push(loading);
|
|
|
|
|
|
|
|
return loading;
|
|
|
|
};
|
|
|
|
|
|
|
|
const wsCloseReasons = {
|
|
|
|
'_1000': 'The connection has been ended.',
|
|
|
|
'_1001': 'Something went wrong on the server side.',
|
|
|
|
'_1002': 'Your client sent broken data to the server.',
|
|
|
|
'_1003': 'Your client sent data to the server that it does not understand.',
|
|
|
|
'_1005': 'No additional information was provided.',
|
|
|
|
'_1006': 'You lost connection unexpectedly!',
|
|
|
|
'_1007': 'Your client sent broken data to the server.',
|
|
|
|
'_1008': 'Your client did something the server did not agree with.',
|
|
|
|
'_1009': 'Your client sent too much data to the server at once.',
|
|
|
|
'_1011': 'Something went wrong on the server side.',
|
|
|
|
'_1012': 'The server is restarting, reconnecting soon...',
|
|
|
|
'_1013': 'You cannot connect to the server right now, try again later.',
|
|
|
|
'_1015': 'Your client and the server could not establish a secure connection.',
|
|
|
|
};
|
2024-02-24 20:26:40 +00:00
|
|
|
const sessFailReasons = {
|
|
|
|
'authfail': 'Authentication failed.',
|
|
|
|
'sockfail': 'Too many active connections.',
|
|
|
|
'userfail': 'Name in use.',
|
|
|
|
'joinfail': 'You are banned.',
|
|
|
|
};
|
2024-02-24 01:10:30 +00:00
|
|
|
|
2024-03-01 19:17:20 +00:00
|
|
|
const sockChat = new Umi.Protocol.SockChat.Protocol(futami.get('ping') * 1000);
|
2024-02-29 23:57:36 +00:00
|
|
|
MamiCompat('Umi.Server', { get: () => sockChat, configurable: true });
|
|
|
|
|
2024-02-24 01:10:30 +00:00
|
|
|
let dumpEvents = false;
|
2024-03-01 19:07:17 +00:00
|
|
|
settings.watch('dumpEvents', ev => dumpEvents = ev.detail.value);
|
|
|
|
settings.watch('dumpPackets', ev => sockChat.setDumpPackets(ev.detail.value));
|
2024-02-24 01:10:30 +00:00
|
|
|
|
2024-02-29 23:57:36 +00:00
|
|
|
Umi.UI.Hooks.SetCallbacks(sockChat.sendMessage, sockChat.switchChannel);
|
|
|
|
|
|
|
|
MamiCompat('Umi.Server.SendMessage', { value: text => sockChat.sendMessage(text), configurable: true });
|
|
|
|
MamiCompat('Umi.Protocol.SockChat.Protocol.Instance.SendMessage', { value: text => sockChat.sendMessage(text), configurable: true });
|
|
|
|
MamiCompat('Umi.Protocol.SockLegacy.Protocol.Instance.SendMessage', { value: text => sockChat.sendMessage(text), configurable: true });
|
|
|
|
|
2024-03-01 19:07:17 +00:00
|
|
|
sockChat.watch('conn:init', ev => {
|
|
|
|
if(dumpEvents) console.log('conn:init', ev);
|
2024-02-24 01:10:30 +00:00
|
|
|
|
|
|
|
let message = 'Connecting to server...';
|
2024-03-01 19:07:17 +00:00
|
|
|
if(ev.detail.attempt > 2)
|
2024-02-24 01:10:30 +00:00
|
|
|
message += ` (Attempt ${connectAttempts})`;
|
|
|
|
|
|
|
|
getLoadingOverlay('spinner', 'Loading...', message);
|
|
|
|
});
|
2024-03-01 19:07:17 +00:00
|
|
|
sockChat.watch('conn:ready', ev => {
|
|
|
|
if(dumpEvents) console.log('conn:ready', ev);
|
2024-02-24 01:10:30 +00:00
|
|
|
|
|
|
|
getLoadingOverlay('spinner', 'Loading...', 'Authenticating...');
|
2024-02-29 23:19:36 +00:00
|
|
|
|
|
|
|
const authInfo = MamiMisuzuAuth.getInfo();
|
2024-02-29 23:57:36 +00:00
|
|
|
sockChat.sendAuth(authInfo.method, authInfo.token);
|
2024-02-24 01:10:30 +00:00
|
|
|
});
|
2024-03-01 19:07:17 +00:00
|
|
|
sockChat.watch('conn:lost', ev => {
|
|
|
|
if(dumpEvents) console.log('conn:lost', ev);
|
2024-02-24 01:10:30 +00:00
|
|
|
|
|
|
|
getLoadingOverlay(
|
|
|
|
'unlink', 'Disconnected!',
|
2024-03-01 19:07:17 +00:00
|
|
|
wsCloseReasons[`_${ev.detail.code}`] ?? `Something caused an unexpected connection loss. (${ev.detail.code})`
|
2024-02-24 01:10:30 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2024-03-01 19:07:17 +00:00
|
|
|
sockChat.watch('ping:send', ev => {
|
|
|
|
if(dumpEvents) console.log('ping:send', ev);
|
2024-02-24 01:10:30 +00:00
|
|
|
});
|
2024-03-01 19:07:17 +00:00
|
|
|
sockChat.watch('ping:long', ev => {
|
|
|
|
if(dumpEvents) console.log('ping:long', ev);
|
2024-02-29 21:43:00 +00:00
|
|
|
|
2024-02-29 21:55:29 +00:00
|
|
|
pingToggle.title = '+2000ms';
|
2024-02-29 21:43:00 +00:00
|
|
|
pingIndicator.setStrength(0);
|
2024-02-24 01:10:30 +00:00
|
|
|
});
|
2024-03-01 19:07:17 +00:00
|
|
|
sockChat.watch('ping:recv', ev => {
|
|
|
|
if(dumpEvents) console.log('ping:recv', ev);
|
2024-02-29 21:43:00 +00:00
|
|
|
|
|
|
|
let strength = 3;
|
2024-03-01 19:07:17 +00:00
|
|
|
if(ev.detail.diff >= 1000) --strength;
|
|
|
|
if(ev.detail.diff >= 250) --strength;
|
2024-02-29 21:43:00 +00:00
|
|
|
|
2024-03-01 19:07:17 +00:00
|
|
|
pingToggle.title = `${ev.detail.diff.toLocaleString()}ms`;
|
2024-02-29 21:43:00 +00:00
|
|
|
pingIndicator.setStrength(strength);
|
2024-02-24 01:10:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2024-03-01 19:07:17 +00:00
|
|
|
sockChat.watch('session:start', ev => {
|
|
|
|
if(dumpEvents) console.log('session:start', ev);
|
2024-02-24 01:10:30 +00:00
|
|
|
|
2024-03-01 19:07:17 +00:00
|
|
|
const userInfo = new Umi.User(ev.detail.user.id, ev.detail.user.name, ev.detail.user.colour, ev.detail.user.permsRaw);
|
2024-02-24 01:10:30 +00:00
|
|
|
Umi.User.setCurrentUser(userInfo);
|
|
|
|
Umi.Users.Add(userInfo);
|
|
|
|
|
|
|
|
Umi.UI.Markup.Reset();
|
|
|
|
Umi.UI.Emoticons.Init();
|
|
|
|
Umi.Parsing.Init();
|
|
|
|
|
|
|
|
views.pop(ctx => MamiAnimate({
|
|
|
|
async: true,
|
|
|
|
duration: 120,
|
|
|
|
easing: 'inOutSine',
|
|
|
|
start: () => {
|
|
|
|
ctx.toElem.style.zIndex = '100';
|
|
|
|
ctx.fromElem.style.pointerEvents = 'none';
|
|
|
|
ctx.fromElem.style.zIndex = '200';
|
|
|
|
},
|
|
|
|
update: t => {
|
|
|
|
ctx.fromElem.style.transform = `scale(${1 + (.25 * t)})`;
|
|
|
|
ctx.fromElem.style.opacity = 1 - (1 * t).toString();
|
|
|
|
},
|
|
|
|
end: () => {
|
|
|
|
ctx.toElem.style.zIndex = null;
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
});
|
2024-03-01 19:07:17 +00:00
|
|
|
sockChat.watch('session:fail', ev => {
|
|
|
|
if(dumpEvents) console.log('session:fail', ev);
|
2024-02-24 01:10:30 +00:00
|
|
|
|
2024-03-01 19:07:17 +00:00
|
|
|
if(ev.detail.baka !== undefined) {
|
|
|
|
new MamiForceDisconnectNotice(ev.detail.baka).pushOn(views);
|
2024-02-24 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-02-24 20:26:40 +00:00
|
|
|
getLoadingOverlay(
|
|
|
|
'cross', 'Failed!',
|
2024-03-01 19:07:17 +00:00
|
|
|
sessFailReasons[ev.detail.session.reason] ?? `Unknown reason: ${ev.detail.session.reason}`
|
2024-02-24 20:26:40 +00:00
|
|
|
);
|
2024-02-24 01:10:30 +00:00
|
|
|
|
2024-03-01 19:07:17 +00:00
|
|
|
if(ev.detail.session.needsAuth)
|
2024-02-24 01:10:30 +00:00
|
|
|
setTimeout(() => location.assign(futami.get('login')), 1000);
|
|
|
|
});
|
2024-03-01 19:07:17 +00:00
|
|
|
sockChat.watch('session:term', ev => {
|
|
|
|
if(dumpEvents) console.log('session:term', ev);
|
2024-02-24 01:10:30 +00:00
|
|
|
|
2024-03-01 19:07:17 +00:00
|
|
|
new MamiForceDisconnectNotice(ev.detail.baka).pushOn(views);
|
2024-02-24 01:10:30 +00:00
|
|
|
});
|
|
|
|
|
2024-03-01 19:07:17 +00:00
|
|
|
sockChat.watch('user:add', ev => {
|
|
|
|
if(dumpEvents) console.log('user:add', ev);
|
2024-02-24 01:10:30 +00:00
|
|
|
|
2024-03-01 19:07:17 +00:00
|
|
|
if(ev.detail.user.self)
|
2024-02-24 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
2024-03-01 19:07:17 +00:00
|
|
|
const userInfo = new Umi.User(ev.detail.user.id, ev.detail.user.name, ev.detail.user.colour, ev.detail.user.permsRaw);
|
2024-02-24 01:10:30 +00:00
|
|
|
Umi.Users.Add(userInfo);
|
|
|
|
|
2024-03-01 19:07:17 +00:00
|
|
|
if(ev.detail.msg !== undefined)
|
2024-02-24 01:10:30 +00:00
|
|
|
Umi.Messages.Add(new Umi.Message(
|
2024-03-01 19:07:17 +00:00
|
|
|
ev.detail.msg.id, ev.detail.msg.time, undefined, '', ev.detail.msg.channel, false,
|
2024-02-24 01:10:30 +00:00
|
|
|
{
|
|
|
|
isError: false,
|
2024-03-01 19:07:17 +00:00
|
|
|
type: ev.detail.msg.botInfo.type,
|
|
|
|
args: ev.detail.msg.botInfo.args,
|
2024-02-24 01:10:30 +00:00
|
|
|
target: userInfo,
|
|
|
|
}
|
|
|
|
));
|
|
|
|
});
|
2024-03-01 19:07:17 +00:00
|
|
|
sockChat.watch('user:remove', ev => {
|
|
|
|
if(dumpEvents) console.log('user:remove', ev);
|
2024-02-24 01:10:30 +00:00
|
|
|
|
2024-03-01 19:07:17 +00:00
|
|
|
const userInfo = Umi.Users.Get(ev.detail.user.id);
|
2024-02-24 01:10:30 +00:00
|
|
|
if(userInfo === null)
|
|
|
|
return;
|
|
|
|
|
2024-03-01 19:07:17 +00:00
|
|
|
if(ev.detail.msg !== undefined)
|
2024-02-24 01:10:30 +00:00
|
|
|
Umi.Messages.Add(new Umi.Message(
|
2024-03-01 19:07:17 +00:00
|
|
|
ev.detail.msg.id,
|
|
|
|
ev.detail.msg.time,
|
2024-02-24 01:10:30 +00:00
|
|
|
undefined,
|
|
|
|
'',
|
2024-03-01 19:07:17 +00:00
|
|
|
ev.detail.msg.channel,
|
2024-02-24 01:10:30 +00:00
|
|
|
false,
|
|
|
|
{
|
|
|
|
isError: false,
|
2024-03-01 19:07:17 +00:00
|
|
|
type: ev.detail.msg.botInfo.type,
|
|
|
|
args: ev.detail.msg.botInfo.args,
|
2024-02-24 01:10:30 +00:00
|
|
|
target: userInfo,
|
|
|
|
},
|
|
|
|
));
|
|
|
|
|
|
|
|
Umi.Users.Remove(userInfo);
|
|
|
|
});
|
2024-03-01 19:07:17 +00:00
|
|
|
sockChat.watch('user:update', ev => {
|
|
|
|
if(dumpEvents) console.log('user:update', ev);
|
2024-02-24 01:10:30 +00:00
|
|
|
|
2024-03-01 19:07:17 +00:00
|
|
|
const userInfo = Umi.Users.Get(ev.detail.user.id);
|
|
|
|
userInfo.setName(ev.detail.user.name);
|
|
|
|
userInfo.setColour(ev.detail.user.colour);
|
|
|
|
userInfo.setPermissions(ev.detail.user.permsRaw);
|
2024-02-24 01:10:30 +00:00
|
|
|
Umi.Users.Update(userInfo.getId(), userInfo);
|
|
|
|
});
|
2024-03-01 19:07:17 +00:00
|
|
|
sockChat.watch('user:clear', ev => {
|
|
|
|
if(dumpEvents) console.log('user:clear', ev);
|
2024-02-24 01:10:30 +00:00
|
|
|
|
|
|
|
const self = Umi.User.currentUser;
|
|
|
|
Umi.Users.Clear();
|
|
|
|
if(self !== undefined)
|
|
|
|
Umi.Users.Add(self);
|
|
|
|
});
|
|
|
|
|
2024-03-01 19:07:17 +00:00
|
|
|
sockChat.watch('chan:add', ev => {
|
|
|
|
if(dumpEvents) console.log('chan:add', ev);
|
2024-02-24 01:10:30 +00:00
|
|
|
|
|
|
|
Umi.Channels.Add(new Umi.Channel(
|
2024-03-01 19:07:17 +00:00
|
|
|
ev.detail.channel.name,
|
|
|
|
ev.detail.channel.hasPassword,
|
|
|
|
ev.detail.channel.isTemporary,
|
2024-02-24 01:10:30 +00:00
|
|
|
));
|
|
|
|
});
|
2024-03-01 19:07:17 +00:00
|
|
|
sockChat.watch('chan:remove', ev => {
|
|
|
|
if(dumpEvents) console.log('chan:remove', ev);
|
2024-02-24 01:10:30 +00:00
|
|
|
|
2024-03-01 19:07:17 +00:00
|
|
|
Umi.Channels.Remove(Umi.Channels.Get(ev.detail.channel.name));
|
2024-02-24 01:10:30 +00:00
|
|
|
});
|
2024-03-01 19:07:17 +00:00
|
|
|
sockChat.watch('chan:update', ev => {
|
|
|
|
if(dumpEvents) console.log('chan:update', ev);
|
2024-02-24 01:10:30 +00:00
|
|
|
|
2024-03-01 19:07:17 +00:00
|
|
|
const chanInfo = Umi.Channels.Get(ev.detail.channel.previousName);
|
|
|
|
chanInfo.setName(ev.detail.channel.name);
|
|
|
|
chanInfo.setHasPassword(ev.detail.channel.hasPassword);
|
|
|
|
chanInfo.setTemporary(ev.detail.channel.isTemporary);
|
|
|
|
Umi.Channels.Update(ev.detail.channel.previousName, chanInfo);
|
2024-02-24 01:10:30 +00:00
|
|
|
});
|
2024-03-01 19:07:17 +00:00
|
|
|
sockChat.watch('chan:clear', ev => {
|
|
|
|
if(dumpEvents) console.log('chan:clear', ev);
|
2024-02-24 01:10:30 +00:00
|
|
|
|
|
|
|
Umi.Channels.Clear();
|
|
|
|
});
|
2024-03-01 19:07:17 +00:00
|
|
|
sockChat.watch('chan:focus', ev => {
|
|
|
|
if(dumpEvents) console.log('chan:focus', ev);
|
2024-02-24 01:10:30 +00:00
|
|
|
|
2024-03-01 19:07:17 +00:00
|
|
|
Umi.Channels.Switch(Umi.Channels.Get(ev.detail.channel.name));
|
2024-02-24 01:10:30 +00:00
|
|
|
});
|
2024-03-01 19:07:17 +00:00
|
|
|
sockChat.watch('chan:join', ev => {
|
|
|
|
if(dumpEvents) console.log('chan:join', ev);
|
2024-02-24 01:10:30 +00:00
|
|
|
|
2024-03-01 19:07:17 +00:00
|
|
|
const userInfo = new Umi.User(ev.detail.user.id, ev.detail.user.name, ev.detail.user.colour, ev.detail.user.permsRaw);
|
2024-02-24 01:10:30 +00:00
|
|
|
Umi.Users.Add(userInfo);
|
|
|
|
|
2024-03-01 19:07:17 +00:00
|
|
|
if(ev.detail.msg !== undefined)
|
2024-02-24 01:10:30 +00:00
|
|
|
Umi.Messages.Add(new Umi.Message(
|
2024-03-01 19:07:17 +00:00
|
|
|
ev.detail.msg.id, null, undefined, '', ev.detail.msg.channel, false,
|
2024-02-24 01:10:30 +00:00
|
|
|
{
|
|
|
|
isError: false,
|
|
|
|
type: leave.msg.botInfo.type,
|
|
|
|
args: [ userInfo.getName() ],
|
|
|
|
target: userInfo,
|
|
|
|
},
|
|
|
|
));
|
|
|
|
});
|
2024-03-01 19:07:17 +00:00
|
|
|
sockChat.watch('chan:leave', ev => {
|
|
|
|
if(dumpEvents) console.log('chan:leave', ev);
|
2024-02-24 01:10:30 +00:00
|
|
|
|
2024-03-01 19:07:17 +00:00
|
|
|
if(ev.detail.user.self)
|
2024-02-24 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
2024-03-01 19:07:17 +00:00
|
|
|
const userInfo = Umi.Users.Get(ev.detail.user.id);
|
2024-02-24 01:10:30 +00:00
|
|
|
if(userInfo === null)
|
|
|
|
return;
|
|
|
|
|
2024-03-01 19:07:17 +00:00
|
|
|
if(ev.detail.msg !== undefined)
|
2024-02-24 01:10:30 +00:00
|
|
|
Umi.Messages.Add(new Umi.Message(
|
2024-03-01 19:07:17 +00:00
|
|
|
ev.detail.msg.id, null, undefined, '', ev.detail.msg.channel, false,
|
2024-02-24 01:10:30 +00:00
|
|
|
{
|
|
|
|
isError: false,
|
2024-03-01 19:07:17 +00:00
|
|
|
type: ev.detail.msg.botInfo.type,
|
2024-02-24 01:10:30 +00:00
|
|
|
args: [ userInfo.getName() ],
|
|
|
|
target: userInfo,
|
|
|
|
},
|
|
|
|
));
|
|
|
|
|
|
|
|
Umi.Users.Remove(userInfo);
|
|
|
|
});
|
|
|
|
|
2024-03-01 19:07:17 +00:00
|
|
|
sockChat.watch('msg:add', ev => {
|
|
|
|
if(dumpEvents) console.log('msg:add', ev);
|
2024-02-24 01:10:30 +00:00
|
|
|
|
2024-03-01 19:07:17 +00:00
|
|
|
const senderInfo = ev.detail.msg.sender;
|
2024-02-24 01:10:30 +00:00
|
|
|
const userInfo = senderInfo.name === undefined
|
|
|
|
? Umi.Users.Get(senderInfo.id)
|
|
|
|
: new Umi.User(senderInfo.id, senderInfo.name, senderInfo.colour, senderInfo.permsRaw);
|
|
|
|
|
|
|
|
// hack
|
2024-03-01 19:07:17 +00:00
|
|
|
let channelName = ev.detail.msg.channel;
|
2024-02-24 01:10:30 +00:00
|
|
|
if(channelName !== undefined && channelName.startsWith('@~')) {
|
|
|
|
const chanUserInfo = Umi.Users.Get(channelName.substring(2));
|
|
|
|
if(chanUserInfo !== null)
|
|
|
|
channelName = `@${chanUserInfo.getName()}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
// also hack
|
2024-03-01 19:07:17 +00:00
|
|
|
if(ev.detail.msg.flags.isPM) {
|
2024-02-24 01:10:30 +00:00
|
|
|
if(Umi.Channels.Get(channelName) === null)
|
|
|
|
Umi.Channels.Add(new Umi.Channel(channelName, false, true, true));
|
|
|
|
|
|
|
|
// this should be raised for other channels too, but that is not possible yet
|
|
|
|
Umi.UI.Menus.Attention('channels');
|
|
|
|
}
|
|
|
|
|
|
|
|
Umi.Messages.Add(new Umi.Message(
|
2024-03-01 19:07:17 +00:00
|
|
|
ev.detail.msg.id,
|
|
|
|
ev.detail.msg.time,
|
2024-02-24 01:10:30 +00:00
|
|
|
userInfo,
|
2024-03-01 19:07:17 +00:00
|
|
|
ev.detail.msg.text,
|
2024-02-24 01:10:30 +00:00
|
|
|
channelName,
|
|
|
|
false,
|
2024-03-01 19:07:17 +00:00
|
|
|
ev.detail.msg.botInfo,
|
|
|
|
ev.detail.msg.flags.isAction,
|
|
|
|
ev.detail.msg.silent,
|
2024-02-24 01:10:30 +00:00
|
|
|
));
|
|
|
|
});
|
2024-03-01 19:07:17 +00:00
|
|
|
sockChat.watch('msg:remove', ev => {
|
|
|
|
if(dumpEvents) console.log('msg:remove', ev);
|
2024-02-24 01:10:30 +00:00
|
|
|
|
2024-03-01 19:07:17 +00:00
|
|
|
Umi.Messages.Remove(Umi.Messages.Get(ev.detail.msg.id));
|
2024-02-24 01:10:30 +00:00
|
|
|
});
|
2024-03-01 19:07:17 +00:00
|
|
|
sockChat.watch('msg:clear', ev => {
|
|
|
|
if(dumpEvents) console.log('msg:clear', ev);
|
2024-02-24 01:10:30 +00:00
|
|
|
|
|
|
|
Umi.UI.Messages.RemoveAll();
|
|
|
|
});
|
|
|
|
|
2024-02-29 23:57:36 +00:00
|
|
|
sockChat.open();
|
2024-01-18 19:50:37 +00:00
|
|
|
|
|
|
|
if(window.dispatchEvent)
|
|
|
|
window.dispatchEvent(new Event('umi:connect'));
|
|
|
|
})();
|