mirror of
https://github.com/duckietm/Nitro-V3.git
synced 2026-06-19 23:16:21 +00:00
🆙 New: Added a new Chat window, handy for in game / building etc.
This commit is contained in:
@@ -5,7 +5,6 @@ import { ChatEntryType, ChatHistoryCurrentDate, IChatEntry, IRoomHistoryEntry, M
|
||||
import { useMessageEvent, useNitroEvent } from '../events';
|
||||
import { useLocalStorage } from '../useLocalStorage';
|
||||
|
||||
const CHAT_HISTORY_MAX = 1000;
|
||||
const ROOM_HISTORY_MAX = 10;
|
||||
const MESSENGER_HISTORY_MAX = 1000;
|
||||
|
||||
@@ -29,12 +28,13 @@ const useChatHistoryState = () =>
|
||||
|
||||
newValue.push(entry);
|
||||
|
||||
if(newValue.length > CHAT_HISTORY_MAX) newValue.shift();
|
||||
|
||||
return newValue;
|
||||
});
|
||||
};
|
||||
|
||||
const clearChatHistory = () => setChatHistory([]);
|
||||
|
||||
const addRoomHistoryEntry = (entry: IRoomHistoryEntry) =>
|
||||
{
|
||||
setRoomHistory(prevValue =>
|
||||
@@ -99,7 +99,7 @@ const useChatHistoryState = () =>
|
||||
addMessengerEntry({ id: -1, webId: parser.senderId, entityId: -1, name: '', message: parser.messageText, roomId: -1, timestamp: MessengerHistoryCurrentDate(), type: ChatEntryType.TYPE_IM });
|
||||
});
|
||||
|
||||
return { addChatEntry, chatHistory, roomHistory, messengerHistory };
|
||||
return { addChatEntry, clearChatHistory, chatHistory, roomHistory, messengerHistory };
|
||||
};
|
||||
|
||||
export const useChatHistory = () => useBetween(useChatHistoryState);
|
||||
|
||||
@@ -22,3 +22,4 @@ export * from './session';
|
||||
export * from './useLocalStorage';
|
||||
export * from './useSharedVisibility';
|
||||
export * from './wired';
|
||||
export * from './useChatWindow';
|
||||
|
||||
@@ -5,6 +5,8 @@ import { useMessageEvent, useNitroEvent } from '../../events';
|
||||
import { useRoom } from '../useRoom';
|
||||
import { useChatHistory } from './../../chat-history';
|
||||
|
||||
const CHAT_MESSAGES_MAX = 250;
|
||||
|
||||
const useChatWidgetState = () =>
|
||||
{
|
||||
const [chatMessages, setChatMessages] = useState<ChatBubbleMessage[]>([]);
|
||||
@@ -146,7 +148,14 @@ const useChatWidgetState = () =>
|
||||
imageUrl,
|
||||
color);
|
||||
|
||||
setChatMessages(prevValue => [...prevValue, chatMessage]);
|
||||
setChatMessages(prevValue =>
|
||||
{
|
||||
const newValue = [ ...prevValue, chatMessage ];
|
||||
|
||||
if(newValue.length > CHAT_MESSAGES_MAX) newValue.shift();
|
||||
|
||||
return newValue;
|
||||
});
|
||||
addChatEntry({ id: -1, webId: userData.webID, entityId: userData.roomIndex, name: username, imageUrl, style: styleId, chatType: chatType, entityType: userData.type, message: formattedText, timestamp: ChatHistoryCurrentDate(), type: ChatEntryType.TYPE_CHAT, roomId: roomSession.roomId, color });
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
import { useBetween } from 'use-between';
|
||||
import { LocalStorageKeys } from '../api';
|
||||
import { useLocalStorage } from './useLocalStorage';
|
||||
|
||||
const useChatWindowState = () => useLocalStorage(LocalStorageKeys.CHAT_WINDOW_ENABLED, false);
|
||||
|
||||
export const useChatWindow = () => useBetween(useChatWindowState);
|
||||
Reference in New Issue
Block a user