Fixed text sanitisation issues.

This commit is contained in:
Pachira 2024-03-03 01:07:56 +00:00
parent c105b57488
commit d01a1d454c

View file

@ -143,7 +143,16 @@ Umi.Protocol.SockChat.Protocol = function(pingDuration) {
});
};
const unfuckText = text => text.replace(/ <br\/> /g, "\n");
const unfuckText = (text, isAction) => {
// P7.1 doesn't wrap in <i>, likely a bug in SharpChat
// check if this is the case with the PHPChat impl
if(isAction && text.startsWith('<i>'))
text = text.slice(3, -4);
return text.replace(/ <br\/> /g, "\n")
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>');
};
const onMessage = ev => {
const args = ev.detail.data.split("\t");
@ -249,7 +258,8 @@ Umi.Protocol.SockChat.Protocol = function(pingDuration) {
// message add
handlers['2'] = (timeStamp, userId, msgText, msgId, msgFlags) => {
let mText = unfuckText(msgText);
const mFlags = parseMsgFlags(msgFlags);
let mText = unfuckText(msgText, mFlags.isAction);
let mChannelName = selfChannelName;
if(msgFlags[4] !== '0') {
@ -271,7 +281,7 @@ Umi.Protocol.SockChat.Protocol = function(pingDuration) {
id: userId,
self: userId === selfUserId,
},
flags: parseMsgFlags(msgFlags),
flags: mFlags,
flagsRaw: msgFlags,
isBot: userId === '-1',
text: mText,
@ -433,6 +443,7 @@ Umi.Protocol.SockChat.Protocol = function(pingDuration) {
// existing message
handlers['7']['1'] = (timeStamp, userId, userName, userColour, userPerms, msgText, msgId, msgNotify, msgFlags) => {
const mFlags = parseMsgFlags(msgFlags);
const info = {
msg: {
id: msgId,
@ -448,9 +459,9 @@ Umi.Protocol.SockChat.Protocol = function(pingDuration) {
},
isBot: userId === '-1',
silent: msgNotify === '0',
flags: parseMsgFlags(msgFlags),
flags: mFlags,
flagsRaw: msgFlags,
text: unfuckText(msgText),
text: unfuckText(msgText, mFlags.isAction),
},
};
@ -465,6 +476,10 @@ Umi.Protocol.SockChat.Protocol = function(pingDuration) {
type: botParts[1],
args: botParts.slice(2),
};
// i think this is more Inaccurate Behaviour on the server side
if(info.msg.botInfo.type === 'say')
info.msg.botInfo.args[0] = unfuckText(info.msg.botInfo.args[0]);
}
eventTarget.dispatch('msg:add', info);