Skip to content

Commit

Permalink
Fix #2125. Add message sender when available
Browse files Browse the repository at this point in the history
  • Loading branch information
corrideat committed Aug 17, 2024
1 parent 79b5631 commit 8c585ad
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
13 changes: 11 additions & 2 deletions frontend/model/notifications/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
PROPOSAL_GROUP_SETTING_CHANGE, PROPOSAL_PROPOSAL_SETTING_CHANGE, PROPOSAL_GENERIC
} from '@model/contracts/shared/constants.js'
import { getProposalDetails } from '@model/contracts/shared/functions.js'
import { findContractIDByForeignKeyId } from '~/shared/domains/chelonia/utils.js'

export default ({
CHELONIA_ERROR (data: { activity: string, error: Error, message: GIMessage }) {
Expand All @@ -24,14 +25,22 @@ export default ({
if ([GIMessage.OP_ACTION_ENCRYPTED, GIMessage.OP_ACTION_UNENCRYPTED].includes(opType) && value) {
action = value.action
}
const state = sbp('state/vuex/state')
let who

if (message.innerSigningKeyId()) {
const innerSigningContractID = findContractIDByForeignKeyId(state[message.contractID()], message.innerSigningKeyId())
who = innerSigningContractID && `${CHATROOM_MEMBER_MENTION_SPECIAL_CHAR}${innerSigningContractID}`
}

return {
body: L("{errName} during {activity} for '{action}' to '{contract}': '{errMsg}'", {
body: L(who ? "{errName} during {activity} for '{action}' from {b_}{who}{_b} to '{contract}': '{errMsg}'" : "{errName} during {activity} for '{action}' to '{contract}': '{errMsg}'", {
...LTags('b'),
errName: error.name,
activity,
action: action ?? opType,
contract: sbp('state/vuex/state').contracts[contractID]?.type ?? contractID,
contract: state.contracts[contractID]?.type ?? contractID,
who,
errMsg: error.message ?? '?'
}),
icon: 'exclamation-triangle',
Expand Down
14 changes: 12 additions & 2 deletions shared/domains/chelonia/GIMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ export class GIMessage {
_signedMessageData: SignedData<GIOpValue>
_direction: GIMsgDirection
_decryptedValue: Object
_innerSigningKeyId: ?string

static OP_CONTRACT: 'c' = 'c'
static OP_ACTION_ENCRYPTED: 'ae' = 'ae' // e2e-encrypted action
Expand Down Expand Up @@ -405,6 +406,7 @@ export class GIMessage {
// The data inside could be signed. In this case, we unwrap that to get
// to the inner contents
if (isSignedData(data.data)) {
this._innerSigningKeyId = data.data.signingKeyId
this._decryptedValue = data.data.valueOf()
} else {
this._decryptedValue = data.data
Expand All @@ -419,6 +421,13 @@ export class GIMessage {
}
}

innerSigningKeyId (): any {
if (!this._decryptedValue) {
this.decryptedValue()
}
return this._innerSigningKeyId
}

head (): Object { return this._head }

message (): GIOpValue { return this._message }
Expand Down Expand Up @@ -475,14 +484,15 @@ export class GIMessage {

// $FlowFixMe[unsupported-syntax]
static [serdesSerializeSymbol] (m: GIMessage) {
return [m.serialize(), m.direction(), m.decryptedValue()]
return [m.serialize(), m.direction(), m.decryptedValue(), m.innerSigningKey()]
}

// $FlowFixMe[unsupported-syntax]
static [serdesDeserializeSymbol] ([serialized, direction, decryptedValue]) {
static [serdesDeserializeSymbol] ([serialized, direction, decryptedValue, innerSigningKeyId]) {
const m = GIMessage.deserialize(serialized)
m._direction = direction
m._decryptedValue = decryptedValue
m._innerSigningKeyId = innerSigningKeyId
return m
}
}
Expand Down
10 changes: 5 additions & 5 deletions shared/domains/chelonia/chelonia.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ import sbp from '@sbp/sbp'
import { handleFetchResult } from '~/frontend/controller/utils/misc.js'
import { cloneDeep, delay, difference, has, intersection, merge, randomHexString, randomIntFromRange } from '~/frontend/model/contracts/shared/giLodash.js'
import { NOTIFICATION_TYPE, createClient } from '~/shared/pubsub.js'
import type { GIKey, GIOpActionUnencrypted, GIOpContract, GIOpKeyAdd, GIOpKeyDel, GIOpKeyRequest, GIOpKeyRequestSeen, GIOpKeyShare, GIOpKeyUpdate } from './GIMessage.js'
import type { GIKey, GIOpKeyAdd, GIOpKeyDel, GIOpKeyRequestSeen, GIOpKeyShare, GIOpKeyUpdate } from './GIMessage.js'
import type { Key } from './crypto.js'
import { EDWARDS25519SHA512BATCH, deserializeKey, keyId, keygen, serializeKey } from './crypto.js'
import { ChelErrorUnexpected, ChelErrorUnrecoverable } from './errors.js'
import { CONTRACTS_MODIFIED, CONTRACT_REGISTERED } from './events.js'
// TODO: rename this to ChelMessage
import { GIMessage } from './GIMessage.js'
import type { Secret } from './Secret.js'
import { encryptedOutgoingData, isEncryptedData, maybeEncryptedIncomingData, unwrapMaybeEncryptedData } from './encryptedData.js'
import type { EncryptedData } from './encryptedData.js'
import { isSignedData, signedIncomingData, signedOutgoingData, signedOutgoingDataWithRawKey } from './signedData.js'
import './internals.js'
import { encryptedOutgoingData, isEncryptedData, maybeEncryptedIncomingData, unwrapMaybeEncryptedData } from './encryptedData.js'
import './files.js'
import './internals.js'
import { isSignedData, signedIncomingData, signedOutgoingData, signedOutgoingDataWithRawKey } from './signedData.js'
import './time-sync.js'
import { buildShelterAuthorizationHeader, clearObject, checkCanBeGarbageCollected, eventsAfter, findForeignKeysByContractID, findKeyIdByName, findRevokedKeyIdsByName, findSuitableSecretKeyId, getContractIDfromKeyId, reactiveClearObject } from './utils.js'
import { buildShelterAuthorizationHeader, checkCanBeGarbageCollected, clearObject, eventsAfter, findForeignKeysByContractID, findKeyIdByName, findRevokedKeyIdsByName, findSuitableSecretKeyId, getContractIDfromKeyId, reactiveClearObject } from './utils.js'

// TODO: define ChelContractType for /defineContract

Expand Down
9 changes: 9 additions & 0 deletions shared/domains/chelonia/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ export const findSuitableSecretKeyId = (state: Object, permissions: '*' | string
.sort((a, b) => b.ringLevel - a.ringLevel)[0]?.id
}

export const findContractIDByForeignKeyId = (state: Object, keyId: string): ?string => {
if (!keyId || !state?._vm?.authorizedKeys?.[keyId]?.foreignKey) return

try {
const fkUrl = new URL(state._vm?.authorizedKeys?.[keyId]?.foreignKey)
return fkUrl.pathname
} catch {}
}

// TODO: Resolve inviteKey being added (doesn't have krs permission)
export const findSuitablePublicKeyIds = (state: Object, permissions: '*' | string[], purposes: GIKeyPurpose[], ringLevel?: number): ?string[] => {
return state._vm?.authorizedKeys &&
Expand Down

0 comments on commit 8c585ad

Please sign in to comment.