Server now seperates links and media. Client now embeds links, but not media.
This commit is contained in:
parent
a83dbdcb7f
commit
23df4f88f9
4 changed files with 141 additions and 58 deletions
|
|
@ -11,6 +11,9 @@ class chatPostprocessor{
|
|||
//We could pass this through arguments but these functions wont be very interoperable anyways since they expect a purpose-made hashtable
|
||||
this.splitBody();
|
||||
|
||||
//Inject links into un-processed placeholders
|
||||
this.processLinks();
|
||||
|
||||
//Inject whitespace into un-processed words
|
||||
this.addWhitespace();
|
||||
|
||||
|
|
@ -26,8 +29,8 @@ class chatPostprocessor{
|
|||
splitBody(){
|
||||
//Create an empty array to hold the body
|
||||
this.bodyArray = [];
|
||||
//Split string by words
|
||||
const splitString = this.chatBody.innerHTML.split(/\b/g); //Group words together
|
||||
//Split string by words (except for file seperator to keep link placeholders in-tact)
|
||||
const splitString = this.chatBody.innerHTML.split(/(?<!␜)\b(?!␜)/g); //Group words together
|
||||
|
||||
//for each word in the splitstring
|
||||
splitString.forEach((string) => {
|
||||
|
|
@ -48,7 +51,18 @@ class chatPostprocessor{
|
|||
|
||||
//Extract strings into the empty array
|
||||
this.bodyArray.forEach((wordObj) => {
|
||||
stringArray.push(wordObj.string);
|
||||
if(wordObj.type == 'word'){
|
||||
stringArray.push(wordObj.string);
|
||||
}else if(wordObj.type == 'link'){
|
||||
//Create a link node from our link
|
||||
const link = document.createElement('a');
|
||||
link.classList.add('chat-link');
|
||||
link.href = wordObj.link;
|
||||
link.innerHTML = wordObj.link;
|
||||
|
||||
//Inject it into the original string, and add it to string array
|
||||
stringArray.push(wordObj.string.replace('␜',link.outerHTML));
|
||||
}
|
||||
});
|
||||
|
||||
//Join the strings to fill the chat entry
|
||||
|
|
@ -62,7 +76,6 @@ class chatPostprocessor{
|
|||
if(wordObj.type == "word"){
|
||||
var wordArray = [];
|
||||
//Add invisible whitespace in-between characters to keep it from breaking page layout
|
||||
//this.bodyArray[index].string = wordObj.string.split("").join("ㅤ");
|
||||
this.bodyArray[wordIndex].string.split("").forEach((char, charIndex) => {
|
||||
wordArray.push(char);
|
||||
//After eight characters
|
||||
|
|
@ -78,6 +91,24 @@ class chatPostprocessor{
|
|||
});
|
||||
}
|
||||
|
||||
processLinks(){
|
||||
this.rawData.links.forEach((link, linkIndex) => {
|
||||
this.bodyArray.forEach((wordObj, wordIndex) => {
|
||||
//Check current wordobj for link (placeholder may contain whitespace with it)
|
||||
if(wordObj.string.match(`␜${linkIndex}␜`)){
|
||||
//Set current word object in the body array to the new link object
|
||||
this.bodyArray[wordIndex] = {
|
||||
//Don't want to use a numbered placeholder to make this easier during body injection
|
||||
//but we also don't want to clobber any surrounding whitespace
|
||||
string: wordObj.string.replace(`␜${linkIndex}␜`, '␜'),
|
||||
link: link.link,
|
||||
type: "link"
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
handleChatType(){
|
||||
if(this.rawData.type == "whisper"){
|
||||
//add whisper class
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue