Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/fix_pmp_id_handling.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
default: patch
---

fix id handling and id generation for Personas
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from '$hooks/usePerMessageProfile';
import { useEffect, useState } from 'react';
import { Box, Button, Text } from 'folds';
import { generateShortId } from '$utils/shortIdGen';
import { PerMessageProfileEditor } from './PerMessageProfileEditor';

/**
Expand Down Expand Up @@ -36,7 +37,7 @@ export function PerMessageProfileOverview() {
<Button
onClick={() => {
const newProfile: PerMessageProfile = {
id: crypto.randomUUID(),
id: generateShortId(5),
name: 'New Profile',
};
addOrUpdatePerMessageProfile(mx, newProfile).then(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/app/hooks/useCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ const FLAG_PAT = String.raw`(?:^|\s)-(\w+)\b`;
const FLAG_REG = new RegExp(FLAG_PAT);
const FLAG_REG_G = new RegExp(FLAG_PAT, 'g');

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

export const splitPayloadContentAndFlags = (payload: string): [string, string | undefined] => {
const flagMatch = new RegExp(FLAG_REG).exec(payload);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from '$hooks/usePerMessageProfile';
import { sendFeedback } from '$utils/sendFeedbackToUser';
import { MatrixClient, Room } from 'matrix-js-sdk';
import { generateShortId } from '$utils/shortIdGen';

const pkMemberRenameRegex = /^(pk;member)\s+"?([\w\s]+)"?\s*rename\s+"?([\w\s]+)"?$/;
const pkMemberNewRegex = /^(pk;member)\s+new\s+"?([\w\s]+)"?$/;
Expand Down Expand Up @@ -90,7 +91,7 @@ export class PKitCommandMessageHandler {
return;
}
const memberName = cmdParts[2];
const generatedID = crypto.randomUUID();
const generatedID = generateShortId(5);
sendFeedback(
`adding new member has been created with id: ${generatedID} and name ${memberName}`,
this.room,
Expand Down
4 changes: 4 additions & 0 deletions src/app/utils/shortIdGen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export function generateShortId(length: number): string {
const uuid = crypto.randomUUID();
return uuid.replaceAll('-', '').substring(0, length);
}
Loading