@webinex/chatify 1.0.0-alpha08 → 1.0.0-build2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -35,14 +35,14 @@ export interface SendMessageRequest {
35
35
  files: File[];
36
36
  requestId: string;
37
37
  }
38
- export interface MessageContent {
38
+ export interface MessageBody {
39
39
  text: string;
40
40
  files: File[];
41
41
  }
42
42
  export interface AddChatRequest {
43
43
  requestId: string;
44
44
  name: string;
45
- message?: MessageContent;
45
+ message?: MessageBody;
46
46
  members: string[];
47
47
  }
48
48
  export interface ReadRequest {
@@ -8,9 +8,10 @@ import { AddChatButton } from './AddChatButton';
8
8
  import { Footer } from './Footer';
9
9
  import { ChatName } from './ChatName';
10
10
  import { ChatListItemBox, ChatListItemLastMessage, ChatListItemLastMessageAuthor, ChatListItemLastMessageContent, ChatListItemName, ChatListItemUnreadCount } from './ChatListItem';
11
- import { SendingMessage, SendingMessageBody, SendingMessageInfoBox, SendingMessageText } from './SendingMessage';
12
- import { MessageAuthor, MessageBody, MessageBox, MessageInfoBox, MessageReadObserver, MessageRow, MessageText } from './Message';
11
+ import { SendingMessage, SendingMessageContent, SendingMessageInfoBox, SendingMessageText } from './SendingMessage';
12
+ import { MessageAuthor, MessageContent, MessageBox, MessageInfoBox, MessageReadObserver, MessageRow, MessageText } from './Message';
13
13
  import { Icon } from './Icon';
14
+ import { SystemMessage } from './SystemMessage';
14
15
  export interface ChatifyCustomizeValue {
15
16
  Avatar?: typeof Avatar.Component | null;
16
17
  Header?: typeof Header.Component | null;
@@ -25,14 +26,15 @@ export interface ChatifyCustomizeValue {
25
26
  ChatListItemLastMessage?: typeof ChatListItemLastMessage.Component | null;
26
27
  ChatListItemLastMessageAuthor?: typeof ChatListItemLastMessageAuthor.Component | null;
27
28
  ChatListItemLastMessageContent?: typeof ChatListItemLastMessageContent.Component | null;
29
+ SystemMessage?: typeof SystemMessage.Component | null;
28
30
  SendingMessage?: typeof SendingMessage.Component | null;
29
- SendingMessageBody?: typeof SendingMessageBody.Component | null;
31
+ SendingMessageBody?: typeof SendingMessageContent.Component | null;
30
32
  SendingMessageInfoBox?: typeof SendingMessageInfoBox.Component | null;
31
33
  SendingMessageText?: typeof SendingMessageText.Component | null;
32
34
  MessageBox?: typeof MessageBox.Component | null;
33
35
  MessageReadObserver?: typeof MessageReadObserver.Component | null;
34
36
  MessageRow?: typeof MessageRow.Component | null;
35
- MessageBody?: typeof MessageBody.Component | null;
37
+ MessageContent?: typeof MessageContent.Component | null;
36
38
  MessageInfoBox?: typeof MessageInfoBox.Component | null;
37
39
  MessageText?: typeof MessageText.Component | null;
38
40
  MessageAuthor?: typeof MessageAuthor.Component | null;
@@ -9,7 +9,7 @@ export interface MessageRowProps extends MessageBoxProps {
9
9
  export declare const MessageAuthor: import("../util").Customizable<FC<MessageBoxProps>, string>;
10
10
  export declare const MessageText: import("../util").Customizable<FC<MessageBoxProps>, string>;
11
11
  export declare const MessageInfoBox: import("../util").Customizable<FC<MessageBoxProps>, string>;
12
- export declare const MessageBody: import("../util").Customizable<FC<MessageBoxProps>, string>;
12
+ export declare const MessageContent: import("../util").Customizable<FC<MessageBoxProps>, string>;
13
13
  export declare const MessageRow: import("../util").Customizable<FC<MessageRowProps>, string>;
14
14
  export declare const MessageBox: import("../util").Customizable<FC<MessageBoxProps>, string>;
15
15
  export interface MessageReadObserverProps extends MessageBoxProps {
@@ -6,5 +6,5 @@ export interface SendingMessageProps {
6
6
  }
7
7
  export declare const SendingMessageText: import("../util").Customizable<FC<SendingMessageProps>, string>;
8
8
  export declare const SendingMessageInfoBox: import("../util").Customizable<FC<SendingMessageProps>, string>;
9
- export declare const SendingMessageBody: import("../util").Customizable<FC<SendingMessageProps>, string>;
9
+ export declare const SendingMessageContent: import("../util").Customizable<FC<SendingMessageProps>, string>;
10
10
  export declare const SendingMessage: import("../util").Customizable<FC<SendingMessageProps>, string>;
@@ -1,8 +1,8 @@
1
- /// <reference types="react" />
1
+ import { FC } from 'react';
2
2
  import { Localizer } from './localizer';
3
3
  export interface SystemMessageProps {
4
4
  text: string;
5
5
  sentAt: string;
6
6
  }
7
7
  export declare function formatSystemMessage(localizer: Localizer, text: string): React.ReactNode;
8
- export declare function SystemMessage(props: SystemMessageProps): import("react/jsx-runtime").JSX.Element;
8
+ export declare const SystemMessage: import("../util").Customizable<FC<SystemMessageProps>, string>;
@@ -3,6 +3,7 @@ export interface Localizer {
3
3
  timestamp: (value: string) => string;
4
4
  system: {
5
5
  chatCreated: () => string;
6
+ memberAdded: () => string;
6
7
  };
7
8
  message: {
8
9
  read: () => React.ReactNode;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import React$1, { PropsWithChildren, FC, Ref, RefObject, CSSProperties } from 'react';
3
2
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
3
  import { AxiosInstance } from 'axios';
@@ -7,6 +6,7 @@ interface Localizer {
7
6
  timestamp: (value: string) => string;
8
7
  system: {
9
8
  chatCreated: () => string;
9
+ memberAdded: () => string;
10
10
  };
11
11
  message: {
12
12
  read: () => React$1.ReactNode;
@@ -76,14 +76,14 @@ interface SendMessageRequest {
76
76
  files: File[];
77
77
  requestId: string;
78
78
  }
79
- interface MessageContent {
79
+ interface MessageBody {
80
80
  text: string;
81
81
  files: File[];
82
82
  }
83
83
  interface AddChatRequest {
84
84
  requestId: string;
85
85
  name: string;
86
- message?: MessageContent;
86
+ message?: MessageBody;
87
87
  members: string[];
88
88
  }
89
89
  interface ReadRequest {
@@ -217,9 +217,12 @@ declare const ACTIONS: {
217
217
  read_received: (state: State, { events }: {
218
218
  events: ReadEvent[];
219
219
  }) => State;
220
- member_added: (state: State, { chatId, account }: {
220
+ member_added: (state: State, { chatId, chatName, account, me, message, }: {
221
221
  chatId: string;
222
+ chatName: string;
222
223
  account: Account;
224
+ me: string;
225
+ message: Message;
223
226
  }) => State;
224
227
  member_removed: (state: State, { chatId, accountId, deleteHistory, me, }: {
225
228
  chatId: string;
@@ -321,7 +324,7 @@ interface SendingMessageProps {
321
324
  }
322
325
  declare const SendingMessageText: Customizable<FC<SendingMessageProps>, string>;
323
326
  declare const SendingMessageInfoBox: Customizable<FC<SendingMessageProps>, string>;
324
- declare const SendingMessageBody: Customizable<FC<SendingMessageProps>, string>;
327
+ declare const SendingMessageContent: Customizable<FC<SendingMessageProps>, string>;
325
328
  declare const SendingMessage: Customizable<FC<SendingMessageProps>, string>;
326
329
 
327
330
  interface MessageBoxProps {
@@ -333,7 +336,7 @@ interface MessageRowProps extends MessageBoxProps {
333
336
  declare const MessageAuthor: Customizable<FC<MessageBoxProps>, string>;
334
337
  declare const MessageText: Customizable<FC<MessageBoxProps>, string>;
335
338
  declare const MessageInfoBox: Customizable<FC<MessageBoxProps>, string>;
336
- declare const MessageBody: Customizable<FC<MessageBoxProps>, string>;
339
+ declare const MessageContent: Customizable<FC<MessageBoxProps>, string>;
337
340
  declare const MessageRow: Customizable<FC<MessageRowProps>, string>;
338
341
  declare const MessageBox: Customizable<FC<MessageBoxProps>, string>;
339
342
  interface MessageReadObserverProps extends MessageBoxProps {
@@ -348,6 +351,13 @@ interface IconProps {
348
351
  declare const ICONS: Record<IconType, React.ComponentType>;
349
352
  declare const Icon: Customizable<FC<IconProps>, string>;
350
353
 
354
+ interface SystemMessageProps {
355
+ text: string;
356
+ sentAt: string;
357
+ }
358
+ declare function formatSystemMessage(localizer: Localizer, text: string): React.ReactNode;
359
+ declare const SystemMessage: Customizable<FC<SystemMessageProps>, string>;
360
+
351
361
  interface ChatifyCustomizeValue {
352
362
  Avatar?: typeof Avatar.Component | null;
353
363
  Header?: typeof Header.Component | null;
@@ -362,14 +372,15 @@ interface ChatifyCustomizeValue {
362
372
  ChatListItemLastMessage?: typeof ChatListItemLastMessage.Component | null;
363
373
  ChatListItemLastMessageAuthor?: typeof ChatListItemLastMessageAuthor.Component | null;
364
374
  ChatListItemLastMessageContent?: typeof ChatListItemLastMessageContent.Component | null;
375
+ SystemMessage?: typeof SystemMessage.Component | null;
365
376
  SendingMessage?: typeof SendingMessage.Component | null;
366
- SendingMessageBody?: typeof SendingMessageBody.Component | null;
377
+ SendingMessageBody?: typeof SendingMessageContent.Component | null;
367
378
  SendingMessageInfoBox?: typeof SendingMessageInfoBox.Component | null;
368
379
  SendingMessageText?: typeof SendingMessageText.Component | null;
369
380
  MessageBox?: typeof MessageBox.Component | null;
370
381
  MessageReadObserver?: typeof MessageReadObserver.Component | null;
371
382
  MessageRow?: typeof MessageRow.Component | null;
372
- MessageBody?: typeof MessageBody.Component | null;
383
+ MessageContent?: typeof MessageContent.Component | null;
373
384
  MessageInfoBox?: typeof MessageInfoBox.Component | null;
374
385
  MessageText?: typeof MessageText.Component | null;
375
386
  MessageAuthor?: typeof MessageAuthor.Component | null;
@@ -388,13 +399,6 @@ interface ChatHeaderProps {
388
399
  }
389
400
  declare function ChatHeader(props: ChatHeaderProps): react_jsx_runtime.JSX.Element;
390
401
 
391
- interface SystemMessageProps {
392
- text: string;
393
- sentAt: string;
394
- }
395
- declare function formatSystemMessage(localizer: Localizer, text: string): React.ReactNode;
396
- declare function SystemMessage(props: SystemMessageProps): react_jsx_runtime.JSX.Element;
397
-
398
402
  declare function useClient(): ChatifyClient;
399
403
  declare function useMe(): string;
400
404
  interface ChatifyContextValue {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@webinex/chatify",
3
3
  "description": "Webinex Wispo",
4
4
  "private": false,
5
- "version": "1.0.0-alpha08",
5
+ "version": "1.0.0-build2",
6
6
  "author": "Webinex Dev",
7
7
  "license": "Apache-2.0",
8
8
  "main": "dist/cjs/index.js",
@@ -214,7 +214,16 @@ export const ACTIONS = {
214
214
  return state;
215
215
  },
216
216
 
217
- member_added: (state: State, { chatId, account }: { chatId: string; account: Account }): State => {
217
+ member_added: (
218
+ state: State,
219
+ {
220
+ chatId,
221
+ chatName,
222
+ account,
223
+ me,
224
+ message,
225
+ }: { chatId: string; chatName: string; account: Account; me: string; message: Message },
226
+ ): State => {
218
227
  state = {
219
228
  ...state,
220
229
  query: {
@@ -230,6 +239,34 @@ export const ACTIONS = {
230
239
  state.query['chat.' + chatId].data.members = [...state.query['chat.' + chatId].data.members, account];
231
240
  }
232
241
 
242
+ if (state.query['messages.' + chatId]?.data !== undefined) {
243
+ state.query['messages.' + chatId] = {
244
+ ...state.query['messages.' + chatId],
245
+ data: [{ type: 'message', ...message }, ...state.query['messages.' + chatId].data],
246
+ };
247
+ }
248
+
249
+ if (account.id !== me && state.query['chat-list'].data !== undefined) {
250
+ state.query['chat-list'] = { ...state.query['chat-list'] };
251
+ state.query['chat-list'].data = state.query['chat-list'].data.map((x: ChatListItem) =>
252
+ x.id === chatId ? { ...x, message: { ...message } } : x,
253
+ );
254
+ }
255
+
256
+ if (account.id === me && state.query['chat-list'].data !== undefined) {
257
+ const listItem: ChatListItem = {
258
+ id: chatId,
259
+ name: chatName,
260
+ message: { ...message },
261
+ unreadCount: 0,
262
+ };
263
+
264
+ state.query['chat-list'] = {
265
+ ...state.query['chat-list'],
266
+ data: [...state.query['chat-list'].data, listItem],
267
+ };
268
+ }
269
+
233
270
  return state;
234
271
  },
235
272
 
@@ -41,7 +41,7 @@ export interface SendMessageRequest {
41
41
  requestId: string;
42
42
  }
43
43
 
44
- export interface MessageContent {
44
+ export interface MessageBody {
45
45
  text: string;
46
46
  files: File[];
47
47
  }
@@ -49,7 +49,7 @@ export interface MessageContent {
49
49
  export interface AddChatRequest {
50
50
  requestId: string;
51
51
  name: string;
52
- message?: MessageContent;
52
+ message?: MessageBody;
53
53
  members: string[];
54
54
  }
55
55
 
@@ -26,9 +26,12 @@ export function useSignalRMonitor(me: string, client: ChatifyClient) {
26
26
  }),
27
27
  );
28
28
  unsubscribes.push(
29
- client.subscribe('chatify://member-added', ([chatId, account]: [string, Account]) => {
30
- dispatch({ type: 'member_added', data: { chatId, account } });
31
- }),
29
+ client.subscribe(
30
+ 'chatify://member-added',
31
+ ([chatId, chatName, account, message]: [string, string, Account, Message]) => {
32
+ dispatch({ type: 'member_added', data: { chatId, chatName, account, me, message } });
33
+ },
34
+ ),
32
35
  );
33
36
  unsubscribes.push(
34
37
  client.subscribe(
@@ -9,7 +9,7 @@ function Member(props: { account: Account; chatId: string }) {
9
9
  const [remove] = useRemoveMember();
10
10
 
11
11
  const onRemoveClick = useCallback(
12
- () => remove({ chatId, accountId: account.id, deleteHistory: true }),
12
+ () => remove({ chatId, accountId: account.id, deleteHistory: false }),
13
13
  [remove, chatId, account.id],
14
14
  );
15
15
 
@@ -21,13 +21,13 @@ import {
21
21
  } from './ChatListItem';
22
22
  import {
23
23
  SendingMessage,
24
- SendingMessageBody,
24
+ SendingMessageContent,
25
25
  SendingMessageInfoBox,
26
26
  SendingMessageText,
27
27
  } from './SendingMessage';
28
28
  import {
29
29
  MessageAuthor,
30
- MessageBody,
30
+ MessageContent,
31
31
  MessageBox,
32
32
  MessageInfoBox,
33
33
  MessageReadObserver,
@@ -35,6 +35,7 @@ import {
35
35
  MessageText,
36
36
  } from './Message';
37
37
  import { Icon } from './Icon';
38
+ import { SystemMessage } from './SystemMessage';
38
39
 
39
40
  export interface ChatifyCustomizeValue {
40
41
  Avatar?: typeof Avatar.Component | null;
@@ -50,14 +51,15 @@ export interface ChatifyCustomizeValue {
50
51
  ChatListItemLastMessage?: typeof ChatListItemLastMessage.Component | null;
51
52
  ChatListItemLastMessageAuthor?: typeof ChatListItemLastMessageAuthor.Component | null;
52
53
  ChatListItemLastMessageContent?: typeof ChatListItemLastMessageContent.Component | null;
54
+ SystemMessage?: typeof SystemMessage.Component | null;
53
55
  SendingMessage?: typeof SendingMessage.Component | null;
54
- SendingMessageBody?: typeof SendingMessageBody.Component | null;
56
+ SendingMessageBody?: typeof SendingMessageContent.Component | null;
55
57
  SendingMessageInfoBox?: typeof SendingMessageInfoBox.Component | null;
56
58
  SendingMessageText?: typeof SendingMessageText.Component | null;
57
59
  MessageBox?: typeof MessageBox.Component | null;
58
60
  MessageReadObserver?: typeof MessageReadObserver.Component | null;
59
61
  MessageRow?: typeof MessageRow.Component | null;
60
- MessageBody?: typeof MessageBody.Component | null;
62
+ MessageContent?: typeof MessageContent.Component | null;
61
63
  MessageInfoBox?: typeof MessageInfoBox.Component | null;
62
64
  MessageText?: typeof MessageText.Component | null;
63
65
  MessageAuthor?: typeof MessageAuthor.Component | null;
@@ -48,9 +48,9 @@ export const MessageInfoBox = customize<FC<MessageBoxProps>, string>('MessageInf
48
48
  );
49
49
  });
50
50
 
51
- export const MessageBody = customize<FC<MessageBoxProps>, string>('MessageBody', (props) => {
51
+ export const MessageContent = customize<FC<MessageBoxProps>, string>('MessageContent', (props) => {
52
52
  return (
53
- <div className="wxchtf-message-body">
53
+ <div className="wxchtf-message-content">
54
54
  <MessageText {...props} />
55
55
  <MessageInfoBox {...props} />
56
56
  </div>
@@ -66,7 +66,7 @@ export const MessageRow = customize<FC<MessageRowProps>, string>('MessageRow', (
66
66
  return (
67
67
  <div ref={containerRef} className={'wxchtf-message' + (my ? ' --my' : '')}>
68
68
  <MessageAuthor {...props} />
69
- <MessageBody {...props} />
69
+ <MessageContent {...props} />
70
70
  </div>
71
71
  );
72
72
  });
@@ -29,11 +29,11 @@ export const SendingMessageInfoBox = customize<FC<SendingMessageProps>, string>(
29
29
  },
30
30
  );
31
31
 
32
- export const SendingMessageBody = customize<FC<SendingMessageProps>, string>(
33
- 'SendingMessageBody',
32
+ export const SendingMessageContent = customize<FC<SendingMessageProps>, string>(
33
+ 'SendingMessageContent',
34
34
  (props) => {
35
35
  return (
36
- <div className="wxchtf-sending-message-body">
36
+ <div className="wxchtf-sending-message-content">
37
37
  <SendingMessageText {...props} />
38
38
  <SendingMessageInfoBox {...props} />
39
39
  </div>
@@ -44,7 +44,7 @@ export const SendingMessageBody = customize<FC<SendingMessageProps>, string>(
44
44
  export const SendingMessage = customize<FC<SendingMessageProps>, string>('SendingMessage', (props) => {
45
45
  return (
46
46
  <div className="wxchtf-sending-message">
47
- <SendingMessageBody {...props} />
47
+ <SendingMessageContent {...props} />
48
48
  </div>
49
49
  );
50
50
  });
@@ -1,3 +1,5 @@
1
+ import { FC } from 'react';
2
+ import { customize } from '../util';
1
3
  import { Localizer, useLocalizer } from './localizer';
2
4
 
3
5
  export interface SystemMessageProps {
@@ -10,10 +12,14 @@ export function formatSystemMessage(localizer: Localizer, text: string): React.R
10
12
  return localizer.system.chatCreated();
11
13
  }
12
14
 
13
- throw new Error(`Unknown system message ${text}`);
15
+ if (text.startsWith('chatify://member-added::')) {
16
+ return localizer.system.memberAdded();
17
+ }
18
+
19
+ return text;
14
20
  }
15
21
 
16
- export function SystemMessage(props: SystemMessageProps) {
22
+ export const SystemMessage = customize<FC<SystemMessageProps>, string>('SystemMessage', (props) => {
17
23
  const { text, sentAt } = props;
18
24
  const localizer = useLocalizer();
19
25
 
@@ -23,4 +29,4 @@ export function SystemMessage(props: SystemMessageProps) {
23
29
  <div className="wxchtf-timestamp">{localizer.timestamp(sentAt)}</div>
24
30
  </div>
25
31
  );
26
- }
32
+ });
@@ -5,6 +5,7 @@ export interface Localizer {
5
5
  timestamp: (value: string) => string;
6
6
  system: {
7
7
  chatCreated: () => string;
8
+ memberAdded: () => string;
8
9
  };
9
10
  message: {
10
11
  read: () => React.ReactNode;
@@ -58,6 +59,7 @@ export const defaultLocalizer: Localizer = {
58
59
  },
59
60
  system: {
60
61
  chatCreated: () => 'Chat created',
62
+ memberAdded: () => 'New member added',
61
63
  },
62
64
 
63
65
  input: {
@@ -78,8 +78,8 @@
78
78
  margin-left: 15px;
79
79
  }
80
80
 
81
- .wxchtf-message-body,
82
- .wxchtf-sending-message-body {
81
+ .wxchtf-message-content,
82
+ .wxchtf-sending-message-content {
83
83
  direction: ltr;
84
84
  border-bottom-left-radius: 10px;
85
85
  border-bottom-right-radius: 0;
@@ -96,8 +96,8 @@
96
96
  }
97
97
  }
98
98
 
99
- .wxchtf-message-body,
100
- .wxchtf-sending-message-body {
99
+ .wxchtf-message-content,
100
+ .wxchtf-sending-message-content {
101
101
  min-width: 300px;
102
102
  max-width: 70%;
103
103
  border-radius: $messageBorderRadius;