mirror of
https://github.com/Qortal/qortal-ui.git
synced 2025-04-24 20:07:51 +00:00
add send msg to group
This commit is contained in:
parent
47801033a5
commit
5465582b97
@ -594,13 +594,18 @@ 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
|
||||||
|
|
||||||
|
if(isRecipient){
|
||||||
|
chatResponse = await parentEpml.request('chat', {
|
||||||
type: 18,
|
type: 18,
|
||||||
nonce: this.selectedAddress.nonce,
|
nonce: this.selectedAddress.nonce,
|
||||||
params: {
|
params: {
|
||||||
@ -616,6 +621,31 @@ class WebBrowser extends LitElement {
|
|||||||
isText: 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,6 +696,8 @@ class WebBrowser extends LitElement {
|
|||||||
);
|
);
|
||||||
if (result.action === "accept") {
|
if (result.action === "accept") {
|
||||||
let hasPublicKey = true;
|
let hasPublicKey = true;
|
||||||
|
|
||||||
|
if(isRecipient){
|
||||||
const res = await parentEpml.request('apiCall', {
|
const res = await parentEpml.request('apiCall', {
|
||||||
type: 'api',
|
type: 'api',
|
||||||
url: `/addresses/publickey/${recipient}`
|
url: `/addresses/publickey/${recipient}`
|
||||||
@ -683,11 +715,12 @@ class WebBrowser extends LitElement {
|
|||||||
this._publicKey.hasPubKey = false
|
this._publicKey.hasPubKey = false
|
||||||
hasPublicKey = 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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -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…
x
Reference in New Issue
Block a user