Skip to content

Commit

Permalink
HF 30 - Private groups - Do not decrypt own messages
Browse files Browse the repository at this point in the history
  • Loading branch information
1aerostorm committed Oct 2, 2024
1 parent 80eaea4 commit 9b4df9b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 17 deletions.
7 changes: 6 additions & 1 deletion src/components/pages/Messages.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 3 additions & 14 deletions src/redux/TransactionSaga.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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 => {
Expand Down
32 changes: 30 additions & 2 deletions src/utils/Normalizators.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 [];
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit 9b4df9b

Please sign in to comment.