6 Commits

Author SHA1 Message Date
Noel Maróti
56d6065eef Minor update 2026-11-28 07:14:03 +01:00
Noel Maróti
aa811bff1b Added new variable to help with timing 2026-11-28 07:13:50 +01:00
Noel Maróti
b4ff8356ab Updated Chatenium SDK 2026-11-28 07:13:39 +01:00
Noel Maróti
f836df391b Renamed DmList to ContactList and updated logic to V3 2026-11-28 07:13:31 +01:00
Noel Maróti
1988c0a61e New singleton to hold cache globally in-memory 2026-11-28 07:13:18 +01:00
Noel Maróti
043a97ada5 New component (WIP) to handle avatar image loading, blurHash display and monogram avatar generation for accounts without PFPs (now possible in API/v3) 2026-11-28 07:13:00 +01:00
17 changed files with 208 additions and 103 deletions

8
package-lock.json generated
View File

@@ -33,7 +33,7 @@
"@taiga-ui/icons": "^5.25.0", "@taiga-ui/icons": "^5.25.0",
"@taiga-ui/kit": "^5.25.0", "@taiga-ui/kit": "^5.25.0",
"@taiga-ui/layout": "^5.25.0", "@taiga-ui/layout": "^5.25.0",
"chatenium-sdk-preview": "npm:@chatenium/chatenium-sdk@^2.0.0-preview.4", "chatenium-sdk-preview": "npm:@chatenium/chatenium-sdk@^2.0.0-preview.6",
"libphonenumber-js": "^1.12.41", "libphonenumber-js": "^1.12.41",
"ngx-cookie-service": "^21.3.1", "ngx-cookie-service": "^21.3.1",
"ngx-device-detector": "^11.0.0", "ngx-device-detector": "^11.0.0",
@@ -5919,9 +5919,9 @@
}, },
"node_modules/chatenium-sdk-preview": { "node_modules/chatenium-sdk-preview": {
"name": "@chatenium/chatenium-sdk", "name": "@chatenium/chatenium-sdk",
"version": "2.0.0-preview.4", "version": "2.0.0-preview.6",
"resolved": "https://registry.npmjs.org/@chatenium/chatenium-sdk/-/chatenium-sdk-2.0.0-preview.4.tgz", "resolved": "https://registry.npmjs.org/@chatenium/chatenium-sdk/-/chatenium-sdk-2.0.0-preview.6.tgz",
"integrity": "sha512-mPmyKdZZpwSGkW94LTqQ5zfZiOUgPZRLem0XO3h+9vrQ7L5Wy2RCwnu8HtO+DnTXszQQv6DXH0EvFSVL3H/MpA==", "integrity": "sha512-Coj2Hcf9AKdYloNT9y5qLL+B5CwbJq4nZhE4WnEeh8VG9AHiSuoyPK+YeTpLhS+JDUht54bQUFMXu313s824Yg==",
"license": "GPL-3.0-or-later", "license": "GPL-3.0-or-later",
"dependencies": { "dependencies": {
"@openapitools/openapi-generator-cli": "^2.42.0" "@openapitools/openapi-generator-cli": "^2.42.0"

View File

@@ -36,7 +36,7 @@
"@taiga-ui/icons": "^5.25.0", "@taiga-ui/icons": "^5.25.0",
"@taiga-ui/kit": "^5.25.0", "@taiga-ui/kit": "^5.25.0",
"@taiga-ui/layout": "^5.25.0", "@taiga-ui/layout": "^5.25.0",
"chatenium-sdk-preview": "npm:@chatenium/chatenium-sdk@^2.0.0-preview.4", "chatenium-sdk-preview": "npm:@chatenium/chatenium-sdk@^2.0.0-preview.6",
"libphonenumber-js": "^1.12.41", "libphonenumber-js": "^1.12.41",
"ngx-cookie-service": "^21.3.1", "ngx-cookie-service": "^21.3.1",
"ngx-device-detector": "^11.0.0", "ngx-device-detector": "^11.0.0",

16
src/app/cache.spec.ts Normal file
View File

@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { Cache } from './cache';
describe('Cache', () => {
let service: Cache;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(Cache);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

17
src/app/cache.ts Normal file
View File

@@ -0,0 +1,17 @@
import { Injectable, signal } from '@angular/core';
import { Contact } from 'chatenium-sdk-preview';
@Injectable({
providedIn: 'root',
})
export class Cache {
contacts = signal<Contact[]>([])
contactsState = signal<LoadState>(LoadState.CLEAN_LOADING)
}
export enum LoadState {
CLEAN_LOADING,
CACHE_UPDATING,
LOADED,
ERROR
}

View File

@@ -16,7 +16,7 @@
<user-settings (close)="userSettingsOpen.set(false)" /> <user-settings (close)="userSettingsOpen.set(false)" />
</ng-template> </ng-template>
@if (sessionManager.userData() == undefined) { @if (!sessionManager.sessionReady()) {
<main style="width: 100%; height: 100svh; display: flex; justify-content: center; align-items: center;"> <main style="width: 100%; height: 100svh; display: flex; justify-content: center; align-items: center;">
<tui-loader size="xl" /> <tui-loader size="xl" />
</main> </main>
@@ -44,11 +44,10 @@
</aside> </aside>
<main> <main>
<!-- @switch (navigationActiveIndex) { @switch (navigationActiveIndex) {
@case (0) { @case (0) {
<app-dm-list [token]="serviceManager.currentSession()!.token" <app-contact-list></app-contact-list>
[userid]="serviceManager.currentSession()!.userData.userid"></app-dm-list> } <!--
}
@case (1) { @case (1) {
<network-list <network-list
[(expandedSidenav)]="expandedSidenav" [(expandedSidenav)]="expandedSidenav"
@@ -58,8 +57,8 @@
@case (2) { @case (2) {
<app-picture-list [token]="serviceManager.currentSession()!.token" <app-picture-list [token]="serviceManager.currentSession()!.token"
[userid]="serviceManager.currentSession()!.userData.userid"></app-picture-list> [userid]="serviceManager.currentSession()!.userData.userid"></app-picture-list>
}
}--> }-->
}
</main> </main>
</aside> </aside>
@@ -88,8 +87,8 @@
<!-- <!--
@switch (navigationActiveIndex) { @switch (navigationActiveIndex) {
@case (0) { @case (0) {
<app-dm-list [token]="serviceManager.currentSession()!.token" <app-contact-list [token]="serviceManager.currentSession()!.token"
[userid]="serviceManager.currentSession()!.userData.userid"></app-dm-list> [userid]="serviceManager.currentSession()!.userData.userid"></app-contact-list>
} }
@case (1) { @case (1) {
<network-list <network-list

View File

@@ -4,7 +4,7 @@ import {TuiSegmented} from '@taiga-ui/kit';
import {TUI_BREAKPOINT, TuiAppearance, TuiButton, TuiDialog, TuiGroup, TuiIcon, TuiLoader} from '@taiga-ui/core'; import {TUI_BREAKPOINT, TuiAppearance, TuiButton, TuiDialog, TuiGroup, TuiIcon, TuiLoader} from '@taiga-ui/core';
import {LoadStatus, ServiceManager} from '../service-manager'; import {LoadStatus, ServiceManager} from '../service-manager';
import {IndexedDB} from '../storage/indexed-db'; import {IndexedDB} from '../storage/indexed-db';
import {DmList} from './dm-list/dm-list'; import {ContactList} from './contact-list/contact-list';
import {JsonPipe} from '@angular/common'; import {JsonPipe} from '@angular/common';
import {WebSocketHandler} from '@chatenium/chatenium-sdk/core/webSocketHandler'; import {WebSocketHandler} from '@chatenium/chatenium-sdk/core/webSocketHandler';
import {TranslatePipe, TranslateService} from '@ngx-translate/core'; import {TranslatePipe, TranslateService} from '@ngx-translate/core';
@@ -25,7 +25,7 @@ import { SessionManager } from '../session-manager';
TuiIcon, TuiIcon,
TuiButton, TuiButton,
TuiLoader, TuiLoader,
DmList, ContactList,
JsonPipe, JsonPipe,
TuiAppearance, TuiAppearance,
TuiGroup, TuiGroup,

View File

@@ -0,0 +1,31 @@
<button disabled tuiButton appearance="secondary" iconStart="@tui.mail-plus">
{{ "chat.chatnav.dmList.newChat"|translate }}
</button>
@if (cache.contactsState() == LoadState.CACHE_UPDATING) {
<div id="loader">
<tui-loader/>
{{ "updating"|translate }}
</div>
}
@for (contact of cache.contacts(); track contact.contactId) {
<button [class.enlarge]="breakpoint() == 'mobile'" tuiButton
[appearance]="router.url == '/chat/dm/' + contact.contactId ? 'primary' : 'flat'"
[routerLink]="'/chat/dm/' + contact.contactId">
<avatar height="35px" width="35px" [radius]="10" [src]="contact.pfp" [name]="contact.username"></avatar>
<div class="info">
@if (contact.displayName == "") {
<span>{{ '@' + contact.username }}</span>
} @else {
<span>{{ contact.displayName }}</span>
}
@if (contact.latestMessage) {
<span class="latest_message">
@if (contact.latestMessage.isAuthor) {
{{ "chat.chatnav.dmList.messageBox.latestMessage.you"|translate }}
}
{{ contact.latestMessage.message }}
</span>
}
</div>
</button>
}

View File

@@ -1,17 +1,17 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing';
import { DmList } from './dm-list'; import { ContactList } from './contact-list';
describe('PictureList', () => { describe('PictureList', () => {
let component: DmList; let component: ContactList;
let fixture: ComponentFixture<DmList>; let fixture: ComponentFixture<ContactList>;
beforeEach(async () => { beforeEach(async () => {
await TestBed.configureTestingModule({ await TestBed.configureTestingModule({
imports: [DmList], imports: [ContactList],
}).compileComponents(); }).compileComponents();
fixture = TestBed.createComponent(DmList); fixture = TestBed.createComponent(ContactList);
component = fixture.componentInstance; component = fixture.componentInstance;
await fixture.whenStable(); await fixture.whenStable();
}); });

View File

@@ -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;
}

View File

@@ -1,31 +0,0 @@
<button disabled tuiButton appearance="secondary" iconStart="@tui.mail-plus">
{{ "chat.chatnav.dmList.newChat"|translate }}
</button>
@if (serviceManager.chatsStatus() == LoadStatus.updating) {
<div id="loader">
<tui-loader/>
{{ "updating"|translate }}
</div>
}
@for (chat of serviceManager.chats(); track chat.chatid) {
<button [class.enlarge]="breakpoint() == 'mobile'" tuiButton
[appearance]="router.url == '/chat/dm/' + chat.chatid ? 'primary' : 'flat'"
[routerLink]="'/chat/dm/' + chat.chatid">
<oimg [src]="chat.pfp" height="35px" width="35px" [radius]="10"></oimg>
<div class="info">
@if (chat.displayName == "") {
<span>{{ '@' + chat.username }}</span>
} @else {
<span>{{ chat.displayName }}</span>
}
@if (chat.latestMessage) {
<span class="latest_message">
@if (chat.latestMessage.isAuthor) {
{{ "chat.chatnav.dmList.messageBox.latestMessage.you"|translate }}
}
{{ chat.latestMessage.message }}
</span>
}
</div>
</button>
}

View File

@@ -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<string>("")
token = input<string>("")
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;
}

View File

@@ -0,0 +1,3 @@
<div class="avatar" [style]="'width: '+width()+'; height: '+height()+'; background-color: '+stringToHexColor(name())+'; border-radius: '+radius()+'px;'">
<span>{{name()[0]}}</span>
</div>

View File

@@ -0,0 +1,6 @@
.avatar {
display: flex;
align-items: center;
justify-content: center;
color: white;
}

View File

@@ -0,0 +1,22 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { Avatar } from './avatar';
describe('Avatar', () => {
let component: Avatar;
let fixture: ComponentFixture<Avatar>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [Avatar],
}).compileComponents();
fixture = TestBed.createComponent(Avatar);
component = fixture.componentInstance;
await fixture.whenStable();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -0,0 +1,29 @@
import { Component, input } from '@angular/core';
@Component({
selector: 'avatar',
imports: [],
templateUrl: './avatar.html',
styleUrl: './avatar.scss',
})
export class Avatar {
height = input.required<string>();
width = input.required<string>();
src = input<string>();
name = input.required<string>();
radius = input.required<number>();
PALETTE = ['#ff6b6b', '#ffd166', '#06d6a0', '#4cc9f0', '#b56576', '#f78c6b'];
/**
* Picks 1 color from a few for avatar background
* @param str
*/
stringToHexColor(str: string): string {
let hash = 0;
for (let i = 0; i < str.length; i++) {
hash = str.charCodeAt(i) + ((hash << 5) - hash);
}
return this.PALETTE[Math.abs(hash) % this.PALETTE.length];
}
}

View File

@@ -15,6 +15,7 @@ export class SessionManager {
private notification = inject(TuiNotificationService); private notification = inject(TuiNotificationService);
public userData = signal<PersonalUserData|undefined>(undefined); public userData = signal<PersonalUserData|undefined>(undefined);
public sessionReady = signal(false); // Helps with timing session loading
async addSession(refreshToken: string, accessToken: string, userId: string) { async addSession(refreshToken: string, accessToken: string, userId: string) {
const date = new Date(); const date = new Date();
@@ -90,6 +91,8 @@ export class SessionManager {
console.log( console.log(
`Successfully rotated token pair for ID: ${userData.userId} Username: ${userData.username}. This session is now ready to be used.`, `Successfully rotated token pair for ID: ${userData.userId} Username: ${userData.username}. This session is now ready to be used.`,
); );
console.log(data.accessToken)
this.sessionReady.set(true);
} catch (e) { } catch (e) {
console.error(e); console.error(e);
} }