Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions packages/common/src/hooks/chats/useSetInboxPermissions.ts
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
import { useCallback } from 'react'

import type { AudiusSdk } from '@audius/sdk'
import { useDispatch, useSelector } from 'react-redux'

import { useAudiusQueryContext } from '~/audius-query'
import { useAppContext } from '~/context/appContext'
import { Name } from '~/models/Analytics'
import { accountSelectors } from '~/store/account'
Expand All@@ -17,13 +17,8 @@ const { fetchPermissions } = chatActions
const { getChatPermissionsStatus, getUserChatPermissions } = chatSelectors
const { getUserId } = accountSelectors

type useSetInboxPermissionsProps = {
audiusSdk: () => Promise<AudiusSdk>
}

export const useSetInboxPermissions = ({
audiusSdk
}: useSetInboxPermissionsProps) => {
export const useSetInboxPermissions = () => {
const { audiusSdk, reportToSentry } = useAudiusQueryContext()
const dispatch = useDispatch()
const permissions = useSelector(getUserChatPermissions)
const {
Expand DownExpand Up@@ -53,7 +48,10 @@ export const useSetInboxPermissions = ({
})
)
} catch (e) {
console.error('Error saving chat permissions:', e)
reportToSentry({
name: 'Chats',
error: e as Error
})
track(
make({
eventName: Name.CHANGE_INBOX_SETTINGS_FAILURE,
Expand All@@ -62,7 +60,7 @@ export const useSetInboxPermissions = ({
)
}
},
[audiusSdk, track, make, doFetchPermissions]
[audiusSdk, doFetchPermissions, track, make, reportToSentry]
)

return {
Expand Down
54 changes: 18 additions & 36 deletions packages/common/src/store/pages/chat/sagas.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,7 +16,6 @@ import {
import { ulid } from 'ulid'

import { Name } from '~/models/Analytics'
import { ErrorLevel } from '~/models/ErrorReporting'
import { ID } from '~/models/Identifiers'
import { Status } from '~/models/Status'
import { getAccountUser, getUserId } from '~/store/account/selectors'
Expand DownExpand Up@@ -121,11 +120,10 @@ function* doFetchUnreadMessagesCount() {
fetchUnreadMessagesCountSucceeded({ unreadMessagesCount: response.data })
)
} catch (e) {
console.error('fetchUnreadMessagesCountFailed', e)
yield* put(fetchUnreadMessagesCountFailed())
const reportToSentry = yield* getContext('reportToSentry')
reportToSentry({
level: ErrorLevel.Error,
name: 'Chats',
error: e as Error
})
}
Expand DownExpand Up@@ -169,11 +167,10 @@ function* doFetchLatestChats() {
})
)
} catch (e) {
console.error('fetchLatestChatsFailed', e)
yield* put(fetchMoreChatsFailed())
const reportToSentry = yield* getContext('reportToSentry')
reportToSentry({
level: ErrorLevel.Error,
name: 'Chats',
error: e as Error
})
}
Expand All@@ -197,11 +194,10 @@ function* doFetchMoreChats() {
yield* fetchUsersForChats(response.data)
yield* put(fetchMoreChatsSucceeded(response))
} catch (e) {
console.error('fetchMoreChatsFailed', e)
yield* put(fetchMoreChatsFailed())
const reportToSentry = yield* getContext('reportToSentry')
reportToSentry({
level: ErrorLevel.Error,
name: 'Chats',
error: e as Error
})
}
Expand DownExpand Up@@ -262,11 +258,10 @@ function* doFetchLatestMessages(
})
)
} catch (e) {
console.error('fetchLatestChatMessagesFailed', e)
yield* put(fetchMoreMessagesFailed({ chatId }))
const reportToSentry = yield* getContext('reportToSentry')
reportToSentry({
level: ErrorLevel.Error,
name: 'Chats',
error: e as Error,
additionalInfo: {
chatId
Expand DownExpand Up@@ -324,11 +319,10 @@ function* doFetchMoreMessages(action: ReturnType<typeof fetchMoreMessages>) {
})
)
} catch (e) {
console.error('fetchMoreChatMessagesFailed', e)
yield* put(fetchMoreMessagesFailed({ chatId }))
const reportToSentry = yield* getContext('reportToSentry')
reportToSentry({
level: ErrorLevel.Error,
name: 'Chats',
error: e as Error,
additionalInfo: {
chatId
Expand DownExpand Up@@ -372,11 +366,10 @@ function* doSetMessageReaction(action: ReturnType<typeof setMessageReaction>) {
})
)
} catch (e) {
console.error('setMessageReactionFailed', e)
yield* put(setMessageReactionFailed(action.payload))
const reportToSentry = yield* getContext('reportToSentry')
reportToSentry({
level: ErrorLevel.Error,
name: 'Chats',
error: e as Error,
additionalInfo: {
chatId,
Expand DownExpand Up@@ -434,7 +427,6 @@ function* doCreateChat(action: ReturnType<typeof createChat>) {
yield* call(track, make({ eventName: Name.CREATE_CHAT_SUCCESS }))
}
} catch (e) {
console.error('createChatFailed', e)
yield* put(
toast({
type: 'error',
Expand All@@ -443,7 +435,7 @@ function* doCreateChat(action: ReturnType<typeof createChat>) {
)
const reportToSentry = yield* getContext('reportToSentry')
reportToSentry({
level: ErrorLevel.Error,
name: 'Chats',
error: e as Error,
additionalInfo: {
userIds
Expand DownExpand Up@@ -502,7 +494,6 @@ function* doCreateChatBlast(action: ReturnType<typeof createChatBlast>) {
yield* call(track, make({ eventName: Name.CREATE_CHAT_SUCCESS }))
}
} catch (e) {
console.error('createChatBlastFailed', e)
yield* put(
toast({
type: 'error',
Expand All@@ -511,7 +502,7 @@ function* doCreateChatBlast(action: ReturnType<typeof createChatBlast>) {
)
const reportToSentry = yield* getContext('reportToSentry')
reportToSentry({
level: ErrorLevel.Error,
name: 'Chats',
error: e as Error,
additionalInfo: {
audience,
Expand DownExpand Up@@ -547,11 +538,10 @@ function* doMarkChatAsRead(action: ReturnType<typeof markChatAsRead>) {
yield* put(markChatAsReadFailed({ chatId }))
}
} catch (e) {
console.error('markChatAsReadFailed', e)
yield* put(markChatAsReadFailed({ chatId }))
const reportToSentry = yield* getContext('reportToSentry')
reportToSentry({
level: ErrorLevel.Error,
name: 'Chats',
error: e as Error,
additionalInfo: {
chatId
Expand DownExpand Up@@ -608,7 +598,6 @@ function* doSendMessage(action: ReturnType<typeof sendMessage>) {
}
yield* call(track, make({ eventName: Name.SEND_MESSAGE_SUCCESS }))
} catch (e) {
console.error('sendMessageFailed', e)
yield* put(sendMessageFailed({ chatId, messageId: messageIdToUse }))

// Fetch the chat to see if permissions need rechecking
Expand All@@ -629,7 +618,7 @@ function* doSendMessage(action: ReturnType<typeof sendMessage>) {
}
const reportToSentry = yield* getContext('reportToSentry')
reportToSentry({
level: ErrorLevel.Error,
name: 'Chats',
error: e as Error,
additionalInfo: {
chatId,
Expand DownExpand Up@@ -671,10 +660,9 @@ function* doFetchBlockees() {
})
)
} catch (e) {
console.error('fetchBlockeesFailed', e)
const reportToSentry = yield* getContext('reportToSentry')
reportToSentry({
level: ErrorLevel.Error,
name: 'Chats',
error: e as Error
})
}
Expand All@@ -693,10 +681,9 @@ function* doFetchBlockers() {
})
)
} catch (e) {
console.error('fetchBlockersFailed', e)
const reportToSentry = yield* getContext('reportToSentry')
reportToSentry({
level: ErrorLevel.Error,
name: 'Chats',
error: e as Error
})
}
Expand All@@ -717,10 +704,9 @@ function* doBlockUser(action: ReturnType<typeof blockUser>) {
make({ eventName: Name.BLOCK_USER_SUCCESS, blockedUserId: userId })
)
} catch (e) {
console.error('blockUserFailed', e)
const reportToSentry = yield* getContext('reportToSentry')
reportToSentry({
level: ErrorLevel.Error,
name: 'Chats',
error: e as Error
})
yield* call(
Expand All@@ -739,10 +725,9 @@ function* doUnblockUser(action: ReturnType<typeof unblockUser>) {
})
yield* put(fetchBlockees())
} catch (e) {
console.error('unblockUserFailed', e)
const reportToSentry = yield* getContext('reportToSentry')
reportToSentry({
level: ErrorLevel.Error,
name: 'Chats',
error: e as Error
})
}
Expand DownExpand Up@@ -771,10 +756,9 @@ function* doFetchPermissions(action: ReturnType<typeof fetchPermissions>) {
})
)
} catch (e) {
console.error('fetchPermissionsFailed', e)
const reportToSentry = yield* getContext('reportToSentry')
reportToSentry({
level: ErrorLevel.Error,
name: 'Chats',
error: e as Error
})
}
Expand All@@ -800,10 +784,9 @@ function* doFetchLinkUnfurlMetadata(
fetchLinkUnfurlSucceeded({ chatId, messageId, unfurlMetadata: data[0] })
)
} catch (e) {
console.error('fetchUnfurlFailed', e)
const reportToSentry = yield* getContext('reportToSentry')
reportToSentry({
level: ErrorLevel.Error,
name: 'Chats',
error: e as Error,
additionalInfo: {
chatId,
Expand DownExpand Up@@ -831,10 +814,9 @@ function* doDeleteChat(action: ReturnType<typeof deleteChat>) {
yield* put(deleteChatSucceeded({ chatId }))
yield* call(track, make({ eventName: Name.DELETE_CHAT_SUCCESS }))
} catch (e) {
console.error('deleteChat failed', e, { chatId })
const reportToSentry = yield* getContext('reportToSentry')
reportToSentry({
level: ErrorLevel.Error,
name: 'Chats',
error: e as Error,
additionalInfo: {
chatId
Expand All@@ -849,7 +831,7 @@ function* doLogError({ payload: { error } }: ReturnType<typeof logError>) {
const reportToSentry = yield* getContext('reportToSentry')
const { code, url } = error
reportToSentry({
level: ErrorLevel.Error,
name: 'Chats',
error,
additionalInfo: {
code,
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,7 +8,6 @@ import { Formik } from 'formik'

import { Button, Flex, IconMessage } from '@audius/harmony-native'
import { HeaderShadow, ScreenContent } from 'app/components/core'
import { audiusSdk } from 'app/services/sdk/audius-sdk'

import { FormScreen } from '../form-screen'

Expand All@@ -21,9 +20,7 @@ const messages = {

export const InboxSettingsScreenNew = () => {
const { permissions, doFetchPermissions, savePermissions } =
useSetInboxPermissions({
audiusSdk
})
useSetInboxPermissions()

const initialValues = useMemo(() => {
return transformPermitListToMap(
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,7 +22,6 @@ import { ChatPermission } from '@audius/sdk'
import { Formik, useField, useFormikContext } from 'formik'

import { useModalState } from 'common/hooks/useModalState'
import { audiusSdk } from 'services/audius-sdk'

const messages = {
title: 'Inbox Settings',
Expand DownExpand Up@@ -84,9 +83,7 @@ export const InboxSettingsModalNew = () => {
doFetchPermissions,
permissionsStatus,
savePermissions
} = useSetInboxPermissions({
audiusSdk
})
} = useSetInboxPermissions()

const handleSave = useCallback(
(values: InboxSettingsFormValues) => {
Expand Down