4
1
mirror of https://github.com/Qortal/qortal-ui.git synced 2025-02-11 09:45:52 +00:00

Added chatReference to ChatTransaction and GroupChatTransaction.

Since this affects transaction serialization, it will need to take effect from a future undecided timestamp (defined in constants.js), and both core & UI will need to share the same timestamp.

The feature trigger timestamp comparisons can be removed 24 hours (or more) post-activation. This is because CHAT messages are currently discarded after 24 hours so we don't need to maintain backwards support of the old serialization approach. The feature trigger is only to ensure full chat operation during the 24 hours that the switchover occurs.
This commit is contained in:
CalDescent 2022-10-22 13:16:17 +01:00
parent aa5842b940
commit d9b1ec488b
8 changed files with 50 additions and 2 deletions

View File

@ -249,6 +249,8 @@ const ERROR_CODES = {
1000: "Not yet released." 1000: "Not yet released."
} }
const CHAT_REFERENCE_FEATURE_TRIGGER_TIMESTAMP = 9999999999999
const QORT_DECIMALS = 1e8 const QORT_DECIMALS = 1e8
const PROXY_URL = "/proxy/" // Proxy for api calls const PROXY_URL = "/proxy/" // Proxy for api calls
@ -265,7 +267,7 @@ const STATIC_BCRYPT_SALT = `$${BCRYPT_VERSION}$${BCRYPT_ROUNDS}$IxVE941tXVUD4cW0
const KDF_THREADS = 16 // 16 Threads seems like a good number :) . No you dumbass nigerian. Its not ! -_- const KDF_THREADS = 16 // 16 Threads seems like a good number :) . No you dumbass nigerian. Its not ! -_-
export { TX_TYPES, ERROR_CODES, QORT_DECIMALS, PROXY_URL, STATIC_SALT, ADDRESS_VERSION, KDF_THREADS, STATIC_BCRYPT_SALT } export { TX_TYPES, ERROR_CODES, QORT_DECIMALS, PROXY_URL, STATIC_SALT, ADDRESS_VERSION, KDF_THREADS, STATIC_BCRYPT_SALT, CHAT_REFERENCE_FEATURE_TRIGGER_TIMESTAMP }
//const TX_TYPES = { //const TX_TYPES = {
// GENESIS_TRANSACTION: 1, // GENESIS_TRANSACTION: 1,
@ -291,4 +293,4 @@ export { TX_TYPES, ERROR_CODES, QORT_DECIMALS, PROXY_URL, STATIC_SALT, ADDRESS_V
// DEPLOY_AT_TRANSACTION: 16, // DEPLOY_AT_TRANSACTION: 16,
// //
// MESSAGE_TRANSACTION: 17 // MESSAGE_TRANSACTION: 17
//}; //};

View File

@ -3,6 +3,7 @@ import ChatBase from "./ChatBase.js"
import nacl from '../../deps/nacl-fast.js' import nacl from '../../deps/nacl-fast.js'
import ed2curve from '../../deps/ed2curve.js' import ed2curve from '../../deps/ed2curve.js'
import { Sha256 } from 'asmcrypto.js' import { Sha256 } from 'asmcrypto.js'
import { CHAT_REFERENCE_FEATURE_TRIGGER_TIMESTAMP } from '../../constants.js'
export default class ChatTransaction extends ChatBase { export default class ChatTransaction extends ChatBase {
@ -29,6 +30,15 @@ export default class ChatTransaction extends ChatBase {
this._hasReceipient[0] = 1 this._hasReceipient[0] = 1
} }
set hasChatReference(hasChatReference) {
this._hasChatReference = new Uint8Array(1)
this._hasChatReference[0] = hasChatReference
}
set chatReference(chatReference) {
this._chatReference = chatReference instanceof Uint8Array ? chatReference : this.constructor.Base58.decode(chatReference)
}
set message(message) { set message(message) {
this.messageText = message; this.messageText = message;
@ -72,6 +82,16 @@ export default class ChatTransaction extends ChatBase {
this._isText, this._isText,
this._feeBytes this._feeBytes
) )
// After the feature trigger timestamp we need to include chat reference
if (new Date(this._timestamp).getTime() >= CHAT_REFERENCE_FEATURE_TRIGGER_TIMESTAMP) {
params.push(this._hasChatReference)
if (this._hasChatReference[0] == 1) {
params.push(this._chatReference)
}
}
return params; return params;
} }
} }

View File

@ -1,5 +1,6 @@
"use strict"; "use strict";
import ChatBase from "./ChatBase.js" import ChatBase from "./ChatBase.js"
import { CHAT_REFERENCE_FEATURE_TRIGGER_TIMESTAMP } from '../../constants.js'
export default class GroupChatTransaction extends ChatBase { export default class GroupChatTransaction extends ChatBase {
constructor() { constructor() {
@ -18,6 +19,15 @@ export default class GroupChatTransaction extends ChatBase {
this._hasReceipient[0] = hasReceipient this._hasReceipient[0] = hasReceipient
} }
set hasChatReference(hasChatReference) {
this._hasChatReference = new Uint8Array(1)
this._hasChatReference[0] = hasChatReference
}
set chatReference(chatReference) {
this._chatReference = chatReference instanceof Uint8Array ? chatReference : this.constructor.Base58.decode(chatReference)
}
set message(message) { set message(message) {
this.messageText = message; this.messageText = message;
@ -47,6 +57,16 @@ export default class GroupChatTransaction extends ChatBase {
this._isText, this._isText,
this._feeBytes this._feeBytes
) )
// After the feature trigger timestamp we need to include chat reference
if (new Date(this._timestamp).getTime() >= CHAT_REFERENCE_FEATURE_TRIGGER_TIMESTAMP) {
params.push(this._hasChatReference)
if (this._hasChatReference[0] == 1) {
params.push(this._chatReference)
}
}
return params; return params;
} }
} }

View File

@ -183,6 +183,7 @@ class ChatModals extends LitElement {
timestamp: sendTimestamp, timestamp: sendTimestamp,
recipient: recipient, recipient: recipient,
recipientPublicKey: _publicKey, recipientPublicKey: _publicKey,
hasChatReference: 0,
message: messageText, message: messageText,
lastReference: reference, lastReference: reference,
proofOfWorkNonce: 0, proofOfWorkNonce: 0,

View File

@ -667,6 +667,7 @@ class ChatPage extends LitElement {
timestamp: Date.now(), timestamp: Date.now(),
recipient: this._chatId, recipient: this._chatId,
recipientPublicKey: this._publicKey.key, recipientPublicKey: this._publicKey.key,
hasChatReference: 0,
message: messageText, message: messageText,
lastReference: reference, lastReference: reference,
proofOfWorkNonce: 0, proofOfWorkNonce: 0,
@ -684,6 +685,7 @@ class ChatPage extends LitElement {
timestamp: Date.now(), timestamp: Date.now(),
groupID: Number(this._chatId), groupID: Number(this._chatId),
hasReceipient: 0, hasReceipient: 0,
hasChatReference: 0,
message: messageText, message: messageText,
lastReference: reference, lastReference: reference,
proofOfWorkNonce: 0, proofOfWorkNonce: 0,

View File

@ -410,6 +410,7 @@ class ChatWelcomePage extends LitElement {
timestamp: sendTimestamp, timestamp: sendTimestamp,
recipient: recipient, recipient: recipient,
recipientPublicKey: _publicKey, recipientPublicKey: _publicKey,
hasChatReference: 0,
message: messageText, message: messageText,
lastReference: reference, lastReference: reference,
proofOfWorkNonce: 0, proofOfWorkNonce: 0,

View File

@ -529,6 +529,7 @@ class NameMenu extends LitElement {
timestamp: sendTimestamp, timestamp: sendTimestamp,
recipient: recipient, recipient: recipient,
recipientPublicKey: _publicKey, recipientPublicKey: _publicKey,
hasChatReference: 0,
message: messageText, message: messageText,
lastReference: reference, lastReference: reference,
proofOfWorkNonce: 0, proofOfWorkNonce: 0,

View File

@ -819,6 +819,7 @@ class Chat extends LitElement {
timestamp: sendTimestamp, timestamp: sendTimestamp,
recipient: recipient, recipient: recipient,
recipientPublicKey: _publicKey, recipientPublicKey: _publicKey,
hasChatReference: 0,
message: messageText, message: messageText,
lastReference: reference, lastReference: reference,
proofOfWorkNonce: 0, proofOfWorkNonce: 0,