Skip to content

Commit

Permalink
HF 30 - Private groups
Browse files Browse the repository at this point in the history
  • Loading branch information
1aerostorm committed Sep 2, 2024
1 parent 0a1e39d commit be4e832
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 13 deletions.
29 changes: 21 additions & 8 deletions src/components/pages/Messages.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ class Messages extends React.Component {
onPanelDeleteClick = (event) => {
const { messages } = this.state;

const { account, accounts, } = this.props;
const { account, accounts, the_group } = this.props;
const to = this.getToAcc()

// TODO: works wrong if few messages have same create_time
Expand Down Expand Up @@ -533,13 +533,22 @@ class Messages extends React.Component {
if (!this.state.selectedMessages[message_object.nonce]) {
continue;
}

const extensions = []
if (this.isGroup()) {
extensions.push([0, {
group: the_group.name
}])
}

const json = JSON.stringify(['private_delete_message', {
requester: account.name,
from: message_object.from,
to: message_object.to,
start_date: '1970-01-01T00:00:00',
stop_date: '1970-01-01T00:00:00',
nonce: message_object.nonce,
extensions,
}]);
OPERATIONS.push(['custom_json',
{
Expand All @@ -550,7 +559,9 @@ class Messages extends React.Component {
]);
}

this.props.sendOperations(account, accounts[to], OPERATIONS);
this.props.sendOperations(account, accounts[to], OPERATIONS, (err, errStr) => {
this.props.showError(errStr, 10000)
})

this.setState({
selectedMessages: {},
Expand Down Expand Up @@ -1078,15 +1089,16 @@ export default withRouter(connect(
fake: true
}});
},
sendOperations: (senderAcc, toAcc, OPERATIONS) => {
sendOperations: (senderAcc, toAcc, OPERATIONS, onError = null) => {
if (!OPERATIONS.length) return;
dispatch(
transaction.actions.broadcastOperation({
type: 'custom_json',
trx: OPERATIONS,
successCallback: null,
errorCallback: (e) => {
console.log(e);
errorCallback: (e, errStr) => {
if (onError) onError(e, errStr)
console.error(e)
}
})
);
Expand Down Expand Up @@ -1125,14 +1137,14 @@ export default withRouter(connect(
const opData = {
from: senderAcc.name,
to: toAcc ? toAcc.name : '',
nonce: /*editInfo ? editInfo.nonce : */data.nonce,
nonce: editInfo ? editInfo.nonce : data.nonce,
from_memo_key: data.from_memo_key,
to_memo_key: data.to_memo_key,
checksum: data.checksum,
update: editInfo ? true : false,
encrypted_message: data.encrypted_message,
}
alert(JSON.stringify(data.encrypted_message))
//alert(JSON.stringify(data.encrypted_message))

if (group) {
opData.extensions = [[0, {
Expand All @@ -1158,7 +1170,7 @@ export default withRouter(connect(
json,
},
successCallback: null,
errorCallback: (err) => {
errorCallback: (err, errStr) => {
if (err && err.message) {
if (err.message.includes('blocked by')) {
this.showError(tt(
Expand All @@ -1178,6 +1190,7 @@ export default withRouter(connect(
}
}
console.error(err)
this.showError(errStr, 10000)
},
}));
},
Expand Down
6 changes: 5 additions & 1 deletion src/locales/ru-RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@
"sync_error": "Ошибка синхронизации. Для получения новых сообщений обновляйте страницу.",
"sync_error_short": "Ошибка синхронизации. Для получения новых сообщений нажимайте ",
"blocked_BY": "Вы заблокированы пользователем @%(BY)s.",
"do_not_bother_BY": "@%(BY)s просит пользователей с низкой репутацией не беспокоить."
"do_not_bother_BY": "@%(BY)s просит пользователей с низкой репутацией не беспокоить.",
"too_low_gp": "Не хватает Силы Голоса. Для участия в группах нужно не менее ",
"too_low_gp2": ".",
"you_not_moder": "Вы не модератор."
},
"msgs_group_dropdown": {
"join": "Вступить",
Expand Down Expand Up @@ -374,6 +377,7 @@
"login": "Войти",
"logout": "Выйти",
"mentions": "Упоминания",
"modified": " (изменено)",
"name": "Имя",
"night_mode": "Ночной режим",
"ok": "OK",
Expand Down
11 changes: 11 additions & 0 deletions src/redux/TransactionSaga.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,21 @@ function* preBroadcast_custom_json({operation}) {
updater: msgs => {
const idx = msgs.findIndex(i => i.get('nonce') === json[1].nonce);
if (idx === -1) {
let group = ''
const exts = json[1].extensions || []
for (const [key, val ] of exts) {
if (key === 0) {
group = val.group
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',
Expand Down
2 changes: 0 additions & 2 deletions src/redux/UserSaga.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,7 @@ function* getAccountHandler({ payload: { usernames, resolve, reject }}) {
usernames = [current.get('username')]
}

alert('ac')
const accounts = yield call([api, api.getAccountsAsync], usernames)
alert('ac2')
for (let account of accounts) {
yield put(g.actions.receiveAccount({ account }))
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/Normalizators.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export async function normalizeMessages(messages, accounts, currentUser, to, pre
saveToCache(preDecoded, msg)
},
on_error: (msg, i, err) => {
console.error(err)
console.error(err, msg)
msg.message = {body: tt_invalid_message, invalid: true}
},
begin_idx: messagesCopy.length - 1,
Expand Down
27 changes: 26 additions & 1 deletion src/utils/translateError.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ const getErrorData = (errPayload, errName, depth = 0) => {
if (depth > 50) {
throw new Error('getErrorData - infinity loop detected...')
}
if (errPayload === null) {
if (!errPayload) {
return null
}
console.error(errPayload.name)
if (errPayload.name === errName) {
let { stack } = errPayload
stack = stack && stack[0]
Expand Down Expand Up @@ -69,6 +70,7 @@ export function translateError(string, errPayload) {
'Account exceeded maximum allowed bandwidth per vesting share'
)) {
string = tt('chain_errors.exceeded_maximum_allowed_bandwidth')
return string
}

if (string.includes(
Expand All @@ -91,11 +93,34 @@ export function translateError(string, errPayload) {
} else {
string += '.'
}
return string
}
} catch (err) {
console.error('getErrorData', err)
}
}

if (string.includes(
'Too low golos power'
)) {
let errData
try {
errData = getErrorData(errPayload, 'logic_exception')
if (errData && errData.r) {
string = tt('messages.too_low_gp')
string += Asset(errData.r).floatString
string += tt('messages.too_low_gp2')
return string
}
} catch (err) {
console.error('getErrorData', err)
}
}

if (string.includes('You should be moder')) {
string = tt('messages.you_not_moder')
return string
}

return string
}

0 comments on commit be4e832

Please sign in to comment.