Skip to content

Commit f78e94f

Browse files
author
Krajcik Ondrej
committed
message data support
1 parent 49a5ba0 commit f78e94f

File tree

7 files changed

+20
-11
lines changed

7 files changed

+20
-11
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,14 @@ As of v3.0, messages now have an optional ID that can be added on creation.If yo
197197
- params:
198198
- text: string (supports markdown)
199199
- id: string (optional)
200+
- date: Date (optional)
200201
- Method to add a new message written as a response to a user input.
201202

202203
- **addUserMessage**
203204
- params:
204205
- text: string (supports markdown)
205206
- id: string (optional)
207+
- date: Date (optional)
206208
- This method will add a new message written as a user. Keep in mind it will not trigger the prop handleNewUserMessage()
207209

208210
- **addLinkSnippet**

index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ declare const Widget: ElementType;
88

99
export function addUserMessage(text: string): void;
1010
export function addUserMessage(text: string, id: string): void;
11+
export function addUserMessage(text: string, id: string, date: Date): void;
1112

1213
export function addResponseMessage(text: string): void;
1314
export function addResponseMessage(text: string, id: string): void;
15+
export function addResponseMessage(text: string, id: string, date: Date): void;
1416

1517
export function addLinkSnippet(link: { link: string, title: string, target?: string }): void;
1618
export function addLinkSnippet(link: { link: string, title: string, target?: string }, id: string): void;

src/store/actions/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,21 @@ export function toggleInputDisabled(): actionsTypes.ToggleInputDisabled {
1515
};
1616
}
1717

18-
export function addUserMessage(text: string, id?: string): actionsTypes.AddUserMessage {
18+
export function addUserMessage(text: string, id?: string, date?: Date): actionsTypes.AddUserMessage {
1919
return {
2020
type: actionsTypes.ADD_NEW_USER_MESSAGE,
2121
text,
22-
id
22+
id,
23+
date,
2324
};
2425
}
2526

26-
export function addResponseMessage(text: string, id?: string): actionsTypes.AddResponseMessage {
27+
export function addResponseMessage(text: string, id?: string, date?: Date): actionsTypes.AddResponseMessage {
2728
return {
2829
type: actionsTypes.ADD_NEW_RESPONSE_MESSAGE,
2930
text,
30-
id
31+
id,
32+
date,
3133
};
3234
}
3335

src/store/actions/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ export interface AddUserMessage {
3030
type: typeof ADD_NEW_USER_MESSAGE;
3131
text: string;
3232
id?: string;
33+
date?: Date;
3334
}
3435

3536
export interface AddResponseMessage {
3637
type: typeof ADD_NEW_RESPONSE_MESSAGE;
3738
text: string;
3839
id?: string;
40+
date?: Date;
3941
}
4042

4143
export interface ToggleMsgLoader {

src/store/dispatcher.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ export function addUserMessage(text: string, id?: string) {
88
store.dispatch(actions.addUserMessage(text, id));
99
}
1010

11-
export function addResponseMessage(text: string, id?: string) {
12-
store.dispatch(actions.addResponseMessage(text, id));
11+
export function addResponseMessage(text: string, id?: string, date?: Date) {
12+
store.dispatch(actions.addResponseMessage(text, id, date));
1313
}
1414

1515
export function addLinkSnippet(link: LinkParams, id?: string) {

src/store/reducers/messagesReducer.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ const initialState = {
2222
};
2323

2424
const messagesReducer = {
25-
[ADD_NEW_USER_MESSAGE]: (state: MessagesState, { text, showClientAvatar, id }) =>
26-
({ ...state, messages: [...state.messages, createNewMessage(text, MESSAGE_SENDER.CLIENT, id)]}),
25+
[ADD_NEW_USER_MESSAGE]: (state: MessagesState, { text, showClientAvatar, id, date }) =>
26+
({ ...state, messages: [...state.messages, createNewMessage(text, MESSAGE_SENDER.CLIENT, id, date)]}),
2727

28-
[ADD_NEW_RESPONSE_MESSAGE]: (state: MessagesState, { text, id }) =>
29-
({ ...state, messages: [...state.messages, createNewMessage(text, MESSAGE_SENDER.RESPONSE, id)], badgeCount: state.badgeCount + 1 }),
28+
[ADD_NEW_RESPONSE_MESSAGE]: (state: MessagesState, { text, id, date }) =>
29+
({ ...state, messages: [...state.messages, createNewMessage(text, MESSAGE_SENDER.RESPONSE, id, date)], badgeCount: state.badgeCount + 1 }),
3030

3131
[ADD_NEW_LINK_SNIPPET]: (state: MessagesState, { link, id }) =>
3232
({ ...state, messages: [...state.messages, createLinkSnippet(link, id)] }),

src/utils/messages.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ export function createNewMessage(
1212
text: string,
1313
sender: string,
1414
id?: string,
15+
date?: Date,
1516
): MessageI {
1617
return {
1718
type: MESSAGES_TYPES.TEXT,
1819
component: Message,
1920
text,
2021
sender,
21-
timestamp: new Date(),
22+
timestamp: date ? date : new Date(),
2223
showAvatar: true,
2324
customId: id,
2425
unread: sender === MESSAGE_SENDER.RESPONSE

0 commit comments

Comments
 (0)