Skip to content

Commit

Permalink
Merge branch 'feature/1697' of github.com:TryQuiet/quiet into feature…
Browse files Browse the repository at this point in the history
…/1697
  • Loading branch information
vinkabuki committed Sep 29, 2023
2 parents 5375941 + 1fca2fe commit e019b86
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ describe('Username taken', () => {
class="MuiTypography-root MuiTypography-caption css-1d4bzk2-MuiTypography-root"
style="margin-top: 8px;"
>
Your username will be public, but you can choose any name you like. No spaces or special characters. Lowercase letters and numbers only.
You can choose any username you like. No spaces or special characters.
</span>
<div
class="CreateUsernameComponent-gutter"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ export const CreateUsernameComponent: React.FC<CreateUsernameComponentProps> = (
setUserName(parsedName)
setParsedNameDiffers(name !== parsedName)
if (registeredUsers && !isNewUser) {
const allUsersArr = Object.values(registeredUsers).map(user => user.username)
if (allUsersArr.includes(name)) {
const allUsersSet = new Set(Object.values(registeredUsers).map(user => user.username))
if (allUsersSet.has(name)) {
setError('userName', { message: `${name} is already taken` })
}
}
Expand Down Expand Up @@ -301,8 +301,7 @@ export const CreateUsernameComponent: React.FC<CreateUsernameComponentProps> = (

{!isNewUser && (
<Typography variant='caption' style={{ marginTop: 8 }}>
Your username will be public, but you can choose any name you like. No spaces or special characters.
Lowercase letters and numbers only.
You can choose any username you like. No spaces or special characters.
</Typography>
)}
<div className={classes.gutter}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ export const UsernameRegistration: FC<UsernameRegistrationProps> = ({
setUserName(parsedName)
setParsedNameDiffers(name !== parsedName)
if (registeredUsers && !isNewUser) {
const allUsersArr = Object.values(registeredUsers).map(user => user.username)
if (allUsersArr.includes(name)) {
const allUsersSet = new Set(Object.values(registeredUsers).map(user => user.username))
if (allUsersSet.has(name)) {
setInputError(`Username @${name} is already taken`)
}
}
Expand Down
10 changes: 7 additions & 3 deletions packages/state-manager/src/sagas/identity/identity.selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export const communityMembership = createSelector(currentIdentity, identity => {
return Boolean(identity?.userCsr)
})

export const hasCertificate = createSelector(currentIdentity, identity => {
return Boolean(identity?.userCertificate)
})

export const joinedCommunities = createSelector(selectCommunities, selectEntities, (communities, identities) => {
return communities.filter(community => {
return identities[community.id]?.userCertificate
Expand All @@ -45,9 +49,8 @@ export const usernameTaken = createSelector(currentIdentity, certificatesMapping
const username = identity?.nickname
if (!username) return false

const allUsernames: string[] = Object.values(certs).map(u => u.username)

if (allUsernames.includes(username)) {
const allUsersSet = new Set(Object.values(certs).map(user => user.username))
if (allUsersSet.has(username)) {
return true
}

Expand All @@ -63,4 +66,5 @@ export const identitySelectors = {
joinTimestamp,
csr,
usernameTaken,
hasCertificate,
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('registerUsernameSaga', () => {
.run()
})

it.only('username taken - use current CSR and new nickname', async () => {
it('username taken - use current CSR and new nickname', async () => {
setupCrypto()
const socket = { emit: jest.fn(), on: jest.fn() } as unknown as Socket

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { SendCertificatesResponse } from '@quiet/types'
import { PayloadAction } from '@reduxjs/toolkit'
import { select, call, put } from 'typed-redux-saga'
import { identitySelectors } from '../identity.selectors'
import { CertFieldsTypes, getCertFieldValue, getReqFieldValue, loadCSR, parseCertificate } from '@quiet/identity'
import { loadCSR, pubKeyMatch } from '@quiet/identity'
import { identityActions } from '../identity.slice'
import { communitiesSelectors } from '../../communities/communities.selectors'

export function* updateCertificateSaga(action: PayloadAction<SendCertificatesResponse>): Generator {
const certificate = yield* select(identitySelectors.communityMembership)
const certificate = yield* select(identitySelectors.hasCertificate)
const communityId = yield* select(communitiesSelectors.currentCommunityId)

if (certificate) return
Expand All @@ -17,12 +17,9 @@ export function* updateCertificateSaga(action: PayloadAction<SendCertificatesRes
if (!csr?.userCsr) return

const parsedCsr = yield* call(loadCSR, csr?.userCsr)
const pubKey = getReqFieldValue(parsedCsr, CertFieldsTypes.dmPublicKey)

const cert = action.payload.certificates.find(cert => {
const parsedCert = parseCertificate(cert)
const certPubKey = getCertFieldValue(parsedCert, CertFieldsTypes.dmPublicKey)
if (certPubKey === pubKey) return cert
if (pubKeyMatch(cert, parsedCsr)) return cert
})

if (cert) {
Expand Down

0 comments on commit e019b86

Please sign in to comment.