Skip to content

Commit

Permalink
Remove more logger references
Browse files Browse the repository at this point in the history
  • Loading branch information
islathehut committed May 13, 2024
1 parent 25e2d4b commit 2294715
Show file tree
Hide file tree
Showing 22 changed files with 34 additions and 96 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { delay, put } from 'typed-redux-saga'
import createLogger from '../../../utils/logger'
import { connectionActions } from '../connection.slice'

const logger = createLogger('connection')

export function* uptimeSaga(): Generator {
// There is no point in updating this more often as we don't need precise data here, but we want to avoid spamming redux with excess actions
const interval = 10000
logger.debug(`Updating uptime on interval ${interval}ms`)
console.info(`Updating uptime on interval ${interval}ms`)
while (true) {
yield* put(connectionActions.updateUptime(interval))
yield* delay(interval)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import { createSelector } from 'reselect'
import { communitiesAdapter } from './communities.adapter'
import { type CreatedSelectors, type StoreState } from '../store.types'
import { CertFieldsTypes, getCertFieldValue, parseCertificate } from '@quiet/identity'
import createLogger from '../../utils/logger'

const logger = createLogger('communities')

// Workaround for "The inferred type of 'communitiesSelectors' cannot be named without a reference to
// 'packages/identity/node_modules/pkijs/build'. This is likely not portable. A type annotation is necessary."
Expand Down Expand Up @@ -67,7 +64,7 @@ export const ownerNickname = createSelector(ownerCertificate, ownerCertificate =
const nickname = getCertFieldValue(parsedCert, CertFieldsTypes.nickName)

if (!nickname) {
logger.error('Could not retrieve owner nickname from certificate')
console.error('Could not retrieve owner nickname from certificate')
}

return nickname
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ import { connectionSelectors } from '../../appConnection/connection.selectors'
import { networkSelectors } from '../../network/network.selectors'
import { pairsToP2pAddresses } from '@quiet/common'
import { type Community, type InitCommunityPayload, SocketActionTypes } from '@quiet/types'
import createLogger from '../../../utils/logger'

const logger = createLogger('communities')

export function* initCommunities(): Generator {
const joinedCommunities = yield* select(identitySelectors.joinedCommunities)
Expand Down Expand Up @@ -46,7 +43,7 @@ export function* launchCommunitySaga(
const identity = yield* select(identitySelectors.selectById(communityId))

if (!community || !identity?.userCsr?.userKey) {
logger.error('Could not launch community, missing community or user private key')
console.error('Could not launch community, missing community or user private key')
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ import { AUTODOWNLOAD_SIZE_LIMIT } from '../../../constants'
import { filesActions } from '../files.slice'
import { applyEmitParams, type Socket } from '../../../types'
import { DownloadState, MessageType, SocketActionTypes } from '@quiet/types'
import createLogger from '../../../utils/logger'

const logger = createLogger('files')

export function* autoDownloadFilesSaga(
socket: Socket,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import { identitySelectors } from '../../identity/identity.selectors'
import { messagesSelectors } from '../../messages/messages.selectors'
import { type filesActions } from '../files.slice'
import { instanceOfChannelMessage, SocketActionTypes } from '@quiet/types'
import createLogger from '../../../utils/logger'

const logger = createLogger('files')

export function* broadcastHostedFileSaga(
socket: Socket,
Expand All @@ -24,7 +21,7 @@ export function* broadcastHostedFileSaga(
const message = channelMessages[action.payload.message.id]

if (!message || !instanceOfChannelMessage(message)) {
logger.error(
console.error(
`Cannot broadcast message after uploading. Draft ${action.payload.message.id} from #${action.payload.message.channelId} does not exist in local storage.`
)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import { messagesSelectors } from '../../messages/messages.selectors'
import { messagesActions } from '../../messages/messages.slice'
import { type filesActions } from '../files.slice'
import { instanceOfChannelMessage } from '@quiet/types'
import createLogger from '../../../utils/logger'

const logger = createLogger('files')

export function* updateMessageMediaSaga(
action: PayloadAction<ReturnType<typeof filesActions.updateMessageMedia>['payload']>
Expand All @@ -17,7 +14,7 @@ export function* updateMessageMediaSaga(

const message = channelMessages[action.payload.message.id]
if (!message || !instanceOfChannelMessage(message)) {
logger.error(
console.error(
`Cannot update message media. Message ${action.payload.message.id} from #${action.payload.message.channelId} does not exist in local storage.`
)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import { messagesActions } from '../../messages/messages.slice'
import { generateMessageId } from '../../messages/utils/message.utils'
import { publicChannelsSelectors } from '../../publicChannels/publicChannels.selectors'
import { DownloadState, type FileMetadata, imagesExtensions, MessageType } from '@quiet/types'
import createLogger from '../../../utils/logger'

const logger = createLogger('files')

export function* sendFileMessageSaga(
action: PayloadAction<ReturnType<typeof filesActions.uploadFile>['payload']>
Expand All @@ -26,7 +23,7 @@ export function* sendFileMessageSaga(
filePath = decodeURIComponent(filePath.startsWith(fileProtocol) ? filePath.slice(fileProtocol.length) : filePath)
tmpPath = tmpPath ? decodeURIComponent(tmpPath.slice(fileProtocol.length)) : undefined
} catch (e) {
logger.error(`Can't send file with path ${filePath}, Details: ${e.message}`)
console.error(`Can't send file with path ${filePath}, Details: ${e.message}`)
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ import { Socket } from '../../../types'
import { communitiesActions } from '../../communities/communities.slice'
import { communitiesSelectors } from '../../communities/communities.selectors'
import { CreateUserCsrPayload, RegisterCertificatePayload, Community } from '@quiet/types'
import createLogger from '../../../utils/logger'

const logger = createLogger('identity')

export function* registerUsernameSaga(
socket: Socket,
Expand All @@ -29,7 +26,7 @@ export function* registerUsernameSaga(
}
community = yield* select(communitiesSelectors.currentCommunity)
if (!community) {
logger.error('Could not register username, no community data')
console.error('Could not register username, no community data')
return
}
console.log('Found community', community.id)
Expand All @@ -41,7 +38,7 @@ export function* registerUsernameSaga(
}
identity = yield* select(identitySelectors.currentIdentity)
if (!identity) {
logger.error('Could not register username, no identity')
console.error('Could not register username, no identity')
return
}
console.log('Found identity', identity.id)
Expand All @@ -51,7 +48,7 @@ export function* registerUsernameSaga(
if (userCsr) {
try {
if (identity.userCsr?.userCsr == null || identity.userCsr.userKey == null) {
logger.error('identity.userCsr?.userCsr == null || identity.userCsr.userKey == null')
console.error('identity.userCsr?.userCsr == null || identity.userCsr.userKey == null')
return
}
const _pubKey = yield* call(pubKeyFromCsr, identity.userCsr.userCsr)
Expand All @@ -72,7 +69,7 @@ export function* registerUsernameSaga(
console.log('Recreating user CSR')
userCsr = yield* call(createUserCsr, payload)
} catch (e) {
logger.error('Error occurred while creating new CSR from existing', e)
console.error('Error occurred while creating new CSR from existing', e)
return
}
} else {
Expand All @@ -88,7 +85,7 @@ export function* registerUsernameSaga(
console.log('Creating user CSR')
userCsr = yield* call(createUserCsr, payload)
} catch (e) {
logger.error('Error occurred while generating new user CSR', e)
console.error('Error occurred while generating new user CSR', e)
return
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ import { SaveCSRPayload, SocketActionTypes } from '@quiet/types'
import { applyEmitParams, type Socket } from '../../../types'
import { apply, select } from 'typed-redux-saga'
import { identitySelectors } from '../identity.selectors'
import createLogger from '../../../utils/logger'

const logger = createLogger('identity')

export function* saveUserCsrSaga(socket: Socket): Generator {
console.log('Saving user CSR')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import { publicChannelsSelectors } from '../../publicChannels/publicChannels.sel
import { messagesActions } from '../messages.slice'
import { generateMessageId, getCurrentTime } from '../utils/message.utils'
import { type ChannelMessage, MessageType, SendingStatus, SocketActionTypes } from '@quiet/types'
import createLogger from '../../../utils/logger'

const logger = createLogger('messages')

export function* sendMessageSaga(
socket: Socket,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import { publicChannelsSelectors } from '../../publicChannels/publicChannels.sel

import { usersSelectors } from '../../users/users.selectors'
import { verifyUserInfoMessage } from '@quiet/common'
import createLogger from '../../../utils/logger'

const logger = createLogger('messages')

export function* verifyMessagesSaga(
action: PayloadAction<ReturnType<typeof messagesActions.addMessages>>['payload']
Expand Down Expand Up @@ -44,7 +41,7 @@ export function* verifyMessagesSaga(
const expectedMessage = yield* call(verifyUserInfoMessage, user.username, channel)

if (message.message !== expectedMessage) {
logger.error(`${user.username} tried to send a malicious info message`)
console.error(`${user.username} tried to send a malicious info message`)
isVerified = false
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
import { publicChannelsActions } from '../publicChannels.slice'
import { type PayloadAction } from '@reduxjs/toolkit'
import createLogger from '../../../utils/logger'
import { put, delay, select } from 'typed-redux-saga'
import { messagesActions } from '../../messages/messages.slice'
import { communitiesSelectors } from '../../communities/communities.selectors'
import { publicChannelsSelectors } from '../publicChannels.selectors'
import { type PublicChannelStorage } from '@quiet/types'

const logger = createLogger('publicChannels')

export function* channelDeletionResponseSaga(
action: PayloadAction<ReturnType<typeof publicChannelsActions.channelDeletionResponse>['payload']>
): Generator {
logger(`Deleted channel ${action.payload.channelId} saga`)
console.log(`Deleted channel ${action.payload.channelId} saga`)

const { channelId } = action.payload
const generalChannel = yield* select(publicChannelsSelectors.generalChannel)

const isChannelExist = yield* select(publicChannelsSelectors.getChannelById(channelId))
const currentChannelId = yield* select(publicChannelsSelectors.currentChannelId)
if (!isChannelExist) {
logger(`Channel with id ${channelId} doesnt exist in store`)
console.error(`Channel with id ${channelId} doesnt exist in store`)
return
}

if (!generalChannel) {
logger('General Channel doesnt exist in store')
console.error('General Channel doesnt exist in store')
return
}

Expand Down Expand Up @@ -59,7 +56,7 @@ export function* channelDeletionResponseSaga(
if (isGeneral && isUserOnGeneral) {
let newGeneralChannel: PublicChannelStorage | undefined = yield* select(publicChannelsSelectors.generalChannel)
while (!newGeneralChannel) {
logger('General channel has not been replicated yet')
console.log('General channel has not been replicated yet')
yield* delay(1000)
newGeneralChannel = yield* select(publicChannelsSelectors.generalChannel)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import { messagesSelectors } from '../../messages/messages.selectors'
import { messagesActions } from '../../messages/messages.slice'
import { communitiesSelectors } from '../../communities/communities.selectors'

import createLogger from '../../../utils/logger'
import logger from '../../../utils/logger'
import { type PublicChannel } from '@quiet/types'
const logger = createLogger('channels')
const log = logger('channels')

export function* channelsReplicatedSaga(
action: PayloadAction<ReturnType<typeof publicChannelsActions.channelsReplicated>['payload']>
): Generator {
// TODO: Refactor to use QuietLogger
logger(`Syncing channels: ${JSON.stringify(action.payload, null, 2)}`)
log(`Syncing channels: ${JSON.stringify(action.payload, null, 2)}`)
const { channels } = action.payload
const _locallyStoredChannels = yield* select(publicChannelsSelectors.publicChannels)
const locallyStoredChannels = _locallyStoredChannels.map(channel => channel.id)
Expand All @@ -23,13 +23,13 @@ export function* channelsReplicatedSaga(
const databaseStoredChannels = Object.values(channels) as PublicChannel[]

const databaseStoredChannelsIds = databaseStoredChannels.map(channel => channel.id)
logger({ locallyStoredChannels, databaseStoredChannelsIds })
log({ locallyStoredChannels, databaseStoredChannelsIds })

// Upserting channels to local storage
for (const channel of databaseStoredChannels) {
if (!locallyStoredChannels.includes(channel.id)) {
// TODO: Refactor to use QuietLogger
logger(`Adding #${channel.name} to store`)
log(`Adding #${channel.name} to store`)
yield* putResolve(
publicChannelsActions.addChannel({
channel,
Expand All @@ -48,7 +48,7 @@ export function* channelsReplicatedSaga(
for (const channelId of locallyStoredChannels) {
if (!databaseStoredChannelsIds.includes(channelId)) {
// TODO: Refactor to use QuietLogger
logger(`Removing #${channelId} from store`)
log(`Removing #${channelId} from store`)
yield* putResolve(publicChannelsActions.deleteChannel({ channelId }))
yield* take(publicChannelsActions.completeChannelDeletion)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@ import { type PayloadAction } from '@reduxjs/toolkit'
import { apply, put } from 'typed-redux-saga'

import { type Socket, applyEmitParams } from '../../../types'
import createLogger from '../../../utils/logger'

import { SocketActionTypes, type CreateChannelResponse } from '@quiet/types'

const logger = createLogger('publicChannels')

export function* createChannelSaga(
socket: Socket,
action: PayloadAction<ReturnType<typeof publicChannelsActions.createChannel>['payload']>
): Generator {
logger.info(`Creating channel ${action.payload.channel.name}`)
console.info(`Creating channel ${action.payload.channel.name}`)

const response = yield* apply(
socket,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@ import { select, put, call } from 'typed-redux-saga'
import { publicChannelsActions } from '../publicChannels.slice'
import { identitySelectors } from '../../identity/identity.selectors'
import { DateTime } from 'luxon'
import createLogger from '../../../utils/logger'
import { generateChannelId } from '@quiet/common'
import { type PublicChannel } from '@quiet/types'

const logger = createLogger('publicChannels')

export function* createGeneralChannelSaga(): Generator {
const identity = yield* select(identitySelectors.currentIdentity)
if (!identity) {
logger.error('Could not create general channel. No identity')
console.error('Could not create general channel. No identity')
return
}
logger.info(`Creating general channel for ${identity.nickname}`)
console.info(`Creating general channel for ${identity.nickname}`)

const timestamp = yield* call(getChannelTimestamp)
const id = yield* call(generateChannelId, 'general')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ import { type PayloadAction } from '@reduxjs/toolkit'
import { publicChannelsActions } from '../publicChannels.slice'
import { apply, put, select } from 'typed-redux-saga'
import { type Socket, applyEmitParams } from '../../../types'
import createLogger from '../../../utils/logger'
import { filesActions } from '../../files/files.slice'
import { SocketActionTypes } from '@quiet/types'
import { publicChannelsSelectors } from '../publicChannels.selectors'
import { usersSelectors } from '../../users/users.selectors'

const logger = createLogger('publicChannels')

export function* deleteChannelSaga(
socket: Socket,
action: PayloadAction<ReturnType<typeof publicChannelsActions.deleteChannel>['payload']>
Expand All @@ -25,7 +22,7 @@ export function* deleteChannelSaga(

const isGeneral = channelId === generalChannel.id

logger.info(`Deleting channel ${channelId}`)
console.info(`Deleting channel ${channelId}`)

const response = yield* apply(
socket,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@ import {
} from '@quiet/types'
import { networkSelectors } from '../network/network.selectors'
import { communitiesSelectors } from '../communities/communities.selectors'
import createLogger from '../../utils/logger'
import { isMessageUnsent } from '../../utils/messages/messages.utils'

const logger = createLogger('publicChannels')

const selectState: CreatedSelectors[StoreKeys.PublicChannels] = (state: StoreState) => state[StoreKeys.PublicChannels]

export const selectChannels = createSelector(selectState, state => {
Expand All @@ -56,7 +53,7 @@ export const subscribedChannels = createSelector(selectChannelsSubscriptions, su
export const selectGeneralChannel = createSelector(selectChannels, channels => {
const draft = channels.find(item => item.name === 'general')
if (!draft) {
logger.error('No general channel')
console.error('No general channel')
return
}
const channel: PublicChannel = {
Expand Down Expand Up @@ -130,7 +127,7 @@ export const getChannelById = (channelId: string) =>
createSelector(publicChannels, channels => {
const channel = channels.find(channel => channel.id === channelId)
if (!channel) {
logger.warn(`Channel with ID ${channelId} does not exist`)
console.warn(`Channel with ID ${channelId} does not exist`)
}
return channel
})
Expand Down
Loading

0 comments on commit 2294715

Please sign in to comment.