feat: enhance push notification management and error handling
- Implemented error handling for unhandled promise rejections related to message channels, improving stability during push notification operations. - Updated the PushNotificationManager component to manage push subscription registration with timeouts, preventing application hangs. - Enhanced the sidebar and chat components to display user avatars, improving user experience and visual consistency. - Refactored email processing logic to support scheduled email sending, integrating new backend functionalities for better email management. - Improved overall error handling and logging across components to reduce console spam and enhance debugging capabilities.
This commit is contained in:
@@ -152,11 +152,12 @@ export const enviarPushNotification = internalMutation({
|
||||
}
|
||||
|
||||
// Se há conversaId, verificar preferências específicas da conversa
|
||||
if (args.data?.conversaId) {
|
||||
const conversaId = args.data?.conversaId;
|
||||
if (conversaId) {
|
||||
const preferencias = await ctx.db
|
||||
.query("preferenciasNotificacaoConversa")
|
||||
.withIndex("by_usuario_conversa", (q) =>
|
||||
q.eq("usuarioId", args.usuarioId).eq("conversaId", args.data.conversaId)
|
||||
q.eq("usuarioId", args.usuarioId).eq("conversaId", conversaId)
|
||||
)
|
||||
.first();
|
||||
|
||||
@@ -167,7 +168,7 @@ export const enviarPushNotification = internalMutation({
|
||||
}
|
||||
|
||||
// Se apenas menções e não é menção, não enviar
|
||||
if (preferencias.apenasMencoes && args.data.tipo !== "mencao") {
|
||||
if (preferencias.apenasMencoes && args.data?.tipo !== "mencao") {
|
||||
return { enviados: 0, falhas: 0 };
|
||||
}
|
||||
}
|
||||
@@ -177,17 +178,28 @@ export const enviarPushNotification = internalMutation({
|
||||
let enviados = 0;
|
||||
let falhas = 0;
|
||||
|
||||
// Converter IDs para strings ao passar para a action
|
||||
// A action espera strings, mas recebemos Ids do Convex
|
||||
const dataParaAction = args.data
|
||||
? {
|
||||
conversaId: args.data.conversaId ? String(args.data.conversaId) : undefined,
|
||||
mensagemId: args.data.mensagemId ? String(args.data.mensagemId) : undefined,
|
||||
tipo: args.data.tipo,
|
||||
}
|
||||
: undefined;
|
||||
|
||||
for (const subscription of subscriptions) {
|
||||
try {
|
||||
await ctx.scheduler.runAfter(0, api.actions.pushNotifications.enviarPush, {
|
||||
subscriptionId: subscription._id,
|
||||
titulo: args.titulo,
|
||||
corpo: args.corpo,
|
||||
data: args.data,
|
||||
data: dataParaAction,
|
||||
});
|
||||
enviados++;
|
||||
} catch (error) {
|
||||
console.error(`Erro ao agendar push para subscription ${subscription._id}:`, error);
|
||||
} catch (error: unknown) {
|
||||
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||
console.error(`Erro ao agendar push para subscription ${subscription._id}:`, errorMessage);
|
||||
falhas++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user