diff --git a/qortal-ui-plugins/plugins/core/components/ChatPage.js b/qortal-ui-plugins/plugins/core/components/ChatPage.js
index f0168fc7..26a2d7d2 100644
--- a/qortal-ui-plugins/plugins/core/components/ChatPage.js
+++ b/qortal-ui-plugins/plugins/core/components/ChatPage.js
@@ -315,7 +315,6 @@ class ChatPage extends LitElement {
// Attach Event Handler
this.emojiPickerHandler.addEventListener('click', () => this.emojiPicker.togglePicker(this.emojiPickerHandler));
-
window.addEventListener('storage', () => {
const checkLanguage = localStorage.getItem('qortalLanguage')
use(checkLanguage)
@@ -429,6 +428,7 @@ class ChatPage extends LitElement {
.setRepliedToMessageObj=${(val) => this.setRepliedToMessageObj(val)}
.setEditedMessageObj=${(val) => this.setEditedMessageObj(val)}
.focusChatEditor=${() => this.focusChatEditor()}
+ .sendMessage=${(val)=> this._sendMessage(val)}
>
`
}
@@ -991,7 +991,7 @@ class ChatPage extends LitElement {
// Add to the messages... TODO: Save messages to localstorage and fetch from it to make it persistent...
}
- _sendMessage() {
+ _sendMessage(outSideMsg) {
// have params to determine if it's a reply or not
// have variable to determine if it's a response, holds signature in constructor
// need original message signature
@@ -1007,9 +1007,58 @@ class ChatPage extends LitElement {
const sanitizedMessage = messageText.replace(/ /gi, ' ').replace(/
/gi, '\n');
const trimmedMessage = sanitizedMessage.trim();
-
+ if(outSideMsg && outSideMsg.type === 'reaction'){
+ typeMessage = 'edit'
+ let chatReference = outSideMsg.editedMessageObj.reference
- if (/^\s*$/.test(trimmedMessage)) {
+ if(outSideMsg.editedMessageObj.chatReference){
+ chatReference = outSideMsg.editedMessageObj.chatReference
+ }
+
+ let message = ""
+ try {
+ const parsedMessageObj = JSON.parse(outSideMsg.editedMessageObj.decodedMessage)
+ message = parsedMessageObj
+
+ } catch (error) {
+ message = outSideMsg.editedMessageObj.decodedMessage
+ }
+
+ let reactions = message.reactions || []
+ const findEmojiIndex = reactions.findIndex((reaction)=> reaction.type === outSideMsg.reaction)
+ if(findEmojiIndex !== -1){
+ let users = reactions[findEmojiIndex].users || []
+ const findUserIndex = users.find((user)=> user === this.selectedAddress.address )
+ if(findUserIndex !== -1){
+ users.splice(findUserIndex, 1)
+ } else {
+ users.push(this.selectedAddress.address)
+ }
+ reactions[findEmojiIndex] = {
+ ...reactions[findEmojiIndex],
+ qty: users.length,
+ users
+ }
+ if(users.length === 0){
+ reactions.splice(findEmojiIndex, 1)
+ }
+ } else {
+ reactions = [...reactions, {
+ type: outSideMsg.reaction,
+ qty: 1,
+ users: [this.selectedAddress.address]
+ }]
+ }
+
+ const messageObject = {
+ ...message,
+ reactions
+
+ }
+ const stringifyMessageObject = JSON.stringify(messageObject)
+ this.sendMessage(stringifyMessageObject, typeMessage, chatReference);
+
+ } else if (/^\s*$/.test(trimmedMessage)) {
this.isLoading = false;
this.chatEditor.enable();
} else if (trimmedMessage.length >= 256) {
@@ -1046,7 +1095,7 @@ class ChatPage extends LitElement {
message = parsedMessageObj
} catch (error) {
- message = this.messageObj.decodedMessage
+ message = this.editedMessageObj.decodedMessage
}
const messageObject = {
...message,
diff --git a/qortal-ui-plugins/plugins/core/components/ChatScroller-css.js b/qortal-ui-plugins/plugins/core/components/ChatScroller-css.js
index 3e56949f..6e633de8 100644
--- a/qortal-ui-plugins/plugins/core/components/ChatScroller-css.js
+++ b/qortal-ui-plugins/plugins/core/components/ChatScroller-css.js
@@ -320,4 +320,13 @@ export const chatStyles = css`
padding: 3px 8px;
box-shadow: rgba(77, 77, 82, 0.2) 0px 7px 29px 0px;
}
+
+ .reactions-bg {
+ background-color: #3C4048;
+ border-radius: 10px;
+ padding: 4px;
+ color: white;
+ margin-right: 10px;
+ cursor: pointer
+ }
`
diff --git a/qortal-ui-plugins/plugins/core/components/ChatScroller.js b/qortal-ui-plugins/plugins/core/components/ChatScroller.js
index 0182fba8..5fe748a8 100644
--- a/qortal-ui-plugins/plugins/core/components/ChatScroller.js
+++ b/qortal-ui-plugins/plugins/core/components/ChatScroller.js
@@ -13,6 +13,8 @@ import '@vaadin/icon';
import '@material/mwc-button';
import '@material/mwc-dialog';
import '@material/mwc-icon';
+import { EmojiPicker } from 'emoji-picker-js';
+
const parentEpml = new Epml({ type: 'WINDOW', source: window.parent })
class ChatScroller extends LitElement {
@@ -27,7 +29,8 @@ class ChatScroller extends LitElement {
hideMessages: { type: Array },
setRepliedToMessageObj: { type: Function },
setEditedMessageObj: { type: Function },
- focusChatEditor: { type: Function }
+ focusChatEditor: { type: Function },
+ sendMessage: { type: Function}
}
}
@@ -44,8 +47,6 @@ class ChatScroller extends LitElement {
render() {
- console.log({messages: this.messages})
-
return html`