Chat changes

This commit is contained in:
Bill 2022-08-03 22:16:44 -04:00
parent e6522743b2
commit a9bac2afa6
2 changed files with 10 additions and 10 deletions

View File

@ -1,6 +1,7 @@
import * as joypixels from 'emoji-toolkit'; import * as joypixels from 'emoji-toolkit';
const allowedColours: Map<string, string> = new Map(); const allowedColours: Map<string, string> = new Map();
allowedColours.set('r', 'red'); allowedColours.set('r', 'red');
allowedColours.set('b', 'blue'); allowedColours.set('b', 'blue');
allowedColours.set('g', 'green'); allowedColours.set('g', 'green');
@ -23,14 +24,13 @@ allowedColours.set('brown', 'brown');
allowedColours.set('purple', 'purple'); allowedColours.set('purple', 'purple');
allowedColours.set('pink', 'pink'); allowedColours.set('pink', 'pink');
function encodeHTML(str: string) const encodeHTML = (str: string) =>
{ {
return str.replace(/([\u00A0-\u9999<>&])(.|$)/g, function(full, char, next) return str.replace(/([\u00A0-\u9999<>&])(.|$)/g, (full, char, next) =>
{ {
if(char !== '&' || next !== '#') if(char !== '&' || next !== '#')
{ {
if(/[\u00A0-\u9999<>&]/.test(next)) if(/[\u00A0-\u9999<>&]/.test(next)) next = '&#' + next.charCodeAt(0) + ';';
next = '&#' + next.charCodeAt(0) + ';';
return '&#' + char.charCodeAt(0) + ';' + next; return '&#' + char.charCodeAt(0) + ';' + next;
} }
@ -39,12 +39,11 @@ function encodeHTML(str: string)
}); });
} }
export const RoomChatFormatter = (content: string) =>
export function RoomChatFormatter(content: string): string
{ {
let result = ''; let result = '';
content = encodeHTML(content) content = encodeHTML(content);
content = (joypixels.shortnameToUnicode(content) as string) content = (joypixels.shortnameToUnicode(content) as string)
if(content.startsWith('@') && content.indexOf('@', 1) > -1) if(content.startsWith('@') && content.indexOf('@', 1) > -1)

View File

@ -22,16 +22,17 @@ export const ChatWidgetView: FC<{}> = props =>
{ {
const collides = chatMessages[i]; const collides = chatMessages[i];
if(!collides || (chat === collides) || (tempChats.indexOf(collides) >= 0) || ((collides.top - moved) >= (chat.top + chat.height))) continue; if(!collides || (chat === collides) || (tempChats.indexOf(collides) >= 0) || (((collides.top + collides.height) - moved) > (chat.top + chat.height))) continue;
if(DoChatsOverlap(chat, collides, -moved, 4)) chat.skipMovement = true;
if(DoChatsOverlap(chat, collides, -moved, 0))
{ {
const amount = Math.abs((collides.top + collides.height) - chat.top); const amount = Math.abs((collides.top + collides.height) - chat.top);
tempChats.push(collides); tempChats.push(collides);
collides.top -= amount; collides.top -= amount;
collides.skipMovement = true; collides.skipMovement = true;
checkOverlappingChats(collides, amount, tempChats); checkOverlappingChats(collides, amount, tempChats);