Chats: typescript

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak
2022-04-12 18:52:56 +02:00
parent ae396544a7
commit b5ae9adf63
18 changed files with 431 additions and 400 deletions

View File

@ -0,0 +1,18 @@
import { Map as ImmutableMap, Record as ImmutableRecord, fromJS } from 'immutable';
import type { ReducerAccount } from 'soapbox/reducers/accounts';
import type { Account, EmbeddedEntity } from 'soapbox/types/entities';
export const ChatRecord = ImmutableRecord({
account: null as EmbeddedEntity<Account | ReducerAccount>,
id: '',
unread: 0,
last_message: '' as string || null,
updated_at: new Date(),
});
export const normalizeChat = (chat: Record<string, any>) => {
return ChatRecord(
ImmutableMap(fromJS(chat)),
);
};

View File

@ -0,0 +1,29 @@
import {
List as ImmutableList,
Map as ImmutableMap,
Record as ImmutableRecord,
fromJS,
} from 'immutable';
import type { Attachment, Card, Emoji } from 'soapbox/types/entities';
export const ChatMessageRecord = ImmutableRecord({
account_id: '',
attachment: null as Attachment | null,
card: null as Card | null,
chat_id: '',
content: '',
created_at: new Date(),
emojis: ImmutableList<Emoji>(),
id: '',
unread: false,
deleting: false,
pending: false,
});
export const normalizeChatMessage = (chatMessage: Record<string, any>) => {
return ChatMessageRecord(
ImmutableMap(fromJS(chatMessage)),
);
};

View File

@ -1,6 +1,8 @@
export { AccountRecord, FieldRecord, normalizeAccount } from './account';
export { AttachmentRecord, normalizeAttachment } from './attachment';
export { CardRecord, normalizeCard } from './card';
export { ChatRecord, normalizeChat } from './chat';
export { ChatMessageRecord, normalizeChatMessage } from './chat_message';
export { EmojiRecord, normalizeEmoji } from './emoji';
export { InstanceRecord, normalizeInstance } from './instance';
export { MentionRecord, normalizeMention } from './mention';