Skip to content

Commit dd0186d

Browse files
Merge pull request #6325 from nguyentrannhan/develop
Develop
2 parents 9c27ae0 + a9f5899 commit dd0186d

File tree

8 files changed

+103
-35
lines changed

8 files changed

+103
-35
lines changed

apps/mobile/src/app/screens/home/homedrawer/ChannelApp/index.tsx

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,6 @@ const ChannelAppScreen = memo(({ channelId }: { channelId: string }) => {
4141
true;
4242
`;
4343

44-
const injectedCSS = `
45-
(function() {
46-
var style = document.createElement('style');
47-
style.innerHTML = \`
48-
.h-heightTopBar {
49-
display: none !important;
50-
}
51-
\`;
52-
document.head.appendChild(style);
53-
})();
54-
`;
55-
5644
return (
5745
<View style={styles.container}>
5846
{loading && (
@@ -84,7 +72,6 @@ const ChannelAppScreen = memo(({ channelId }: { channelId: string }) => {
8472
await sleep(500);
8573
setLoading(false);
8674
}}
87-
injectedJavaScript={injectedCSS}
8875
/>
8976
</View>
9077
);

libs/components/src/lib/components/ChannelTopbar/index.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ const TopBarChannelApps = ({ channel, mode }: ChannelTopbarProps) => {
169169

170170
<div className="items-center h-full ml-auto flex">
171171
<div className="justify-end items-center gap-2 flex">
172-
<div className="hidden sbm:flex">
172+
<div className="flex">
173173
<div className="relative justify-start items-center gap-[15px] flex mr-4">
174174
<StartCallButton
175175
loading={loading}
@@ -178,14 +178,9 @@ const TopBarChannelApps = ({ channel, mode }: ChannelTopbarProps) => {
178178
/>
179179

180180
<MicButton onClick={() => dispatch(channelAppActions.setEnableVoice(!enableMic))} isTalking={enableMic} />
181-
182181
{/* <VideoButoon onClick={() => dispatch(channelAppActions.setEnableVideo(!enableVideo))} isEnable={enableVideo} /> */}
183182
</div>
184183
</div>
185-
186-
<div className="sbm:hidden mr-5">
187-
<ChannelListButton />
188-
</div>
189184
</div>
190185
</div>
191186
</>

libs/components/src/lib/components/MessageBox/ReactionMentionInput/ReactionMentionInput.tsx

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ import {
6464
IHashtagOnMessage,
6565
IMarkdownOnMessage,
6666
IMentionOnMessage,
67+
MEZON_MENTIONS_COPY_KEY,
6768
MIN_THRESHOLD_CHARS,
6869
MentionDataProps,
6970
MentionReactInputProps,
@@ -82,6 +83,7 @@ import {
8283
formatMentionsToString,
8384
generateMentionItems,
8485
getDisplayMention,
86+
getMarkupInsertIndex,
8587
insertStringAt,
8688
parseHtmlAsFormattedText,
8789
parsePastedMentionData,
@@ -93,7 +95,7 @@ import {
9395
} from '@mezon/utils';
9496
import { ChannelStreamMode } from 'mezon-js';
9597
import { ApiMessageMention } from 'mezon-js/api.gen';
96-
import { KeyboardEvent, ReactElement, RefObject, memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
98+
import React, { KeyboardEvent, ReactElement, RefObject, memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
9799
import { Mention, MentionItem, MentionsInput, OnChangeHandlerFunc } from 'react-mentions';
98100
import { useSelector, useStore } from 'react-redux';
99101
import textFieldEdit from 'text-field-edit';
@@ -770,7 +772,7 @@ export const MentionReactInput = memo((props: MentionReactInputProps): ReactElem
770772

771773
const onPasteMentions = useCallback(
772774
(event: React.ClipboardEvent<HTMLTextAreaElement>) => {
773-
const pastedData = event.clipboardData.getData('text/mezon-mentions');
775+
const pastedData = event.clipboardData.getData(MEZON_MENTIONS_COPY_KEY);
774776

775777
if (!pastedData) return;
776778

@@ -786,7 +788,12 @@ export const MentionReactInput = memo((props: MentionReactInputProps): ReactElem
786788

787789
const transformedText =
788790
pastedContent?.content?.t && pastedContent?.mentions
789-
? transformTextWithMentions(pastedContent.content.t, pastedContent.mentions, currentChatUsersEntities, clanRolesEntities)
791+
? transformTextWithMentions(
792+
pastedContent.content.t?.slice(startIndex, endIndex),
793+
pastedContent.mentions,
794+
currentChatUsersEntities,
795+
clanRolesEntities
796+
)
790797
: pastedContent?.content?.t || '';
791798

792799
const mentionRaw = generateMentionItems(
@@ -796,10 +803,19 @@ export const MentionReactInput = memo((props: MentionReactInputProps): ReactElem
796803
currentInputValueLength
797804
);
798805

806+
const { mentionList } = processMention(
807+
[...(request?.mentionRaw || []), ...mentionRaw],
808+
rolesClan,
809+
membersOfChild as ChannelMembersEntity[],
810+
membersOfParent as ChannelMembersEntity[]
811+
);
812+
813+
const transformedTextInsertIndex = getMarkupInsertIndex(currentFocusIndex, mentionList, currentChatUsersEntities, clanRolesEntities);
814+
799815
setRequestInput(
800816
{
801817
...request,
802-
valueTextInput: insertStringAt(request?.valueTextInput || '', transformedText || '', currentFocusIndex),
818+
valueTextInput: insertStringAt(request?.valueTextInput || '', transformedText || '', transformedTextInsertIndex),
803819
content: insertStringAt(request?.content || '', pastedContent?.content?.t?.slice(startIndex, endIndex) || '', currentFocusIndex),
804820
mentionRaw: [...(request?.mentionRaw || []), ...mentionRaw]
805821
},
@@ -866,7 +882,7 @@ export const MentionReactInput = memo((props: MentionReactInputProps): ReactElem
866882
<MentionsInput
867883
onFocus={handleFocusInput}
868884
onPaste={(event) => {
869-
const pastedData = event.clipboardData.getData('text/mezon-mentions');
885+
const pastedData = event.clipboardData.getData(MEZON_MENTIONS_COPY_KEY);
870886
if (pastedData) {
871887
onPasteMentions(event);
872888
event.preventDefault();
@@ -876,12 +892,12 @@ export const MentionReactInput = memo((props: MentionReactInputProps): ReactElem
876892
setPastedContent(pastedText);
877893
}
878894
}}
879-
onPasteCapture={(event) => {
880-
if (event.clipboardData.getData('text/mezon-mentions')) {
895+
onPasteCapture={async (event) => {
896+
if (event.clipboardData.getData(MEZON_MENTIONS_COPY_KEY)) {
881897
event.preventDefault();
882898
} else {
883899
if (props.handlePaste) {
884-
props.handlePaste(event);
900+
await props.handlePaste(event);
885901
}
886902
}
887903
}}

libs/components/src/lib/components/MessageWithUser/MessageContent.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ import {
1414
ETypeLinkMedia,
1515
IExtendedMessage,
1616
IMessageWithUser,
17+
MEZON_MENTIONS_COPY_KEY,
1718
TypeMessage,
1819
addMention,
1920
convertTimeString,
2021
createImgproxyUrl,
2122
isValidEmojiData
2223
} from '@mezon/utils';
2324
import { safeJSONParse } from 'mezon-js';
24-
import { memo, useCallback } from 'react';
25+
import React, { memo, useCallback } from 'react';
2526
import { useSelector } from 'react-redux';
2627
import { MessageLine } from './MessageLine';
2728
import { MessageLineSystem } from './MessageLineSystem';
@@ -65,9 +66,23 @@ const MessageContent = memo(({ message, mode, isSearchMessage, isInTopic }: IMes
6566
const handleCopyMessage = useCallback(
6667
(event: React.ClipboardEvent<HTMLDivElement>, startIndex: number, endIndex: number) => {
6768
if (message?.content && message?.mentions) {
68-
const key = 'text/mezon-mentions';
69+
const key = MEZON_MENTIONS_COPY_KEY;
6970
const copyData = {
70-
message: message,
71+
message: {
72+
...message,
73+
mentions:
74+
message?.mentions
75+
?.map((mention) => {
76+
if ((mention?.s || 0) >= startIndex && mention?.e && mention?.e <= endIndex) {
77+
return {
78+
...mention,
79+
s: (mention?.s || 0) - startIndex,
80+
e: mention?.e - startIndex
81+
};
82+
}
83+
})
84+
?.filter(Boolean) || []
85+
},
7186
startIndex: startIndex,
7287
endIndex: endIndex
7388
};

libs/store/src/index-mobile.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export * from './lib/categories/categories.slice';
1313
export * from './lib/channelmembers/AllUsersChannelByAddChannel.slice';
1414
export * from './lib/channelmembers/channel.members';
1515
export * from './lib/channels/channelUser.slice';
16+
export * from './lib/channels/channelapp.slice';
1617
export * from './lib/channels/channelmeta.slice';
1718
export * from './lib/channels/channels.slice';
1819
export * from './lib/channels/hashtagDm.slice';
@@ -24,6 +25,7 @@ export * from './lib/clanProfile/clanProfile.slice';
2425
export * from './lib/clanWebhook/clanWebhook.slide';
2526
export * from './lib/clans/clanSettingChannel.slice';
2627
export * from './lib/clans/clans.slice';
28+
export * from './lib/direct/direct.members.meta';
2729
export * from './lib/direct/direct.slice';
2830
export * from './lib/direct/directmeta.slice';
2931
export * from './lib/dmcall/audioCall.slice';
@@ -42,6 +44,8 @@ export * from './lib/giveCoffee/giveCoffee.slice';
4244
export * from './lib/giveCoffee/historyTransaction.slice';
4345
export * from './lib/helpers';
4446
export * from './lib/invite/invite.slice';
47+
export * from './lib/meet/meet.slice';
48+
export * from './lib/memoize';
4549
export * from './lib/messages/SeenMessagePool';
4650
export * from './lib/messages/embedMessage.slice';
4751
export * from './lib/messages/messages.slice';

libs/store/src/lib/store-mobile.tsx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ import { canvasReducer } from './canvas/canvas.slice';
3333
import { canvasAPIReducer } from './canvas/canvasAPI.slice';
3434
import { userChannelsReducer } from './channelmembers/AllUsersChannelByAddChannel.slice';
3535
import { listchannelsByUserReducer } from './channels/channelUser.slice';
36+
import { channelAppReducer } from './channels/channelapp.slice';
3637
import { channelMetaReducer } from './channels/channelmeta.slice';
3738
import { hashtagDmReducer } from './channels/hashtagDm.slice';
3839
import { CHANNEL_LIST_RENDER, listChannelRenderReducer } from './channels/listChannelRender.slice';
3940
import { listUsersByUserReducer } from './channels/listUsers.slice';
4041
import { clanMembersMetaReducer } from './clanMembers/clan.members.meta';
4142
import { integrationClanWebhookReducer } from './clanWebhook/clanWebhook.slide';
4243
import { settingChannelReducer } from './clans/clanSettingChannel.slice';
44+
import { directMembersMetaReducer } from './direct/direct.members.meta';
4345
import { directMetaReducer } from './direct/directmeta.slice';
4446
import { audioCallReducer } from './dmcall/audioCall.slice';
4547
import { DMCallReducer } from './dmcall/dmcall.slice';
@@ -48,6 +50,7 @@ import { E2EE_FEATURE_KEY, e2eeReducer } from './e2ee/e2ee.slice';
4850
import { errorListenerMiddleware } from './errors/errors.listener';
4951
import { ERRORS_FEATURE_KEY, errorsReducer } from './errors/errors.slice';
5052
import { eventManagementReducer } from './eventManagement/eventManagement.slice';
53+
import { fcmReducer } from './fcm/fcm.slice';
5154
import { popupForwardReducer } from './forwardMessage/forwardMessage.slice';
5255
import { giveCoffeeReducer } from './giveCoffee/giveCoffee.slice';
5356
import { walletLedgerReducer } from './giveCoffee/historyTransaction.slice';
@@ -56,7 +59,6 @@ import { notifiReactMessageReducer } from './notificationSetting/notificationRea
5659
import { channelCategorySettingReducer, defaultNotificationCategoryReducer } from './notificationSetting/notificationSettingCategory.slice';
5760
import { notificationSettingReducer } from './notificationSetting/notificationSettingChannel.slice';
5861
import { defaultNotificationClanReducer } from './notificationSetting/notificationSettingClan.slice';
59-
import { ONBOARDING_FEATURE_KEY, onboardingReducer } from './onboarding/onboarding.slice';
6062
import { permissionRoleChannelReducer } from './permissionChannel/permissionRoleChannel.slice';
6163
import { pinMessageReducer } from './pinMessages/pinMessage.slice';
6264
import { OVERRIDDEN_POLICIES_FEATURE_KEY, overriddenPoliciesReducer } from './policies/overriddenPolicies.slice';
@@ -71,7 +73,7 @@ import { toastListenerMiddleware } from './toasts/toasts.listener';
7173
import { TOASTS_FEATURE_KEY, toastsReducer } from './toasts/toasts.slice';
7274
import { topicsReducer } from './topicDiscussion/topicDiscussions.slice';
7375
import { USER_STATUS_API_FEATURE_KEY, userStatusAPIReducer } from './userstatus/userstatusAPI.slice';
74-
import { voiceReducer } from './voice/voice.slice';
76+
import { VOICE_FEATURE_KEY, voiceReducer } from './voice/voice.slice';
7577
import { integrationWebhookReducer } from './webhook/webhook.slice';
7678
const persistedReducer = persistReducer(
7779
{
@@ -350,6 +352,15 @@ const persistListChannelRenderReducer = persistReducer(
350352
listChannelRenderReducer
351353
);
352354

355+
const persistedVoiceReducer = persistReducer(
356+
{
357+
key: VOICE_FEATURE_KEY,
358+
storage,
359+
whitelist: ['voiceInfo']
360+
},
361+
voiceReducer
362+
);
363+
353364
const reducer = {
354365
app: persistedAppReducer,
355366
account: persistAccountReducer,
@@ -365,6 +376,7 @@ const reducer = {
365376
channelMembers: persistedChannelMembersReducer,
366377
listusersbyuserid: persistedListUsersByUserReducer,
367378
threads: persistedThreadReducer,
379+
topicdiscussions: persistedTopicReducer,
368380
[SEARCH_MESSAGES_FEATURE_KEY]: searchMessageReducer,
369381
messages: persistedMessageReducer,
370382
categories: persistedCatReducer,
@@ -390,14 +402,16 @@ const reducer = {
390402
isshow: IsShowReducer,
391403
forwardmessage: popupForwardReducer,
392404
notification: notificationReducer,
393-
voice: voiceReducer,
405+
voice: persistedVoiceReducer,
394406
usersstream: usersStreamReducer,
395407
videostream: videoStreamReducer,
408+
channelApp: channelAppReducer,
396409
canvas: canvasReducer,
397410
canvasapi: canvasAPIReducer,
398411
activitiesapi: activitiesAPIReducer,
399412
auditlog: auditLogReducer,
400413
audiocall: audioCallReducer,
414+
fcm: fcmReducer,
401415
auditlogfilter: auditLogFilterReducer,
402416
references: referencesReducer,
403417
reaction: reactionReducer,
@@ -414,12 +428,11 @@ const reducer = {
414428
giveCoffee: giveCoffeeReducer,
415429
settingClanChannel: settingChannelReducer,
416430
clanMembersMeta: clanMembersMetaReducer,
417-
[ONBOARDING_FEATURE_KEY]: onboardingReducer,
431+
directmembersmeta: directMembersMetaReducer,
418432
dmcall: DMCallReducer,
419433
[USER_STATUS_API_FEATURE_KEY]: userStatusAPIReducer,
420434
[E2EE_FEATURE_KEY]: e2eeReducer,
421435
[EMBED_MESSAGE]: embedReducer,
422-
topicdiscussions: persistedTopicReducer,
423436
walletLedger: walletLedgerReducer,
424437
[CHANNEL_LIST_RENDER]: persistListChannelRenderReducer
425438
};

libs/utils/src/lib/constant/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,5 @@ export const TOKEN_TO_AMOUNT = {
100100
export const ADD_ROLE_CHANNEL_STATUS = 'Add Role Channel';
101101
export const KOMU_CLAN_ID = '1779484504377790464';
102102
export const WELCOME_CHANNEL_ID = '1827883133219901440';
103+
104+
export const MEZON_MENTIONS_COPY_KEY = 'text/mezon-mentions';

libs/utils/src/lib/utils/index.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,42 @@ export const generateMentionItems = (
998998
.filter((item): item is MentionItem => item !== null);
999999
};
10001000

1001+
// Calculates the updated insert index when converting from plain text to markup text
1002+
export const getMarkupInsertIndex = (
1003+
plainInsertIndex: number,
1004+
mentions: IMentionOnMessage[],
1005+
usersEntities: Record<string, ChannelMembersEntity> | Record<string, UsersClanEntity>,
1006+
clanRoles: Record<string, IRolesClan>
1007+
) => {
1008+
const mentionsBeforeInsert = mentions.filter((mention) => mention?.e && mention?.e <= plainInsertIndex);
1009+
let totalInsertedLength = 0;
1010+
1011+
mentionsBeforeInsert.forEach((mention) => {
1012+
const { user_id, role_id } = mention;
1013+
1014+
if (role_id) {
1015+
const role = clanRoles?.[role_id as string];
1016+
if (role) {
1017+
// Plain text: @name
1018+
// Mention markup format: @[name](id)
1019+
// => Adding 4 extra characters: `[`, `]`, `(`, `)`
1020+
totalInsertedLength += 4 + (role?.id?.length || 0);
1021+
}
1022+
return;
1023+
}
1024+
1025+
const user = usersEntities?.[mention.user_id as string];
1026+
if (user) {
1027+
// Plain text: @name
1028+
// Mention markup format: @[name](id)
1029+
// => Adding 4 extra characters: `[`, `]`, `(`, `)`
1030+
totalInsertedLength += 4 + (user_id?.length || 0);
1031+
}
1032+
});
1033+
1034+
return plainInsertIndex + totalInsertedLength;
1035+
};
1036+
10011037
export const parseThreadInfo = (messageContent: string) => {
10021038
const match = messageContent.match(/\(([^,]+),\s*([^)]+)\)/);
10031039
if (match) {

0 commit comments

Comments
 (0)