@sendbird/uikit-utils 2.1.0 → 2.2.0
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.
- package/lib/commonjs/hooks/index.js +14 -1
- package/lib/commonjs/hooks/index.js.map +1 -1
- package/lib/commonjs/index.js +24 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/sendbird/channel.js +7 -1
- package/lib/commonjs/sendbird/channel.js.map +1 -1
- package/lib/commonjs/sendbird/message.js +12 -2
- package/lib/commonjs/sendbird/message.js.map +1 -1
- package/lib/commonjs/sendbird/user.js +5 -0
- package/lib/commonjs/sendbird/user.js.map +1 -1
- package/lib/commonjs/shared/regex.js +52 -6
- package/lib/commonjs/shared/regex.js.map +1 -1
- package/lib/commonjs/shared/replace.js +14 -0
- package/lib/commonjs/shared/replace.js.map +1 -0
- package/lib/commonjs/types.js +3 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/ui-format/common.js +17 -14
- package/lib/commonjs/ui-format/common.js.map +1 -1
- package/lib/commonjs/ui-format/groupChannel.js +7 -10
- package/lib/commonjs/ui-format/groupChannel.js.map +1 -1
- package/lib/module/hooks/index.js +10 -0
- package/lib/module/hooks/index.js.map +1 -1
- package/lib/module/index.js +2 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/sendbird/channel.js +3 -0
- package/lib/module/sendbird/channel.js.map +1 -1
- package/lib/module/sendbird/message.js +9 -3
- package/lib/module/sendbird/message.js.map +1 -1
- package/lib/module/sendbird/user.js +3 -0
- package/lib/module/sendbird/user.js.map +1 -1
- package/lib/module/shared/regex.js +43 -3
- package/lib/module/shared/regex.js.map +1 -1
- package/lib/module/shared/replace.js +6 -0
- package/lib/module/shared/replace.js.map +1 -0
- package/lib/module/types.js +1 -4
- package/lib/module/types.js.map +1 -1
- package/lib/module/ui-format/common.js +12 -7
- package/lib/module/ui-format/common.js.map +1 -1
- package/lib/module/ui-format/groupChannel.js +5 -4
- package/lib/module/ui-format/groupChannel.js.map +1 -1
- package/lib/typescript/src/hooks/index.d.ts +3 -2
- package/lib/typescript/src/index.d.ts +3 -2
- package/lib/typescript/src/sendbird/channel.d.ts +1 -0
- package/lib/typescript/src/sendbird/message.d.ts +4 -2
- package/lib/typescript/src/sendbird/user.d.ts +2 -0
- package/lib/typescript/src/shared/bufferedRequest.d.ts +1 -1
- package/lib/typescript/src/shared/logger.d.ts +1 -1
- package/lib/typescript/src/shared/pubsub.d.ts +2 -2
- package/lib/typescript/src/shared/regex.d.ts +8 -0
- package/lib/typescript/src/shared/replace.d.ts +2 -0
- package/lib/typescript/src/types.d.ts +42 -36
- package/lib/typescript/src/ui-format/common.d.ts +7 -6
- package/package.json +3 -3
- package/src/hooks/index.ts +11 -0
- package/src/index.ts +8 -0
- package/src/sendbird/channel.ts +4 -0
- package/src/sendbird/message.ts +13 -3
- package/src/sendbird/user.ts +6 -0
- package/src/shared/regex.ts +35 -0
- package/src/shared/replace.ts +5 -0
- package/src/types.ts +20 -3
- package/src/ui-format/common.ts +9 -7
- package/src/ui-format/groupChannel.ts +5 -4
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type SubscribeListener = ((...args: unknown[]) => void) & {
|
|
2
2
|
onError?: (error: unknown) => void;
|
|
3
3
|
};
|
|
4
|
-
export
|
|
4
|
+
export type SubscribeListenerPool = Record<symbol, SubscribeListener>;
|
|
5
5
|
export declare const createPubSub: (label?: string) => {
|
|
6
6
|
subscribe: (event: string, listener: SubscribeListener, subscriber?: string) => () => void;
|
|
7
7
|
publish: (event: string, ...args: unknown[]) => void;
|
|
@@ -3,6 +3,14 @@ export declare const urlRegexRough: RegExp;
|
|
|
3
3
|
export declare const phoneRegex: RegExp;
|
|
4
4
|
export declare const emailRegex: RegExp;
|
|
5
5
|
export declare const newLineRegex: RegExp;
|
|
6
|
+
export declare const createMentionTemplateRegex: (trigger: string) => RegExp;
|
|
7
|
+
export declare const replaceWithRegex: <T>(text: string, regex: RegExp, replacer: (params: {
|
|
8
|
+
match: string;
|
|
9
|
+
groups: string[];
|
|
10
|
+
matchIndex: number | undefined;
|
|
11
|
+
index: number;
|
|
12
|
+
keyPrefix: string;
|
|
13
|
+
}) => T, keyPrefix: string) => (string | T)[];
|
|
6
14
|
export declare const replaceUrlAsComponents: <T>(originText: string, replacer: (url: string) => T, strict?: boolean) => (string | T)[];
|
|
7
15
|
export declare const imageExtRegex: RegExp;
|
|
8
16
|
export declare const audioExtRegex: RegExp;
|
|
@@ -1,50 +1,56 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
2
|
import type SendbirdChat from '@sendbird/chat';
|
|
3
|
-
import type { BaseChannel, RestrictedUser, SendbirdError as SBError, User, UserUpdateParams } from '@sendbird/chat';
|
|
3
|
+
import type { BaseChannel, Emoji, EmojiCategory, EmojiContainer, RestrictedUser, SendbirdError as SBError, User, UserUpdateParams } from '@sendbird/chat';
|
|
4
4
|
import type { GroupChannel, GroupChannelCollection, GroupChannelCreateParams, GroupChannelListQuery, GroupChannelModule, GroupChannelUpdateParams, Member, MessageCollection } from '@sendbird/chat/groupChannel';
|
|
5
5
|
import type { ModuleNamespaces, SendableMessage } from '@sendbird/chat/lib/__definition';
|
|
6
|
-
import type { AdminMessage, BaseMessage, FileMessage, FileMessageCreateParams, FileMessageUpdateParams, PreviousMessageListQuery, UserMessage, UserMessageCreateParams, UserMessageUpdateParams } from '@sendbird/chat/message';
|
|
6
|
+
import type { AdminMessage, BaseMessage, FileMessage, FileMessageCreateParams, FileMessageUpdateParams, PreviousMessageListQuery, Reaction, UserMessage, UserMessageCreateParams, UserMessageUpdateParams } from '@sendbird/chat/message';
|
|
7
7
|
import type { OpenChannel, OpenChannelModule } from '@sendbird/chat/openChannel';
|
|
8
|
-
|
|
9
|
-
export declare type FilterByValueType<T extends object, Type> = {
|
|
8
|
+
export type FilterByValueType<T extends object, Type> = {
|
|
10
9
|
[K in keyof T as T[K] extends Type ? K : never]: T[K];
|
|
11
10
|
};
|
|
12
|
-
export
|
|
13
|
-
export
|
|
14
|
-
export
|
|
11
|
+
export type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
12
|
+
export type OmittedValues<T, K extends keyof T> = Omit<T, K>[keyof Omit<T, K>];
|
|
13
|
+
export type PartialDeep<T> = T extends object ? T extends Function ? T : {
|
|
15
14
|
[P in keyof T]?: PartialDeep<T[P]>;
|
|
16
15
|
} : T;
|
|
17
|
-
export
|
|
16
|
+
export type PartialNullable<T> = {
|
|
18
17
|
[P in keyof T]?: T[P] | null;
|
|
19
18
|
};
|
|
20
|
-
export
|
|
21
|
-
export
|
|
22
|
-
export
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
export
|
|
26
|
-
export
|
|
27
|
-
export
|
|
28
|
-
export
|
|
29
|
-
export
|
|
30
|
-
export
|
|
31
|
-
export
|
|
32
|
-
export
|
|
33
|
-
export
|
|
34
|
-
export
|
|
35
|
-
export
|
|
36
|
-
export
|
|
37
|
-
export
|
|
38
|
-
export
|
|
39
|
-
export
|
|
40
|
-
export
|
|
41
|
-
export
|
|
42
|
-
export
|
|
43
|
-
export
|
|
44
|
-
export
|
|
45
|
-
export
|
|
46
|
-
export
|
|
47
|
-
export
|
|
19
|
+
export type Optional<T> = T | undefined;
|
|
20
|
+
export type ContextValue<T extends React.Context<any>> = T extends React.Context<infer V> ? V : never;
|
|
21
|
+
export interface UserStruct {
|
|
22
|
+
userId: string;
|
|
23
|
+
}
|
|
24
|
+
export type SendbirdChatSDK = SendbirdChat & ModuleNamespaces<[GroupChannelModule, OpenChannelModule]>;
|
|
25
|
+
export type SendbirdMessage = BaseMessage | FileMessage | UserMessage | AdminMessage | SendableMessage;
|
|
26
|
+
export type SendbirdChannel = BaseChannel | GroupChannel | OpenChannel;
|
|
27
|
+
export type SendbirdUserMessage = UserMessage;
|
|
28
|
+
export type SendbirdFileMessage = FileMessage;
|
|
29
|
+
export type SendbirdAdminMessage = AdminMessage;
|
|
30
|
+
export type SendbirdBaseMessage = BaseMessage;
|
|
31
|
+
export type SendbirdSendableMessage = SendableMessage;
|
|
32
|
+
export type SendbirdFileMessageCreateParams = FileMessageCreateParams;
|
|
33
|
+
export type SendbirdFileMessageUpdateParams = FileMessageUpdateParams;
|
|
34
|
+
export type SendbirdUserMessageCreateParams = UserMessageCreateParams;
|
|
35
|
+
export type SendbirdUserMessageUpdateParams = UserMessageUpdateParams;
|
|
36
|
+
export type SendbirdGroupChannelCreateParams = GroupChannelCreateParams;
|
|
37
|
+
export type SendbirdGroupChannelUpdateParams = GroupChannelUpdateParams;
|
|
38
|
+
export type SendbirdUserUpdateParams = UserUpdateParams;
|
|
39
|
+
export type SendbirdUser = User;
|
|
40
|
+
export type SendbirdRestrictedUser = RestrictedUser;
|
|
41
|
+
export type SendbirdMember = Member;
|
|
42
|
+
export type SendbirdGroupChannel = GroupChannel;
|
|
43
|
+
export type SendbirdBaseChannel = BaseChannel;
|
|
44
|
+
export type SendbirdOpenChannel = OpenChannel;
|
|
45
|
+
export type SendbirdReaction = Reaction;
|
|
46
|
+
export type SendbirdEmoji = Emoji;
|
|
47
|
+
export type SendbirdEmojiCategory = EmojiCategory;
|
|
48
|
+
export type SendbirdEmojiContainer = EmojiContainer;
|
|
49
|
+
export type SendbirdGroupChannelCollection = GroupChannelCollection;
|
|
50
|
+
export type SendbirdGroupChannelListQuery = GroupChannelListQuery;
|
|
51
|
+
export type SendbirdMessageCollection = MessageCollection;
|
|
52
|
+
export type SendbirdPreviousMessageListQuery = PreviousMessageListQuery;
|
|
53
|
+
export type SendbirdError = SBError;
|
|
48
54
|
export interface SendbirdDataPayload {
|
|
49
55
|
app_id: string;
|
|
50
56
|
audience_type: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Locale } from 'date-fns';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
type TruncateMode = 'head' | 'mid' | 'tail';
|
|
3
|
+
type TruncateOption = {
|
|
4
4
|
mode: TruncateMode;
|
|
5
5
|
maxLen: number;
|
|
6
6
|
separator: string;
|
|
@@ -16,14 +16,15 @@ declare type TruncateOption = {
|
|
|
16
16
|
* */
|
|
17
17
|
export declare const truncate: (str: string, opts?: Partial<TruncateOption>) => string;
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
19
|
+
* Count truncate util
|
|
20
20
|
* If count exceed the limit, it comes in the form of "MAX+"
|
|
21
21
|
*
|
|
22
22
|
* @param {number} count
|
|
23
23
|
* @param {number} MAX default 99
|
|
24
|
+
* @param {string} MAX_SUFFIX default +
|
|
24
25
|
* @returns {string}
|
|
25
26
|
* */
|
|
26
|
-
export declare const
|
|
27
|
+
export declare const truncatedCount: (count: number, MAX?: number, MAX_SUFFIX?: string) => string;
|
|
27
28
|
/**
|
|
28
29
|
* Messages date separator format
|
|
29
30
|
*
|
|
@@ -31,7 +32,7 @@ export declare const truncatedBadgeCount: (count: number, MAX?: number) => strin
|
|
|
31
32
|
* @param {Locale} [locale]
|
|
32
33
|
* @returns {string}
|
|
33
34
|
* */
|
|
34
|
-
export declare const
|
|
35
|
+
export declare const getDateSeparatorFormat: (date: Date, locale?: Locale) => string;
|
|
35
36
|
/**
|
|
36
37
|
* Message time format
|
|
37
38
|
*
|
|
@@ -39,5 +40,5 @@ export declare const dateSeparator: (date: Date, locale?: Locale) => string;
|
|
|
39
40
|
* @param {Locale} [locale]
|
|
40
41
|
* @returns {string}
|
|
41
42
|
* */
|
|
42
|
-
export declare const
|
|
43
|
+
export declare const getMessageTimeFormat: (date: Date, locale?: Locale) => string;
|
|
43
44
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sendbird/uikit-utils",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "UIKit utilities",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"react": "17.0.2",
|
|
47
47
|
"react-native": "0.67.4",
|
|
48
48
|
"react-native-builder-bob": "^0.18.0",
|
|
49
|
-
"typescript": "
|
|
49
|
+
"typescript": "4.9.4"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"@sendbird/chat": "^4.0.13",
|
|
@@ -76,5 +76,5 @@
|
|
|
76
76
|
"readmeFile": "./README.md",
|
|
77
77
|
"displayName": "@sendbird/uikit-utils"
|
|
78
78
|
},
|
|
79
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "bd7ab217a07e91ba644c0cb69694a92b123326bf"
|
|
80
80
|
}
|
package/src/hooks/index.ts
CHANGED
|
@@ -56,6 +56,17 @@ export const useIsMountedRef = () => {
|
|
|
56
56
|
return isMounted;
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
+
export const useIsFirstMount = () => {
|
|
60
|
+
const isFirstMount = useRef(true);
|
|
61
|
+
|
|
62
|
+
if (isFirstMount.current) {
|
|
63
|
+
isFirstMount.current = false;
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return isFirstMount.current;
|
|
68
|
+
};
|
|
69
|
+
|
|
59
70
|
export const useFreshCallback = <T extends (...args: any[]) => any>(callback: T): T => {
|
|
60
71
|
const ref = useRef<T>(callback);
|
|
61
72
|
ref.current = callback;
|
package/src/index.ts
CHANGED
|
@@ -15,8 +15,11 @@ export {
|
|
|
15
15
|
normalizeFileName,
|
|
16
16
|
emailRegex,
|
|
17
17
|
phoneRegex,
|
|
18
|
+
replaceWithRegex,
|
|
19
|
+
createMentionTemplateRegex,
|
|
18
20
|
} from './shared/regex';
|
|
19
21
|
export { BufferedRequest } from './shared/bufferedRequest';
|
|
22
|
+
export { default as replace } from './shared/replace';
|
|
20
23
|
|
|
21
24
|
export * from './hooks';
|
|
22
25
|
export * from './ui-format/groupChannel';
|
|
@@ -43,6 +46,7 @@ export const SBErrorMessage = {
|
|
|
43
46
|
};
|
|
44
47
|
|
|
45
48
|
export type {
|
|
49
|
+
UserStruct,
|
|
46
50
|
FilterByValueType,
|
|
47
51
|
UnionToIntersection,
|
|
48
52
|
OmittedValues,
|
|
@@ -80,4 +84,8 @@ export type {
|
|
|
80
84
|
SendbirdFileMessageUpdateParams,
|
|
81
85
|
SendbirdUserUpdateParams,
|
|
82
86
|
SendbirdRestrictedUser,
|
|
87
|
+
SendbirdReaction,
|
|
88
|
+
SendbirdEmojiContainer,
|
|
89
|
+
SendbirdEmoji,
|
|
90
|
+
SendbirdEmojiCategory,
|
|
83
91
|
} from './types';
|
package/src/sendbird/channel.ts
CHANGED
|
@@ -46,3 +46,7 @@ export function getGroupChannels(channels: SendbirdChannel[]): SendbirdGroupChan
|
|
|
46
46
|
export function getOpenChannels(channels: SendbirdChannel[]): SendbirdOpenChannel[] {
|
|
47
47
|
return channels.filter((c): c is SendbirdOpenChannel => c.isOpenChannel());
|
|
48
48
|
}
|
|
49
|
+
|
|
50
|
+
export function getChannelUniqId(channel: SendbirdChannel) {
|
|
51
|
+
return channel.url;
|
|
52
|
+
}
|
package/src/sendbird/message.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
SendbirdBaseChannel,
|
|
2
3
|
SendbirdBaseMessage,
|
|
3
4
|
SendbirdDataPayload,
|
|
4
5
|
SendbirdFileMessage,
|
|
5
6
|
SendbirdMessage,
|
|
7
|
+
SendbirdReaction,
|
|
6
8
|
SendbirdSendableMessage,
|
|
7
9
|
} from '../types';
|
|
8
|
-
import {
|
|
10
|
+
import { getMessageTimeFormat } from '../ui-format/common';
|
|
9
11
|
|
|
10
12
|
export function isNewMessage(msg: SendbirdMessage, currentUserId?: string) {
|
|
11
13
|
const myMessage = isMyMessage(msg, currentUserId);
|
|
@@ -67,7 +69,7 @@ export function calcMessageGrouping(
|
|
|
67
69
|
if (!prev) return false;
|
|
68
70
|
if (curr.isAdminMessage()) return false;
|
|
69
71
|
if (!hasSameSender(curr, prev)) return false;
|
|
70
|
-
if (
|
|
72
|
+
if (getMessageTimeFormat(new Date(curr.createdAt)) !== getMessageTimeFormat(new Date(prev.createdAt))) return false;
|
|
71
73
|
return true;
|
|
72
74
|
};
|
|
73
75
|
|
|
@@ -76,7 +78,7 @@ export function calcMessageGrouping(
|
|
|
76
78
|
if (!next) return false;
|
|
77
79
|
if (curr.isAdminMessage()) return false;
|
|
78
80
|
if (!hasSameSender(curr, next)) return false;
|
|
79
|
-
if (
|
|
81
|
+
if (getMessageTimeFormat(new Date(curr.createdAt)) !== getMessageTimeFormat(new Date(next.createdAt))) return false;
|
|
80
82
|
return true;
|
|
81
83
|
};
|
|
82
84
|
|
|
@@ -110,3 +112,11 @@ export function isSendbirdNotification(dataPayload?: {
|
|
|
110
112
|
export function parseSendbirdNotification(dataPayload: RawSendbirdDataPayload): SendbirdDataPayload {
|
|
111
113
|
return typeof dataPayload.sendbird === 'string' ? JSON.parse(dataPayload.sendbird) : dataPayload.sendbird;
|
|
112
114
|
}
|
|
115
|
+
|
|
116
|
+
export function shouldRenderReaction(channel: SendbirdBaseChannel, reactionEnabled: boolean) {
|
|
117
|
+
return channel.isGroupChannel() && !channel.isBroadcast && !channel.isSuper && reactionEnabled;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function getReactionCount(reaction: SendbirdReaction) {
|
|
121
|
+
return reaction.userIds.length;
|
|
122
|
+
}
|
package/src/sendbird/user.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { Role } from '@sendbird/chat';
|
|
2
2
|
|
|
3
|
+
import type { UserStruct } from '../types';
|
|
4
|
+
|
|
3
5
|
export function ifOperator<T>(role: Role, then: T): T | undefined;
|
|
4
6
|
export function ifOperator<T, V>(role: Role, then: T, or: V): T | V;
|
|
5
7
|
export function ifOperator(role: Role, then: unknown, or?: unknown) {
|
|
@@ -13,3 +15,7 @@ export function ifMuted(muted: boolean, then: unknown, or?: unknown) {
|
|
|
13
15
|
if (muted) return then;
|
|
14
16
|
return or;
|
|
15
17
|
}
|
|
18
|
+
|
|
19
|
+
export function getUserUniqId<T extends UserStruct>(user: T) {
|
|
20
|
+
return user.userId;
|
|
21
|
+
}
|
package/src/shared/regex.ts
CHANGED
|
@@ -9,6 +9,8 @@ export const phoneRegex = /[+]?[(]?[0-9]{3}[)]?[-\s.]?[0-9]{3}[-\s.]?[0-9]{4,7}/
|
|
|
9
9
|
export const emailRegex = /\S+@\S+\.\S+/;
|
|
10
10
|
export const newLineRegex = /\r\n|\r|\n/g;
|
|
11
11
|
|
|
12
|
+
export const createMentionTemplateRegex = (trigger: string) => new RegExp(`(${trigger}[{])(.*?)([}])`, 'g');
|
|
13
|
+
|
|
12
14
|
// const cases = [
|
|
13
15
|
// {
|
|
14
16
|
// type: 'urlStrict',
|
|
@@ -28,6 +30,39 @@ export const newLineRegex = /\r\n|\r|\n/g;
|
|
|
28
30
|
// },
|
|
29
31
|
// ];
|
|
30
32
|
|
|
33
|
+
export const replaceWithRegex = <T>(
|
|
34
|
+
text: string,
|
|
35
|
+
regex: RegExp,
|
|
36
|
+
replacer: (params: {
|
|
37
|
+
match: string;
|
|
38
|
+
groups: string[];
|
|
39
|
+
matchIndex: number | undefined;
|
|
40
|
+
index: number;
|
|
41
|
+
keyPrefix: string;
|
|
42
|
+
}) => T,
|
|
43
|
+
keyPrefix: string,
|
|
44
|
+
) => {
|
|
45
|
+
const matches = [...text.matchAll(regex)];
|
|
46
|
+
const founds = matches.map((value) => {
|
|
47
|
+
const text = value[0];
|
|
48
|
+
const start = value.index ?? 0;
|
|
49
|
+
const end = start + text.length;
|
|
50
|
+
return { text, start, end, groups: value, matchIndex: value.index };
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const items: Array<T | string> = [text];
|
|
54
|
+
let cursor = 0;
|
|
55
|
+
founds.forEach(({ text, start, end, groups, matchIndex }, index) => {
|
|
56
|
+
const restText = items.pop() as string;
|
|
57
|
+
const head = restText.slice(0, start - cursor);
|
|
58
|
+
const mid = replacer({ match: text, groups, matchIndex, index, keyPrefix });
|
|
59
|
+
const tail = restText.slice(end - cursor);
|
|
60
|
+
items.push(head, mid, tail);
|
|
61
|
+
cursor = end;
|
|
62
|
+
});
|
|
63
|
+
return items;
|
|
64
|
+
};
|
|
65
|
+
|
|
31
66
|
export const replaceUrlAsComponents = <T>(originText: string, replacer: (url: string) => T, strict?: boolean) => {
|
|
32
67
|
const matches = [...originText.matchAll(strict ? urlRegexStrict : urlRegexRough)];
|
|
33
68
|
const founds = matches.map((value) => {
|
package/src/types.ts
CHANGED
|
@@ -4,7 +4,16 @@
|
|
|
4
4
|
import type React from 'react';
|
|
5
5
|
|
|
6
6
|
import type SendbirdChat from '@sendbird/chat';
|
|
7
|
-
import type {
|
|
7
|
+
import type {
|
|
8
|
+
BaseChannel,
|
|
9
|
+
Emoji,
|
|
10
|
+
EmojiCategory,
|
|
11
|
+
EmojiContainer,
|
|
12
|
+
RestrictedUser,
|
|
13
|
+
SendbirdError as SBError,
|
|
14
|
+
User,
|
|
15
|
+
UserUpdateParams,
|
|
16
|
+
} from '@sendbird/chat';
|
|
8
17
|
import type {
|
|
9
18
|
GroupChannel,
|
|
10
19
|
GroupChannelCollection,
|
|
@@ -23,14 +32,13 @@ import type {
|
|
|
23
32
|
FileMessageCreateParams,
|
|
24
33
|
FileMessageUpdateParams,
|
|
25
34
|
PreviousMessageListQuery,
|
|
35
|
+
Reaction,
|
|
26
36
|
UserMessage,
|
|
27
37
|
UserMessageCreateParams,
|
|
28
38
|
UserMessageUpdateParams,
|
|
29
39
|
} from '@sendbird/chat/message';
|
|
30
40
|
import type { OpenChannel, OpenChannelModule } from '@sendbird/chat/openChannel';
|
|
31
41
|
|
|
32
|
-
import './';
|
|
33
|
-
|
|
34
42
|
export type FilterByValueType<T extends object, Type> = {
|
|
35
43
|
[K in keyof T as T[K] extends Type ? K : never]: T[K];
|
|
36
44
|
};
|
|
@@ -57,6 +65,10 @@ export type Optional<T> = T | undefined;
|
|
|
57
65
|
|
|
58
66
|
export type ContextValue<T extends React.Context<any>> = T extends React.Context<infer V> ? V : never;
|
|
59
67
|
|
|
68
|
+
export interface UserStruct {
|
|
69
|
+
userId: string;
|
|
70
|
+
}
|
|
71
|
+
|
|
60
72
|
export type SendbirdChatSDK = SendbirdChat & ModuleNamespaces<[GroupChannelModule, OpenChannelModule]>;
|
|
61
73
|
export type SendbirdMessage = BaseMessage | FileMessage | UserMessage | AdminMessage | SendableMessage;
|
|
62
74
|
export type SendbirdChannel = BaseChannel | GroupChannel | OpenChannel;
|
|
@@ -79,6 +91,11 @@ export type SendbirdGroupChannel = GroupChannel;
|
|
|
79
91
|
export type SendbirdBaseChannel = BaseChannel;
|
|
80
92
|
export type SendbirdOpenChannel = OpenChannel;
|
|
81
93
|
|
|
94
|
+
export type SendbirdReaction = Reaction;
|
|
95
|
+
export type SendbirdEmoji = Emoji;
|
|
96
|
+
export type SendbirdEmojiCategory = EmojiCategory;
|
|
97
|
+
export type SendbirdEmojiContainer = EmojiContainer;
|
|
98
|
+
|
|
82
99
|
export type SendbirdGroupChannelCollection = GroupChannelCollection;
|
|
83
100
|
export type SendbirdGroupChannelListQuery = GroupChannelListQuery;
|
|
84
101
|
export type SendbirdMessageCollection = MessageCollection;
|
package/src/ui-format/common.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Locale } from 'date-fns';
|
|
2
|
-
import format from 'date-fns
|
|
2
|
+
import { format, isThisYear } from 'date-fns';
|
|
3
3
|
|
|
4
4
|
type TruncateMode = 'head' | 'mid' | 'tail';
|
|
5
5
|
type TruncateOption = { mode: TruncateMode; maxLen: number; separator: string };
|
|
@@ -38,15 +38,16 @@ export const truncate = (str: string, opts: Partial<TruncateOption> = defaultOpt
|
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
|
-
*
|
|
41
|
+
* Count truncate util
|
|
42
42
|
* If count exceed the limit, it comes in the form of "MAX+"
|
|
43
43
|
*
|
|
44
44
|
* @param {number} count
|
|
45
45
|
* @param {number} MAX default 99
|
|
46
|
+
* @param {string} MAX_SUFFIX default +
|
|
46
47
|
* @returns {string}
|
|
47
48
|
* */
|
|
48
|
-
export const
|
|
49
|
-
if (count >= MAX) return `${MAX}
|
|
49
|
+
export const truncatedCount = (count: number, MAX = 99, MAX_SUFFIX = '+') => {
|
|
50
|
+
if (count >= MAX) return `${MAX}${MAX_SUFFIX}`;
|
|
50
51
|
return `${count}`;
|
|
51
52
|
};
|
|
52
53
|
|
|
@@ -57,8 +58,9 @@ export const truncatedBadgeCount = (count: number, MAX = 99) => {
|
|
|
57
58
|
* @param {Locale} [locale]
|
|
58
59
|
* @returns {string}
|
|
59
60
|
* */
|
|
60
|
-
export const
|
|
61
|
-
return format(date, '
|
|
61
|
+
export const getDateSeparatorFormat = (date: Date, locale?: Locale): string => {
|
|
62
|
+
if (isThisYear(date)) return format(date, 'MMM dd, yyyy', { locale });
|
|
63
|
+
return format(date, 'E, MMM dd', { locale });
|
|
62
64
|
};
|
|
63
65
|
|
|
64
66
|
/**
|
|
@@ -68,6 +70,6 @@ export const dateSeparator = (date: Date, locale?: Locale): string => {
|
|
|
68
70
|
* @param {Locale} [locale]
|
|
69
71
|
* @returns {string}
|
|
70
72
|
* */
|
|
71
|
-
export const
|
|
73
|
+
export const getMessageTimeFormat = (date: Date, locale?: Locale): string => {
|
|
72
74
|
return format(date, 'p', { locale });
|
|
73
75
|
};
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import type { Locale } from 'date-fns';
|
|
2
|
-
import format from 'date-fns
|
|
3
|
-
import isToday from 'date-fns/isToday';
|
|
4
|
-
import isYesterday from 'date-fns/isYesterday';
|
|
2
|
+
import { format, isThisYear, isToday, isYesterday } from 'date-fns';
|
|
5
3
|
|
|
6
4
|
import type { SendbirdGroupChannel } from '../types';
|
|
7
5
|
import { truncate } from './common';
|
|
@@ -23,9 +21,12 @@ export const getGroupChannelTitle = (
|
|
|
23
21
|
|
|
24
22
|
export const getGroupChannelPreviewTime = (channel: SendbirdGroupChannel, locale?: Locale) => {
|
|
25
23
|
const timestamp = channel.lastMessage?.createdAt || channel.joinedAt * 1000 || channel.createdAt;
|
|
24
|
+
|
|
26
25
|
if (isToday(timestamp)) return format(timestamp, 'p', { locale });
|
|
27
26
|
if (isYesterday(timestamp)) return 'Yesterday';
|
|
28
|
-
return format(timestamp, 'MMM dd', { locale });
|
|
27
|
+
if (isThisYear(timestamp)) return format(timestamp, 'MMM dd', { locale });
|
|
28
|
+
|
|
29
|
+
return format(timestamp, 'yyyy/MM/dd', { locale });
|
|
29
30
|
};
|
|
30
31
|
|
|
31
32
|
export const getGroupChannelLastMessage = (channel: SendbirdGroupChannel, EMPTY_MESSAGE = '', MAX_LEN = 15) => {
|