Reduce reuse
This commit is contained in:
@@ -188,7 +188,7 @@ export function useNotificationsHandler() {
|
|||||||
return DEFAULT_HANDLER_OPTIONS
|
return DEFAULT_HANDLER_OPTIONS
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug('received', {e})
|
logger.debug('Notifications: received', {e})
|
||||||
|
|
||||||
const payload = e.request.trigger.payload as NotificationPayload
|
const payload = e.request.trigger.payload as NotificationPayload
|
||||||
if (
|
if (
|
||||||
@@ -215,7 +215,7 @@ export function useNotificationsHandler() {
|
|||||||
}
|
}
|
||||||
prevDate = e.notification.date
|
prevDate = e.notification.date
|
||||||
|
|
||||||
logger.debug('response received', {
|
logger.debug('Notifications: response received', {
|
||||||
actionIdentifier: e.actionIdentifier,
|
actionIdentifier: e.actionIdentifier,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -242,7 +242,7 @@ export function useNotificationsHandler() {
|
|||||||
) {
|
) {
|
||||||
truncateAndInvalidate(queryClient, RQKEY_NOTIFS('mentions'))
|
truncateAndInvalidate(queryClient, RQKEY_NOTIFS('mentions'))
|
||||||
}
|
}
|
||||||
logger.debug('handleNotification', {
|
logger.debug('Notifications: handleNotification', {
|
||||||
content: e.notification.request.content,
|
content: e.notification.request.content,
|
||||||
payload: e.notification.request.trigger.payload,
|
payload: e.notification.request.trigger.payload,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -9,13 +9,13 @@ import {devicePlatform, isAndroid, isNative} from '#/platform/detection'
|
|||||||
import {SessionAccount, useAgent, useSession} from '#/state/session'
|
import {SessionAccount, useAgent, useSession} from '#/state/session'
|
||||||
import BackgroundNotificationHandler from '../../../modules/expo-background-notification-handler'
|
import BackgroundNotificationHandler from '../../../modules/expo-background-notification-handler'
|
||||||
|
|
||||||
const logger = Logger.create(Logger.Context.notifications)
|
|
||||||
|
|
||||||
const SERVICE_DID = (serviceUrl?: string) =>
|
const SERVICE_DID = (serviceUrl?: string) =>
|
||||||
serviceUrl?.includes('staging')
|
serviceUrl?.includes('staging')
|
||||||
? 'did:web:api.staging.bsky.dev'
|
? 'did:web:api.staging.bsky.dev'
|
||||||
: 'did:web:api.bsky.app'
|
: 'did:web:api.bsky.app'
|
||||||
|
|
||||||
|
const logger = Logger.create(Logger.Context.notifications)
|
||||||
|
|
||||||
async function registerPushToken(
|
async function registerPushToken(
|
||||||
agent: BskyAgent,
|
agent: BskyAgent,
|
||||||
account: SessionAccount,
|
account: SessionAccount,
|
||||||
@@ -28,7 +28,7 @@ async function registerPushToken(
|
|||||||
token: token.data,
|
token: token.data,
|
||||||
appId: 'xyz.blueskyweb.app',
|
appId: 'xyz.blueskyweb.app',
|
||||||
})
|
})
|
||||||
logger.debug('sent push token (init)', {
|
logger.debug('Notifications: Sent push token (init)', {
|
||||||
tokenType: token.type,
|
tokenType: token.type,
|
||||||
token: token.data,
|
token: token.data,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ export class Convo {
|
|||||||
|
|
||||||
getSnapshot(): ConvoState {
|
getSnapshot(): ConvoState {
|
||||||
if (!this.snapshot) this.snapshot = this.generateSnapshot()
|
if (!this.snapshot) this.snapshot = this.generateSnapshot()
|
||||||
// logger.debug('snapshotted', {})
|
// logger.debug('Convo: snapshotted', {})
|
||||||
return this.snapshot
|
return this.snapshot
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -377,7 +377,7 @@ export class Convo {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug(`dispatch '${action.event}'`, {
|
logger.debug(`Convo: dispatch '${action.event}'`, {
|
||||||
id: this.id,
|
id: this.id,
|
||||||
prev: prevStatus,
|
prev: prevStatus,
|
||||||
next: this.status,
|
next: this.status,
|
||||||
@@ -452,13 +452,13 @@ export class Convo {
|
|||||||
* Some validation prior to `Ready` status
|
* Some validation prior to `Ready` status
|
||||||
*/
|
*/
|
||||||
if (!this.convo) {
|
if (!this.convo) {
|
||||||
throw new Error('could not find convo')
|
throw new Error('Convo: could not find convo')
|
||||||
}
|
}
|
||||||
if (!this.sender) {
|
if (!this.sender) {
|
||||||
throw new Error('could not find sender in convo')
|
throw new Error('Convo: could not find sender in convo')
|
||||||
}
|
}
|
||||||
if (!this.recipients) {
|
if (!this.recipients) {
|
||||||
throw new Error('could not find recipients in convo')
|
throw new Error('Convo: could not find recipients in convo')
|
||||||
}
|
}
|
||||||
|
|
||||||
const userIsDisabled = Boolean(this.sender.chatDisabled)
|
const userIsDisabled = Boolean(this.sender.chatDisabled)
|
||||||
@@ -469,7 +469,7 @@ export class Convo {
|
|||||||
this.dispatch({event: ConvoDispatchEvent.Ready})
|
this.dispatch({event: ConvoDispatchEvent.Ready})
|
||||||
}
|
}
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
logger.error(e, {context: 'setup failed'})
|
logger.error(e, {context: 'Convo: setup failed'})
|
||||||
|
|
||||||
this.dispatch({
|
this.dispatch({
|
||||||
event: ConvoDispatchEvent.Error,
|
event: ConvoDispatchEvent.Error,
|
||||||
@@ -574,7 +574,7 @@ export class Convo {
|
|||||||
this.sender = sender || this.sender
|
this.sender = sender || this.sender
|
||||||
this.recipients = recipients || this.recipients
|
this.recipients = recipients || this.recipients
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
logger.error(e, {context: `failed to refresh convo`})
|
logger.error(e, {context: `Convo: failed to refresh convo`})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -584,7 +584,7 @@ export class Convo {
|
|||||||
}
|
}
|
||||||
| undefined
|
| undefined
|
||||||
async fetchMessageHistory() {
|
async fetchMessageHistory() {
|
||||||
logger.debug('fetch message history', {})
|
logger.debug('Convo: fetch message history', {})
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If oldestRev is null, we've fetched all history.
|
* If oldestRev is null, we've fetched all history.
|
||||||
@@ -638,7 +638,7 @@ export class Convo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
logger.error('failed to fetch message history')
|
logger.error('Convo: failed to fetch message history')
|
||||||
|
|
||||||
this.fetchMessageHistoryError = {
|
this.fetchMessageHistoryError = {
|
||||||
retry: () => {
|
retry: () => {
|
||||||
@@ -771,7 +771,7 @@ export class Convo {
|
|||||||
// Ignore empty messages for now since they have no other purpose atm
|
// Ignore empty messages for now since they have no other purpose atm
|
||||||
if (!message.text.trim() && !message.embed) return
|
if (!message.text.trim() && !message.embed) return
|
||||||
|
|
||||||
logger.debug('send message', {})
|
logger.debug('Convo: send message', {})
|
||||||
|
|
||||||
const tempId = nanoid()
|
const tempId = nanoid()
|
||||||
|
|
||||||
@@ -789,7 +789,7 @@ export class Convo {
|
|||||||
|
|
||||||
async processPendingMessages() {
|
async processPendingMessages() {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`processing messages (${this.pendingMessages.size} remaining)`,
|
`Convo: processing messages (${this.pendingMessages.size} remaining)`,
|
||||||
{},
|
{},
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -834,7 +834,7 @@ export class Convo {
|
|||||||
// continue queue processing
|
// continue queue processing
|
||||||
await this.processPendingMessages()
|
await this.processPendingMessages()
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
logger.error(e, {context: `failed to send message`})
|
logger.error(e, {context: `Convo: failed to send message`})
|
||||||
this.handleSendMessageFailure(e)
|
this.handleSendMessageFailure(e)
|
||||||
this.isProcessingPendingMessages = false
|
this.isProcessingPendingMessages = false
|
||||||
}
|
}
|
||||||
@@ -897,7 +897,7 @@ export class Convo {
|
|||||||
this.commit()
|
this.commit()
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`batch retrying ${this.pendingMessages.size} pending messages`,
|
`Convo: batch retrying ${this.pendingMessages.size} pending messages`,
|
||||||
{},
|
{},
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -930,15 +930,18 @@ export class Convo {
|
|||||||
|
|
||||||
this.commit()
|
this.commit()
|
||||||
|
|
||||||
logger.debug(`sent ${this.pendingMessages.size} pending messages`, {})
|
logger.debug(
|
||||||
|
`Convo: sent ${this.pendingMessages.size} pending messages`,
|
||||||
|
{},
|
||||||
|
)
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
logger.error(e, {context: `failed to batch retry messages`})
|
logger.error(e, {context: `Convo: failed to batch retry messages`})
|
||||||
this.handleSendMessageFailure(e)
|
this.handleSendMessageFailure(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteMessage(messageId: string) {
|
async deleteMessage(messageId: string) {
|
||||||
logger.debug('delete message', {})
|
logger.debug('Convo: delete message', {})
|
||||||
|
|
||||||
this.deletedMessages.add(messageId)
|
this.deletedMessages.add(messageId)
|
||||||
this.commit()
|
this.commit()
|
||||||
@@ -954,7 +957,7 @@ export class Convo {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
logger.error(e, {context: `failed to delete message`})
|
logger.error(e, {context: `Convo: failed to delete message`})
|
||||||
this.deletedMessages.delete(messageId)
|
this.deletedMessages.delete(messageId)
|
||||||
this.commit()
|
this.commit()
|
||||||
throw e
|
throw e
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import {
|
|||||||
} from '#/state/messages/events/types'
|
} from '#/state/messages/events/types'
|
||||||
import {DM_SERVICE_HEADERS} from '#/state/queries/messages/const'
|
import {DM_SERVICE_HEADERS} from '#/state/queries/messages/const'
|
||||||
|
|
||||||
|
const LOGGER_CONTEXT = 'MessagesEventBus'
|
||||||
const logger = Logger.create(Logger.Context.convo)
|
const logger = Logger.create(Logger.Context.convo)
|
||||||
|
|
||||||
export class MessagesEventBus {
|
export class MessagesEventBus {
|
||||||
@@ -90,17 +91,17 @@ export class MessagesEventBus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
background() {
|
background() {
|
||||||
logger.debug(`background`, {})
|
logger.debug(`${LOGGER_CONTEXT}: background`, {})
|
||||||
this.dispatch({event: MessagesEventBusDispatchEvent.Background})
|
this.dispatch({event: MessagesEventBusDispatchEvent.Background})
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend() {
|
suspend() {
|
||||||
logger.debug(`suspend`, {})
|
logger.debug(`${LOGGER_CONTEXT}: suspend`, {})
|
||||||
this.dispatch({event: MessagesEventBusDispatchEvent.Suspend})
|
this.dispatch({event: MessagesEventBusDispatchEvent.Suspend})
|
||||||
}
|
}
|
||||||
|
|
||||||
resume() {
|
resume() {
|
||||||
logger.debug(`resume`, {})
|
logger.debug(`${LOGGER_CONTEXT}: resume`, {})
|
||||||
this.dispatch({event: MessagesEventBusDispatchEvent.Resume})
|
this.dispatch({event: MessagesEventBusDispatchEvent.Resume})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,7 +223,7 @@ export class MessagesEventBus {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug(`dispatch '${action.event}'`, {
|
logger.debug(`${LOGGER_CONTEXT}: dispatch '${action.event}'`, {
|
||||||
id: this.id,
|
id: this.id,
|
||||||
prev: prevStatus,
|
prev: prevStatus,
|
||||||
next: this.status,
|
next: this.status,
|
||||||
@@ -230,7 +231,7 @@ export class MessagesEventBus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async init() {
|
private async init() {
|
||||||
logger.debug(`init`, {})
|
logger.debug(`${LOGGER_CONTEXT}: init`, {})
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await networkRetry(2, () => {
|
const response = await networkRetry(2, () => {
|
||||||
@@ -254,7 +255,7 @@ export class MessagesEventBus {
|
|||||||
this.dispatch({event: MessagesEventBusDispatchEvent.Ready})
|
this.dispatch({event: MessagesEventBusDispatchEvent.Ready})
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
logger.error(e, {
|
logger.error(e, {
|
||||||
context: `init failed`,
|
context: `${LOGGER_CONTEXT}: init failed`,
|
||||||
})
|
})
|
||||||
|
|
||||||
this.dispatch({
|
this.dispatch({
|
||||||
@@ -317,13 +318,12 @@ export class MessagesEventBus {
|
|||||||
this.isPolling = true
|
this.isPolling = true
|
||||||
|
|
||||||
// logger.debug(
|
// logger.debug(
|
||||||
// `poll`,
|
// `${LOGGER_CONTEXT}: poll`,
|
||||||
// {
|
// {
|
||||||
// requestedPollIntervals: Array.from(
|
// requestedPollIntervals: Array.from(
|
||||||
// this.requestedPollIntervals.values(),
|
// this.requestedPollIntervals.values(),
|
||||||
// ),
|
// ),
|
||||||
// },
|
// },
|
||||||
// logger.DebugContext.convo,
|
|
||||||
// )
|
// )
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -368,12 +368,12 @@ export class MessagesEventBus {
|
|||||||
this.emitter.emit('event', {type: 'logs', logs: batch})
|
this.emitter.emit('event', {type: 'logs', logs: batch})
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
logger.error(e, {
|
logger.error(e, {
|
||||||
context: `process latest events`,
|
context: `${LOGGER_CONTEXT}: process latest events`,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
logger.error(e, {context: `poll events failed`})
|
logger.error(e, {context: `${LOGGER_CONTEXT}: poll events failed`})
|
||||||
|
|
||||||
this.dispatch({
|
this.dispatch({
|
||||||
event: MessagesEventBusDispatchEvent.Error,
|
event: MessagesEventBusDispatchEvent.Error,
|
||||||
|
|||||||
Reference in New Issue
Block a user