Skip to content

Commit

Permalink
chore: updated to new chat
Browse files Browse the repository at this point in the history
  • Loading branch information
feildmaster committed Oct 12, 2020
1 parent 086131e commit 1f33716
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
12 changes: 12 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# UnderScript Changelog

## Version 0.41.0 (2020-10-12)
### New Features
1. Reload Cards menu item
### Fixes
1. Load storage more reliably
1. Don't show "turn start" twice
1. Load card name from storage
### Misc.
1. Changed @everyone to @underscript
1. Updated for next patch

## Version 0.40.0 (2020-08-31)
### New Features
1. First/Last page shortcut now works on every valid webpage
Expand All @@ -9,6 +20,7 @@
1. Settings -> Library -> Merge Shiny Cards
Note: When these filter settings are applied, the rarity icons are semi-transparent (making them look darker)


## Version 0.39.2
1. Fixed battle log being inconsistent on game finish for players/spectators
1. Fixed some internal bugs
Expand Down
2 changes: 1 addition & 1 deletion src/base/chat/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ wrap(function setup() {
}

function add(name, list) {
if (name === global('selfUsername')) return;
if (!list || name === global('selfUsername')) return;
const slot = list.indexOf(name);
if (slot > -1) list.splice(slot, 1);
list.push(name);
Expand Down
3 changes: 2 additions & 1 deletion src/base/chat/toast.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ wrap(() => {
if (shouldIgnore(msg, true)) return;
if (!msg.message.toLowerCase().includes(`@${global('selfUsername').toLowerCase()}`) && !fn.pingRegex().test(msg.message)) return;
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;">` : '';
const chatNames = global('chatNames', { throws: false });
fn.toast({
title: `${avatar}${fn.user.name(msg.user)} (${chatRoomNames[data.room]})`,
title: `${avatar}${fn.user.name(msg.user)} (${chatRoomNames[data.room] || chatNames && chatNames[data.idRoom] ? $.i18n(chatNames[data.idRoom]) : data.idRoom || 'UNKNOWN'})`,
text: msg.message,
});
});
Expand Down
21 changes: 21 additions & 0 deletions src/hooks/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,34 @@ eventManager.on(':loaded', () => {
}
if (eventManager.cancelable.emit(`preChat:${action}`, data).canceled) return;
oHandler(event);
if (action === 'getMessage' && data.idRoom) { // For new chat.
data.room = `chat-public-${data.idRoom}`;
data.open = global('openPublicChats').includes(data.idRoom);
} else {
data.open = true; // Just assume it's open for old chat
}
eventManager.emit('ChatMessage', data);
eventManager.emit(`Chat:${action}`, data);

if (action === 'getSelfInfos') {
eventManager.singleton.emit('Chat:Connected');
}
};
// Simulate old getHistory
globalSet('appendChat', function appendChat(idRoom = '', chatMessages = [], isPrivate = true) {
const room = `chat-${isPrivate ? 'private' : 'public'}-${idRoom}`;
const newRoom = !document.querySelector(`#${room}`);
this.super(idRoom, chatMessages, isPrivate);
if (newRoom) {
eventManager.emit('Chat:getHistory', {
room,
roomName: isPrivate ? '' : global('chatNames')[idRoom] || idRoom,
history: JSON.stringify(chatMessages), // TODO: Stop stringify
});
}
}, {
throws: false,
});
eventManager.on('Chat:getHistory', ({ room, roomName: name }) => {
// Send text hook
const messages = $(`#${room} .chat-messages`);
Expand Down

0 comments on commit 1f33716

Please sign in to comment.