mattermost-mobile-upstream/app/utils/channel_bookmark.ts
yasser khan d295fa1c9e
Limit bookmark names to the server's 64 characters (#10211)
Adding a link bookmark fills the name from the page's title and saved it as is.
The server rejects a display name longer than 64 characters
(model.DisplayNameMaxRunes) with only "Could not save bookmark", so bookmarking
a page with a long title failed. mattermost.com's title is now 93 characters,
which is why channel_bookmark_link_external started failing on iOS and Android.

Names from a page title, a file name or typing are cut to 64 characters,
counted as the server counts them so a character is never split, and the name
field takes at most 64, as in the webapp.
2026-10-04 10:23:59 +05:30

21 lines
859 B
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
// The server rejects a bookmark whose display name is longer than this many
// characters (model.DisplayNameMaxRunes), with only a generic "Could not save bookmark."
export const BOOKMARK_DISPLAY_NAME_MAX_LENGTH = 64;
/**
* A display name the server accepts. Names are filled in from a page title or a
* file name, either of which can be longer than the server allows. Counts code
* points, as the server does, so an emoji or other character outside the BMP is
* never split.
*/
export function limitBookmarkDisplayName(name: string): string {
const chars = Array.from(name);
if (chars.length <= BOOKMARK_DISPLAY_NAME_MAX_LENGTH) {
return name;
}
return chars.slice(0, BOOKMARK_DISPLAY_NAME_MAX_LENGTH).join('');
}