Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
<a name="0.27.0"></a>
<a name="v0.27.0"></a>

## 0.27.0
## v0.27.0

### Chores

- new commands `npm run version:major`, `npm run version:minor`, and `npm run version:patch` to bump version in the `package.json`
- added new commands `npm run version:major`, `npm run version:minor`, and `npm run version:patch` to bump version in the `package.json`

### Code Refactoring

- 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;`

### Features

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

<a name="0.26.2"></a>
Expand Down
35 changes: 0 additions & 35 deletions bump-version.cjs

This file was deleted.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@
],
"scripts": {
"build": "rollup -c",
"version": "node bump-version.cjs",
"version": "node ./scripts/bump-version.cjs",
"version:patch": "npm run version patch",
"version:minor": "npm run version minor",
"version:major": "npm run version major",
"changelog": "node ./scripts/changelog.cjs",
"test": "vitest",
"test:ci": "vitest run",
"coverage": "vitest run --coverage"
Expand Down
45 changes: 45 additions & 0 deletions scripts/bump-version.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const fs = require('fs');
const path = require('path');

const arg = process.argv[2]; // major | minor | patch | <version>
if (!arg) {
console.error('Usage: node bump-version.cjs <major|minor|patch|x.y.z>');
process.exit(1);
}

const pkgPath = path.resolve(__dirname, '../package.json');
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));

let newVersion;

if (['major', 'minor', 'patch'].includes(arg)) {
const versionParts = pkg.version.split('.').map(Number);
let [major, minor, patch] = versionParts;

switch (arg) {
case 'major':
major += 1;
minor = 0;
patch = 0;
break;
case 'minor':
minor += 1;
patch = 0;
break;
case 'patch':
patch += 1;
break;
}

newVersion = `${major}.${minor}.${patch}`;
} else if (/^\d+\.\d+\.\d+$/.test(arg)) {
newVersion = arg;
} else {
console.error('❌ Invalid argument. Use major, minor, patch or x.y.z');
process.exit(1);
}

pkg.version = newVersion;
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');

console.log(`✅ Updated package.json version to ${newVersion}`);
26 changes: 26 additions & 0 deletions scripts/changelog.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const { execSync } = require('child_process');

const args = process.argv.slice(2);
let command;

if (args.length === 0) {
command = `git-chglog --output CHANGELOG.md`;
} else if (args[0] === 'latest') {
const latestTag = execSync('git describe --tags $(git rev-list --tags --max-count=1)', { shell: '/bin/bash' })
.toString().trim();
command = `git-chglog ${latestTag} --output CHANGELOG.md`;
} else if (args[0].includes('-')) {
const [from, to] = args[0].split('-');
command = `git-chglog v${from}..v${to} --output CHANGELOG.md`;
} else {
command = `git-chglog --next-tag v${args[0]} --output CHANGELOG.md`;
}

try {
console.log(`🚀 Running: ${command}`);
execSync(command, { stdio: 'inherit' });
console.log('✅ CHANGELOG.md generated');
} catch (err) {
console.error('❌ Failed to generate changelog:', err.message);
process.exit(1);
}
9 changes: 7 additions & 2 deletions src/ChatContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -431,15 +431,15 @@ export const ChatProvider = ({ children }: ChatProviderType): React.ReactElement
}));
};

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

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

const opponentId = getDialogOpponentId(dialog);
const messageId = _sendMessage(body, null, dialog, opponentId);
const messageId = _sendMessage(body, null, dialog, opponentId, extension);

_addMessageToStore(messageId, body, dialog._id, currentUserId as number, opponentId);
};
Expand Down Expand Up @@ -495,13 +495,15 @@ export const ChatProvider = ({ children }: ChatProviderType): React.ReactElement
attachments: Messages.Attachment[] | null,
dialog: Dialogs.Dialog,
opponentId?: number,
extension?: { [key: string]: any },
): string => {
const messageParams: Chat.MessageParams = {
type: dialog.type === DialogType.PRIVATE ? ChatType.CHAT : ChatType.GROUPCHAT,
body,
extension: {
save_to_history: 1,
dialog_id: dialog._id,
...extension,
},
};

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

setDialogs((prevDialogs) =>
prevDialogs
Expand All @@ -552,6 +556,7 @@ export const ChatProvider = ({ children }: ChatProviderType): React.ReactElement
[dialogId]: [
...(prevMessages[dialogId] || []),
{
...ext,
_id: messageId,
created_at: ts,
updated_at: ts,
Expand Down
2 changes: 1 addition & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export interface ChatContextType extends BlockListHook, UsersHookExports, Networ
removeUsersFromGroupChat: (usersIds: number[]) => Promise<void>;
leaveGroupChat: () => Promise<void>;
sendSignal: (userIdOrIds: number | number[], signal: string, params?: any) => void;
sendMessage: (body: string, dialog?: Dialogs.Dialog) => void;
sendMessage: (body: string, dialog?: Dialogs.Dialog, extension?: { [key: string]: any }) => void;
sendMessageWithAttachment: (files: File[], dialog?: Dialogs.Dialog) => Promise<void>;
readMessage: (messageId: string, userId: number, dialogId: string) => void;
addTempMessage: (tempId?: string, dialog?: Dialogs.Dialog, props?: any) => string;
Expand Down