diff --git a/src/components/pages/Messages.jsx b/src/components/pages/Messages.jsx index 3abcf53c..28d9240b 100644 --- a/src/components/pages/Messages.jsx +++ b/src/components/pages/Messages.jsx @@ -30,7 +30,7 @@ import transaction from 'app/redux/TransactionReducer' import user from 'app/redux/UserReducer' import { getRoleInGroup, opGroup } from 'app/utils/groups' import { getProfileImage, } from 'app/utils/NormalizeProfile'; -import { normalizeContacts, normalizeMessages } from 'app/utils/Normalizators'; +import { normalizeContacts, normalizeMessages, saveToCache, messageOpToObject } from 'app/utils/Normalizators'; import { fitToPreview } from 'app/utils/ImageUtils'; import { notificationSubscribe, notificationSubscribeWs, notifyWsPing, notificationShallowUnsubscribe, notificationTake, queueWatch, sendOffchainMessage } from 'app/utils/NotifyApiClient'; @@ -1230,6 +1230,11 @@ export default withRouter(connect( }]] } + const newMsg = messageOpToObject(opData, group ? group.name : '') + newMsg.message = message + newMsg.decrypt_date = newMsg.receive_date + saveToCache(newMsg, true) + if (!editInfo) { sendOffchainMessage(opData).catch(err => { console.error('sendOffchainMessage', err) diff --git a/src/redux/TransactionSaga.js b/src/redux/TransactionSaga.js index e6e85f3d..a97727c8 100644 --- a/src/redux/TransactionSaga.js +++ b/src/redux/TransactionSaga.js @@ -4,6 +4,7 @@ import golos from 'golos-lib-js' import g from 'app/redux/GlobalReducer' import user from 'app/redux/UserReducer' +import { messageOpToObject } from 'app/utils/Normalizators' import { translateError } from 'app/utils/translateError' export function* transactionWatches() { @@ -52,20 +53,8 @@ function* preBroadcast_custom_json({operation}) { break } } - msgs = msgs.insert(0, fromJS({ - nonce: json[1].nonce, - checksum: json[1].checksum, - from: json[1].from, - from_memo_key: json[1].from_memo_key, - to_memo_key: json[1].to_memo_key, - group, - read_date: '1970-01-01T00:00:00', - create_date: new Date().toISOString().split('.')[0], - receive_date: '1970-01-01T00:00:00', - encrypted_message: json[1].encrypted_message, - donates: '0.000 GOLOS', - donates_uia: 0 - })) + const newMsg = messageOpToObject(json[1], group) + msgs = msgs.insert(0, fromJS(newMsg)) } else { messages_update = json[1].nonce; msgs = msgs.update(idx, msg => { diff --git a/src/utils/Normalizators.js b/src/utils/Normalizators.js index a3509b01..487083fc 100644 --- a/src/utils/Normalizators.js +++ b/src/utils/Normalizators.js @@ -37,14 +37,20 @@ export const getContactsSpace = (msg) => { return getSpaceInCache(msg, 'contacts') } +const zeroDate = '1970-01-01T00:00:00' + const cacheKey = (msg) => { let key = [msg.nonce] + let recDate = msg.receive_date + if (recDate === msg.create_date) { + recDate = zeroDate + } if (msg.group) { - key.push(msg.receive_date) + key.push(recDate) key.push(msg.from) key.push(msg.to) } else { - key.push(msg.receive_date) + key.push(recDate) } key = key.join('|') return key @@ -84,6 +90,24 @@ const loadFromCache = (msg, contact = false) => { return false } +export function messageOpToObject(op, group) { + const obj = { + nonce: op.nonce, + checksum: op.checksum, + from: op.from, + from_memo_key: op.from_memo_key, + to_memo_key: op.to_memo_key, + group, + read_date: '1970-01-01T00:00:00', + create_date: new Date().toISOString().split('.')[0], + receive_date: '1970-01-01T00:00:00', + encrypted_message: op.encrypted_message, + donates: '0.000 GOLOS', + donates_uia: 0 + } + return obj +} + export async function normalizeContacts(contacts, accounts, currentUser, cachedProfileImages) { if (!currentUser || !accounts) return []; @@ -130,9 +154,11 @@ export async function normalizeContacts(contacts, accounts, currentUser, cachedP } } + console.log('FCC1') if (loadFromCache(msg, true)) { return true } + console.log('FCC2') return false; }, for_each: (msg) => { @@ -199,10 +225,12 @@ export async function normalizeMessages(messages, accounts, currentUser, to) { } //msg.decrypt_date = null + console.log('FC1') if (loadFromCache(msg)) { results.push(msg) return true } + console.log('FC2') return false; }, for_each: (msg, i) => {