deleted_mock
This commit is contained in:
parent
397d32623d
commit
de3c5b260c
@ -8,17 +8,10 @@ declare global {
|
|||||||
|
|
||||||
import { membersMock } from '../../mocks/mock-signature/membersMocks';
|
import { membersMock } from '../../mocks/mock-signature/membersMocks';
|
||||||
import { ApiReturn, Device, Member } from '../../../pkg/sdk_client';
|
import { ApiReturn, Device, Member } from '../../../pkg/sdk_client';
|
||||||
import {
|
|
||||||
Message,
|
|
||||||
DocumentSignature,
|
|
||||||
} from '../../models/signature.models';
|
|
||||||
import { messageStore } from '../../utils/messageMock';
|
|
||||||
import { Group } from '../../interface/groupInterface';
|
|
||||||
import { getCorrectDOM } from '../../utils/document.utils';
|
import { getCorrectDOM } from '../../utils/document.utils';
|
||||||
import chatStyle from '../../../public/style/chat.css?inline';
|
import chatStyle from '../../../public/style/chat.css?inline';
|
||||||
import { addressToEmoji } from '../../utils/sp-address.utils';
|
import { addressToEmoji } from '../../utils/sp-address.utils';
|
||||||
import Database from '../../services/database.service';
|
import Database from '../../services/database.service';
|
||||||
import Services from '../../services/service';
|
|
||||||
|
|
||||||
const storageUrl = `/storage`;
|
const storageUrl = `/storage`;
|
||||||
|
|
||||||
@ -49,13 +42,10 @@ class ChatElement extends HTMLElement {
|
|||||||
private sdkClient: any;
|
private sdkClient: any;
|
||||||
private processId: string | null = null;
|
private processId: string | null = null;
|
||||||
private selectedMemberId: string | null = null;
|
private selectedMemberId: string | null = null;
|
||||||
private messagesMock: any[] = [];
|
|
||||||
private dom: Node;
|
|
||||||
private notifications: LocalNotification[] = [];
|
private notifications: LocalNotification[] = [];
|
||||||
private notificationBadge = document.querySelector('.notification-badge');
|
private notificationBadge = document.querySelector('.notification-badge');
|
||||||
private notificationBoard = document.getElementById('notification-board');
|
private notificationBoard = document.getElementById('notification-board');
|
||||||
private notificationBell = document.getElementById('notification-bell');
|
private notificationBell = document.getElementById('notification-bell');
|
||||||
private selectedSignatories: DocumentSignature[] = [];
|
|
||||||
private allMembers = membersMock.map(member => ({
|
private allMembers = membersMock.map(member => ({
|
||||||
id: member.id,
|
id: member.id,
|
||||||
name: member.name,
|
name: member.name,
|
||||||
@ -68,14 +58,10 @@ class ChatElement extends HTMLElement {
|
|||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.attachShadow({ mode: 'open' });
|
this.attachShadow({ mode: 'open' });
|
||||||
this.messagesMock = messageStore.getMessages();
|
|
||||||
this.dom = getCorrectDOM('signature-element');
|
|
||||||
this.processId = this.getAttribute('process-id');
|
this.processId = this.getAttribute('process-id');
|
||||||
|
|
||||||
// Initialiser sdkClient
|
|
||||||
this.initSDKClient();
|
this.initSDKClient();
|
||||||
|
|
||||||
// Récupérer le processId depuis l'attribut du composant
|
|
||||||
console.log('🔍 Constructor - Process ID from element:', this.processId);
|
console.log('🔍 Constructor - Process ID from element:', this.processId);
|
||||||
|
|
||||||
this.shadowRoot!.innerHTML = `
|
this.shadowRoot!.innerHTML = `
|
||||||
@ -570,18 +556,15 @@ class ChatElement extends HTMLElement {
|
|||||||
|
|
||||||
const senderEmoji = await addressToEmoji(message.metadata.sender);
|
const senderEmoji = await addressToEmoji(message.metadata.sender);
|
||||||
|
|
||||||
// Vérifier si c'est un fichier
|
|
||||||
if (message.metadata.type === 'file') {
|
if (message.metadata.type === 'file') {
|
||||||
let fileContent = '';
|
let fileContent = '';
|
||||||
if (message.metadata.fileType.startsWith('image/')) {
|
if (message.metadata.fileType.startsWith('image/')) {
|
||||||
// Afficher l'image
|
|
||||||
fileContent = `
|
fileContent = `
|
||||||
<div class="file-preview">
|
<div class="file-preview">
|
||||||
<img src="${message.metadata.fileData}" alt="${message.metadata.fileName}" style="max-width: 200px; max-height: 200px;"/>
|
<img src="${message.metadata.fileData}" alt="${message.metadata.fileName}" style="max-width: 200px; max-height: 200px;"/>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
} else {
|
} else {
|
||||||
// Afficher un lien pour télécharger le fichier
|
|
||||||
const blob = this.base64ToBlob(message.metadata.fileData, message.metadata.fileType);
|
const blob = this.base64ToBlob(message.metadata.fileData, message.metadata.fileType);
|
||||||
const url = URL.createObjectURL(blob);
|
const url = URL.createObjectURL(blob);
|
||||||
fileContent = `
|
fileContent = `
|
||||||
@ -704,71 +687,6 @@ class ChatElement extends HTMLElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Toggle the list of Roles
|
|
||||||
private toggleRoles(group: Group, groupElement: HTMLElement) {
|
|
||||||
console.log('=== toggleRoles START ===');
|
|
||||||
console.log('Group:', group.name);
|
|
||||||
console.log('Group roles:', group.roles); // Afficher tous les rôles disponibles
|
|
||||||
|
|
||||||
let roleList = groupElement.querySelector('.role-list');
|
|
||||||
console.log('Existing roleList:', roleList);
|
|
||||||
|
|
||||||
if (roleList) {
|
|
||||||
const roleItems = roleList.querySelectorAll('.role-item');
|
|
||||||
roleItems.forEach(roleItem => {
|
|
||||||
console.log('Processing roleItem:', roleItem.innerHTML); // Voir le contenu HTML complet
|
|
||||||
|
|
||||||
let container = roleItem.querySelector('.role-item-container');
|
|
||||||
if (!container) {
|
|
||||||
container = document.createElement('div');
|
|
||||||
container.className = 'role-item-container';
|
|
||||||
|
|
||||||
// Créer un span pour le nom du rôle
|
|
||||||
const nameSpan = document.createElement('span');
|
|
||||||
nameSpan.className = 'role-name';
|
|
||||||
nameSpan.textContent = roleItem.textContent?.trim() || '';
|
|
||||||
|
|
||||||
container.appendChild(nameSpan);
|
|
||||||
roleItem.textContent = '';
|
|
||||||
roleItem.appendChild(container);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Récupérer le nom du rôle
|
|
||||||
const roleName = roleItem.textContent?.trim();
|
|
||||||
console.log('Role name from textContent:', roleName);
|
|
||||||
|
|
||||||
// Alternative pour obtenir le nom du rôle
|
|
||||||
const roleNameAlt = container.querySelector('.role-name')?.textContent;
|
|
||||||
console.log('Role name from span:', roleNameAlt);
|
|
||||||
|
|
||||||
if (!container.querySelector('.folder-icon')) {
|
|
||||||
const folderButton = document.createElement('span');
|
|
||||||
folderButton.className = 'folder-icon';
|
|
||||||
|
|
||||||
folderButton.addEventListener('click', (event) => {
|
|
||||||
event.stopPropagation();
|
|
||||||
console.log('Clicked role name:', roleName);
|
|
||||||
console.log('Available roles:', group.roles.map(r => r.name));
|
|
||||||
|
|
||||||
const role = group.roles.find(r => r.name === roleName);
|
|
||||||
if (role) {
|
|
||||||
console.log('Found role:', role);
|
|
||||||
} else {
|
|
||||||
console.error('Role not found. Name:', roleName);
|
|
||||||
console.error('Available roles:', group.roles);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
container.appendChild(folderButton);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
(roleList as HTMLElement).style.display =
|
|
||||||
(roleList as HTMLElement).style.display === 'none' ? 'block' : 'none';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private async loadGroupList(processId: string): Promise<void> {
|
private async loadGroupList(processId: string): Promise<void> {
|
||||||
console.log('Loading group list with processId:', processId);
|
console.log('Loading group list with processId:', processId);
|
||||||
const groupList = this.shadowRoot?.querySelector('#group-list');
|
const groupList = this.shadowRoot?.querySelector('#group-list');
|
||||||
@ -888,26 +806,6 @@ class ChatElement extends HTMLElement {
|
|||||||
(userList as HTMLElement).classList.toggle('show');
|
(userList as HTMLElement).classList.toggle('show');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate an automatic response
|
|
||||||
private generateAutoReply(senderName: string): Message {
|
|
||||||
const now = new Date();
|
|
||||||
const formattedTime = now.toLocaleString('fr-FR', {
|
|
||||||
day: '2-digit',
|
|
||||||
month: '2-digit',
|
|
||||||
year: 'numeric',
|
|
||||||
hour: '2-digit',
|
|
||||||
minute: '2-digit'
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
id: Date.now(),
|
|
||||||
sender: senderName,
|
|
||||||
text: "OK...",
|
|
||||||
time: formattedTime,
|
|
||||||
type: 'text' as const
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send a file
|
// Send a file
|
||||||
private async sendFile(file: File) {
|
private async sendFile(file: File) {
|
||||||
const MAX_FILE_SIZE = 1 * 1024 * 1024;
|
const MAX_FILE_SIZE = 1 * 1024 * 1024;
|
||||||
@ -1042,7 +940,6 @@ class ChatElement extends HTMLElement {
|
|||||||
const ctx = canvas.getContext('2d');
|
const ctx = canvas.getContext('2d');
|
||||||
|
|
||||||
img.onload = () => {
|
img.onload = () => {
|
||||||
// Calculer les nouvelles dimensions
|
|
||||||
let width = img.width;
|
let width = img.width;
|
||||||
let height = img.height;
|
let height = img.height;
|
||||||
const MAX_WIDTH = 800;
|
const MAX_WIDTH = 800;
|
||||||
@ -1064,7 +961,6 @@ class ChatElement extends HTMLElement {
|
|||||||
canvas.height = height;
|
canvas.height = height;
|
||||||
ctx?.drawImage(img, 0, 0, width, height);
|
ctx?.drawImage(img, 0, 0, width, height);
|
||||||
|
|
||||||
// Compression avec qualité réduite
|
|
||||||
resolve(canvas.toDataURL('image/jpeg', 0.7));
|
resolve(canvas.toDataURL('image/jpeg', 0.7));
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1149,7 +1045,6 @@ class ChatElement extends HTMLElement {
|
|||||||
|
|
||||||
private async initSDKClient() {
|
private async initSDKClient() {
|
||||||
try {
|
try {
|
||||||
// Récupérer l'instance du SDK depuis window ou l'initialiser
|
|
||||||
this.sdkClient = (window as any).sdk || await this.createSDKClient();
|
this.sdkClient = (window as any).sdk || await this.createSDKClient();
|
||||||
if (!this.sdkClient) {
|
if (!this.sdkClient) {
|
||||||
throw new Error('Failed to initialize SDK client');
|
throw new Error('Failed to initialize SDK client');
|
||||||
@ -1160,10 +1055,7 @@ class ChatElement extends HTMLElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async createSDKClient() {
|
private async createSDKClient() {
|
||||||
// Implémentez ici la logique de création du SDK client
|
|
||||||
// Ceci est un exemple, ajustez selon votre implémentation réelle
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
// Logique d'initialisation du SDK
|
|
||||||
resolve({
|
resolve({
|
||||||
is_paired: () => true,
|
is_paired: () => true,
|
||||||
create_new_process: async (template: string, parentId: string | null, relayAddress: string, feeRate: number) => {
|
create_new_process: async (template: string, parentId: string | null, relayAddress: string, feeRate: number) => {
|
||||||
@ -1173,46 +1065,9 @@ class ChatElement extends HTMLElement {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getExistingConversationProcess(memberId: string) {
|
|
||||||
const db = await Database.getInstance();
|
|
||||||
try {
|
|
||||||
const processStore = 'processes';
|
|
||||||
const conversations = [];
|
|
||||||
let i = 0;
|
|
||||||
let process;
|
|
||||||
|
|
||||||
|
|
||||||
do {
|
|
||||||
process = await db.getObject(processStore, i.toString());
|
|
||||||
if (process) {
|
|
||||||
conversations.push(process);
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
} while (process);
|
|
||||||
|
|
||||||
return conversations.find(process =>
|
|
||||||
process.description === 'messaging' &&
|
|
||||||
process.roles.owner.members.some((m: any) =>
|
|
||||||
m.sp_addresses.includes(memberId)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error getting conversation process:', error);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async getProcessFromDB(processId: string) {
|
|
||||||
const db = await Database.getInstance();
|
|
||||||
const processStore = 'processes';
|
|
||||||
const process = await db.getObject(processStore, processId);
|
|
||||||
console.log('📦 Process trouvé dans IndexedDB:', {
|
|
||||||
store: processStore,
|
|
||||||
processId: processId,
|
|
||||||
data: process
|
|
||||||
});
|
|
||||||
return process;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async getExistingMessageProcess(parentId: string, spAddresses: string[]): Promise<any> {
|
private async getExistingMessageProcess(parentId: string, spAddresses: string[]): Promise<any> {
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user