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:
@@ -21,8 +21,19 @@
|
||||
let shouldScrollToBottom = true;
|
||||
let lastMessageCount = 0;
|
||||
|
||||
// Obter ID do usuário atual
|
||||
const usuarioAtualId = $derived(authStore.usuario?._id);
|
||||
// Obter ID do usuário atual - usar $state para garantir reatividade
|
||||
let usuarioAtualId = $state<string | null>(null);
|
||||
|
||||
// Atualizar usuarioAtualId sempre que authStore.usuario mudar
|
||||
$effect(() => {
|
||||
const usuario = authStore.usuario;
|
||||
if (usuario?._id) {
|
||||
const idStr = String(usuario._id).trim();
|
||||
usuarioAtualId = idStr || null;
|
||||
} else {
|
||||
usuarioAtualId = null;
|
||||
}
|
||||
});
|
||||
|
||||
// Auto-scroll para a última mensagem quando novas mensagens chegam
|
||||
$effect(() => {
|
||||
@@ -49,8 +60,11 @@
|
||||
$effect(() => {
|
||||
if (mensagens?.data && mensagens.data.length > 0 && usuarioAtualId) {
|
||||
const ultimaMensagem = mensagens.data[mensagens.data.length - 1];
|
||||
const remetenteIdStr = ultimaMensagem.remetenteId
|
||||
? String(ultimaMensagem.remetenteId).trim()
|
||||
: (ultimaMensagem.remetente?._id ? String(ultimaMensagem.remetente._id).trim() : null);
|
||||
// Só marcar como lida se não for minha mensagem
|
||||
if (ultimaMensagem.remetente?._id !== usuarioAtualId) {
|
||||
if (remetenteIdStr && remetenteIdStr !== usuarioAtualId) {
|
||||
client.mutation(api.chat.marcarComoLida, {
|
||||
conversaId,
|
||||
mensagemId: ultimaMensagem._id,
|
||||
@@ -77,6 +91,7 @@
|
||||
|
||||
interface Mensagem {
|
||||
_id: Id<"mensagens">;
|
||||
remetenteId: Id<"usuarios">;
|
||||
remetente?: {
|
||||
_id: Id<"usuarios">;
|
||||
nome: string;
|
||||
@@ -226,11 +241,26 @@
|
||||
|
||||
<!-- Mensagens do dia -->
|
||||
{#each mensagensDia as mensagem (mensagem._id)}
|
||||
{@const isMinha = mensagem.remetente?._id === usuarioAtualId}
|
||||
{@const remetenteIdStr = (() => {
|
||||
// Priorizar remetenteId direto da mensagem
|
||||
if (mensagem.remetenteId) {
|
||||
return String(mensagem.remetenteId).trim();
|
||||
}
|
||||
// Fallback para remetente._id
|
||||
if (mensagem.remetente?._id) {
|
||||
return String(mensagem.remetente._id).trim();
|
||||
}
|
||||
return null;
|
||||
})()}
|
||||
{@const isMinha = usuarioAtualId && remetenteIdStr && remetenteIdStr === usuarioAtualId}
|
||||
<div class={`flex mb-4 w-full ${isMinha ? "justify-end" : "justify-start"}`}>
|
||||
<div class={`flex flex-col max-w-[75%] ${isMinha ? "items-end" : "items-start"}`}>
|
||||
<!-- Nome do remetente (apenas se não for minha) -->
|
||||
{#if !isMinha}
|
||||
<!-- Nome do remetente (sempre exibido, mas discreto para mensagens próprias) -->
|
||||
{#if isMinha}
|
||||
<p class="text-xs text-base-content/40 mb-1 px-3">
|
||||
Você
|
||||
</p>
|
||||
{:else}
|
||||
<p class="text-xs text-base-content/60 mb-1 px-3">
|
||||
{mensagem.remetente?.nome || "Usuário"}
|
||||
</p>
|
||||
@@ -240,7 +270,7 @@
|
||||
<div
|
||||
class={`rounded-2xl px-4 py-2 ${
|
||||
isMinha
|
||||
? "bg-primary text-primary-content rounded-br-sm"
|
||||
? "bg-blue-200 text-gray-900 rounded-br-sm"
|
||||
: "bg-base-200 text-base-content rounded-bl-sm"
|
||||
}`}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user