Skip to content

Commit dae8e6a

Browse files
committed
fix(PMP, ID): changed pmp id handling and generation
1 parent a8ddeb6 commit dae8e6a

5 files changed

Lines changed: 15 additions & 4 deletions

File tree

.changeset/fix_pmp_id_handling.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
default: patch
3+
---
4+
5+
fix id handling and id generation for Personas

src/app/features/settings/Persona/PerMessageProfileOverview.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
} from '$hooks/usePerMessageProfile';
77
import { useEffect, useState } from 'react';
88
import { Box, Button, Text } from 'folds';
9+
import { generateShortId } from '$utils/shortIdGen';
910
import { PerMessageProfileEditor } from './PerMessageProfileEditor';
1011

1112
/**
@@ -36,7 +37,7 @@ export function PerMessageProfileOverview() {
3637
<Button
3738
onClick={() => {
3839
const newProfile: PerMessageProfile = {
39-
id: crypto.randomUUID(),
40+
id: generateShortId(5),
4041
name: 'New Profile',
4142
};
4243
addOrUpdatePerMessageProfile(mx, newProfile).then(() => {

src/app/hooks/useCommands.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ const FLAG_PAT = String.raw`(?:^|\s)-(\w+)\b`;
5151
const FLAG_REG = new RegExp(FLAG_PAT);
5252
const FLAG_REG_G = new RegExp(FLAG_PAT, 'g');
5353

54-
const ADDPMP_REGEX = /(\w+) (name=)?"?([\w\s]*)"? (avatar=)?([\w.:/]+)/;
55-
const USEPMP_REGEX = /^(\w+)\s*(-g)?(-o)?(-u)?\s*(\d+)?$/;
54+
const ADDPMP_REGEX = /(\S+) (name=)?"?([\w\s]*)"? (avatar=)?([\w.:/]+)/;
55+
const USEPMP_REGEX = /^(\S+)\s*(-g)?(-o)?(-u)?\s*(\d+)?$/;
5656

5757
export const splitPayloadContentAndFlags = (payload: string): [string, string | undefined] => {
5858
const flagMatch = new RegExp(FLAG_REG).exec(payload);

src/app/plugins/pluralkit-handler/PKitCommandMessageHandler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
} from '$hooks/usePerMessageProfile';
99
import { sendFeedback } from '$utils/sendFeedbackToUser';
1010
import { MatrixClient, Room } from 'matrix-js-sdk';
11+
import { generateShortId } from '$utils/shortIdGen';
1112

1213
const pkMemberRenameRegex = /^(pk;member)\s+"?([\w\s]+)"?\s*rename\s+"?([\w\s]+)"?$/;
1314
const pkMemberNewRegex = /^(pk;member)\s+new\s+"?([\w\s]+)"?$/;
@@ -90,7 +91,7 @@ export class PKitCommandMessageHandler {
9091
return;
9192
}
9293
const memberName = cmdParts[2];
93-
const generatedID = crypto.randomUUID();
94+
const generatedID = generateShortId(5);
9495
sendFeedback(
9596
`adding new member has been created with id: ${generatedID} and name ${memberName}`,
9697
this.room,

src/app/utils/shortIdGen.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export function generateShortId(length: number): string {
2+
const uuid = crypto.randomUUID();
3+
return uuid.replaceAll('-', '').substring(0, length);
4+
}

0 commit comments

Comments
 (0)