fix: solve small pm chat ui issues
unwrap the pill fix the fetching images in pm not auto download
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { getWatchedAttachmentRoomIdFromUrl, isDirectMessageAttachmentRoomId } from './attachment.logic';
|
||||
|
||||
describe('attachment logic', () => {
|
||||
it('extracts watched server room ids from room URLs', () => {
|
||||
expect(getWatchedAttachmentRoomIdFromUrl('/room/general')).toBe('general');
|
||||
expect(getWatchedAttachmentRoomIdFromUrl('/room/general/chat')).toBe('general');
|
||||
});
|
||||
|
||||
it('extracts watched direct-message storage ids from DM URLs', () => {
|
||||
expect(getWatchedAttachmentRoomIdFromUrl('/dm/alice%3Abob')).toBe('direct-message:alice:bob');
|
||||
expect(getWatchedAttachmentRoomIdFromUrl('/pm/dm-group-1?tab=chat')).toBe('direct-message:dm-group-1');
|
||||
});
|
||||
|
||||
it('ignores non-message URLs', () => {
|
||||
expect(getWatchedAttachmentRoomIdFromUrl('/settings')).toBeNull();
|
||||
expect(getWatchedAttachmentRoomIdFromUrl('/dm')).toBeNull();
|
||||
});
|
||||
|
||||
it('identifies direct-message attachment storage ids', () => {
|
||||
expect(isDirectMessageAttachmentRoomId('direct-message:alice:bob')).toBe(true);
|
||||
expect(isDirectMessageAttachmentRoomId('room-1')).toBe(false);
|
||||
expect(isDirectMessageAttachmentRoomId(null)).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -1,6 +1,10 @@
|
||||
import { MAX_AUTO_SAVE_SIZE_BYTES } from '../constants/attachment.constants';
|
||||
import type { Attachment } from '../models/attachment.model';
|
||||
|
||||
const ROOM_URL_PATTERN = /\/room\/([^/]+)/;
|
||||
const DIRECT_MESSAGE_URL_PATTERN = /^\/(?:dm|pm)\/([^/]+)/;
|
||||
const DIRECT_MESSAGE_ATTACHMENT_STORAGE_PREFIX = 'direct-message:';
|
||||
|
||||
export function isAttachmentMedia(attachment: Pick<Attachment, 'mime'>): boolean {
|
||||
return attachment.mime.startsWith('image/') ||
|
||||
attachment.mime.startsWith('video/') ||
|
||||
@@ -17,3 +21,28 @@ export function shouldPersistDownloadedAttachment(attachment: Pick<Attachment, '
|
||||
attachment.mime.startsWith('video/') ||
|
||||
attachment.mime.startsWith('audio/');
|
||||
}
|
||||
|
||||
export function getWatchedAttachmentRoomIdFromUrl(url: string): string | null {
|
||||
const path = url.split(/[?#]/, 1)[0];
|
||||
const directMessageMatch = path.match(DIRECT_MESSAGE_URL_PATTERN);
|
||||
|
||||
if (directMessageMatch) {
|
||||
return `${DIRECT_MESSAGE_ATTACHMENT_STORAGE_PREFIX}${decodeUrlSegment(directMessageMatch[1])}`;
|
||||
}
|
||||
|
||||
const roomMatch = path.match(ROOM_URL_PATTERN);
|
||||
|
||||
return roomMatch ? decodeUrlSegment(roomMatch[1]) : null;
|
||||
}
|
||||
|
||||
export function isDirectMessageAttachmentRoomId(roomId: string | null | undefined): boolean {
|
||||
return !!roomId && roomId.startsWith(DIRECT_MESSAGE_ATTACHMENT_STORAGE_PREFIX);
|
||||
}
|
||||
|
||||
function decodeUrlSegment(value: string): string {
|
||||
try {
|
||||
return decodeURIComponent(value);
|
||||
} catch {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user