Skip to content
Merged
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
10 changes: 7 additions & 3 deletions web/pages/messages/[channelId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ export function PrivateMessagesContent(props: {user: User; channelId: number}) {
)
}

export const getFirstName = (name: string) => {
const parts = name.trim().split(/\s+/)
const first = parts[0].endsWith('.') && parts.length > 1 ? parts.slice(0, 2).join(' ') : parts[0]
return first
}
Comment on lines +104 to +108

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Add docstring for the exported getFirstName function.

This exported function lacks a docstring explaining its purpose and the special period-handling logic. As per coding guidelines, all public functions should have docstrings.

📝 Suggested docstring
+/**
+ * Extracts the first name from a full name string.
+ * If the first token ends with a period (e.g., "Dr."), returns the first two tokens.
+ * `@param` name - The full name to parse
+ * `@returns` The first name or prefix + first name (e.g., "Dr. John")
+ */
 export const getFirstName = (name: string) => {
   const parts = name.trim().split(/\s+/)
   const first = parts[0].endsWith('.') && parts.length > 1 ? parts.slice(0, 2).join(' ') : parts[0]
   return first
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const getFirstName = (name: string) => {
const parts = name.trim().split(/\s+/)
const first = parts[0].endsWith('.') && parts.length > 1 ? parts.slice(0, 2).join(' ') : parts[0]
return first
}
/**
* Extracts the first name from a full name string.
* If the first token ends with a period (e.g., "Dr."), returns the first two tokens.
* `@param` name - The full name to parse
* `@returns` The first name or prefix + first name (e.g., "Dr. John")
*/
export const getFirstName = (name: string) => {
const parts = name.trim().split(/\s+/)
const first = parts[0].endsWith('.') && parts.length > 1 ? parts.slice(0, 2).join(' ') : parts[0]
return first
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@web/pages/messages/`[channelId].tsx around lines 104 - 108, Add a docstring
to the exported function getFirstName explaining its purpose (returns the first
name portion from a full name string), describing the trimming/splitting
behavior, and documenting the special-case logic that if the first token ends
with a period and there is more than one token it returns the first two tokens
joined (e.g., "J. R. Smith" -> "J. R."). Keep the docstring concise, include
parameter and return descriptions for name: string and the returned string, and
place it immediately above the getFirstName function declaration.

Source: Coding guidelines


export const PrivateChat = (props: {
user: User
channel: PrivateMessageChannel
Expand Down Expand Up @@ -290,9 +296,7 @@ export const PrivateChat = (props: {
>
{members
.map((user) =>
user.name
? user.name.split(' ')[0].trim()
: t('messages.deleted_user', 'Deleted user'),
user.name ? getFirstName(user.name) : t('messages.deleted_user', 'Deleted user'),
)
.slice(0, 2)
.join(', ')}
Expand Down
Loading