mirror of
https://github.com/mattermost/mattermost-mobile.git
synced 2026-11-05 18:38:54 +00:00
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.
21 lines
859 B
TypeScript
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('');
|
|
}
|