Skip to content

Commit

Permalink
Merge pull request #1778 from okTurtles/e2e-protocol-ricardo
Browse files Browse the repository at this point in the history
E2e protocol ricardo
  • Loading branch information
taoeffect authored Oct 20, 2023
2 parents 8bcff5d + 26d5179 commit 22139cc
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
8 changes: 4 additions & 4 deletions frontend/views/containers/group-settings/InvitationsTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ page-section.c-section(:title='L("Invite links")')
transition-group(name='slidedown' tag='tbody')
tr(
v-for='(item, index) in invitesToShow'
:key='item.inviteSecret'
:key='index'
)
td.c-name
| {{ item.invitee }}
Expand Down Expand Up @@ -167,11 +167,11 @@ export default ({
'currentGroupId'
]),
invitesToShow () {
const invites = this.currentGroupState.invites
const vmInvites = this.currentGroupState._vm.invites
const vmInvites = this.currentGroupState._vm?.invites
if (!vmInvites) { return [] }
const invites = this.currentGroupState.invites || {}
const invitesList = Object.entries(vmInvites)
.map(([id, invite]) => [id, { ...invite, creator: invites[id]?.creator, invitee: invites[id]?.invitee }])
.filter(([, invite]) => invite.creator === INVITE_INITIAL_CREATOR || invite.creator === this.ourUsername)
Expand Down
37 changes: 34 additions & 3 deletions shared/domains/chelonia/internals.js
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,20 @@ export default (sbp('sbp/selectors/register', {
// For each pending watch operation, queue a synchronization event in the
// respective contract queue
Object.entries(pendingWatch).forEach(([contractID, keys]) => {
if (!Array.isArray(keys) || keys.length === 0) return
if (
!Array.isArray(keys) ||
// Check that the keys exist and haven't been revoked
// $FlowFixMe[incompatible-use]
!keys.reduce((acc, [, id]) => {
return acc || has(externalContractState._vm.authorizedKeys, id)
}, false)
) {
console.info('[chelonia/private/watchForeignKeys]: Skipping as none of the keys to watch exist', {
externalContractID,
contractID
})
return
}

sbp('okTurtles.eventQueue/queueEvent', contractID, ['chelonia/private/in/syncContractAndWatchKeys', contractID, externalContractID]).catch((e) => {
console.error(`Error at syncContractAndWatchKeys for contractID ${contractID} and externalContractID ${externalContractID}`, e)
Expand All @@ -871,7 +884,25 @@ export default (sbp('sbp/selectors/register', {
const externalContractState = rootState[externalContractID]
const pendingWatch = externalContractState?._vm?.pendingWatch?.[contractID]?.splice(0)

if (!Array.isArray(pendingWatch) || pendingWatch.length === 0) return
// We duplicate the check in 'chelonia/private/watchForeignKeys' because
// new events may have been received in the meantime. This avoids
// unnecessarily subscribing to the contract
if (
!Array.isArray(pendingWatch) ||
// Check that the keys exist and haven't been revoked
!pendingWatch.reduce((acc, [, id]) => {
return acc || (
has(externalContractState._vm.authorizedKeys, id) &&
findKeyIdByName(externalContractState, externalContractState._vm.authorizedKeys[id].name) != null
)
}, false)
) {
console.info('[chelonia/private/syncContractAndWatchKeys]: Skipping as none of the keys to watch exist', {
externalContractID,
contractID
})
return
}

await sbp('chelonia/private/in/syncContract', contractID)

Expand Down Expand Up @@ -1242,7 +1273,7 @@ export default (sbp('sbp/selectors/register', {
}): string[])

const eventsToReinjest = []
const reprocessDebounced = debounce((contractID) => sbp('chelonia/contract/sync', contractID), 1000)
const reprocessDebounced = debounce((contractID) => sbp('chelonia/contract/sync', contractID, { force: true }), 1000)

const handleEvent = {
async addMessageToDB (message: GIMessage) {
Expand Down
2 changes: 1 addition & 1 deletion shared/domains/chelonia/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ export const keyAdditionProcessor = function (keys: (GIKey | EncryptedData<GIKey
export const subscribeToForeignKeyContracts = function (contractID: string, state: Object) {
try {
// $FlowFixMe[incompatible-call]
Object.values((state._vm.authorizedKeys: { [x: string]: GIKey })).filter((key) => !!((key: any): GIKey).foreignKey).forEach((key: GIKey) => {
Object.values((state._vm.authorizedKeys: { [x: string]: GIKey })).filter((key) => !!((key: any): GIKey).foreignKey && findKeyIdByName(state, ((key: any): GIKey).name) != null).forEach((key: GIKey) => {
const foreignKey = String(key.foreignKey)
const fkUrl = new URL(foreignKey)
const foreignContract = fkUrl.pathname
Expand Down

0 comments on commit 22139cc

Please sign in to comment.