Skip to content
Open
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
44 changes: 24 additions & 20 deletions packages/api/src/EmbeddedChatApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export default class EmbeddedChatApi {
async login(userOrEmail: string, password: string, code: string) {
let credentials;
if (!code) {
credentials = credentials = {
credentials = {
user: userOrEmail.trim(),
password,
};
Expand Down Expand Up @@ -351,33 +351,37 @@ export default class EmbeddedChatApi {
);
}

handleTypingEvent({
async handleTypingEvent({
typingUser,
isTyping,
}: {
typingUser: string;
isTyping: boolean;
}) {
// don't wait for more than 2 seconds. Though in practical, the waiting time is insignificant.
setTimeout(() => {
typingHandlerLock = 0;
}, 2000);
// eslint-disable-next-line no-empty
while (typingHandlerLock) {}
typingHandlerLock = 1;
// move user to front if typing else remove it.
const idx = this.typingUsers.indexOf(typingUser);
if (idx !== -1) {
this.typingUsers.splice(idx, 1);
// wait for lock to release
while (typingHandlerLock) {
await new Promise((resolve) => setTimeout(resolve, 100));
}
if (isTyping) {
this.typingUsers.unshift(typingUser);

typingHandlerLock = 1;

try {
// move user to front if typing else remove it.
const idx = this.typingUsers.indexOf(typingUser);
if (idx !== -1) {
this.typingUsers.splice(idx, 1);
}
if (isTyping) {
this.typingUsers.unshift(typingUser);
}

const newTypingStatus = cloneArray(this.typingUsers);
this.onTypingStatusCallbacks.forEach((callback) =>
callback(newTypingStatus)
);
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The async method can throw errors, but there's no error handling in the try block, and callers don't await the promise. If an error occurs while manipulating typingUsers or invoking callbacks (e.g., if a callback throws), it will result in an unhandled promise rejection. Consider adding a catch block to log errors or handle them gracefully.

Suggested change
);
);
} catch (error) {
console.error("Error while handling typing event:", error);

Copilot uses AI. Check for mistakes.
} finally {
typingHandlerLock = 0;
}
typingHandlerLock = 0;
const newTypingStatus = cloneArray(this.typingUsers);
this.onTypingStatusCallbacks.forEach((callback) =>
callback(newTypingStatus)
);
}

async getRCAppInfo() {
Expand Down
Loading