quickblox-react-ui-kit 0.4.2-beta.5 → 0.4.2-beta.6
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/dist/Data/repository/DialogsRepository.d.ts +2 -1
- package/dist/Data/source/remote/IRemoteDataSource.d.ts +2 -1
- package/dist/Data/source/remote/RemoteDataSource.d.ts +7 -1
- package/dist/Domain/use_cases/UpdateCurrentDialogInDataSourceUseCase.d.ts +3 -1
- package/dist/index-ui.js +29574 -29271
- package/dist/index-ui.js.map +1 -1
- package/dist/qb-api-calls/index.d.ts +4 -1
- package/package.json +2 -2
- package/src/App.tsx +10 -1
- package/src/Data/Creator.ts +4 -1
- package/src/Data/DefaultConfigurations.ts +2 -2
- package/src/Data/mapper/DialogRemoteDTOMapper.ts +2 -1
- package/src/Data/repository/ConnectionRepository.ts +7 -2
- package/src/Data/repository/DialogsRepository.ts +3 -1
- package/src/Data/source/remote/IRemoteDataSource.ts +2 -1
- package/src/Data/source/remote/Mapper/FileDTOMapper.ts +3 -4
- package/src/Data/source/remote/Mapper/MessageDTOMapper.ts +3 -1
- package/src/Data/source/remote/RemoteDataSource.ts +130 -10
- package/src/Domain/use_cases/UpdateCurrentDialogInDataSourceUseCase.ts +6 -0
- package/src/Presentation/Views/Dialog/useDialogViewModel.ts +40 -22
- package/src/Presentation/Views/DialogList/useDialogListViewModel.ts +6 -2
- package/src/Presentation/Views/PreviewDialog/PreviewDialog.tsx +2 -1
- package/src/Presentation/providers/QuickBloxUIKitProvider/QuickBloxUIKitProvider.tsx +13 -0
- package/src/QBconfig.ts +2 -2
- package/src/hooks/useQuickBloxUIKit.ts +109 -35
- package/src/qb-api-calls/index.ts +125 -0
- package/public/quickblox.js +0 -52585
- package/public/quickblox.min.js +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AIAnswerResponse, AIChatHistory, ChatConnectParams, GetMessagesResult, GetUserParams, ListUserParams, ListUserResponse, QBBlob, QBBlobCreateUploadParams, QBCustomObject, QBDataDeletedResponse, QBGetDialogResult, QBLoginParams, QBMediaParams, QBMessageStatusParams, QBSession, QBSystemMessage, QBUser, QBUserCreateParams, QBWebRTCSession } from 'quickblox/quickblox';
|
|
1
|
+
import QB, { AIAnswerResponse, AIChatHistory, ChatConnectParams, GetMessagesResult, GetUserParams, ListUserParams, ListUserResponse, QBBlob, QBBlobCreateUploadParams, QBCustomObject, QBDataDeletedResponse, QBGetDialogResult, QBLoginParams, QBMediaParams, QBMessageStatusParams, QBSession, QBSystemMessage, QBUser, QBUserCreateParams, QBWebRTCSession } from 'quickblox/quickblox';
|
|
2
2
|
import { QBUIKitChatDialog, QBUIKitChatNewMessage, QBUIKitConfig } from '../CommonTypes/CommonTypes';
|
|
3
3
|
export type QBInitParams = {
|
|
4
4
|
appIdOrToken: string | number;
|
|
@@ -7,6 +7,9 @@ export type QBInitParams = {
|
|
|
7
7
|
accountKey: string;
|
|
8
8
|
config?: QBUIKitConfig;
|
|
9
9
|
};
|
|
10
|
+
export declare let qbSDK: typeof QB | undefined;
|
|
11
|
+
export declare function setQB(sdk: typeof QB): void;
|
|
12
|
+
export declare function getQB(): typeof QB;
|
|
10
13
|
export declare function QBInit(params: QBInitParams): void;
|
|
11
14
|
export declare function QBCreateSession(params?: QBLoginParams): Promise<QBSession>;
|
|
12
15
|
export declare function QBGetSession(): Promise<QBSession>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "quickblox-react-ui-kit",
|
|
3
|
-
"version": "0.4.2-beta.
|
|
3
|
+
"version": "0.4.2-beta.6",
|
|
4
4
|
"main": "dist/index-ui.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"dependencies": {
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"qb-ai-core": "^0.1.3",
|
|
13
13
|
"qb-ai-rephrase": "^0.1.2",
|
|
14
14
|
"qb-ai-translate": "^0.1.2",
|
|
15
|
-
"quickblox": "^2.
|
|
15
|
+
"quickblox": "^2.19.2",
|
|
16
16
|
"react": "^18.2.0",
|
|
17
17
|
"react-dom": "^18.2.0",
|
|
18
18
|
"react-router-dom": "^6.11.1",
|
package/src/App.tsx
CHANGED
|
@@ -17,7 +17,16 @@ import useQbUIKitDataContext from './Presentation/providers/QuickBloxUIKitProvid
|
|
|
17
17
|
import { QBConfig } from './QBconfig';
|
|
18
18
|
|
|
19
19
|
function App() {
|
|
20
|
-
|
|
20
|
+
if ((window as any).QB === undefined) {
|
|
21
|
+
if (QB !== undefined) {
|
|
22
|
+
(window as any).QB = QB;
|
|
23
|
+
} else {
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires,global-require
|
|
25
|
+
const QBLib = require('quickblox/quickblox.min');
|
|
26
|
+
|
|
27
|
+
(window as any).QB = QBLib;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
21
30
|
const currentContext = useQbUIKitDataContext();
|
|
22
31
|
|
|
23
32
|
const remoteDataSource: RemoteDataSource =
|
package/src/Data/Creator.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import QB from 'quickblox/quickblox';
|
|
2
1
|
import ChatMessageAttachmentEntity from '../Domain/entity/ChatMessageAttachmentEntity';
|
|
3
2
|
import { DialogType } from '../Domain/entity/DialogTypes';
|
|
4
3
|
import { MessageEntity } from '../Domain/entity/MessageEntity';
|
|
5
4
|
import { FileEntity } from '../Domain/entity/FileEntity';
|
|
6
5
|
import { FileType } from '../Domain/entity/FileTypes';
|
|
6
|
+
import { getQB } from '../qb-api-calls';
|
|
7
7
|
|
|
8
8
|
export type MessageEntityParams = {
|
|
9
9
|
id?: string;
|
|
@@ -24,6 +24,7 @@ export type MessageEntityParams = {
|
|
|
24
24
|
|
|
25
25
|
export class Creator {
|
|
26
26
|
public static createPhotoByBlob = async (blob_id: number | string | null) => {
|
|
27
|
+
const QB = getQB();
|
|
27
28
|
const fileId = (blob_id as number) || 0;
|
|
28
29
|
|
|
29
30
|
const file_uid: string = await Creator.getInfoPromise(fileId);
|
|
@@ -63,6 +64,8 @@ export class Creator {
|
|
|
63
64
|
|
|
64
65
|
private static async getInfoPromise(fileId: number): Promise<string> {
|
|
65
66
|
return new Promise((resolve, reject) => {
|
|
67
|
+
const QB = getQB();
|
|
68
|
+
|
|
66
69
|
QB.content.getInfo(fileId, function (error, result) {
|
|
67
70
|
if (error) {
|
|
68
71
|
reject(error);
|
|
@@ -145,7 +145,7 @@ export class DefaultConfigurations {
|
|
|
145
145
|
},
|
|
146
146
|
configAIApi: {
|
|
147
147
|
AIAnswerAssistWidgetConfig: {
|
|
148
|
-
smartChatAssistantId: '',
|
|
148
|
+
smartChatAssistantId: '6633a1300fea600001bd6e71',
|
|
149
149
|
organizationName: 'Quickblox',
|
|
150
150
|
openAIModel: 'gpt-3.5-turbo',
|
|
151
151
|
apiKey: '',
|
|
@@ -158,7 +158,7 @@ export class DefaultConfigurations {
|
|
|
158
158
|
},
|
|
159
159
|
},
|
|
160
160
|
AITranslateWidgetConfig: {
|
|
161
|
-
smartChatAssistantId: '',
|
|
161
|
+
smartChatAssistantId: '6633a1300fea600001bd6e71',
|
|
162
162
|
organizationName: 'Quickblox',
|
|
163
163
|
openAIModel: 'gpt-3.5-turbo',
|
|
164
164
|
apiKey: '',
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import QB from 'quickblox/quickblox';
|
|
2
1
|
import { IMapper } from './IMapper';
|
|
3
2
|
import { DialogEntity } from '../../Domain/entity/DialogEntity';
|
|
4
3
|
import { DialogType } from '../../Domain/entity/DialogTypes';
|
|
@@ -14,6 +13,7 @@ import {
|
|
|
14
13
|
UNEXPECTED_MAPPER_DTO_EXCEPTION_EXCEPTION_CODE,
|
|
15
14
|
UNEXPECTED_MAPPER_DTO_EXCEPTION_MESSAGE,
|
|
16
15
|
} from '../source/exception/MapperDTOException';
|
|
16
|
+
import { getQB } from '../../qb-api-calls';
|
|
17
17
|
|
|
18
18
|
type DtoValidator<T> = {
|
|
19
19
|
[key in keyof T]: (v: unknown) => v is T[key];
|
|
@@ -69,6 +69,7 @@ export class DialogRemoteDTOMapper implements IMapper {
|
|
|
69
69
|
|
|
70
70
|
// eslint-disable-next-line class-methods-use-this
|
|
71
71
|
toEntity<TArg, TResult>(data: TArg): Promise<TResult> {
|
|
72
|
+
const QB = getQB();
|
|
72
73
|
const dialog = data as unknown as RemoteDialogDTO;
|
|
73
74
|
|
|
74
75
|
try {
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import QB from 'quickblox/quickblox';
|
|
2
1
|
import { SubscriptionPerformer } from '../../Domain/use_cases/base/Subscribable/SubscriptionPerformer';
|
|
3
2
|
import { stringifyError } from '../../utils/parse';
|
|
3
|
+
import { getQB } from '../../qb-api-calls';
|
|
4
4
|
|
|
5
5
|
export default class ConnectionRepository extends SubscriptionPerformer<boolean> {
|
|
6
|
-
private timerId: NodeJS.Timer | undefined;
|
|
6
|
+
// private timerId: NodeJS.Timer | undefined;
|
|
7
|
+
private timerId: ReturnType<typeof setTimeout> | undefined;
|
|
7
8
|
|
|
8
9
|
private _needInit: boolean;
|
|
9
10
|
|
|
10
11
|
get needInit(): boolean {
|
|
12
|
+
const QB = getQB();
|
|
11
13
|
const chatConnection = QB && QB.chat && QB.chat.isConnected;
|
|
12
14
|
|
|
13
15
|
if (chatConnection) return false;
|
|
@@ -22,6 +24,7 @@ export default class ConnectionRepository extends SubscriptionPerformer<boolean>
|
|
|
22
24
|
private chatConnectedStatus = false;
|
|
23
25
|
|
|
24
26
|
public isChatConnected(): boolean {
|
|
27
|
+
const QB = getQB();
|
|
25
28
|
const chatConnection = QB && QB.chat && QB.chat.isConnected;
|
|
26
29
|
|
|
27
30
|
if (chatConnection) return true;
|
|
@@ -103,6 +106,8 @@ export default class ConnectionRepository extends SubscriptionPerformer<boolean>
|
|
|
103
106
|
protected async ChatServerPing(): Promise<boolean> {
|
|
104
107
|
const pingChat = (): Promise<string> => {
|
|
105
108
|
return new Promise<string>((resolve, reject) => {
|
|
109
|
+
const QB = getQB();
|
|
110
|
+
|
|
106
111
|
try {
|
|
107
112
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
108
113
|
QB.chat.pingchat((error) => {
|
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
import { GroupDialogEntity } from '../../Domain/entity/GroupDialogEntity';
|
|
32
32
|
import { stringifyError } from '../../utils/parse';
|
|
33
33
|
import { RemoteUserDTO } from '../dto/user/RemoteUserDTO';
|
|
34
|
+
import { QBUIKitConfig } from '../../CommonTypes/CommonTypes';
|
|
34
35
|
|
|
35
36
|
export default class DialogsRepository implements IDialogsRepository {
|
|
36
37
|
private localDataStorage: ILocalDataSource;
|
|
@@ -149,13 +150,14 @@ export default class DialogsRepository implements IDialogsRepository {
|
|
|
149
150
|
|
|
150
151
|
async updateCurrentDialogInLocalDataSource(
|
|
151
152
|
entity: DialogEntity,
|
|
153
|
+
qbConfig: QBUIKitConfig,
|
|
152
154
|
): Promise<DialogEntity> {
|
|
153
155
|
try {
|
|
154
156
|
const dto: RemoteDialogDTO = await this.dialogRemoteDTOMapper.fromEntity(
|
|
155
157
|
entity,
|
|
156
158
|
);
|
|
157
159
|
|
|
158
|
-
this.remoteDataSource.updateCurrentDialog(dto);
|
|
160
|
+
this.remoteDataSource.updateCurrentDialog(dto, qbConfig);
|
|
159
161
|
|
|
160
162
|
return Promise.resolve(entity);
|
|
161
163
|
} catch (e) {
|
|
@@ -9,6 +9,7 @@ import { RemoteFileDTO } from '../../dto/file/RemoteFileDTO';
|
|
|
9
9
|
import { Pagination } from '../../../Domain/repository/Pagination';
|
|
10
10
|
import { CallBackFunction } from '../../../Domain/use_cases/base/IUseCase';
|
|
11
11
|
import { NotificationTypes } from '../../../Domain/entity/NotificationTypes';
|
|
12
|
+
import { QBUIKitConfig } from '../../../CommonTypes/CommonTypes';
|
|
12
13
|
// todo list of all actions - for what we need to create tests
|
|
13
14
|
/*
|
|
14
15
|
0!!! не реализованы эксепшены для createDialog RemouteDataSource и
|
|
@@ -111,7 +112,7 @@ export interface IRemoteDataSource extends IRemoteMessaging<RemoteMessageDTO> {
|
|
|
111
112
|
|
|
112
113
|
subscribeToChatConnectionEvents(fileId: string): Promise<void>;
|
|
113
114
|
|
|
114
|
-
updateCurrentDialog(dto: RemoteDialogDTO): void;
|
|
115
|
+
updateCurrentDialog(dto: RemoteDialogDTO, qbConfig: QBUIKitConfig): void;
|
|
115
116
|
|
|
116
117
|
createAnswer(
|
|
117
118
|
text: string,
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
QBBlobCreate,
|
|
3
|
-
QBBlobCreateUploadParams,
|
|
4
|
-
} from 'quickblox/quickblox';
|
|
1
|
+
import { QBBlobCreate, QBBlobCreateUploadParams } from 'quickblox/quickblox';
|
|
5
2
|
import { IDTOMapper } from './IDTOMapper';
|
|
6
3
|
import { RemoteFileDTO } from '../../../dto/file/RemoteFileDTO';
|
|
7
4
|
import {
|
|
@@ -9,6 +6,7 @@ import {
|
|
|
9
6
|
INCORRECT_DATA_MAPPER_DTO_EXCEPTION_MESSAGE,
|
|
10
7
|
MapperDTOException,
|
|
11
8
|
} from '../../exception/MapperDTOException';
|
|
9
|
+
import { getQB } from '../../../../qb-api-calls';
|
|
12
10
|
|
|
13
11
|
type DtoValidator<T> = {
|
|
14
12
|
[key in keyof T]: (v: unknown) => v is T[key];
|
|
@@ -35,6 +33,7 @@ export class FileDTOMapper implements IDTOMapper {
|
|
|
35
33
|
|
|
36
34
|
// eslint-disable-next-line class-methods-use-this
|
|
37
35
|
toTDO<TArg, TResult>(qbEntity: TArg): Promise<TResult> {
|
|
36
|
+
const QB = getQB();
|
|
38
37
|
const qbFile: QBBlobCreate = qbEntity as unknown as QBBlobCreate;
|
|
39
38
|
|
|
40
39
|
FileDTOMapper.validateQBFileDialog(qbFile);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ChatMessageAttachment, QBChatMessage } from 'quickblox/quickblox';
|
|
2
2
|
import { IDTOMapper } from './IDTOMapper';
|
|
3
3
|
import { RemoteMessageDTO } from '../../../dto/message/RemoteMessageDTO';
|
|
4
4
|
import {
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
MapperDTOException,
|
|
8
8
|
} from '../../exception/MapperDTOException';
|
|
9
9
|
import ChatMessageAttachmentEntity from '../../../../Domain/entity/ChatMessageAttachmentEntity';
|
|
10
|
+
import { getQB } from '../../../../qb-api-calls';
|
|
10
11
|
|
|
11
12
|
type DtoValidator<T> = {
|
|
12
13
|
[key in keyof T]: (v: unknown) => v is T[key];
|
|
@@ -44,6 +45,7 @@ export class MessageDTOMapper implements IDTOMapper {
|
|
|
44
45
|
qbAtts: ChatMessageAttachment[],
|
|
45
46
|
) {
|
|
46
47
|
const result: ChatMessageAttachmentEntity[] = qbAtts.map((item) => {
|
|
48
|
+
const QB = getQB();
|
|
47
49
|
const newItem: ChatMessageAttachmentEntity = {
|
|
48
50
|
id: item.id,
|
|
49
51
|
name: item.name,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
2
|
ChatMessageAttachment,
|
|
3
3
|
GetMessagesResult,
|
|
4
4
|
GetUserParams,
|
|
@@ -63,6 +63,8 @@ import {
|
|
|
63
63
|
QBUpdateDialog,
|
|
64
64
|
QBUsersGet,
|
|
65
65
|
QBUsersGetById,
|
|
66
|
+
setQB,
|
|
67
|
+
getQB,
|
|
66
68
|
} from '../../../qb-api-calls';
|
|
67
69
|
import { UserDTOMapper } from './Mapper/UserDTOMapper';
|
|
68
70
|
import { MessageDTOMapper } from './Mapper/MessageDTOMapper';
|
|
@@ -84,6 +86,7 @@ import { QBConfig } from '../../../QBconfig';
|
|
|
84
86
|
import {
|
|
85
87
|
QBUIKitChatDialog,
|
|
86
88
|
QBUIKitChatNewMessage,
|
|
89
|
+
QBUIKitConfig,
|
|
87
90
|
QBUIKitSystemMessage,
|
|
88
91
|
} from '../../../CommonTypes/CommonTypes';
|
|
89
92
|
|
|
@@ -115,6 +118,7 @@ export class RemoteDataSource implements IRemoteDataSource {
|
|
|
115
118
|
private _authProcessed: boolean;
|
|
116
119
|
|
|
117
120
|
get authProcessed(): boolean {
|
|
121
|
+
const QB = getQB();
|
|
118
122
|
const auth = this._authProcessed;
|
|
119
123
|
const chatConnection = QB && QB.chat && QB.chat.isConnected;
|
|
120
124
|
|
|
@@ -128,6 +132,7 @@ export class RemoteDataSource implements IRemoteDataSource {
|
|
|
128
132
|
}
|
|
129
133
|
|
|
130
134
|
get needInit(): boolean {
|
|
135
|
+
const QB = getQB();
|
|
131
136
|
const needed = this._needInit;
|
|
132
137
|
const chatConnection = QB && QB.chat && QB.chat.isConnected;
|
|
133
138
|
|
|
@@ -168,6 +173,17 @@ export class RemoteDataSource implements IRemoteDataSource {
|
|
|
168
173
|
//
|
|
169
174
|
constructor() {
|
|
170
175
|
console.log('CONSTRUCTOR RemoteDataSourceMock');
|
|
176
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
177
|
+
// @ts-ignore
|
|
178
|
+
console.log('QB inside RemoteDataSource:', window.QB);
|
|
179
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
180
|
+
// @ts-ignore
|
|
181
|
+
if (typeof window !== 'undefined' && window.QB) {
|
|
182
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
183
|
+
// @ts-ignore
|
|
184
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
185
|
+
setQB(window.QB); // Устанавливаем ссылку на QuickBlox SDK
|
|
186
|
+
}
|
|
171
187
|
this.userDTOMapper = new UserDTOMapper();
|
|
172
188
|
this.messageDTOMapper = new MessageDTOMapper();
|
|
173
189
|
this.fileDTOMapper = new FileDTOMapper();
|
|
@@ -201,20 +217,57 @@ export class RemoteDataSource implements IRemoteDataSource {
|
|
|
201
217
|
return QBTranslate(smartChatAssistantId, text, languageCode);
|
|
202
218
|
}
|
|
203
219
|
|
|
204
|
-
async updateCurrentDialog(dto: RemoteDialogDTO): Promise<void> {
|
|
220
|
+
// async updateCurrentDialog(dto: RemoteDialogDTO, qbConfig: QBUIKitConfig): Promise<void> {
|
|
221
|
+
// this.currentDialog = dto;
|
|
222
|
+
// //
|
|
223
|
+
// //
|
|
224
|
+
// const dialogsDTOtoEntityMapper: IMapper = new DialogRemoteDTOMapper();
|
|
225
|
+
//
|
|
226
|
+
// const dialogEntity: DialogEntity = await dialogsDTOtoEntityMapper.toEntity(
|
|
227
|
+
// this.currentDialog,
|
|
228
|
+
// );
|
|
229
|
+
// const userId = this._authInformation?.userId || -1;
|
|
230
|
+
// const dialogId = this.currentDialog.id;
|
|
231
|
+
// const messageId = this.currentDialog.lastMessageId;
|
|
232
|
+
// //
|
|
233
|
+
// //
|
|
234
|
+
// const resultMessage: DialogEventInfo = {
|
|
235
|
+
// eventMessageType: EventMessageType.LocalMessage,
|
|
236
|
+
// dialogInfo: dialogEntity,
|
|
237
|
+
// messageInfo: undefined,
|
|
238
|
+
// messageStatus: {
|
|
239
|
+
// isTyping: false,
|
|
240
|
+
// userId,
|
|
241
|
+
// dialogId,
|
|
242
|
+
// messageId,
|
|
243
|
+
// deliveryStatus: 'delivered',
|
|
244
|
+
// },
|
|
245
|
+
// notificationTypes: undefined,
|
|
246
|
+
// };
|
|
247
|
+
//
|
|
248
|
+
// this.subscriptionOnMessageStatus.informSubscribers(
|
|
249
|
+
// resultMessage,
|
|
250
|
+
// EventMessageType.LocalMessage,
|
|
251
|
+
// );
|
|
252
|
+
// //
|
|
253
|
+
//
|
|
254
|
+
// //
|
|
255
|
+
// }
|
|
256
|
+
async updateCurrentDialog(
|
|
257
|
+
dto: RemoteDialogDTO,
|
|
258
|
+
qbConfig: QBUIKitConfig,
|
|
259
|
+
): Promise<void> {
|
|
205
260
|
this.currentDialog = dto;
|
|
206
|
-
//
|
|
207
|
-
//
|
|
208
|
-
const dialogsDTOtoEntityMapper: IMapper = new DialogRemoteDTOMapper();
|
|
209
261
|
|
|
262
|
+
const dialogsDTOtoEntityMapper: IMapper = new DialogRemoteDTOMapper();
|
|
210
263
|
const dialogEntity: DialogEntity = await dialogsDTOtoEntityMapper.toEntity(
|
|
211
264
|
this.currentDialog,
|
|
212
265
|
);
|
|
266
|
+
|
|
213
267
|
const userId = this._authInformation?.userId || -1;
|
|
214
268
|
const dialogId = this.currentDialog.id;
|
|
215
269
|
const messageId = this.currentDialog.lastMessageId;
|
|
216
|
-
|
|
217
|
-
//
|
|
270
|
+
|
|
218
271
|
const resultMessage: DialogEventInfo = {
|
|
219
272
|
eventMessageType: EventMessageType.LocalMessage,
|
|
220
273
|
dialogInfo: dialogEntity,
|
|
@@ -233,8 +286,58 @@ export class RemoteDataSource implements IRemoteDataSource {
|
|
|
233
286
|
resultMessage,
|
|
234
287
|
EventMessageType.LocalMessage,
|
|
235
288
|
);
|
|
236
|
-
|
|
237
|
-
//
|
|
289
|
+
|
|
290
|
+
// Mark all messages in the dialog as read
|
|
291
|
+
await this.markAllMessagesAsRead(dialogId, qbConfig);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Marks all messages in the specified dialog as read.
|
|
296
|
+
* Uses the QuickBlox API endpoint provided in qbConfig, or defaults to api.quickblox.com.
|
|
297
|
+
*/
|
|
298
|
+
// eslint-disable-next-line class-methods-use-this
|
|
299
|
+
private async markAllMessagesAsRead(
|
|
300
|
+
dialogId: string,
|
|
301
|
+
qbConfig: QBUIKitConfig,
|
|
302
|
+
): Promise<void> {
|
|
303
|
+
try {
|
|
304
|
+
const apiEndpoint =
|
|
305
|
+
qbConfig.appConfig.endpoints.api || 'api.quickblox.com';
|
|
306
|
+
const qbToken = qbConfig.credentials.sessionToken;
|
|
307
|
+
|
|
308
|
+
if (!qbToken) {
|
|
309
|
+
console.warn(
|
|
310
|
+
'QuickBlox session token is missing. Cannot mark messages as read.',
|
|
311
|
+
);
|
|
312
|
+
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
const response = await fetch(`https://${apiEndpoint}/chat/Message.json`, {
|
|
317
|
+
method: 'PUT',
|
|
318
|
+
headers: {
|
|
319
|
+
'QB-Token': qbToken,
|
|
320
|
+
'Content-Type': 'application/json',
|
|
321
|
+
},
|
|
322
|
+
body: JSON.stringify({
|
|
323
|
+
chat_dialog_id: dialogId,
|
|
324
|
+
read: '1',
|
|
325
|
+
}),
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
if (!response.ok) {
|
|
329
|
+
throw new Error(
|
|
330
|
+
`Failed to mark messages as read. HTTP status: ${response.status}`,
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
console.log(`All messages in dialog ${dialogId} marked as read.`);
|
|
335
|
+
} catch (error) {
|
|
336
|
+
console.error(
|
|
337
|
+
`Error marking messages as read in dialog ${dialogId}:`,
|
|
338
|
+
error,
|
|
339
|
+
);
|
|
340
|
+
}
|
|
238
341
|
}
|
|
239
342
|
|
|
240
343
|
public async setUpMockStorage(): Promise<void> {
|
|
@@ -285,6 +388,7 @@ export class RemoteDataSource implements IRemoteDataSource {
|
|
|
285
388
|
accountKey: sdkParams.accountKey,
|
|
286
389
|
config: sdkParams.config,
|
|
287
390
|
});
|
|
391
|
+
const QB = getQB();
|
|
288
392
|
const QuickBloxVersion = `CALL initData: Init SDK was success: version ${QB.version} build ${QB.buildNumber}`;
|
|
289
393
|
|
|
290
394
|
console.log(QuickBloxVersion);
|
|
@@ -307,6 +411,7 @@ export class RemoteDataSource implements IRemoteDataSource {
|
|
|
307
411
|
accountKey: sdkParams.accountKey,
|
|
308
412
|
config: sdkParams.config,
|
|
309
413
|
});
|
|
414
|
+
const QB = getQB();
|
|
310
415
|
const QuickBloxVersion = `CALL initData: Init SDK was success: version ${QB.version} build ${QB.buildNumber}`;
|
|
311
416
|
|
|
312
417
|
console.log(QuickBloxVersion);
|
|
@@ -412,6 +517,19 @@ export class RemoteDataSource implements IRemoteDataSource {
|
|
|
412
517
|
|
|
413
518
|
public initEventsHandlers() {
|
|
414
519
|
console.log('CALL--initEventsHandlers--CALL');
|
|
520
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
521
|
+
// @ts-ignore
|
|
522
|
+
console.log('QB inside library:', window.QB);
|
|
523
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
524
|
+
// @ts-ignore
|
|
525
|
+
if (typeof window !== 'undefined' && window.QB) {
|
|
526
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
527
|
+
// @ts-ignore
|
|
528
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
529
|
+
setQB(window.QB); // Устанавливаем ссылку на QuickBlox SDK
|
|
530
|
+
}
|
|
531
|
+
const QB = getQB();
|
|
532
|
+
|
|
415
533
|
QB.chat.onSystemMessageListener = (message: QBUIKitSystemMessage) => {
|
|
416
534
|
console.log(`EVENT: receive system message: ${JSON.stringify(message)}`);
|
|
417
535
|
const resultMessage = new RemoteMessageDTO();
|
|
@@ -696,6 +814,8 @@ export class RemoteDataSource implements IRemoteDataSource {
|
|
|
696
814
|
|
|
697
815
|
// eslint-disable-next-line class-methods-use-this
|
|
698
816
|
public releaseEventsHandlers() {
|
|
817
|
+
const QB = getQB();
|
|
818
|
+
|
|
699
819
|
QB.chat.onSessionExpiredListener = undefined;
|
|
700
820
|
QB.chat.onReconnectListener = undefined;
|
|
701
821
|
QB.chat.onDisconnectedListener = undefined;
|
|
@@ -1275,7 +1395,7 @@ export class RemoteDataSource implements IRemoteDataSource {
|
|
|
1275
1395
|
async sendMessage(dto: RemoteMessageDTO): Promise<RemoteMessageDTO> {
|
|
1276
1396
|
console.log('call sendMessage');
|
|
1277
1397
|
//
|
|
1278
|
-
|
|
1398
|
+
const QB = getQB();
|
|
1279
1399
|
//
|
|
1280
1400
|
const messageText = dto.message;
|
|
1281
1401
|
|
|
@@ -2,6 +2,7 @@ import { DialogEntity } from '../entity/DialogEntity';
|
|
|
2
2
|
import DialogsRepository from '../../Data/repository/DialogsRepository';
|
|
3
3
|
import { IUseCase } from './base/IUseCase';
|
|
4
4
|
import { GroupDialogEntity } from '../entity/GroupDialogEntity';
|
|
5
|
+
import { QBUIKitConfig } from '../../CommonTypes/CommonTypes';
|
|
5
6
|
|
|
6
7
|
export class UpdateCurrentDialogInDataSourceUseCase
|
|
7
8
|
implements IUseCase<void, DialogEntity>
|
|
@@ -10,13 +11,17 @@ export class UpdateCurrentDialogInDataSourceUseCase
|
|
|
10
11
|
|
|
11
12
|
private updateDialog: GroupDialogEntity;
|
|
12
13
|
|
|
14
|
+
private qbConfig: QBUIKitConfig;
|
|
15
|
+
|
|
13
16
|
constructor(
|
|
14
17
|
dialogRepository: DialogsRepository,
|
|
15
18
|
updateDialog: GroupDialogEntity,
|
|
19
|
+
qbConfig: QBUIKitConfig,
|
|
16
20
|
) {
|
|
17
21
|
console.log('CONSTRUCTOR UpdateCurrentDialogInDataSourceUseCase');
|
|
18
22
|
this.dialogRepository = dialogRepository;
|
|
19
23
|
this.updateDialog = updateDialog;
|
|
24
|
+
this.qbConfig = qbConfig;
|
|
20
25
|
}
|
|
21
26
|
|
|
22
27
|
async execute(): Promise<DialogEntity> {
|
|
@@ -24,6 +29,7 @@ export class UpdateCurrentDialogInDataSourceUseCase
|
|
|
24
29
|
const result: DialogEntity =
|
|
25
30
|
await this.dialogRepository.updateCurrentDialogInLocalDataSource(
|
|
26
31
|
this.updateDialog,
|
|
32
|
+
this.qbConfig,
|
|
27
33
|
);
|
|
28
34
|
|
|
29
35
|
return Promise.resolve(result);
|
|
@@ -37,6 +37,7 @@ import { DefaultConfigurations } from '../../../Data/DefaultConfigurations';
|
|
|
37
37
|
import { MessageDTOMapper } from '../../../Data/source/remote/Mapper/MessageDTOMapper';
|
|
38
38
|
import { UpdateCurrentDialogInDataSourceUseCase } from '../../../Domain/use_cases/UpdateCurrentDialogInDataSourceUseCase';
|
|
39
39
|
import { RemoteDataSource } from '../../../Data/source/remote/RemoteDataSource';
|
|
40
|
+
import { QBUIKitConfig } from '../../../CommonTypes/CommonTypes';
|
|
40
41
|
|
|
41
42
|
export default function useDialogViewModel(
|
|
42
43
|
dialogType: DialogType,
|
|
@@ -55,7 +56,7 @@ export default function useDialogViewModel(
|
|
|
55
56
|
const currentContext = useQbInitializedDataContext();
|
|
56
57
|
const remoteDataSourceMock: RemoteDataSource =
|
|
57
58
|
currentContext.storage.REMOTE_DATA_SOURCE;
|
|
58
|
-
const QBConfig =
|
|
59
|
+
const QBConfig: QBUIKitConfig =
|
|
59
60
|
currentContext.InitParams.qbConfig ||
|
|
60
61
|
DefaultConfigurations.getDefaultQBConfig();
|
|
61
62
|
const { regexUserName } = QBConfig.appConfig;
|
|
@@ -68,6 +69,27 @@ export default function useDialogViewModel(
|
|
|
68
69
|
|
|
69
70
|
const [typingText, setTypingText] = useState<string>('');
|
|
70
71
|
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-empty-function
|
|
73
|
+
function informDataSources(item: DialogEntity) {
|
|
74
|
+
const updateCurrentDialogInDataSourceUseCase: UpdateCurrentDialogInDataSourceUseCase =
|
|
75
|
+
new UpdateCurrentDialogInDataSourceUseCase(
|
|
76
|
+
new DialogsRepository(
|
|
77
|
+
currentContext.storage.LOCAL_DATA_SOURCE,
|
|
78
|
+
remoteDataSourceMock,
|
|
79
|
+
),
|
|
80
|
+
item as GroupDialogEntity,
|
|
81
|
+
QBConfig,
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
updateCurrentDialogInDataSourceUseCase.execute().catch((e) => {
|
|
85
|
+
console.log(
|
|
86
|
+
'useDialogViewModel Error updateCurrentDialogInDataSourceUseCase: ',
|
|
87
|
+
stringifyError(e),
|
|
88
|
+
);
|
|
89
|
+
throw new Error(stringifyError(e));
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
71
93
|
async function getMessages(currentPagination?: Pagination) {
|
|
72
94
|
setLoading(true);
|
|
73
95
|
|
|
@@ -161,6 +183,19 @@ export default function useDialogViewModel(
|
|
|
161
183
|
|
|
162
184
|
return newItems;
|
|
163
185
|
});
|
|
186
|
+
// eslint-disable-next-line promise/always-return
|
|
187
|
+
// if (
|
|
188
|
+
// dialog?.type === DialogType.private ||
|
|
189
|
+
// dialog?.type === DialogType.group
|
|
190
|
+
// ) {
|
|
191
|
+
// const updDialog = { ...dialog };
|
|
192
|
+
//
|
|
193
|
+
// updDialog.unreadMessageCount = 0;
|
|
194
|
+
// setDialog(updDialog);
|
|
195
|
+
//
|
|
196
|
+
// informDataSources(updDialog);
|
|
197
|
+
//
|
|
198
|
+
// }
|
|
164
199
|
setLoading(false);
|
|
165
200
|
setPagination(data.CurrentPagination);
|
|
166
201
|
setError('');
|
|
@@ -385,26 +420,6 @@ export default function useDialogViewModel(
|
|
|
385
420
|
return Promise.resolve(resultEnity);
|
|
386
421
|
};
|
|
387
422
|
|
|
388
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-empty-function
|
|
389
|
-
function informDataSources(item: DialogEntity) {
|
|
390
|
-
const updateCurrentDialogInDataSourceUseCase: UpdateCurrentDialogInDataSourceUseCase =
|
|
391
|
-
new UpdateCurrentDialogInDataSourceUseCase(
|
|
392
|
-
new DialogsRepository(
|
|
393
|
-
currentContext.storage.LOCAL_DATA_SOURCE,
|
|
394
|
-
remoteDataSourceMock,
|
|
395
|
-
),
|
|
396
|
-
item as GroupDialogEntity,
|
|
397
|
-
);
|
|
398
|
-
|
|
399
|
-
updateCurrentDialogInDataSourceUseCase.execute().catch((e) => {
|
|
400
|
-
console.log(
|
|
401
|
-
'useDialogViewModel Error updateCurrentDialogInDataSourceUseCase: ',
|
|
402
|
-
stringifyError(e),
|
|
403
|
-
);
|
|
404
|
-
throw new Error(stringifyError(e));
|
|
405
|
-
});
|
|
406
|
-
}
|
|
407
|
-
|
|
408
423
|
const sendMessage = (messageToSend: MessageEntity) => {
|
|
409
424
|
const sendTextMessageUseCase: SendTextMessageUseCase =
|
|
410
425
|
new SendTextMessageUseCase(
|
|
@@ -431,7 +446,10 @@ export default function useDialogViewModel(
|
|
|
431
446
|
|
|
432
447
|
return newState;
|
|
433
448
|
});
|
|
434
|
-
if (
|
|
449
|
+
if (
|
|
450
|
+
dialog?.type === DialogType.private ||
|
|
451
|
+
dialog?.type === DialogType.group
|
|
452
|
+
) {
|
|
435
453
|
const updDialog = { ...dialog };
|
|
436
454
|
|
|
437
455
|
updDialog.lastMessage.dateSent = messageEntity.date_sent / 1000;
|
|
@@ -543,6 +543,7 @@ export default function useDialogListViewModel(
|
|
|
543
543
|
remoteDataSourceMock,
|
|
544
544
|
),
|
|
545
545
|
item as GroupDialogEntity,
|
|
546
|
+
QBConfig,
|
|
546
547
|
);
|
|
547
548
|
|
|
548
549
|
updateCurrentDialogInDataSourceUseCase.execute().catch((e) => {
|
|
@@ -559,8 +560,11 @@ export default function useDialogListViewModel(
|
|
|
559
560
|
return newDialog as DialogEntity;
|
|
560
561
|
},
|
|
561
562
|
set entity(item) {
|
|
562
|
-
|
|
563
|
-
|
|
563
|
+
const updDialog = { ...item };
|
|
564
|
+
|
|
565
|
+
updDialog.unreadMessageCount = 0;
|
|
566
|
+
setNewDialog(updDialog);
|
|
567
|
+
informDataSources(updDialog);
|
|
564
568
|
},
|
|
565
569
|
dialogs,
|
|
566
570
|
loading,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
2
2
|
import React, { useEffect } from 'react';
|
|
3
|
-
import QB from 'quickblox/quickblox';
|
|
4
3
|
import './PreviewDialog.scss';
|
|
5
4
|
import { DialogType } from '../../../Domain/entity/DialogTypes';
|
|
6
5
|
import PreviewDialogViewModel from './PreviewDialogViewModel';
|
|
@@ -17,6 +16,7 @@ import DialogItemPreview from '../../ui-components/DialogItemPreview/DialogItemP
|
|
|
17
16
|
import Dropdown from '../../ui-components/Dropdown/Dropdown';
|
|
18
17
|
import { GroupChatSvg, MoreSvg, PublicChannelSvg, UserSvg } from '../../icons';
|
|
19
18
|
import Avatar from '../../ui-components/Avatar/Avatar';
|
|
19
|
+
import { getQB } from '../../../qb-api-calls';
|
|
20
20
|
|
|
21
21
|
export type ThemeNames = 'light' | 'dark' | 'custom';
|
|
22
22
|
type PreviewDialogsColorTheme = {
|
|
@@ -171,6 +171,7 @@ const PreviewDialog: React.FC<PreviewDialogsProps> = ({
|
|
|
171
171
|
|
|
172
172
|
async function getFileForPreview() {
|
|
173
173
|
const messageParts = getMessageParts(previewMessage || '');
|
|
174
|
+
const QB = getQB();
|
|
174
175
|
|
|
175
176
|
setMessageContentParts(messageParts);
|
|
176
177
|
|