Skip to content

Commit 24f2252

Browse files
v0.2.3
1 parent 73684d3 commit 24f2252

22 files changed

+650
-193
lines changed

package-lock.json

Lines changed: 29 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "quickblox-react-ui-kit",
3-
"version": "0.2.2",
3+
"version": "0.2.3",
44
"main": "dist/index-ui.js",
55
"license": "MIT",
66
"dependencies": {

src/App.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ function App() {
191191

192192
useEffect(() => {
193193
console.log('0. APP INIT');
194-
prepareSDK(currentUser).catch();
194+
prepareSDK(currentUser).catch((er) => {
195+
console.log(er);
196+
});
195197
}, []);
196198
//
197199
// const { proxyConfig } = QBConfig.configAIApi.AIAnswerAssistWidgetConfig;

src/Data/source/remote/Mapper/DialogDTOMapper.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ export class DialogDTOMapper implements IDTOMapper {
6161
dto.lastMessageId = qbDialog.last_message_id || '';
6262
dto.lastMessageText = qbDialog.last_message as string;
6363
dto.lastMessageDateSent = qbDialog.last_message_date_sent as string;
64+
// dto.lastMessageDateSent = (
65+
// parseInt(qbDialog.last_message_date_sent || '0', 10) * 1000
66+
// ).toString();
6467
dto.lastMessageUserId =
6568
qbDialog.last_message_user_id === null
6669
? ''

src/Data/source/remote/Mapper/MessageDTOMapper.ts

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ export class MessageDTOMapper implements IDTOMapper {
3939
}
4040

4141
// eslint-disable-next-line class-methods-use-this
42-
public static transformAttachment(qbAtts: ChatMessageAttachment[]) {
42+
public static transformAttachment(
43+
qbMessage: string,
44+
qbAtts: ChatMessageAttachment[],
45+
) {
4346
const result: ChatMessageAttachmentEntity[] = qbAtts.map((item) => {
4447
const newItem: ChatMessageAttachmentEntity = {
4548
id: item.id,
@@ -57,6 +60,25 @@ export class MessageDTOMapper implements IDTOMapper {
5760
url: item.uid && QB.content.privateUrl(item.uid),
5861
},
5962
};
63+
const messageParts = MessageDTOMapper.getMessageParts(qbMessage);
64+
65+
if (messageParts && messageParts.length > 0) {
66+
// val messageBody = "${MediaContentEntity::class.java.simpleName}|$fileName|$uid|$fileMimeType"
67+
// 0, 1, 2, 3
68+
// eslint-disable-next-line prefer-destructuring
69+
newItem.uid = messageParts[2];
70+
// eslint-disable-next-line prefer-destructuring
71+
newItem.name = messageParts[1];
72+
// eslint-disable-next-line prefer-destructuring
73+
newItem.type = messageParts[3];
74+
newItem.url = newItem.uid && QB.content.privateUrl(newItem.uid);
75+
if (newItem.file) {
76+
newItem.file.uid = newItem.uid;
77+
newItem.file.name = newItem.name;
78+
newItem.file.url = newItem.uid && QB.content.privateUrl(newItem.uid);
79+
newItem.file.type = newItem.type;
80+
}
81+
}
6082

6183
return newItem;
6284
});
@@ -74,14 +96,15 @@ export class MessageDTOMapper implements IDTOMapper {
7496

7597
dto.id = qbMessage._id;
7698
dto.dialogId = qbMessage.chat_dialog_id;
77-
dto.message = qbMessage.message;
99+
dto.message = MessageDTOMapper.formatMessage(qbMessage.message);
78100
dto.created_at = qbMessage.created_at;
79101
dto.date_sent = qbMessage.date_sent * 1000;
80102
dto.delivered_ids = qbMessage.delivered_ids ? qbMessage.delivered_ids : [];
81103
dto.read_ids = qbMessage.read_ids ? qbMessage.read_ids : [];
82104

83105
dto.recipient_id = qbMessage.recipient_id ? qbMessage.recipient_id : 0;
84106
dto.attachments = MessageDTOMapper.transformAttachment(
107+
qbMessage.message,
85108
qbMessage.attachments ? qbMessage.attachments : [],
86109
);
87110
dto.read = qbMessage.read;
@@ -98,6 +121,36 @@ export class MessageDTOMapper implements IDTOMapper {
98121
return Promise.resolve(dto as TResult);
99122
}
100123

124+
public static formatMessage(qbMessage: string) {
125+
if (
126+
qbMessage.includes('MediaContentEntity') ||
127+
qbMessage.includes('[Attachment]')
128+
) {
129+
const messageParts = qbMessage.split('|');
130+
131+
// val messageBody = "${MediaContentEntity::class.java.simpleName}|$fileName|$uid|$fileMimeType"
132+
// 0, 1, 2, 3
133+
return messageParts[1] || '';
134+
}
135+
136+
return qbMessage;
137+
}
138+
139+
private static getMessageParts(qbMessage: string) {
140+
if (
141+
qbMessage.includes('MediaContentEntity') ||
142+
qbMessage.includes('[Attachment]')
143+
) {
144+
const messageParts = qbMessage.split('|');
145+
146+
// val messageBody = "${MediaContentEntity::class.java.simpleName}|$fileName|$uid|$fileMimeType"
147+
// 0, 1, 2, 3
148+
return messageParts;
149+
}
150+
151+
return [];
152+
}
153+
101154
private static validateDTO(messageDTO: RemoteMessageDTO) {
102155
const messageDTOValidator: DtoValidator<RemoteMessageDTO> = {
103156
created_at(v: unknown): v is RemoteMessageDTO['created_at'] {

src/Data/source/remote/RemoteDataSource.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ export class RemoteDataSource implements IRemoteDataSource {
371371
const resultMessage = new RemoteMessageDTO();
372372

373373
resultMessage.id = message.id;
374-
resultMessage.message = message.body;
374+
resultMessage.message = MessageDTOMapper.formatMessage(message.body);
375375
resultMessage.markable = message.markable
376376
? message.markable.toString()
377377
: '0';
@@ -394,6 +394,7 @@ export class RemoteDataSource implements IRemoteDataSource {
394394

395395
// resultMessage.attachments = message.extension.attachments || [];
396396
resultMessage.attachments = MessageDTOMapper.transformAttachment(
397+
message.body,
397398
message.extension.attachments ? message.extension.attachments : [],
398399
);
399400

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// eslint-disable-next-line import/extensions
2+
import { AISource, IChatMessage } from '../../../Data/source/AISource';
3+
import { IUseCase } from '../base/IUseCase';
4+
import {
5+
Tone,
6+
toneToString,
7+
} from '../../../Presentation/components/UI/Dialogs/MessagesView/AIWidgets/Tone';
8+
9+
export class AIRephraseUseCase implements IUseCase<void, string> {
10+
private textToSend: string;
11+
12+
private tone: Tone;
13+
14+
private dialogMessages: IChatMessage[];
15+
16+
private servername: string;
17+
18+
private api: string;
19+
20+
private port: string;
21+
22+
private sessionToken: string;
23+
24+
private openAIModel: string;
25+
26+
constructor(
27+
textToSend: string,
28+
tone: Tone,
29+
dialogMessages: IChatMessage[],
30+
servername: string,
31+
api: string,
32+
port: string,
33+
sessionToken: string,
34+
openAIModel = 'gpt-3.5-turbo',
35+
) {
36+
console.log('CONSTRUCTOR AIRephraseUseCase');
37+
this.api = api;
38+
this.openAIModel = openAIModel;
39+
this.port = port;
40+
this.sessionToken = sessionToken;
41+
this.textToSend = textToSend;
42+
this.tone = tone;
43+
this.servername = servername;
44+
this.dialogMessages = dialogMessages;
45+
}
46+
47+
async execute(): Promise<string> {
48+
console.log('execute AIRephraseUseCase');
49+
50+
let prompt = `Analyze the entire context of our conversation – all the messages – and create a brief summary of our discussion. Based on this analysis, rephrase the following text in a style and tone that is typical for most of the dialogue messages. Provide only the rephrased text in as the message text to rephrase and nothing more.Give me only rephrase text in brackets and nothing more. Here is the message text to rephrase:"${this.textToSend}"`;
51+
52+
if (this.tone) {
53+
prompt = `Analyze the entire context of our conversation – all the messages – and create a brief summary of our discussion. Based on this analysis, rephrase the following text in a ${toneToString(
54+
this.tone,
55+
)} style. Provide only the rephrased text in the same language as the message text to rephrase and nothing more.Give me only rephrase text in brackets and nothing more. Here is the message text to rephrase:"${
56+
this.textToSend
57+
}"`;
58+
}
59+
//
60+
61+
// return await AISource.getData(
62+
// prompt,
63+
// // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
64+
// context,
65+
// servername,
66+
// api,
67+
// port,
68+
// apiKeyOrSessionToken,
69+
// ).then((data) => {
70+
// setTextFromWidgetToContent(data);
71+
//
72+
// return data;
73+
// });
74+
75+
//
76+
return AISource.getData(
77+
prompt,
78+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
79+
this.dialogMessages,
80+
this.servername,
81+
this.api,
82+
this.port,
83+
this.sessionToken,
84+
this.openAIModel,
85+
);
86+
}
87+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// eslint-disable-next-line import/extensions
2+
import { AISource, IChatMessage } from '../../../Data/source/AISource';
3+
import { IUseCase } from '../base/IUseCase';
4+
import {
5+
Tone,
6+
toneToString,
7+
} from '../../../Presentation/components/UI/Dialogs/MessagesView/AIWidgets/Tone';
8+
9+
export class AIRephraseWithProxyUseCase implements IUseCase<void, string> {
10+
private textToSend: string;
11+
12+
private tone: Tone;
13+
14+
private dialogMessages: IChatMessage[];
15+
16+
private servername: string;
17+
18+
private api: string;
19+
20+
private port: string;
21+
22+
private sessionToken: string;
23+
24+
private openAIModel: string;
25+
26+
constructor(
27+
textToSend: string,
28+
tone: Tone,
29+
dialogMessages: IChatMessage[],
30+
servername: string,
31+
api: string,
32+
port: string,
33+
sessionToken: string,
34+
openAIModel = 'gpt-3.5-turbo',
35+
) {
36+
console.log('CONSTRUCTOR AIRephraseUseCase');
37+
this.api = api;
38+
this.openAIModel = openAIModel;
39+
this.port = port;
40+
this.sessionToken = sessionToken;
41+
this.textToSend = textToSend;
42+
this.tone = tone;
43+
this.servername = servername;
44+
this.dialogMessages = dialogMessages;
45+
}
46+
47+
async execute(): Promise<string> {
48+
console.log('execute AIRephraseUseCase');
49+
50+
let prompt = `Analyze the entire context of our conversation – all the messages – and create a brief summary of our discussion. Based on this analysis, rephrase the following text in a style and tone that is typical for most of the dialogue messages. Provide only the rephrased text in as the message text to rephrase and nothing more.Give me only rephrase text in brackets and nothing more. Here is the message text to rephrase:"${this.textToSend}"`;
51+
52+
if (this.tone) {
53+
prompt = `Analyze the entire context of our conversation – all the messages – and create a brief summary of our discussion. Based on this analysis, rephrase the following text in a ${toneToString(
54+
this.tone,
55+
)} style. Provide only the rephrased text in the same language as the message text to rephrase and nothing more.Give me only rephrase text in brackets and nothing more. Here is the message text to rephrase:"${
56+
this.textToSend
57+
}"`;
58+
}
59+
60+
return AISource.getDataWithProxyServer(
61+
prompt,
62+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
63+
this.dialogMessages,
64+
this.servername,
65+
this.api,
66+
this.port,
67+
this.sessionToken,
68+
this.openAIModel,
69+
);
70+
}
71+
}

0 commit comments

Comments
 (0)