Skip to content

Commit 1f33716

Browse files
committed
chore: updated to new chat
1 parent 086131e commit 1f33716

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

changelog.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# UnderScript Changelog
22

3+
## Version 0.41.0 (2020-10-12)
4+
### New Features
5+
1. Reload Cards menu item
6+
### Fixes
7+
1. Load storage more reliably
8+
1. Don't show "turn start" twice
9+
1. Load card name from storage
10+
### Misc.
11+
1. Changed @everyone to @underscript
12+
1. Updated for next patch
13+
314
## Version 0.40.0 (2020-08-31)
415
### New Features
516
1. First/Last page shortcut now works on every valid webpage
@@ -9,6 +20,7 @@
920
1. Settings -> Library -> Merge Shiny Cards
1021
Note: When these filter settings are applied, the rarity icons are semi-transparent (making them look darker)
1122

23+
1224
## Version 0.39.2
1325
1. Fixed battle log being inconsistent on game finish for players/spectators
1426
1. Fixed some internal bugs

src/base/chat/autocomplete.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ wrap(function setup() {
155155
}
156156

157157
function add(name, list) {
158-
if (name === global('selfUsername')) return;
158+
if (!list || name === global('selfUsername')) return;
159159
const slot = list.indexOf(name);
160160
if (slot > -1) list.splice(slot, 1);
161161
list.push(name);

src/base/chat/toast.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ wrap(() => {
2222
if (shouldIgnore(msg, true)) return;
2323
if (!msg.message.toLowerCase().includes(`@${global('selfUsername').toLowerCase()}`) && !fn.pingRegex().test(msg.message)) return;
2424
const avatar = !settings.value('chatAvatarsDisabled') ? `<img src="/images/avatars/${msg.user.avatar.image}.${msg.user.avatar.extension || 'png'}" class="avatar ${msg.user.avatar.rarity}" height="35" style="float: left; margin-right: 7px;">` : '';
25+
const chatNames = global('chatNames', { throws: false });
2526
fn.toast({
26-
title: `${avatar}${fn.user.name(msg.user)} (${chatRoomNames[data.room]})`,
27+
title: `${avatar}${fn.user.name(msg.user)} (${chatRoomNames[data.room] || chatNames && chatNames[data.idRoom] ? $.i18n(chatNames[data.idRoom]) : data.idRoom || 'UNKNOWN'})`,
2728
text: msg.message,
2829
});
2930
});

src/hooks/chat.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,34 @@ eventManager.on(':loaded', () => {
1616
}
1717
if (eventManager.cancelable.emit(`preChat:${action}`, data).canceled) return;
1818
oHandler(event);
19+
if (action === 'getMessage' && data.idRoom) { // For new chat.
20+
data.room = `chat-public-${data.idRoom}`;
21+
data.open = global('openPublicChats').includes(data.idRoom);
22+
} else {
23+
data.open = true; // Just assume it's open for old chat
24+
}
1925
eventManager.emit('ChatMessage', data);
2026
eventManager.emit(`Chat:${action}`, data);
2127

2228
if (action === 'getSelfInfos') {
2329
eventManager.singleton.emit('Chat:Connected');
2430
}
2531
};
32+
// Simulate old getHistory
33+
globalSet('appendChat', function appendChat(idRoom = '', chatMessages = [], isPrivate = true) {
34+
const room = `chat-${isPrivate ? 'private' : 'public'}-${idRoom}`;
35+
const newRoom = !document.querySelector(`#${room}`);
36+
this.super(idRoom, chatMessages, isPrivate);
37+
if (newRoom) {
38+
eventManager.emit('Chat:getHistory', {
39+
room,
40+
roomName: isPrivate ? '' : global('chatNames')[idRoom] || idRoom,
41+
history: JSON.stringify(chatMessages), // TODO: Stop stringify
42+
});
43+
}
44+
}, {
45+
throws: false,
46+
});
2647
eventManager.on('Chat:getHistory', ({ room, roomName: name }) => {
2748
// Send text hook
2849
const messages = $(`#${room} .chat-messages`);

0 commit comments

Comments
 (0)