Compare commits
6 Commits
3ef5387b8d
...
56d6065eef
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
56d6065eef | ||
|
|
aa811bff1b | ||
|
|
b4ff8356ab | ||
|
|
f836df391b | ||
|
|
1988c0a61e | ||
|
|
043a97ada5 |
8
package-lock.json
generated
8
package-lock.json
generated
@@ -33,7 +33,7 @@
|
||||
"@taiga-ui/icons": "^5.25.0",
|
||||
"@taiga-ui/kit": "^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",
|
||||
"ngx-cookie-service": "^21.3.1",
|
||||
"ngx-device-detector": "^11.0.0",
|
||||
@@ -5919,9 +5919,9 @@
|
||||
},
|
||||
"node_modules/chatenium-sdk-preview": {
|
||||
"name": "@chatenium/chatenium-sdk",
|
||||
"version": "2.0.0-preview.4",
|
||||
"resolved": "https://registry.npmjs.org/@chatenium/chatenium-sdk/-/chatenium-sdk-2.0.0-preview.4.tgz",
|
||||
"integrity": "sha512-mPmyKdZZpwSGkW94LTqQ5zfZiOUgPZRLem0XO3h+9vrQ7L5Wy2RCwnu8HtO+DnTXszQQv6DXH0EvFSVL3H/MpA==",
|
||||
"version": "2.0.0-preview.6",
|
||||
"resolved": "https://registry.npmjs.org/@chatenium/chatenium-sdk/-/chatenium-sdk-2.0.0-preview.6.tgz",
|
||||
"integrity": "sha512-Coj2Hcf9AKdYloNT9y5qLL+B5CwbJq4nZhE4WnEeh8VG9AHiSuoyPK+YeTpLhS+JDUht54bQUFMXu313s824Yg==",
|
||||
"license": "GPL-3.0-or-later",
|
||||
"dependencies": {
|
||||
"@openapitools/openapi-generator-cli": "^2.42.0"
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
"@taiga-ui/icons": "^5.25.0",
|
||||
"@taiga-ui/kit": "^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",
|
||||
"ngx-cookie-service": "^21.3.1",
|
||||
"ngx-device-detector": "^11.0.0",
|
||||
|
||||
16
src/app/cache.spec.ts
Normal file
16
src/app/cache.spec.ts
Normal 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
17
src/app/cache.ts
Normal 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
|
||||
}
|
||||
@@ -16,7 +16,7 @@
|
||||
<user-settings (close)="userSettingsOpen.set(false)" />
|
||||
</ng-template>
|
||||
|
||||
@if (sessionManager.userData() == undefined) {
|
||||
@if (!sessionManager.sessionReady()) {
|
||||
<main style="width: 100%; height: 100svh; display: flex; justify-content: center; align-items: center;">
|
||||
<tui-loader size="xl" />
|
||||
</main>
|
||||
@@ -44,11 +44,10 @@
|
||||
</aside>
|
||||
|
||||
<main>
|
||||
<!-- @switch (navigationActiveIndex) {
|
||||
@switch (navigationActiveIndex) {
|
||||
@case (0) {
|
||||
<app-dm-list [token]="serviceManager.currentSession()!.token"
|
||||
[userid]="serviceManager.currentSession()!.userData.userid"></app-dm-list>
|
||||
}
|
||||
<app-contact-list></app-contact-list>
|
||||
} <!--
|
||||
@case (1) {
|
||||
<network-list
|
||||
[(expandedSidenav)]="expandedSidenav"
|
||||
@@ -58,8 +57,8 @@
|
||||
@case (2) {
|
||||
<app-picture-list [token]="serviceManager.currentSession()!.token"
|
||||
[userid]="serviceManager.currentSession()!.userData.userid"></app-picture-list>
|
||||
}
|
||||
}-->
|
||||
}-->
|
||||
}
|
||||
</main>
|
||||
</aside>
|
||||
|
||||
@@ -88,8 +87,8 @@
|
||||
<!--
|
||||
@switch (navigationActiveIndex) {
|
||||
@case (0) {
|
||||
<app-dm-list [token]="serviceManager.currentSession()!.token"
|
||||
[userid]="serviceManager.currentSession()!.userData.userid"></app-dm-list>
|
||||
<app-contact-list [token]="serviceManager.currentSession()!.token"
|
||||
[userid]="serviceManager.currentSession()!.userData.userid"></app-contact-list>
|
||||
}
|
||||
@case (1) {
|
||||
<network-list
|
||||
|
||||
@@ -4,7 +4,7 @@ import {TuiSegmented} from '@taiga-ui/kit';
|
||||
import {TUI_BREAKPOINT, TuiAppearance, TuiButton, TuiDialog, TuiGroup, TuiIcon, TuiLoader} from '@taiga-ui/core';
|
||||
import {LoadStatus, ServiceManager} from '../service-manager';
|
||||
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 {WebSocketHandler} from '@chatenium/chatenium-sdk/core/webSocketHandler';
|
||||
import {TranslatePipe, TranslateService} from '@ngx-translate/core';
|
||||
@@ -25,7 +25,7 @@ import { SessionManager } from '../session-manager';
|
||||
TuiIcon,
|
||||
TuiButton,
|
||||
TuiLoader,
|
||||
DmList,
|
||||
ContactList,
|
||||
JsonPipe,
|
||||
TuiAppearance,
|
||||
TuiGroup,
|
||||
|
||||
31
src/app/chat/contact-list/contact-list.html
Normal file
31
src/app/chat/contact-list/contact-list.html
Normal 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>
|
||||
}
|
||||
@@ -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<DmList>;
|
||||
let component: ContactList;
|
||||
let fixture: ComponentFixture<ContactList>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [DmList],
|
||||
imports: [ContactList],
|
||||
}).compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(DmList);
|
||||
fixture = TestBed.createComponent(ContactList);
|
||||
component = fixture.componentInstance;
|
||||
await fixture.whenStable();
|
||||
});
|
||||
61
src/app/chat/contact-list/contact-list.ts
Normal file
61
src/app/chat/contact-list/contact-list.ts
Normal 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;
|
||||
}
|
||||
@@ -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>
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
3
src/app/chat/elements/avatar/avatar.html
Normal file
3
src/app/chat/elements/avatar/avatar.html
Normal 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>
|
||||
6
src/app/chat/elements/avatar/avatar.scss
Normal file
6
src/app/chat/elements/avatar/avatar.scss
Normal file
@@ -0,0 +1,6 @@
|
||||
.avatar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: white;
|
||||
}
|
||||
22
src/app/chat/elements/avatar/avatar.spec.ts
Normal file
22
src/app/chat/elements/avatar/avatar.spec.ts
Normal 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();
|
||||
});
|
||||
});
|
||||
29
src/app/chat/elements/avatar/avatar.ts
Normal file
29
src/app/chat/elements/avatar/avatar.ts
Normal 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];
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ export class SessionManager {
|
||||
private notification = inject(TuiNotificationService);
|
||||
|
||||
public userData = signal<PersonalUserData|undefined>(undefined);
|
||||
public sessionReady = signal(false); // Helps with timing session loading
|
||||
|
||||
async addSession(refreshToken: string, accessToken: string, userId: string) {
|
||||
const date = new Date();
|
||||
@@ -90,6 +91,8 @@ export class SessionManager {
|
||||
console.log(
|
||||
`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) {
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user