Skip to content

Commit

Permalink
Merge pull request #1653 from TryQuiet/bug/1565
Browse files Browse the repository at this point in the history
bug/new/unread message indicator sometimes missing
  • Loading branch information
Kacper-RF authored Jul 24, 2023
2 parents eae9844 + b8becaf commit cce4110
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 7 deletions.
15 changes: 9 additions & 6 deletions packages/desktop/src/rtl-tests/channel.main.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -620,11 +620,7 @@ describe('Channel', () => {
await userEvent.type(messageInput, '{enter}')

// sendMessage action trigger
expect(actions).toMatchInlineSnapshot(`
Array [
"Messages/sendMessage",
]
`)
expect(actions).toMatchInlineSnapshot()
})

it('renders a multi-line message', async () => {
Expand Down Expand Up @@ -751,7 +747,7 @@ describe('Channel', () => {
await userEvent.type(messageInput, '{enter}')

// sendMessage action does not trigger
expect(actions).toMatchInlineSnapshot('Array []')
expect(actions).toMatchInlineSnapshot(`Array []`)
})

it('immediately shows uploaded image', async () => {
Expand Down Expand Up @@ -871,6 +867,7 @@ describe('Channel', () => {
"Messages/incomingMessages",
"PublicChannels/cacheMessages",
"Messages/addMessageVerificationStatus",
"Identity/verifyJoinTimestamp",
"PublicChannels/updateNewestMessage",
"Messages/lazyLoading",
"Messages/resetCurrentPublicChannelCache",
Expand All @@ -881,6 +878,7 @@ describe('Channel', () => {
"Messages/incomingMessages",
"PublicChannels/cacheMessages",
"Messages/addMessageVerificationStatus",
"Identity/verifyJoinTimestamp",
"Files/updateDownloadStatus",
]
`)
Expand Down Expand Up @@ -1009,6 +1007,7 @@ describe('Channel', () => {
"Files/updateMessageMedia",
"Messages/incomingMessages",
"Messages/addMessageVerificationStatus",
"Identity/verifyJoinTimestamp",
"PublicChannels/updateNewestMessage",
"PublicChannels/cacheMessages",
]
Expand Down Expand Up @@ -1102,6 +1101,7 @@ describe('Channel', () => {
"Messages/incomingMessages",
"PublicChannels/cacheMessages",
"Messages/addMessageVerificationStatus",
"Identity/verifyJoinTimestamp",
"PublicChannels/updateNewestMessage",
"Messages/lazyLoading",
"Messages/resetCurrentPublicChannelCache",
Expand Down Expand Up @@ -1222,6 +1222,7 @@ describe('Channel', () => {
"Messages/incomingMessages",
"Files/updateDownloadStatus",
"Messages/addMessageVerificationStatus",
"Identity/verifyJoinTimestamp",
"PublicChannels/updateNewestMessage",
]
`)
Expand Down Expand Up @@ -1335,6 +1336,7 @@ describe('Channel', () => {
"Messages/incomingMessages",
"Files/updateDownloadStatus",
"Messages/addMessageVerificationStatus",
"Identity/verifyJoinTimestamp",
"PublicChannels/updateNewestMessage",
"PublicChannels/cacheMessages",
"Messages/lazyLoading",
Expand Down Expand Up @@ -1473,6 +1475,7 @@ describe('Channel', () => {
"Messages/incomingMessages",
"Files/updateDownloadStatus",
"Messages/addMessageVerificationStatus",
"Identity/verifyJoinTimestamp",
"PublicChannels/updateNewestMessage",
"Messages/addMessageVerificationStatus",
"PublicChannels/cacheMessages",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import { registerCertificateSaga } from './registerCertificate/registerCertifica
import { saveOwnerCertToDbSaga } from './saveOwnerCertToDb/saveOwnerCertToDb.saga'
import { registerUsernameSaga } from './registerUsername/registerUsername.saga'
import { savedOwnerCertificateSaga } from './savedOwnerCertificate/savedOwnerCertificate.saga'
import { verifyJoinTimestampSaga } from './verifyJoinTimestamp/verifyJoinTimestamp.saga'

export function* identityMasterSaga(socket: Socket): Generator {
yield all([
takeEvery(identityActions.registerUsername.type, registerUsernameSaga, socket),
takeEvery(identityActions.registerCertificate.type, registerCertificateSaga, socket),
takeEvery(identityActions.saveOwnerCertToDb.type, saveOwnerCertToDbSaga, socket),
takeEvery(identityActions.savedOwnerCertificate.type, savedOwnerCertificateSaga, socket),
takeEvery(identityActions.verifyJoinTimestamp.type, verifyJoinTimestampSaga),
])
}
10 changes: 10 additions & 0 deletions packages/state-manager/src/sagas/identity/identity.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DateTime } from 'luxon'
import { StoreKeys } from '../store.keys'
import { identityAdapter } from './identity.adapter'
import {
type UpdateJoinTimestampPayload,
type CreateUserCsrPayload,
type Identity,
type RegisterCertificatePayload,
Expand Down Expand Up @@ -41,6 +42,15 @@ export const identitySlice = createSlice({
},
})
},
verifyJoinTimestamp: state => state,
updateJoinTimestamp: (state, action: PayloadAction<UpdateJoinTimestampPayload>) => {
identityAdapter.updateOne(state.identities, {
id: action.payload.communityId,
changes: {
joinTimestamp: DateTime.utc().valueOf(),
},
})
},
throwIdentityError: (state, _action: PayloadAction<string>) => state,
},
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { combineReducers } from '@reduxjs/toolkit'
import { expectSaga } from 'redux-saga-test-plan'
import { type Socket } from '../../../types'
import { type communitiesActions } from '../../communities/communities.slice'
import { type Store } from '../../store.types'
import { type FactoryGirl } from 'factory-girl'
import { setupCrypto } from '@quiet/identity'
import { prepareStore, reducers } from '../../../utils/tests/prepareStore'
import { getFactory } from '../../../utils/tests/factories'
import { verifyJoinTimestampSaga } from './verifyJoinTimestamp.saga'
import { identityActions } from '../identity.slice'

describe('verifyJoinTimestampSaga', () => {
let store: Store
let factory: FactoryGirl

beforeEach(async () => {
setupCrypto()
store = prepareStore().store
factory = await getFactory(store)
})

it('user has valid timestamp', async () => {
const community = await factory.create<ReturnType<typeof communitiesActions.addNewCommunity>['payload']>(
'Community'
)

await factory.create<ReturnType<typeof identityActions.addNewIdentity>['payload']>('Identity', {
id: community.id,
nickname: 'john',
})

const reducer = combineReducers(reducers)
await expectSaga(verifyJoinTimestampSaga).withReducer(reducer).withState(store.getState()).run()
})

it('user doesnt have timestamp', async () => {
const community = await factory.create<ReturnType<typeof communitiesActions.addNewCommunity>['payload']>(
'Community'
)

await factory.create<ReturnType<typeof identityActions.addNewIdentity>['payload']>('Identity', {
id: community.id,
nickname: 'john',
joinTimestamp: null,
})

const reducer = combineReducers(reducers)
await expectSaga(verifyJoinTimestampSaga)
.withReducer(reducer)
.withState(store.getState())
.put(identityActions.updateJoinTimestamp({ communityId: community.id }))
.run()
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { put, select } from 'typed-redux-saga'
import { communitiesSelectors } from '../../communities/communities.selectors'
import { identitySelectors } from '../identity.selectors'
import { identityActions } from '../identity.slice'

export function* verifyJoinTimestampSaga(): Generator {
const joinTimestamp = yield* select(identitySelectors.joinTimestamp)

if (!joinTimestamp) {
const communityId = yield* select(communitiesSelectors.currentCommunityId)
yield* put(identityActions.updateJoinTimestamp({ communityId }))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { publicChannelsActions } from '../publicChannels.slice'
import { type communitiesActions } from '../../communities/communities.slice'
import { type FactoryGirl } from 'factory-girl'
import { combineReducers } from 'redux'
import { type identityActions } from '../../identity/identity.slice'
import { identityActions } from '../../identity/identity.slice'
import { DateTime } from 'luxon'
import { markUnreadChannelsSaga } from './markUnreadChannels.saga'
import { messagesActions } from '../../messages/messages.slice'
Expand Down Expand Up @@ -118,6 +118,7 @@ describe('markUnreadChannelsSaga', () => {
)
.withReducer(reducer)
.withState(store.getState())
.put(identityActions.verifyJoinTimestamp())
.put(
publicChannelsActions.markUnreadChannel({
channelId: channelIdMemes,
Expand Down Expand Up @@ -209,6 +210,7 @@ describe('markUnreadChannelsSaga', () => {
)
.withReducer(reducer)
.withState(store.getState())
.put(identityActions.verifyJoinTimestamp())
.not.put(
publicChannelsActions.markUnreadChannel({
channelId: channelIdMemes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { publicChannelsSelectors } from '../publicChannels.selectors'
import { type messagesActions } from '../../messages/messages.slice'
import { identitySelectors } from '../../identity/identity.selectors'
import { type MarkUnreadChannelPayload } from '@quiet/types'
import { identityActions } from '../../identity/identity.slice'
import { communitiesSelectors } from '../../communities/communities.selectors'

export function* markUnreadChannelsSaga(
action: PayloadAction<ReturnType<typeof messagesActions.incomingMessages>['payload']>
Expand All @@ -13,6 +15,9 @@ export function* markUnreadChannelsSaga(

const { messages } = action.payload

// Fix for users whose has damaged property with join timestamp and problem with proper checking new message
yield* put(identityActions.verifyJoinTimestamp())

for (const message of messages) {
// Do not proceed for current channel
if (message.channelId !== currentChannelId) {
Expand Down
4 changes: 4 additions & 0 deletions packages/types/src/identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,7 @@ export interface StoreUserCertificatePayload {
userCertificate: string
communityId: string
}

export interface UpdateJoinTimestampPayload {
communityId: string
}

0 comments on commit cce4110

Please sign in to comment.