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

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

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

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

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

Loading…
Cancel
Save