update and fix messanger
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
import * as React from 'react';
|
||||
import { useAuth } from '@/components/id/auth-provider';
|
||||
import { getWsUrl, type ChatMessage } from '@/lib/api';
|
||||
import { dispatchAvatarUpdated, dispatchChatRoomAvatarUpdated } from '@/lib/avatar-events';
|
||||
|
||||
export interface RealtimeEvent {
|
||||
userId?: string;
|
||||
@@ -74,6 +75,22 @@ export function RealtimeProvider({ children }: { children: React.ReactNode }) {
|
||||
try {
|
||||
const data = JSON.parse(event.data as string) as RealtimeEvent;
|
||||
emit(data);
|
||||
if (data.type === 'user_avatar_updated' && typeof data.payload?.userId === 'string') {
|
||||
dispatchAvatarUpdated(data.payload.userId);
|
||||
}
|
||||
if (data.type === 'chat_message') {
|
||||
const message = data.payload?.message;
|
||||
if (message?.type === 'SYSTEM' && message.roomId && message.metadataJson) {
|
||||
try {
|
||||
const metadata = JSON.parse(message.metadataJson) as { systemKind?: string };
|
||||
if (metadata.systemKind === 'avatar_changed') {
|
||||
dispatchChatRoomAvatarUpdated(message.roomId);
|
||||
}
|
||||
} catch {
|
||||
// ignore malformed metadata
|
||||
}
|
||||
}
|
||||
}
|
||||
if (
|
||||
data.type === 'family_invite' ||
|
||||
data.type === 'role_assigned' ||
|
||||
|
||||
Reference in New Issue
Block a user