Skip to content

Commit

Permalink
Recreate anyone can join
Browse files Browse the repository at this point in the history
  • Loading branch information
corrideat committed Oct 2, 2024
1 parent eed98aa commit 196a7b9
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 5 deletions.
43 changes: 43 additions & 0 deletions frontend/controller/actions/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { Secret } from '~/shared/domains/chelonia/Secret.js'
import type { ChelKeyRequestParams } from '~/shared/domains/chelonia/chelonia.js'
import { encryptedOutgoingData, encryptedOutgoingDataWithRawKey } from '~/shared/domains/chelonia/encryptedData.js'
import { CONTRACT_HAS_RECEIVED_KEYS, EVENT_HANDLED } from '~/shared/domains/chelonia/events.js'
import { findKeyIdByName } from '~/shared/domains/chelonia/utils.js'
// Using relative path to crypto.js instead of ~-path to workaround some esbuild bug
import type { Key } from '../../../shared/domains/chelonia/crypto.js'
import { CURVE25519XSALSA20POLY1305, EDWARDS25519SHA512BATCH, keyId, keygen, serializeKey } from '../../../shared/domains/chelonia/crypto.js'
Expand Down Expand Up @@ -898,6 +899,48 @@ export default (sbp('sbp/selectors/register', {
sbp('okTurtles.events/emit', REPLACE_MODAL, 'IncomeDetails')
}
},
'gi.actions/group/fixAnyoneCanJoinLink': async function ({ contractID }) {
const state = await sbp('chelonia/contract/state', contractID)
const CEKid = findKeyIdByName(state, 'cek')
const CSKid = findKeyIdByName(state, 'csk')

if (!CEKid || !CSKid) {
throw new Error('Contract is missing a CEK or CSK')
}

const inviteKey = keygen(EDWARDS25519SHA512BATCH)
const inviteKeyId = keyId(inviteKey)
const inviteKeyP = serializeKey(inviteKey, false)
const inviteKeyS = encryptedOutgoingData(state, CEKid, serializeKey(inviteKey, true))

const ik = {
id: inviteKeyId,
name: '#inviteKey-' + inviteKeyId,
purpose: ['sig'],
ringLevel: Number.MAX_SAFE_INTEGER,
permissions: [GIMessage.OP_KEY_REQUEST],
meta: {
quantity: 60,
...(INVITE_EXPIRES_IN_DAYS.ON_BOARDING && {
expires:
await sbp('chelonia/time') + DAYS_MILLIS * INVITE_EXPIRES_IN_DAYS.ON_BOARDING
}),
private: {
content: inviteKeyS
}
},
data: inviteKeyP
}

await sbp('chelonia/out/keyAdd', {
contractName: 'gi.contracts/group',
contractID,
data: [ik],
signingKeyId: CSKid
})

await sbp('gi.actions/group/invite', { contractID, data: { inviteKeyId, creatorID: 'invite-initial-creator' } })
},
...encryptedAction('gi.actions/group/leaveChatRoom', L('Failed to leave chat channel.'), async (sendMessage, params) => {
const state = await sbp('chelonia/contract/state', params.contractID)
const memberID = params.data.memberID || sbp('chelonia/rootState').loggedIn.identityContractID
Expand Down
2 changes: 1 addition & 1 deletion frontend/model/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ const getters = {
},
currentWelcomeInvite (state, getters) {
const invites = getters.currentGroupState.invites
const inviteId = Object.keys(invites).find(invite => invites[invite].creatorID === INVITE_INITIAL_CREATOR)
const inviteId = Object.keys(invites).find(invite => invites[invite].creatorID === INVITE_INITIAL_CREATOR && !(getters.currentGroupState._vm.invites[inviteId].expires < Date.now()))
const expires = getters.currentGroupState._vm.invites[inviteId].expires
return { inviteId, expires }
},
Expand Down
2 changes: 1 addition & 1 deletion frontend/views/containers/dashboard/GroupMembers.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default ({
},
async fixWelcomeInvite () {
try {
await sbp('gi.app/group/fixAnyoneCanJoinLink')
await sbp('gi.actions/group/fixAnyoneCanJoinLink', { contractID: this.$store.state.currentGroupId })
} catch (err) {
console.error('GroupMembers.vue failed to fix anyone-to-join invite and caught: ', err)
}
Expand Down
6 changes: 3 additions & 3 deletions frontend/views/containers/group-settings/InvitationsTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ export default ({
if (expiryTime == null) return
const { years, months, days, hours, minutes } = timeLeft(expiryTime)
// In the cases when displaying years/months, count the remainer hours/mins as +1 day eg) 3days 15hrs 25mins -> 4days.
if (years) return L('{years}yr {months}mth {days}d left', { years, months, days })
if (months) return L('{months}mth {days}d left', { months, days })
if (years) return L('{years}y {months}mo {days}d left', { years, months, days })
if (months) return L('{months}mo {days}d left', { months, days })
if (days) return L('{days}d {hours}h {minutes}m left', { days, hours, minutes })
if (hours) return L('{hours}h {minutes}m left', { hours, minutes })
Expand Down Expand Up @@ -361,7 +361,7 @@ export default ({
},
async fixWelcomeInvite () {
try {
await sbp('gi.app/group/fixAnyoneCanJoinLink')
await sbp('gi.actions/group/fixAnyoneCanJoinLink', { contractID: this.currentGroupId })
} catch (err) {
console.error('InvitationTable.vue failed to fix anyone-to-join invite and caught: ', err)
}
Expand Down

0 comments on commit 196a7b9

Please sign in to comment.