Browse Source

Merge pull request #139 from PhillipLangMartinez/bugfix/send-message-group

Bugfix/send message group
q-apps
AlphaX-Projects 2 years ago committed by GitHub
parent
commit
399b8e1001
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      qortal-ui-plugins/plugins/core/components/ChatPage.js
  2. 2
      qortal-ui-plugins/plugins/core/components/ChatWelcomePage.js
  3. 51
      qortal-ui-plugins/plugins/core/qdn/browser/browser.src.js

6
qortal-ui-plugins/plugins/core/components/ChatPage.js

@ -3425,7 +3425,7 @@ class ChatPage extends LitElement {
}],
isImageDeleted: false,
repliedTo: '',
version: 2
version: 3
};
const stringifyMessageObject = JSON.stringify(messageObject);
this.sendMessage(stringifyMessageObject, typeMessage);
@ -3446,7 +3446,7 @@ class ChatPage extends LitElement {
filePath: outSideMsg.filePath
}],
repliedTo: '',
version: 2
version: 3
};
const stringifyMessageObject = JSON.stringify(messageObject);
this.sendMessage(stringifyMessageObject, typeMessage);
@ -3508,7 +3508,7 @@ class ChatPage extends LitElement {
}],
isAttachmentDeleted: false,
repliedTo: '',
version: 2
version: 3
};
const stringifyMessageObject = JSON.stringify(messageObject);
this.sendMessage(stringifyMessageObject, typeMessage);

2
qortal-ui-plugins/plugins/core/components/ChatWelcomePage.js

@ -412,7 +412,7 @@ class ChatWelcomePage extends LitElement {
messageText,
images: [''],
repliedTo: '',
version: 1
version: 3
};
const stringifyMessageObject = JSON.stringify(messageObject);
let chatResponse = await parentEpml.request('chat', {

51
qortal-ui-plugins/plugins/core/qdn/browser/browser.src.js

@ -594,13 +594,18 @@ class WebBrowser extends LitElement {
case actions.SEND_CHAT_MESSAGE: {
const message = data.message;
const recipient = data.destinationAddress;
const groupId = data.groupId;
const isRecipient = groupId ? false : true
const sendMessage = async (messageText, chatReference) => {
let _reference = new Uint8Array(64);
window.crypto.getRandomValues(_reference);
let reference = window.parent.Base58.encode(_reference);
const sendMessageRequest = async () => {
let chatResponse = await parentEpml.request('chat', {
let chatResponse
if(isRecipient){
chatResponse = await parentEpml.request('chat', {
type: 18,
nonce: this.selectedAddress.nonce,
params: {
@ -616,6 +621,31 @@ class WebBrowser extends LitElement {
isText: 1
}
});
}
if(!isRecipient){
chatResponse = await parentEpml.request('chat', {
type: 181,
nonce: this.selectedAddress.nonce,
params: {
timestamp: Date.now(),
groupID: Number(groupId),
hasReceipient: 0,
hasChatReference: 0,
chatReference: chatReference,
message: messageText,
lastReference: reference,
proofOfWorkNonce: 0,
isEncrypted: 0,
isText: 1
}
});
}
const msgResponse = await _computePow(chatResponse)
return msgResponse;
};
@ -666,6 +696,8 @@ class WebBrowser extends LitElement {
);
if (result.action === "accept") {
let hasPublicKey = true;
if(isRecipient){
const res = await parentEpml.request('apiCall', {
type: 'api',
url: `/addresses/publickey/${recipient}`
@ -683,11 +715,12 @@ class WebBrowser extends LitElement {
this._publicKey.hasPubKey = false
hasPublicKey = false;
}
}
if (!hasPublicKey) {
let err4string = get("chatpage.cchange39");
parentEpml.request('showSnackBar', `${err4string}`)
return
if (!hasPublicKey && isRecipient) {
response = '{"error": "Cannot send an encrypted message to this user since they do not have their publickey on chain."}';
break
}
@ -712,7 +745,7 @@ class WebBrowser extends LitElement {
messageText: tiptapJson,
images: [''],
repliedTo: '',
version: 2
version: 3
};
const stringifyMessageObject = JSON.stringify(messageObject);
@ -729,6 +762,12 @@ class WebBrowser extends LitElement {
response = msgResponse;
} catch (error) {
console.error(error);
if(error.message){
let data = {};
data['error'] = error.message;
response = JSON.stringify(data);
break
}
response = '{"error": "Request could not be fulfilled"}';
} finally {
this.loader.hide();

Loading…
Cancel
Save