From f836df391bf7baf03037fca7152d253ca7ee0c49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noel=20Mar=C3=B3ti?= Date: Sat, 28 Nov 2026 07:13:31 +0100 Subject: [PATCH] Renamed DmList to ContactList and updated logic to V3 --- src/app/chat/contact-list/contact-list.html | 31 ++++++++++ .../contact-list.scss} | 0 .../contact-list.spec.ts} | 10 +-- src/app/chat/contact-list/contact-list.ts | 61 +++++++++++++++++++ src/app/chat/dm-list/dm-list.html | 31 ---------- src/app/chat/dm-list/dm-list.ts | 51 ---------------- 6 files changed, 97 insertions(+), 87 deletions(-) create mode 100644 src/app/chat/contact-list/contact-list.html rename src/app/chat/{dm-list/dm-list.scss => contact-list/contact-list.scss} (100%) rename src/app/chat/{dm-list/dm-list.spec.ts => contact-list/contact-list.spec.ts} (63%) create mode 100644 src/app/chat/contact-list/contact-list.ts delete mode 100644 src/app/chat/dm-list/dm-list.html delete mode 100644 src/app/chat/dm-list/dm-list.ts diff --git a/src/app/chat/contact-list/contact-list.html b/src/app/chat/contact-list/contact-list.html new file mode 100644 index 0000000..60cd1cb --- /dev/null +++ b/src/app/chat/contact-list/contact-list.html @@ -0,0 +1,31 @@ + +@if (cache.contactsState() == LoadState.CACHE_UPDATING) { +
+ + {{ "updating"|translate }} +
+} +@for (contact of cache.contacts(); track contact.contactId) { + +} diff --git a/src/app/chat/dm-list/dm-list.scss b/src/app/chat/contact-list/contact-list.scss similarity index 100% rename from src/app/chat/dm-list/dm-list.scss rename to src/app/chat/contact-list/contact-list.scss diff --git a/src/app/chat/dm-list/dm-list.spec.ts b/src/app/chat/contact-list/contact-list.spec.ts similarity index 63% rename from src/app/chat/dm-list/dm-list.spec.ts rename to src/app/chat/contact-list/contact-list.spec.ts index 5aedba4..0a9addd 100644 --- a/src/app/chat/dm-list/dm-list.spec.ts +++ b/src/app/chat/contact-list/contact-list.spec.ts @@ -1,17 +1,17 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { DmList } from './dm-list'; +import { ContactList } from './contact-list'; describe('PictureList', () => { - let component: DmList; - let fixture: ComponentFixture; + let component: ContactList; + let fixture: ComponentFixture; beforeEach(async () => { await TestBed.configureTestingModule({ - imports: [DmList], + imports: [ContactList], }).compileComponents(); - fixture = TestBed.createComponent(DmList); + fixture = TestBed.createComponent(ContactList); component = fixture.componentInstance; await fixture.whenStable(); }); diff --git a/src/app/chat/contact-list/contact-list.ts b/src/app/chat/contact-list/contact-list.ts new file mode 100644 index 0000000..a927a0b --- /dev/null +++ b/src/app/chat/contact-list/contact-list.ts @@ -0,0 +1,61 @@ +import {Component, inject, input, OnInit} from '@angular/core'; +import {ChatService} from '@chatenium/chatenium-sdk/services/chatService'; +import {IndexedDB} from '../../storage/indexed-db'; +import { TUI_BREAKPOINT, TuiButton, TuiLoader, TuiNotificationService } from '@taiga-ui/core'; +import {Oimg} from '../elements/oimg/oimg'; +import {Router, RouterLink} from '@angular/router'; +import {TranslatePipe} from '@ngx-translate/core'; +import {LoadStatus, ServiceManager} from '../../service-manager'; +import { Contact, createContactWrapper } from 'chatenium-sdk-preview'; +import { CHATENIUM_SDK } from '../../chatenium.token'; +import { Cache, LoadState } from '../../cache'; +import { Avatar } from '../elements/avatar/avatar'; + +@Component({ + selector: 'app-contact-list', + imports: [TuiButton, Oimg, RouterLink, TranslatePipe, TuiLoader, Avatar], + templateUrl: './contact-list.html', + styleUrl: './contact-list.scss', +}) +export class ContactList implements OnInit { + SDK = inject(CHATENIUM_SDK); + idb = inject(IndexedDB); + router = inject(Router); + cache = inject(Cache); + notification = inject(TuiNotificationService); + serviceManager = inject(ServiceManager); + breakpoint = inject(TUI_BREAKPOINT); + + async ngOnInit() { + if (this.cache.contactsState() != LoadState.LOADED) { + try { + const contacts = (await this.idb.getAll('contacts')) as Contact[]; + this.cache.contacts.set(contacts); + this.cache.contactsState.set(LoadState.CACHE_UPDATING); + } catch (e) { + console.warn(`Contacts cache load failed: ${e}. Skipping cache load...`); + } + try { + const resp = await this.SDK.contacts.getContacts(); + const data = resp.data as Contact[]; + if (data == null) { + console.log("No contacts were fetched - user possibly has 0 contacts") + this.cache.contactsState.set(LoadState.LOADED); + return + } + this.cache.contacts.set(data); + this.cache.contactsState.set(LoadState.LOADED); + console.log(`Successfully fetched ${data.length} contacts`); + } catch (e) { + console.error(e); + this.serviceManager.chatsStatus.set(LoadStatus.error); + this.notification + .open(`Loading contacts failed: ${e}`, { appearance: 'negative' }) + .subscribe(); + } + } + } + + protected readonly LoadStatus = LoadStatus; + protected readonly LoadState = LoadState; +} diff --git a/src/app/chat/dm-list/dm-list.html b/src/app/chat/dm-list/dm-list.html deleted file mode 100644 index 14ba5cd..0000000 --- a/src/app/chat/dm-list/dm-list.html +++ /dev/null @@ -1,31 +0,0 @@ - -@if (serviceManager.chatsStatus() == LoadStatus.updating) { -
- - {{ "updating"|translate }} -
-} -@for (chat of serviceManager.chats(); track chat.chatid) { - -} diff --git a/src/app/chat/dm-list/dm-list.ts b/src/app/chat/dm-list/dm-list.ts deleted file mode 100644 index b2b37d9..0000000 --- a/src/app/chat/dm-list/dm-list.ts +++ /dev/null @@ -1,51 +0,0 @@ -import {Component, inject, input, OnInit} from '@angular/core'; -import {ChatService} from '@chatenium/chatenium-sdk/services/chatService'; -import {IndexedDB} from '../../storage/indexed-db'; -import {TUI_BREAKPOINT, TuiButton, TuiLoader} from '@taiga-ui/core'; -import {Oimg} from '../elements/oimg/oimg'; -import {Router, RouterLink} from '@angular/router'; -import {TranslatePipe} from '@ngx-translate/core'; -import {LoadStatus, ServiceManager} from '../../service-manager'; - -@Component({ - selector: 'app-dm-list', - imports: [ - TuiButton, - Oimg, - RouterLink, - TranslatePipe, - TuiLoader - ], - templateUrl: './dm-list.html', - styleUrl: './dm-list.scss', -}) -export class DmList implements OnInit { - userid = input("") - token = input("") - - indexedDb = inject(IndexedDB) - router = inject(Router) - serviceManager = inject(ServiceManager) - breakpoint = inject(TUI_BREAKPOINT) - - async ngOnInit() { - this.serviceManager.chatService = new ChatService(this.userid(), this.token(), this.indexedDb.getApi(), () => {}) - if (this.serviceManager.chatsStatus() != LoadStatus.loaded) { - try { - this.serviceManager.chats.set(await this.serviceManager.chatService.getQuick()) - this.serviceManager.chatsStatus.set(LoadStatus.updating) - } catch (e) { - console.warn(`Cache load failed: ${e}. Skipping cache load...`) - } - try { - this.serviceManager.chats.set(await this.serviceManager.chatService.get()) - this.serviceManager.chatsStatus.set(LoadStatus.loaded) - } catch (e) { - console.error(e) - this.serviceManager.chatsStatus.set(LoadStatus.error) - } - } - } - - protected readonly LoadStatus = LoadStatus; -}