Skip to content

Commit 34d173f

Browse files
authored
Merge pull request #52 from ConnectyCube/rc-0.27.0
Rc 0.27.0 update
2 parents eb255a4 + 049fbd8 commit 34d173f

File tree

7 files changed

+89
-43
lines changed

7 files changed

+89
-43
lines changed

CHANGELOG.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
<a name="0.27.0"></a>
1+
<a name="v0.27.0"></a>
22

3-
## 0.27.0
3+
## v0.27.0
44

55
### Chores
66

7-
- new commands `npm run version:major`, `npm run version:minor`, and `npm run version:patch` to bump version in the `package.json`
7+
- added new commands `npm run version:major`, `npm run version:minor`, and `npm run version:patch` to bump version in the `package.json`
8+
9+
### Code Refactoring
10+
11+
- the method sendMessage can add an extension object to a sending message as third parameter. `sendMessage: (body: string, dialog?: Dialogs.Dialog, extension?: { [key: string]: any }) => void;`
812

913
### Features
1014

11-
- new method `generateTempMessageId` to create custom/temporary identifier for message
15+
- new method `generateTempMessageId` to create a custom/temporary identifier for a message
1216
- add `addTempMessage` and `updateTempMessage` methods to create and update a temporary custom message in chat messages
1317

1418
<a name="0.26.2"></a>

bump-version.cjs

Lines changed: 0 additions & 35 deletions
This file was deleted.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@
3333
],
3434
"scripts": {
3535
"build": "rollup -c",
36-
"version": "node bump-version.cjs",
36+
"version": "node ./scripts/bump-version.cjs",
3737
"version:patch": "npm run version patch",
3838
"version:minor": "npm run version minor",
3939
"version:major": "npm run version major",
40+
"changelog": "node ./scripts/changelog.cjs",
4041
"test": "vitest",
4142
"test:ci": "vitest run",
4243
"coverage": "vitest run --coverage"

scripts/bump-version.cjs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
const arg = process.argv[2]; // major | minor | patch | <version>
5+
if (!arg) {
6+
console.error('Usage: node bump-version.cjs <major|minor|patch|x.y.z>');
7+
process.exit(1);
8+
}
9+
10+
const pkgPath = path.resolve(__dirname, '../package.json');
11+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
12+
13+
let newVersion;
14+
15+
if (['major', 'minor', 'patch'].includes(arg)) {
16+
const versionParts = pkg.version.split('.').map(Number);
17+
let [major, minor, patch] = versionParts;
18+
19+
switch (arg) {
20+
case 'major':
21+
major += 1;
22+
minor = 0;
23+
patch = 0;
24+
break;
25+
case 'minor':
26+
minor += 1;
27+
patch = 0;
28+
break;
29+
case 'patch':
30+
patch += 1;
31+
break;
32+
}
33+
34+
newVersion = `${major}.${minor}.${patch}`;
35+
} else if (/^\d+\.\d+\.\d+$/.test(arg)) {
36+
newVersion = arg;
37+
} else {
38+
console.error('❌ Invalid argument. Use major, minor, patch or x.y.z');
39+
process.exit(1);
40+
}
41+
42+
pkg.version = newVersion;
43+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
44+
45+
console.log(`✅ Updated package.json version to ${newVersion}`);

scripts/changelog.cjs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const { execSync } = require('child_process');
2+
3+
const args = process.argv.slice(2);
4+
let command;
5+
6+
if (args.length === 0) {
7+
command = `git-chglog --output CHANGELOG.md`;
8+
} else if (args[0] === 'latest') {
9+
const latestTag = execSync('git describe --tags $(git rev-list --tags --max-count=1)', { shell: '/bin/bash' })
10+
.toString().trim();
11+
command = `git-chglog ${latestTag} --output CHANGELOG.md`;
12+
} else if (args[0].includes('-')) {
13+
const [from, to] = args[0].split('-');
14+
command = `git-chglog v${from}..v${to} --output CHANGELOG.md`;
15+
} else {
16+
command = `git-chglog --next-tag v${args[0]} --output CHANGELOG.md`;
17+
}
18+
19+
try {
20+
console.log(`🚀 Running: ${command}`);
21+
execSync(command, { stdio: 'inherit' });
22+
console.log('✅ CHANGELOG.md generated');
23+
} catch (err) {
24+
console.error('❌ Failed to generate changelog:', err.message);
25+
process.exit(1);
26+
}

src/ChatContext.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,15 +431,15 @@ export const ChatProvider = ({ children }: ChatProviderType): React.ReactElement
431431
}));
432432
};
433433

434-
const sendMessage = (body: string, dialog?: Dialogs.Dialog) => {
434+
const sendMessage = (body: string, dialog?: Dialogs.Dialog, extension: { [key: string]: any } = {}) => {
435435
dialog ??= selectedDialog;
436436

437437
if (!dialog) {
438438
throw "No dialog provided. You need to provide a dialog via function argument or select a dialog via 'selectDialog'.";
439439
}
440440

441441
const opponentId = getDialogOpponentId(dialog);
442-
const messageId = _sendMessage(body, null, dialog, opponentId);
442+
const messageId = _sendMessage(body, null, dialog, opponentId, extension);
443443

444444
_addMessageToStore(messageId, body, dialog._id, currentUserId as number, opponentId);
445445
};
@@ -495,13 +495,15 @@ export const ChatProvider = ({ children }: ChatProviderType): React.ReactElement
495495
attachments: Messages.Attachment[] | null,
496496
dialog: Dialogs.Dialog,
497497
opponentId?: number,
498+
extension?: { [key: string]: any },
498499
): string => {
499500
const messageParams: Chat.MessageParams = {
500501
type: dialog.type === DialogType.PRIVATE ? ChatType.CHAT : ChatType.GROUPCHAT,
501502
body,
502503
extension: {
503504
save_to_history: 1,
504505
dialog_id: dialog._id,
506+
...extension,
505507
},
506508
};
507509

@@ -525,8 +527,10 @@ export const ChatProvider = ({ children }: ChatProviderType): React.ReactElement
525527
recipientId?: number,
526528
attachments?: Messages.Attachment[],
527529
isLoading?: boolean,
530+
extension?: { [key: string]: any },
528531
) => {
529532
const ts = Math.round(new Date().getTime() / 1000);
533+
const ext = extension || {};
530534

531535
setDialogs((prevDialogs) =>
532536
prevDialogs
@@ -552,6 +556,7 @@ export const ChatProvider = ({ children }: ChatProviderType): React.ReactElement
552556
[dialogId]: [
553557
...(prevMessages[dialogId] || []),
554558
{
559+
...ext,
555560
_id: messageId,
556561
created_at: ts,
557562
updated_at: ts,

src/types/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export interface ChatContextType extends BlockListHook, UsersHookExports, Networ
3939
removeUsersFromGroupChat: (usersIds: number[]) => Promise<void>;
4040
leaveGroupChat: () => Promise<void>;
4141
sendSignal: (userIdOrIds: number | number[], signal: string, params?: any) => void;
42-
sendMessage: (body: string, dialog?: Dialogs.Dialog) => void;
42+
sendMessage: (body: string, dialog?: Dialogs.Dialog, extension?: { [key: string]: any }) => void;
4343
sendMessageWithAttachment: (files: File[], dialog?: Dialogs.Dialog) => Promise<void>;
4444
readMessage: (messageId: string, userId: number, dialogId: string) => void;
4545
addTempMessage: (tempId?: string, dialog?: Dialogs.Dialog, props?: any) => string;

0 commit comments

Comments
 (0)