Compare commits
15 Commits
3.0-beta8
...
56d6065eef
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
56d6065eef | ||
|
|
aa811bff1b | ||
|
|
b4ff8356ab | ||
|
|
f836df391b | ||
|
|
1988c0a61e | ||
|
|
043a97ada5 | ||
|
|
3ef5387b8d | ||
|
|
086d27c9a4 | ||
|
|
eeee9d5154 | ||
| aa3e1de412 | |||
| f9518a9164 | |||
| 3ed025ee61 | |||
| 5f032c5098 | |||
| 20e67ecd85 | |||
| 4eaaacac2c |
@@ -24,6 +24,11 @@
|
|||||||
"glob": "**/*",
|
"glob": "**/*",
|
||||||
"input": "public"
|
"input": "public"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"glob": "**/*",
|
||||||
|
"input": "node_modules/@taiga-ui/icons/src",
|
||||||
|
"output": "assets/taiga-ui/icons"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"glob": "**/*",
|
"glob": "**/*",
|
||||||
"input": "node_modules/@taiga-ui/icons/src",
|
"input": "node_modules/@taiga-ui/icons/src",
|
||||||
|
|||||||
4614
package-lock.json
generated
4614
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
25
package.json
25
package.json
@@ -19,21 +19,27 @@
|
|||||||
"@angular/platform-browser": "^21.2.0",
|
"@angular/platform-browser": "^21.2.0",
|
||||||
"@angular/router": "^21.2.0",
|
"@angular/router": "^21.2.0",
|
||||||
"@angular/service-worker": "^21.2.0",
|
"@angular/service-worker": "^21.2.0",
|
||||||
"@chatenium/chatenium-sdk": "^1.2.0",
|
"@chatenium/chatenium-sdk": "^1.2.2",
|
||||||
"@fortawesome/angular-fontawesome": "^4.0.0",
|
"@fortawesome/angular-fontawesome": "^4.0.0",
|
||||||
"@fortawesome/free-brands-svg-icons": "^7.1.0",
|
"@fortawesome/free-brands-svg-icons": "^7.1.0",
|
||||||
"@fortawesome/free-solid-svg-icons": "^7.1.0",
|
"@fortawesome/free-solid-svg-icons": "^7.1.0",
|
||||||
"@ngx-translate/core": "^17.0.0",
|
"@ngx-translate/core": "^17.0.0",
|
||||||
"@ngx-translate/http-loader": "^17.0.0",
|
"@ngx-translate/http-loader": "^17.0.0",
|
||||||
"@taiga-ui/addon-charts": "^5.1.0",
|
"@taiga-ui/addon-charts": "^5.25.0",
|
||||||
"@taiga-ui/addon-mobile": "^5.1.0",
|
"@taiga-ui/addon-commerce": "^5.25.0",
|
||||||
"@taiga-ui/addon-table": "^5.1.0",
|
"@taiga-ui/addon-doc": "^5.25.0",
|
||||||
"@taiga-ui/cdk": "^5.1.0",
|
"@taiga-ui/addon-mobile": "^5.25.0",
|
||||||
"@taiga-ui/core": "^5.1.0",
|
"@taiga-ui/addon-table": "^5.25.0",
|
||||||
"@taiga-ui/icons": "^5.1.0",
|
"@taiga-ui/cdk": "^5.25.0",
|
||||||
"@taiga-ui/kit": "^5.1.0",
|
"@taiga-ui/core": "^5.25.0",
|
||||||
"@taiga-ui/layout": "^5.1.0",
|
"@taiga-ui/i18n": "^5.2.0",
|
||||||
|
"@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.6",
|
||||||
|
"libphonenumber-js": "^1.12.41",
|
||||||
"ngx-cookie-service": "^21.3.1",
|
"ngx-cookie-service": "^21.3.1",
|
||||||
|
"ngx-device-detector": "^11.0.0",
|
||||||
"rxjs": "~7.8.0",
|
"rxjs": "~7.8.0",
|
||||||
"tslib": "^2.3.0",
|
"tslib": "^2.3.0",
|
||||||
"uuid": "^13.0.0"
|
"uuid": "^13.0.0"
|
||||||
@@ -42,6 +48,7 @@
|
|||||||
"@angular/build": "^21.2.6",
|
"@angular/build": "^21.2.6",
|
||||||
"@angular/cli": "^21.2.6",
|
"@angular/cli": "^21.2.6",
|
||||||
"@angular/compiler-cli": "^21.2.0",
|
"@angular/compiler-cli": "^21.2.0",
|
||||||
|
"@types/google.accounts": "^0.0.18",
|
||||||
"jsdom": "^28.0.0",
|
"jsdom": "^28.0.0",
|
||||||
"less": "^4.6.4",
|
"less": "^4.6.4",
|
||||||
"prettier": "^3.8.1",
|
"prettier": "^3.8.1",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"version": "Chatenium Nexum 3.0 Beta 8 (April 17, 2026)",
|
"version": "Chatenium Nexum 3.0 Beta 11 (October 4, 2026)",
|
||||||
"ok": "Ok",
|
"ok": "Ok",
|
||||||
"back": "Back",
|
"back": "Back",
|
||||||
"aChatProgram": "A messaging platform that you can trust.",
|
"aChatProgram": "A messaging platform that you can trust.",
|
||||||
@@ -79,24 +79,126 @@
|
|||||||
"microsoftStoreDesc": "Start testing the application on your Windows computer via the Microsoft Store!"
|
"microsoftStoreDesc": "Start testing the application on your Windows computer via the Microsoft Store!"
|
||||||
},
|
},
|
||||||
"signIn": {
|
"signIn": {
|
||||||
"formTitle": "Sign in",
|
"initial": {
|
||||||
"mainInput": {
|
"formTitle": "Welcome back!",
|
||||||
"label": "Username, email or phone number",
|
"formSubtitle": "Sign in with your Chatenium account.",
|
||||||
"placeholder": "bob, bob@example.com, +36201234567"
|
"mainInput": {
|
||||||
|
"label": "Username, email or phone number",
|
||||||
|
"placeholder": "bob, bob@example.com, +36201234567"
|
||||||
|
},
|
||||||
|
"password": {
|
||||||
|
"label": "Password"
|
||||||
|
},
|
||||||
|
"signInButton": "Sign in"
|
||||||
},
|
},
|
||||||
"password": {
|
"methodChoose": {
|
||||||
"label": "Password"
|
"formTitle": "Choose a verification method",
|
||||||
|
"formSubtitle": "Based on your security settings, more than 1 verification method may be required.",
|
||||||
|
"formTitleAlt": "Choose another verification method",
|
||||||
|
"formSubtitleAlt": "Because of your security settings, multiple verification methods are required",
|
||||||
|
"methods": {
|
||||||
|
"password": {
|
||||||
|
"title": "Password",
|
||||||
|
"desc": "Use your password to verify your identity"
|
||||||
|
},
|
||||||
|
"mail": {
|
||||||
|
"title": "E-mail",
|
||||||
|
"desc": "Use a one-time e-mail code to verify your identity"
|
||||||
|
},
|
||||||
|
"sms": {
|
||||||
|
"title": "SMS",
|
||||||
|
"desc": "Use a one-time SMS code to verify your identity"
|
||||||
|
},
|
||||||
|
"google": {
|
||||||
|
"title": "Google",
|
||||||
|
"desc": "Use your linked Google account to verify your identity"
|
||||||
|
},
|
||||||
|
"apple": {
|
||||||
|
"title": "Apple",
|
||||||
|
"desc": "Use your linked Apple account to verify your identity"
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"emailButton": "Sign in with email code",
|
"anyAuth": {
|
||||||
"smsButton": "Sign in with SMS code",
|
"verifyButton": "Verify identity"
|
||||||
"signInButton": "Sign in",
|
},
|
||||||
"errors": {
|
"passwordAuth": {
|
||||||
"unameMailPhoneRequired": "Username, email or phone number is required",
|
"formTitle": "Password authentication",
|
||||||
"passwordRequired": "Password is required",
|
"formSubtitle": "Enter your password below",
|
||||||
"passwordIncorrect": "Password is incorrect"
|
"errors": {
|
||||||
|
"passwordRequired": "Password is required",
|
||||||
|
"passwordIncorrect": "Password is incorrect"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"emailAuth": {
|
||||||
|
"formTitle": "E-mail authentication",
|
||||||
|
"formSubtitle": "Enter your one-time e-mail code below",
|
||||||
|
"errors": {
|
||||||
|
"passwordRequired": "Code is required",
|
||||||
|
"passwordIncorrect": "Code is incorrect"
|
||||||
|
},
|
||||||
|
"emailCode": {
|
||||||
|
"label": "E-mail code"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"chat": {
|
"chat": {
|
||||||
|
"userSettingsDialog": {
|
||||||
|
"label": "Settings",
|
||||||
|
"options": {
|
||||||
|
"security": "Privacy & Security",
|
||||||
|
"profile": "Profile",
|
||||||
|
"themes": "Themes",
|
||||||
|
"sessions": "Sessions",
|
||||||
|
"storage": "Data and Storage"
|
||||||
|
},
|
||||||
|
"security": {
|
||||||
|
"changePasswordDialog": {
|
||||||
|
"label": "Change password",
|
||||||
|
"labelSet": "Set password",
|
||||||
|
"labelRemove": "Remove password",
|
||||||
|
"warn": "After you change your password, you will be logged out of all your sessions.",
|
||||||
|
"currentPassword": "Current password",
|
||||||
|
"newPassword": "New password",
|
||||||
|
"newPasswordRepeat": "Repeat new password"
|
||||||
|
},
|
||||||
|
"changeEmailDialog": {
|
||||||
|
"label": "Change e-mail address",
|
||||||
|
"labelSet": "Set e-mail address",
|
||||||
|
"labelRemove": "Remove e-mail address",
|
||||||
|
"warn": "After you change your e-mail address, you will be logged out of all your sessions.",
|
||||||
|
"newMail": "New e-mail address",
|
||||||
|
"currentPassword": "Current password",
|
||||||
|
"oldCode": "Code sent to the old e-mail address",
|
||||||
|
"newCode": "Code sent to the new e-mail address"
|
||||||
|
},
|
||||||
|
"changePhoneDialog": {
|
||||||
|
"label": "Change phone number",
|
||||||
|
"labelSet": "Set phone number",
|
||||||
|
"labelRemove": "Remove phone number",
|
||||||
|
"warn": "After you change your phone number, you will be logged out of all your sessions.",
|
||||||
|
"newPhone": "New phone number",
|
||||||
|
"currentPassword": "Current password",
|
||||||
|
"oldCode": "Code sent to the old phone number",
|
||||||
|
"newCode": "Code sent to the new phone number"
|
||||||
|
},
|
||||||
|
"label": "Keep your account safe by using as much sign in methods as possible. Also check your credentials regularly to keep them up to date.",
|
||||||
|
"password": "Password",
|
||||||
|
"set": "Set",
|
||||||
|
"notSet": "Not set",
|
||||||
|
"changePassword": "Change password",
|
||||||
|
"phoneNumber": "Phone number",
|
||||||
|
"email": "E-mail address",
|
||||||
|
"removePassword": "Remove password",
|
||||||
|
"changePhone": "Change phone number",
|
||||||
|
"changeMail": "Change e-mail address",
|
||||||
|
"removePhone": "Remove phone number",
|
||||||
|
"removeMail": "Remove e-mail address",
|
||||||
|
"setPassword": "Set password",
|
||||||
|
"setPhone": "Set phone number",
|
||||||
|
"setMail": "Set e-mail address"
|
||||||
|
}
|
||||||
|
},
|
||||||
"tabBar": {
|
"tabBar": {
|
||||||
"tab1": "Chats",
|
"tab1": "Chats",
|
||||||
"tab2": "Networks",
|
"tab2": "Networks",
|
||||||
@@ -162,12 +264,8 @@
|
|||||||
"changeLogDialog": {
|
"changeLogDialog": {
|
||||||
"label": "Chatenium has been updated",
|
"label": "Chatenium has been updated",
|
||||||
"changeLog": {
|
"changeLog": {
|
||||||
"1": "Optimized the loading of chats and networks",
|
"1": "The network UI have been merged with the left side navigation panel.",
|
||||||
"2": "Added skeleton loaders for messages inside DMs and channels",
|
"2": "Categories and channels now have a threaded UI to align with recent changes"
|
||||||
"3": "Added tabs in networks",
|
|
||||||
"4": "Added option to edit network name",
|
|
||||||
"5": "Added option to change network visibility",
|
|
||||||
"6": "Fixed overflow issues in the mobile UI"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"chatnav": {
|
"chatnav": {
|
||||||
|
|||||||
@@ -1,30 +1,39 @@
|
|||||||
import {provideTaiga} from '@taiga-ui/core';
|
import { provideTaiga } from '@taiga-ui/core';
|
||||||
import {ApplicationConfig, provideBrowserGlobalErrorListeners, isDevMode} from '@angular/core';
|
import { ApplicationConfig, provideBrowserGlobalErrorListeners, isDevMode } from '@angular/core';
|
||||||
import {provideRouter, withRouterConfig} from '@angular/router';
|
import { provideRouter, withRouterConfig } from '@angular/router';
|
||||||
|
|
||||||
import {routes} from './app.routes';
|
import { routes } from './app.routes';
|
||||||
import {provideTranslateService} from '@ngx-translate/core';
|
import { provideTranslateService } from '@ngx-translate/core';
|
||||||
import {provideTranslateHttpLoader} from '@ngx-translate/http-loader';
|
import { provideTranslateHttpLoader } from '@ngx-translate/http-loader';
|
||||||
import {provideServiceWorker} from '@angular/service-worker';
|
import { provideServiceWorker } from '@angular/service-worker';
|
||||||
|
import { tuiInputPhoneInternationalOptionsProvider } from '@taiga-ui/kit';
|
||||||
|
import { defer } from 'rxjs';
|
||||||
|
|
||||||
export const appConfig: ApplicationConfig = {
|
export const appConfig: ApplicationConfig = {
|
||||||
providers: [
|
providers: [
|
||||||
provideBrowserGlobalErrorListeners(),
|
provideBrowserGlobalErrorListeners(),
|
||||||
provideRouter(routes, withRouterConfig({
|
provideRouter(
|
||||||
paramsInheritanceStrategy: "always"
|
routes,
|
||||||
})),
|
withRouterConfig({
|
||||||
|
paramsInheritanceStrategy: 'always',
|
||||||
|
}),
|
||||||
|
),
|
||||||
provideTaiga(),
|
provideTaiga(),
|
||||||
provideTranslateService({
|
provideTranslateService({
|
||||||
fallbackLang: "en",
|
fallbackLang: 'en',
|
||||||
lang: "hu",
|
lang: 'en',
|
||||||
loader: provideTranslateHttpLoader({
|
loader: provideTranslateHttpLoader({
|
||||||
prefix: "/i18n/",
|
prefix: '/i18n/',
|
||||||
suffix: ".json"
|
suffix: '.json',
|
||||||
})
|
}),
|
||||||
}),
|
}),
|
||||||
provideServiceWorker('ngsw-worker.js', {
|
provideServiceWorker('ngsw-worker.js', {
|
||||||
enabled: !isDevMode(),
|
enabled: !isDevMode(),
|
||||||
registrationStrategy: 'registerWhenStable:30000'
|
registrationStrategy: 'registerWhenStable:30000',
|
||||||
})
|
}),
|
||||||
|
tuiInputPhoneInternationalOptionsProvider({
|
||||||
|
metadata: defer(async () => import('libphonenumber-js/max/metadata').then((m) => m.default)),
|
||||||
|
}),
|
||||||
|
provideTaiga(),
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,30 +1,29 @@
|
|||||||
import {Routes} from '@angular/router';
|
import { Routes } from '@angular/router';
|
||||||
import {SignIn} from './signin/signin';
|
import { SignIn } from './signin/signin';
|
||||||
import {Chat} from './chat/chat';
|
import { Chat } from './chat/chat';
|
||||||
import {Dm} from './chat/dm/dm';
|
import { Dm } from './chat/dm/dm';
|
||||||
import {noAuthGuard} from './guards/no-auth-guard';
|
import { noAuthGuard } from './guards/no-auth-guard';
|
||||||
import {authNeededGuard} from './guards/auth-needed-guard';
|
import { authNeededGuard } from './guards/auth-needed-guard';
|
||||||
import {Homepage} from './homepage/homepage';
|
import { Homepage } from './homepage/homepage';
|
||||||
import {Privacy} from './privacy/privacy';
|
import { Privacy } from './privacy/privacy';
|
||||||
import {TOS} from './tos/tos';
|
import { TOS } from './tos/tos';
|
||||||
import {Network} from './chat/network/network';
|
import { Network } from './chat/network/network';
|
||||||
import {Text} from './chat/network/channel/text/text';
|
import { Text } from './chat/network/channel/text/text';
|
||||||
import {See} from './chat/picture/see/see';
|
import { See } from './chat/picture/see/see';
|
||||||
|
|
||||||
export const routes: Routes = [
|
export const routes: Routes = [
|
||||||
{path: '', component: Homepage},
|
{ path: '', component: Homepage },
|
||||||
{path: 'privacy', component: Privacy},
|
{ path: 'privacy', component: Privacy },
|
||||||
{path: 'tos', component: TOS},
|
{ path: 'tos', component: TOS },
|
||||||
{path: 'signin', component: SignIn, canActivate: [noAuthGuard]},
|
{ path: 'signin', component: SignIn, canActivate: [noAuthGuard] },
|
||||||
{
|
{
|
||||||
path: 'chat', component: Chat, canActivate: [authNeededGuard], children: [
|
path: 'chat',
|
||||||
{path: 'dm/:chatid', component: Dm},
|
component: Chat,
|
||||||
{path: 'picture/:uploaderId', component: See},
|
canActivate: [authNeededGuard],
|
||||||
{
|
children: [
|
||||||
path: 'network/:networkId', component: Network, children: [
|
{ path: 'dm/:chatid', component: Dm },
|
||||||
{path: ":categoryId/:channelId", component: Text}
|
{ path: 'picture/:uploaderId', component: See },
|
||||||
]
|
{ path: 'network/:networkId/:categoryId/:channelId', component: Text },
|
||||||
},
|
],
|
||||||
]
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1,18 +1,20 @@
|
|||||||
import { TuiRoot } from '@taiga-ui/core';
|
import { TuiRoot } from '@taiga-ui/core';
|
||||||
import {Component, inject, OnInit, signal} from '@angular/core';
|
import { Component, inject, OnInit, signal } from '@angular/core';
|
||||||
import { RouterOutlet } from '@angular/router';
|
import { RouterOutlet } from '@angular/router';
|
||||||
import { environment as env } from '../environments/environment';
|
import { environment as env } from '../environments/environment';
|
||||||
import {environment, SDKConfig} from '@chatenium/chatenium-sdk/core/environment';
|
import { environment, SDKConfig } from '@chatenium/chatenium-sdk/core/environment';
|
||||||
import {IndexedDB} from './storage/indexed-db';
|
import { IndexedDB } from './storage/indexed-db';
|
||||||
|
import { SessionManager } from './session-manager';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-root',
|
selector: 'app-root',
|
||||||
imports: [RouterOutlet, TuiRoot],
|
imports: [RouterOutlet, TuiRoot, TuiRoot],
|
||||||
templateUrl: './app.html',
|
templateUrl: './app.html',
|
||||||
styleUrl: './app.scss',
|
styleUrl: './app.scss',
|
||||||
})
|
})
|
||||||
export class App implements OnInit {
|
export class App implements OnInit {
|
||||||
indexedDb = inject(IndexedDB)
|
indexedDb = inject(IndexedDB);
|
||||||
|
sessionManager = inject(SessionManager);
|
||||||
|
|
||||||
protected readonly title = signal('Chatenium-On-Web');
|
protected readonly title = signal('Chatenium-On-Web');
|
||||||
|
|
||||||
@@ -22,5 +24,8 @@ export class App implements OnInit {
|
|||||||
apiUrl: env.api_url,
|
apiUrl: env.api_url,
|
||||||
wsUrl: env.ws_url,
|
wsUrl: env.ws_url,
|
||||||
});
|
});
|
||||||
|
this.indexedDb.openDatabase().then(() => {
|
||||||
|
this.sessionManager.loadSessions();
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
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
|
||||||
|
}
|
||||||
@@ -4,10 +4,6 @@
|
|||||||
<ul>
|
<ul>
|
||||||
<li>{{ "chat.changeLogDialog.changeLog.1"|translate }}</li>
|
<li>{{ "chat.changeLogDialog.changeLog.1"|translate }}</li>
|
||||||
<li>{{ "chat.changeLogDialog.changeLog.2"|translate }}</li>
|
<li>{{ "chat.changeLogDialog.changeLog.2"|translate }}</li>
|
||||||
<li>{{ "chat.changeLogDialog.changeLog.3"|translate }}</li>
|
|
||||||
<li>{{ "chat.changeLogDialog.changeLog.4"|translate }}</li>
|
|
||||||
<li>{{ "chat.changeLogDialog.changeLog.5"|translate }}</li>
|
|
||||||
<li>{{ "chat.changeLogDialog.changeLog.6"|translate }}</li>
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<button tuiButton iconStart="@tui.check"
|
<button tuiButton iconStart="@tui.check"
|
||||||
@@ -15,46 +11,53 @@
|
|||||||
</button>
|
</button>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
|
|
||||||
@if (serviceManager.currentSession() == null) {
|
<ng-template [(tuiDialog)]="userSettingsOpen" [tuiDialogOptions]="{closable: false, appearance: 'taiga big'}"
|
||||||
|
class="user-settings">
|
||||||
|
<user-settings (close)="userSettingsOpen.set(false)" />
|
||||||
|
</ng-template>
|
||||||
|
|
||||||
|
@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>
|
||||||
} @else {
|
} @else {
|
||||||
@if (breakpoint() != "mobile") {
|
@if (breakpoint() != "mobile") {
|
||||||
<main id="layout" tuiGroup [collapsed]="true">
|
<main id="layout" tuiGroup [collapsed]="true" [class.expanded]="expandedSidenav()">
|
||||||
<aside id="chatnav">
|
<aside id="chatnav">
|
||||||
<aside>
|
<aside>
|
||||||
<tui-segmented id="mode_switcher" [(activeItemIndex)]="navigationActiveIndex">
|
<tui-segmented id="mode_switcher" [(activeItemIndex)]="navigationActiveIndex">
|
||||||
<button>
|
<button (click)="expandedSidenav.set(false)">
|
||||||
<tui-icon icon="@tui.message-circle"/>
|
<tui-icon icon="@tui.message-circle" />
|
||||||
</button>
|
</button>
|
||||||
<button>
|
<button>
|
||||||
<tui-icon icon="@tui.network"/>
|
<tui-icon icon="@tui.network" />
|
||||||
</button>
|
</button>
|
||||||
<button>
|
<button (click)="expandedSidenav.set(false)">
|
||||||
<tui-icon icon="@tui.image"/>
|
<tui-icon icon="@tui.image" />
|
||||||
</button>
|
</button>
|
||||||
</tui-segmented>
|
</tui-segmented>
|
||||||
|
|
||||||
<button id="bottom_btn" tuiButton appearance="flat" disabled>
|
<button id="bottom_btn" tuiButton [appearance]="userSettingsOpen() ? 'primary' : 'flat'"
|
||||||
<tui-icon icon="@tui.cog"/>
|
(click)="userSettingsOpen.set(true)">
|
||||||
|
<tui-icon icon="@tui.cog" />
|
||||||
</button>
|
</button>
|
||||||
</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 [token]="serviceManager.currentSession()!.token"
|
<network-list
|
||||||
[userid]="serviceManager.currentSession()!.userData.userid"></network-list>
|
[(expandedSidenav)]="expandedSidenav"
|
||||||
|
[token]="serviceManager.currentSession()!.token"
|
||||||
|
[userid]="serviceManager.currentSession()!.userData.userid"></network-list>
|
||||||
}
|
}
|
||||||
@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>
|
||||||
@@ -64,14 +67,14 @@
|
|||||||
@if (router.url.startsWith("/chat/dm") || router.url.startsWith("/chat/picture")) {
|
@if (router.url.startsWith("/chat/dm") || router.url.startsWith("/chat/picture")) {
|
||||||
<!-- To ensure data is loaded -->
|
<!-- To ensure data is loaded -->
|
||||||
@defer (when serviceManager.chatsStatus() != LoadStatus.loading) {
|
@defer (when serviceManager.chatsStatus() != LoadStatus.loading) {
|
||||||
<router-outlet/>
|
<router-outlet />
|
||||||
}
|
}
|
||||||
} @else if (router.url.startsWith("/chat/network")) {
|
} @else if (router.url.startsWith("/chat/network")) {
|
||||||
@defer (when serviceManager.networksStatus() != LoadStatus.loading) {
|
@defer (when serviceManager.networksStatus() != LoadStatus.loading) {
|
||||||
<router-outlet/>
|
<router-outlet />
|
||||||
}
|
}
|
||||||
} @else {
|
} @else {
|
||||||
<router-outlet/>
|
<router-outlet />
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
@@ -81,16 +84,27 @@
|
|||||||
@if (!routerOutletActive()) {
|
@if (!routerOutletActive()) {
|
||||||
<div id="navigation">
|
<div id="navigation">
|
||||||
<div id="navigation_content">
|
<div id="navigation_content">
|
||||||
|
<!--
|
||||||
@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 [token]="serviceManager.currentSession()!.token"
|
<network-list
|
||||||
[userid]="serviceManager.currentSession()!.userData.userid"></network-list>
|
[(expandedSidenav)]="expandedSidenav"
|
||||||
|
[token]="serviceManager.currentSession()!.token"
|
||||||
|
[userid]="serviceManager.currentSession()!.userData.userid"></network-list>
|
||||||
|
}
|
||||||
|
@case (2) {
|
||||||
|
<app-picture-list [token]="serviceManager.currentSession()!.token"
|
||||||
|
[userid]="serviceManager.currentSession()!.userData.userid"></app-picture-list>
|
||||||
|
}
|
||||||
|
@case (3) {
|
||||||
|
<user-settings />
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
-->
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<nav tuiTabBar [(activeItemIndex)]="navigationActiveIndex">
|
<nav tuiTabBar [(activeItemIndex)]="navigationActiveIndex">
|
||||||
@@ -110,17 +124,17 @@
|
|||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
@if (router.url.startsWith("/chat/dm")) {
|
@if (router.url.startsWith("/chat/dm") || router.url.startsWith("/chat/picture")) {
|
||||||
<!-- To ensure data is loaded -->
|
<!-- To ensure data is loaded -->
|
||||||
@defer (when serviceManager.chatsStatus() != LoadStatus.loading) {
|
@defer (when serviceManager.chatsStatus() != LoadStatus.loading) {
|
||||||
<router-outlet (activate)="routerOutletActive.set(true)" (deactivate)="routerOutletActive.set(false)"/>
|
<router-outlet (activate)="routerOutletActive.set(true)" (deactivate)="routerOutletActive.set(false)" />
|
||||||
}
|
}
|
||||||
} @else if (router.url.startsWith("/chat/network")) {
|
} @else if (router.url.startsWith("/chat/network")) {
|
||||||
@defer (when serviceManager.networksStatus() != LoadStatus.loading) {
|
@defer (when serviceManager.networksStatus() != LoadStatus.loading) {
|
||||||
<router-outlet (activate)="routerOutletActive.set(true)" (deactivate)="routerOutletActive.set(false)"/>
|
<router-outlet (activate)="routerOutletActive.set(true)" (deactivate)="routerOutletActive.set(false)" />
|
||||||
}
|
}
|
||||||
} @else {
|
} @else {
|
||||||
<router-outlet (activate)="routerOutletActive.set(true)" (deactivate)="routerOutletActive.set(false)"/>
|
<router-outlet (activate)="routerOutletActive.set(true)" (deactivate)="routerOutletActive.set(false)" />
|
||||||
}
|
}
|
||||||
</main>
|
</main>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
#layout {
|
#layout {
|
||||||
|
transition: 0.3s ease;
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 350px minmax(0, 1fr);
|
grid-template-columns: 350px minmax(0, 1fr);
|
||||||
height: 100svh;
|
height: 100svh;
|
||||||
overflow: hidden;
|
|
||||||
|
&.expanded {
|
||||||
|
grid-template-columns: 450px minmax(0, 1fr) !important;
|
||||||
|
}
|
||||||
|
|
||||||
#chatnav {
|
#chatnav {
|
||||||
display: grid;
|
display: grid;
|
||||||
@@ -44,11 +48,12 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
main {
|
main {
|
||||||
|
overflow-y: scroll;
|
||||||
|
overflow-x: hidden;
|
||||||
background: var(--tui-background-base-alt);
|
background: var(--tui-background-base-alt);
|
||||||
border-radius: 20px 0 0 20px;
|
border-radius: 20px 0 0 20px;
|
||||||
margin: 10px 0 10px 10px;
|
margin: 10px 0 10px 10px;
|
||||||
padding: 15px;
|
padding: 15px;
|
||||||
overflow-y: scroll;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,3 +90,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
::ng-deep tui-dialog[data-appearance~=big] {
|
||||||
|
height: 90svh;
|
||||||
|
width: 90svw !important;
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,10 +2,9 @@ import {Component, computed, inject, OnInit, signal} from '@angular/core';
|
|||||||
import {isActive, IsActiveMatchOptions, Router, RouterOutlet} from '@angular/router';
|
import {isActive, IsActiveMatchOptions, Router, RouterOutlet} from '@angular/router';
|
||||||
import {TuiSegmented} from '@taiga-ui/kit';
|
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 {SessionManager} from '@chatenium/chatenium-sdk/services/sessionManager';
|
|
||||||
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';
|
||||||
@@ -13,6 +12,10 @@ import {environment} from '../../environments/environment';
|
|||||||
import {TuiTabBarComponent, TuiTabBarItem} from '@taiga-ui/addon-mobile';
|
import {TuiTabBarComponent, TuiTabBarItem} from '@taiga-ui/addon-mobile';
|
||||||
import {NetworkList} from './network-list/network-list';
|
import {NetworkList} from './network-list/network-list';
|
||||||
import {PictureList} from './picture-list/picture-list';
|
import {PictureList} from './picture-list/picture-list';
|
||||||
|
import {UserSettings} from './user-settings/user-settings';
|
||||||
|
import {AuthService} from '@chatenium/chatenium-sdk/services/authService';
|
||||||
|
import {UserService} from '@chatenium/chatenium-sdk/services/userService';
|
||||||
|
import { SessionManager } from '../session-manager';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-chat',
|
selector: 'app-chat',
|
||||||
@@ -22,7 +25,7 @@ import {PictureList} from './picture-list/picture-list';
|
|||||||
TuiIcon,
|
TuiIcon,
|
||||||
TuiButton,
|
TuiButton,
|
||||||
TuiLoader,
|
TuiLoader,
|
||||||
DmList,
|
ContactList,
|
||||||
JsonPipe,
|
JsonPipe,
|
||||||
TuiAppearance,
|
TuiAppearance,
|
||||||
TuiGroup,
|
TuiGroup,
|
||||||
@@ -31,18 +34,23 @@ import {PictureList} from './picture-list/picture-list';
|
|||||||
TuiTabBarComponent,
|
TuiTabBarComponent,
|
||||||
TuiTabBarItem,
|
TuiTabBarItem,
|
||||||
NetworkList,
|
NetworkList,
|
||||||
PictureList
|
PictureList,
|
||||||
|
UserSettings
|
||||||
],
|
],
|
||||||
templateUrl: './chat.html',
|
templateUrl: './chat.html',
|
||||||
styleUrl: './chat.scss',
|
styleUrl: './chat.scss',
|
||||||
})
|
})
|
||||||
export class Chat implements OnInit {
|
export class Chat implements OnInit {
|
||||||
|
sessionManager = inject(SessionManager);
|
||||||
serviceManager = inject(ServiceManager)
|
serviceManager = inject(ServiceManager)
|
||||||
indexedDb = inject(IndexedDB)
|
indexedDb = inject(IndexedDB)
|
||||||
breakpoint = inject(TUI_BREAKPOINT)
|
breakpoint = inject(TUI_BREAKPOINT)
|
||||||
router = inject(Router)
|
router = inject(Router)
|
||||||
|
|
||||||
|
expandedSidenav = signal(false)
|
||||||
|
|
||||||
routerOutletActive = signal(false)
|
routerOutletActive = signal(false)
|
||||||
|
userSettingsOpen = signal(false)
|
||||||
|
|
||||||
navigationActiveIndex = 0
|
navigationActiveIndex = 0
|
||||||
// Mobile navigation //
|
// Mobile navigation //
|
||||||
@@ -60,12 +68,12 @@ export class Chat implements OnInit {
|
|||||||
{
|
{
|
||||||
text: "chat.tabBar.tab3",
|
text: "chat.tabBar.tab3",
|
||||||
icon: '@tui.image',
|
icon: '@tui.image',
|
||||||
implemented: false,
|
implemented: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: "chat.tabBar.tab4",
|
text: "chat.tabBar.tab4",
|
||||||
icon: '@tui.cog',
|
icon: '@tui.cog',
|
||||||
implemented: false,
|
implemented: true,
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -81,7 +89,19 @@ export class Chat implements OnInit {
|
|||||||
this.indexedDb.openDatabase().then(async () => {
|
this.indexedDb.openDatabase().then(async () => {
|
||||||
const session = await this.serviceManager.sessionManager.loadPreferredSession()
|
const session = await this.serviceManager.sessionManager.loadPreferredSession()
|
||||||
this.serviceManager.currentSession.set(session)
|
this.serviceManager.currentSession.set(session)
|
||||||
|
this.serviceManager.currentSessionHandler = new UserService(session.userData.userid, session.token, this.indexedDb.getApi())
|
||||||
await WebSocketHandler.getInstance().connect(session.userData.userid, session.token)
|
await WebSocketHandler.getInstance().connect(session.userData.userid, session.token)
|
||||||
|
try {
|
||||||
|
console.log("Updating sessions...")
|
||||||
|
const sessions = await this.serviceManager.sessionManager.loadSessions()
|
||||||
|
console.log("Updating sessions: saved sessions loaded...")
|
||||||
|
await this.serviceManager.sessionManager.updateSessions(sessions)
|
||||||
|
const session = await this.serviceManager.sessionManager.loadPreferredSession()
|
||||||
|
console.log("Updating sessions succeeded: updating sessions...")
|
||||||
|
this.serviceManager.currentSession.set(session)
|
||||||
|
} catch (e) {
|
||||||
|
console.warn("Session update failed, skipping...", e)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|||||||
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 { 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();
|
||||||
});
|
});
|
||||||
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;
|
|
||||||
}
|
|
||||||
@@ -43,7 +43,6 @@ export class Dm implements OnInit {
|
|||||||
|
|
||||||
async sendMessage(message: string, files: FileDataWithPreview[] | null) {
|
async sendMessage(message: string, files: FileDataWithPreview[] | null) {
|
||||||
if (!files && message.trim() == "") return
|
if (!files && message.trim() == "") return
|
||||||
this.scrollToBottom("smooth")
|
|
||||||
|
|
||||||
const session = this.serviceManager.currentSession();
|
const session = this.serviceManager.currentSession();
|
||||||
if (session != null) {
|
if (session != null) {
|
||||||
@@ -102,14 +101,13 @@ export class Dm implements OnInit {
|
|||||||
forwardedFromName: ""
|
forwardedFromName: ""
|
||||||
}])
|
}])
|
||||||
|
|
||||||
this.scrollToBottom("smooth")
|
|
||||||
|
|
||||||
const respMessage = await this.store.service.sendMessage(tempMsgId, message, null, null, files, <FileUploadProgressListener>{
|
const respMessage = await this.store.service.sendMessage(tempMsgId, message, null, null, files, <FileUploadProgressListener>{
|
||||||
fileProgressUpdate: (tempMsgId, fileId, allChunks, chunksDone) => {
|
fileProgressUpdate: (tempMsgId, fileId, allChunks, chunksDone) => {
|
||||||
this.uploadProgressUpdate(tempMsgId, fileId, allChunks, chunksDone)
|
this.uploadProgressUpdate(tempMsgId, fileId, allChunks, chunksDone)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
this.updateTempMessage(tempMsgId, respMessage)
|
this.updateTempMessage(tempMsgId, respMessage)
|
||||||
|
this.scrollToBottom("smooth")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,13 +124,13 @@ export class Dm implements OnInit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
scrollToBottom(anim: 'instant' | 'smooth'): void {
|
restoreScrollState(): void {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const scrollContainer = <HTMLDivElement>document.querySelector("#scrollContainer")
|
const scrollContainer = <HTMLDivElement>document.querySelector("#scrollContainer")
|
||||||
scrollContainer.scroll({
|
scrollContainer.scroll({
|
||||||
top: this.store.messagesVm.scrollBarStatus() == -1 ? scrollContainer.scrollHeight : this.store.messagesVm.scrollBarStatus(),
|
top: this.store.messagesVm.scrollBarStatus() == -1 ? scrollContainer.scrollHeight : this.store.messagesVm.scrollBarStatus(),
|
||||||
left: 0,
|
left: 0,
|
||||||
behavior: anim
|
behavior: "instant"
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.store.messagesVm.scrollBarStatus() == -1) {
|
if (this.store.messagesVm.scrollBarStatus() == -1) {
|
||||||
@@ -141,6 +139,17 @@ export class Dm implements OnInit {
|
|||||||
}, 0)
|
}, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scrollToBottom(anim: 'instant' | 'smooth'): void {
|
||||||
|
setTimeout(() => {
|
||||||
|
const scrollContainer = <HTMLDivElement>document.querySelector("#scrollContainer")
|
||||||
|
scrollContainer.scroll({
|
||||||
|
top: scrollContainer.scrollHeight,
|
||||||
|
left: 0,
|
||||||
|
behavior: anim
|
||||||
|
});
|
||||||
|
}, 0)
|
||||||
|
}
|
||||||
|
|
||||||
handleMessagesScroll(e: any) {
|
handleMessagesScroll(e: any) {
|
||||||
this.store.messagesVm.scrollBarStatus.set(e.target.scrollTop)
|
this.store.messagesVm.scrollBarStatus.set(e.target.scrollTop)
|
||||||
}
|
}
|
||||||
@@ -241,18 +250,18 @@ export class Dm implements OnInit {
|
|||||||
const messagesCache = await currentStore.service.getQuick();
|
const messagesCache = await currentStore.service.getQuick();
|
||||||
currentStore.messages.set(messagesCache);
|
currentStore.messages.set(messagesCache);
|
||||||
this.store.messagesStatus.set(LoadStatus.updating)
|
this.store.messagesStatus.set(LoadStatus.updating)
|
||||||
this.scrollToBottom("instant")
|
this.restoreScrollState()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn(`Cache load failed: ${e}. Skipping cache load...`)
|
console.warn(`Cache load failed: ${e}. Skipping cache load...`)
|
||||||
}
|
}
|
||||||
const messages = await currentStore.service.get();
|
const messages = await currentStore.service.get();
|
||||||
currentStore.messages.set(messages);
|
currentStore.messages.set(messages);
|
||||||
this.store.messagesStatus.set(LoadStatus.loaded)
|
this.store.messagesStatus.set(LoadStatus.loaded)
|
||||||
this.scrollToBottom("instant")
|
this.restoreScrollState()
|
||||||
|
|
||||||
await currentStore.service.joinWebSocketRoom();
|
await currentStore.service.joinWebSocketRoom();
|
||||||
} else {
|
} else {
|
||||||
this.scrollToBottom("instant")
|
this.restoreScrollState()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
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];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,19 +1,35 @@
|
|||||||
<button disabled tuiButton appearance="secondary" iconStart="@tui.plus">
|
<div id="holder" [class.networkActive]="selectedNetwork() != null">
|
||||||
{{ "chat.chatnav.networkList.newNetwork"|translate }}
|
<div id="networks">
|
||||||
</button>
|
<button disabled tuiButton appearance="secondary" iconStart="@tui.plus">
|
||||||
@if (serviceManager.networksStatus() == LoadStatus.updating) {
|
{{ "chat.chatnav.networkList.newNetwork"|translate }}
|
||||||
<div id="loader">
|
</button>
|
||||||
<tui-loader />
|
@if (serviceManager.networksStatus() == LoadStatus.updating) {
|
||||||
{{"updating"|translate}}
|
<div id="loader">
|
||||||
|
<tui-loader />
|
||||||
|
{{"updating"|translate}}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
@for (network of serviceManager.networks(); track network.networkId) {
|
||||||
|
<button [class.enlarge]="breakpoint() == 'mobile'" tuiButton
|
||||||
|
appearance="flat"
|
||||||
|
(click)="selectNetwork(network)">
|
||||||
|
<oimg [src]="network.picture" height="35px" width="35px" [radius]="10"></oimg>
|
||||||
|
<div class="info">
|
||||||
|
<span>{{ network.name }}</span>
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
}
|
|
||||||
@for (network of serviceManager.networks(); track network.networkId) {
|
<div id="network">
|
||||||
<button [class.enlarge]="breakpoint() == 'mobile'" tuiButton
|
<div style="display: flex; align-items: center; gap: 1rem;">
|
||||||
[appearance]="router.url.startsWith('/chat/network/' + network.networkId) ? 'primary' : 'flat'"
|
<button tuiButton appearance="secondary" iconStart="@tui.arrow-left" (click)="selectNetwork(null)"></button>
|
||||||
[routerLink]="'/chat/network/' + network.networkId">
|
@if (selectedNetwork() != null) {
|
||||||
<oimg [src]="network.picture" height="35px" width="35px" [radius]="10"></oimg>
|
<oimg [src]="selectedNetwork()!.picture" height="35px" width="35px" [radius]="15"></oimg>
|
||||||
<div class="info">
|
<h3>{{ selectedNetwork()!.name }}</h3>
|
||||||
<span>{{ network.name }}</span>
|
}
|
||||||
</div>
|
</div>
|
||||||
</button>
|
<network [network]="selectedNetwork()!"></network>
|
||||||
}
|
</div>
|
||||||
|
</div>
|
||||||
|
|||||||
@@ -1,28 +1,68 @@
|
|||||||
:host {
|
#holder {
|
||||||
display: flex;
|
position: relative;
|
||||||
flex-direction: column;
|
|
||||||
gap: 5px;
|
|
||||||
|
|
||||||
button {
|
&.networkActive {
|
||||||
width: 100%;
|
#networks {
|
||||||
display: flex;
|
transform: translateX(100px);
|
||||||
justify-content: start;
|
opacity: 0;
|
||||||
font-weight: 600;
|
pointer-events: none;
|
||||||
|
|
||||||
&.enlarge {
|
|
||||||
height: 75px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.info {
|
#network {
|
||||||
display: flex;
|
pointer-events: all;
|
||||||
flex-direction: column;
|
transform: translateX(0);
|
||||||
text-align: start;
|
opacity: 1;
|
||||||
|
|
||||||
.latest_message {
|
network {
|
||||||
margin-top: -5px;
|
display: block;
|
||||||
font-size: 12px;
|
|
||||||
opacity: 50%;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#networks {
|
||||||
|
transition: 0.3s;
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
top: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 5px;
|
||||||
|
|
||||||
|
button {
|
||||||
|
width: 100%;
|
||||||
|
display: flex;
|
||||||
|
justify-content: start;
|
||||||
|
font-weight: 600;
|
||||||
|
|
||||||
|
&.enlarge {
|
||||||
|
height: 75px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
text-align: start;
|
||||||
|
|
||||||
|
.latest_message {
|
||||||
|
margin-top: -5px;
|
||||||
|
font-size: 12px;
|
||||||
|
opacity: 50%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#network {
|
||||||
|
pointer-events: none;
|
||||||
|
transform: translateX(-100px);
|
||||||
|
opacity: 0;
|
||||||
|
transition: 0.2s;
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
top: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import {Component, inject, input, OnInit} from '@angular/core';
|
import { Component, inject, input, model, OnInit, signal } from '@angular/core';
|
||||||
import {IndexedDB} from '../../storage/indexed-db';
|
import {IndexedDB} from '../../storage/indexed-db';
|
||||||
import {Router, RouterLink} from '@angular/router';
|
import {Router, RouterLink} from '@angular/router';
|
||||||
import {LoadStatus, ServiceManager} from '../../service-manager';
|
import {LoadStatus, ServiceManager} from '../../service-manager';
|
||||||
@@ -6,43 +6,53 @@ import {TUI_BREAKPOINT, TuiButton, TuiLoader} from '@taiga-ui/core';
|
|||||||
import {NetworkService} from '@chatenium/chatenium-sdk/services/networkService';
|
import {NetworkService} from '@chatenium/chatenium-sdk/services/networkService';
|
||||||
import {Oimg} from '../elements/oimg/oimg';
|
import {Oimg} from '../elements/oimg/oimg';
|
||||||
import {TranslatePipe} from '@ngx-translate/core';
|
import {TranslatePipe} from '@ngx-translate/core';
|
||||||
|
import { Network as NetworkData } from '@chatenium/chatenium-sdk/domain/networkService.schema';
|
||||||
|
import { Network } from '../network/network';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'network-list',
|
selector: 'network-list',
|
||||||
imports: [
|
imports: [Oimg, TranslatePipe, TuiButton, TuiLoader, Network],
|
||||||
Oimg,
|
|
||||||
TranslatePipe,
|
|
||||||
TuiButton,
|
|
||||||
RouterLink,
|
|
||||||
TuiLoader
|
|
||||||
],
|
|
||||||
templateUrl: './network-list.html',
|
templateUrl: './network-list.html',
|
||||||
styleUrl: './network-list.scss',
|
styleUrl: './network-list.scss',
|
||||||
})
|
})
|
||||||
export class NetworkList implements OnInit {
|
export class NetworkList implements OnInit {
|
||||||
userid = input<string>("")
|
userid = input<string>('');
|
||||||
token = input<string>("")
|
token = input<string>('');
|
||||||
|
expandedSidenav = model.required<boolean>();
|
||||||
|
|
||||||
indexedDb = inject(IndexedDB)
|
selectedNetwork = signal<NetworkData | null>(null);
|
||||||
router = inject(Router)
|
|
||||||
serviceManager = inject(ServiceManager)
|
indexedDb = inject(IndexedDB);
|
||||||
breakpoint = inject(TUI_BREAKPOINT)
|
router = inject(Router);
|
||||||
|
serviceManager = inject(ServiceManager);
|
||||||
|
breakpoint = inject(TUI_BREAKPOINT);
|
||||||
|
|
||||||
|
selectNetwork(network: NetworkData | null) {
|
||||||
|
this.selectedNetwork.set(network);
|
||||||
|
this.expandedSidenav.set(network !== null);
|
||||||
|
}
|
||||||
|
|
||||||
async ngOnInit() {
|
async ngOnInit() {
|
||||||
this.serviceManager.networkService = new NetworkService(this.userid(), this.token(), "", this.indexedDb.getApi(), () => {})
|
this.serviceManager.networkService = new NetworkService(
|
||||||
|
this.userid(),
|
||||||
|
this.token(),
|
||||||
|
'',
|
||||||
|
this.indexedDb.getApi(),
|
||||||
|
() => {},
|
||||||
|
);
|
||||||
if (this.serviceManager.networksStatus() != LoadStatus.loaded) {
|
if (this.serviceManager.networksStatus() != LoadStatus.loaded) {
|
||||||
try {
|
try {
|
||||||
this.serviceManager.networks.set(await this.serviceManager.networkService.getQuick())
|
this.serviceManager.networks.set(await this.serviceManager.networkService.getQuick());
|
||||||
this.serviceManager.networksStatus.set(LoadStatus.updating)
|
this.serviceManager.networksStatus.set(LoadStatus.updating);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn(`Cache load failed: ${e}. Skipping cache load...`)
|
console.warn(`Cache load failed: ${e}. Skipping cache load...`);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
this.serviceManager.networks.set(await this.serviceManager.networkService.get())
|
this.serviceManager.networks.set(await this.serviceManager.networkService.get());
|
||||||
this.serviceManager.networksStatus.set(LoadStatus.loaded)
|
this.serviceManager.networksStatus.set(LoadStatus.loaded);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e);
|
||||||
this.serviceManager.networksStatus.set(LoadStatus.error)
|
this.serviceManager.networksStatus.set(LoadStatus.error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,14 +116,13 @@ export class Text {
|
|||||||
forwardedFromName: ""
|
forwardedFromName: ""
|
||||||
}])
|
}])
|
||||||
|
|
||||||
this.scrollToBottom("smooth")
|
|
||||||
|
|
||||||
const respMessage = await this.store.service.sendMessage(tempMsgId, message, null, null, files, <FileUploadProgressListener>{
|
const respMessage = await this.store.service.sendMessage(tempMsgId, message, null, null, files, <FileUploadProgressListener>{
|
||||||
fileProgressUpdate: (tempMsgId, fileId, allChunks, chunksDone) => {
|
fileProgressUpdate: (tempMsgId, fileId, allChunks, chunksDone) => {
|
||||||
this.uploadProgressUpdate(tempMsgId, fileId, allChunks, chunksDone)
|
this.uploadProgressUpdate(tempMsgId, fileId, allChunks, chunksDone)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
this.updateTempMessage(tempMsgId, respMessage)
|
this.updateTempMessage(tempMsgId, respMessage)
|
||||||
|
this.scrollToBottom("smooth")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +140,7 @@ export class Text {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
scrollToBottom(anim: 'instant' | 'smooth'): void {
|
restoreScrollState() {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (!this.store) {
|
if (!this.store) {
|
||||||
return
|
return
|
||||||
@@ -150,7 +149,7 @@ export class Text {
|
|||||||
scrollContainer.scroll({
|
scrollContainer.scroll({
|
||||||
top: this.store.messagesVm.scrollBarStatus() == -1 ? scrollContainer.scrollHeight : this.store.messagesVm.scrollBarStatus(),
|
top: this.store.messagesVm.scrollBarStatus() == -1 ? scrollContainer.scrollHeight : this.store.messagesVm.scrollBarStatus(),
|
||||||
left: 0,
|
left: 0,
|
||||||
behavior: anim
|
behavior: "instant"
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.store.messagesVm.scrollBarStatus() == -1) {
|
if (this.store.messagesVm.scrollBarStatus() == -1) {
|
||||||
@@ -159,6 +158,17 @@ export class Text {
|
|||||||
}, 0)
|
}, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scrollToBottom(anim: 'instant' | 'smooth'): void {
|
||||||
|
setTimeout(() => {
|
||||||
|
const scrollContainer = <HTMLDivElement>document.querySelector("#scrollContainer")
|
||||||
|
scrollContainer.scroll({
|
||||||
|
top: scrollContainer.scrollHeight,
|
||||||
|
left: 0,
|
||||||
|
behavior: anim
|
||||||
|
});
|
||||||
|
}, 0)
|
||||||
|
}
|
||||||
|
|
||||||
handleMessagesScroll(e: any) {
|
handleMessagesScroll(e: any) {
|
||||||
if (!this.store) return
|
if (!this.store) return
|
||||||
this.store.messagesVm.scrollBarStatus.set(e.target.scrollTop)
|
this.store.messagesVm.scrollBarStatus.set(e.target.scrollTop)
|
||||||
@@ -282,7 +292,7 @@ export class Text {
|
|||||||
try {
|
try {
|
||||||
const messagesCache = await currentStore.service.getQuick();
|
const messagesCache = await currentStore.service.getQuick();
|
||||||
currentStore.messages.set(messagesCache);
|
currentStore.messages.set(messagesCache);
|
||||||
this.scrollToBottom("instant")
|
this.restoreScrollState()
|
||||||
currentStore.messagesStatus.set(LoadStatus.updating)
|
currentStore.messagesStatus.set(LoadStatus.updating)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn(`Cache load failed: ${e}. Skipping cache load...`)
|
console.warn(`Cache load failed: ${e}. Skipping cache load...`)
|
||||||
@@ -290,11 +300,11 @@ export class Text {
|
|||||||
const messages = await currentStore.service.get();
|
const messages = await currentStore.service.get();
|
||||||
currentStore.messages.set(messages);
|
currentStore.messages.set(messages);
|
||||||
currentStore.messagesStatus.set(LoadStatus.loaded)
|
currentStore.messagesStatus.set(LoadStatus.loaded)
|
||||||
this.scrollToBottom("instant")
|
this.restoreScrollState()
|
||||||
|
|
||||||
await currentStore.service.joinWebSocketRoom();
|
await currentStore.service.joinWebSocketRoom();
|
||||||
} else {
|
} else {
|
||||||
this.scrollToBottom("instant")
|
this.restoreScrollState()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,82 +1,43 @@
|
|||||||
@defer(when store) {
|
@defer (when store) {
|
||||||
<div id="layout" [class.routerOutletActive]="routerOutletActive()" [class.hideNetworkNav]="routerOutletActive() && breakpoint() == 'desktopSmall'">
|
<div id="layout" [class.routerOutletActive]="routerOutletActive()"
|
||||||
<div id="router">
|
[class.hideNetworkNav]="routerOutletActive() && breakpoint() == 'desktopSmall'">
|
||||||
<router-outlet (activate)="routerOutletActive.set(true)" (deactivate)="routerOutletActive.set(false)"></router-outlet>
|
|
||||||
</div>
|
|
||||||
<div id="network-data">
|
<div id="network-data">
|
||||||
<navbar backButtonDest="/chat" dataAlignment="center">
|
<main tuiGroup orientation="vertical" style="width: 100%; height: 80svh">
|
||||||
<div class="data">
|
@for (category of store.networkData().categories; track category) {
|
||||||
<oimg [src]="store.networkData().picture" height="50px" width="50px" [radius]="15"></oimg>
|
<div class="category">
|
||||||
<h2>{{store.networkData().name}}</h2>
|
<h2>{{ category.name }}</h2>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="items-right"></div>
|
<div class="channels">
|
||||||
</navbar>
|
@for (channel of category.channels; track channel) {
|
||||||
|
<div class="channel">
|
||||||
<tui-tabs [(activeItemIndex)]="tabActiveIndex">
|
<button tuiButton
|
||||||
<button
|
[appearance]="router.url.endsWith(channel.channelId) ? 'secondary' : 'flat'"
|
||||||
iconStart="@tui.hash"
|
[disabled]="channel.type != 'message'"
|
||||||
tuiTab
|
[routerLink]="'/chat/network/'+store.networkData().networkId+'/'+category.categoryId+'/'+channel.channelId">
|
||||||
type="button"
|
@switch (channel.type) {
|
||||||
>
|
@case ("message") {
|
||||||
{{"chat.network.tabs.channels"|translate}}
|
<tui-icon icon="@tui.hash"></tui-icon>
|
||||||
</button>
|
|
||||||
|
|
||||||
<button
|
|
||||||
disabled
|
|
||||||
iconStart="@tui.users"
|
|
||||||
tuiTab
|
|
||||||
type="button"
|
|
||||||
>
|
|
||||||
{{"chat.network.tabs.members"|translate}}
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<button
|
|
||||||
iconStart="@tui.cog"
|
|
||||||
tuiTab
|
|
||||||
type="button"
|
|
||||||
>
|
|
||||||
{{"chat.network.tabs.settings"|translate}}
|
|
||||||
</button>
|
|
||||||
</tui-tabs>
|
|
||||||
|
|
||||||
<br/>
|
|
||||||
|
|
||||||
@switch (tabActiveIndex) {
|
|
||||||
@case (0) {
|
|
||||||
<main tuiGroup orientation="vertical" style="width: 100%">
|
|
||||||
@for (category of store.networkData().categories; track category) {
|
|
||||||
<div class="category">
|
|
||||||
<h2>{{category.name}}</h2>
|
|
||||||
|
|
||||||
<div tuiGroup orientation="vertical" style="width: 100%">
|
|
||||||
@for (channel of category.channels; track channel) {
|
|
||||||
<button tuiButton class="channel" [appearance]="router.url.endsWith(channel.channelId) ? 'primary' : 'secondary'" [disabled]="channel.type != 'message'" [routerLink]="'/chat/network/'+store.networkData().networkId+'/'+category.categoryId+'/'+channel.channelId">
|
|
||||||
@switch (channel.type) {
|
|
||||||
@case ("message") {
|
|
||||||
<tui-icon icon="@tui.hash"></tui-icon>
|
|
||||||
}
|
|
||||||
@case ("broadcast") {
|
|
||||||
<tui-icon icon="@tui.radio"></tui-icon>
|
|
||||||
}
|
|
||||||
@case ("voice") {
|
|
||||||
<tui-icon icon="@tui.audio-lines"></tui-icon>
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
<span>{{channel.name}}</span>
|
@case ("broadcast") {
|
||||||
</button>
|
<tui-icon icon="@tui.radio"></tui-icon>
|
||||||
}
|
}
|
||||||
|
@case ("voice") {
|
||||||
|
<tui-icon icon="@tui.audio-lines"></tui-icon>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
<span>{{ channel.name }}</span>
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
}
|
||||||
}
|
</div>
|
||||||
</main>
|
</div>
|
||||||
}
|
}
|
||||||
@case (2) {
|
</main>
|
||||||
<main id="settings">
|
<!-- @case (2) {
|
||||||
<network-settings [networkStore]="this.store"></network-settings>
|
<main id="settings">
|
||||||
</main>
|
<network-settings [networkStore]="this.store"></network-settings>
|
||||||
}
|
</main>
|
||||||
}
|
}-->
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,6 @@
|
|||||||
overflow-y: scroll;
|
overflow-y: scroll;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
display: grid;
|
|
||||||
grid-template-columns: 0 100%;
|
|
||||||
overflow-x: hidden;
|
overflow-x: hidden;
|
||||||
padding: 15px;
|
padding: 15px;
|
||||||
transition: 0.2s;
|
transition: 0.2s;
|
||||||
@@ -13,20 +11,6 @@
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
|
|
||||||
&.routerOutletActive {
|
|
||||||
overflow-y: hidden;
|
|
||||||
padding: 0;
|
|
||||||
grid-template-columns: 1fr 300px;
|
|
||||||
|
|
||||||
#router {
|
|
||||||
background: var(--tui-background-neutral-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
main {
|
|
||||||
padding: 15px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&.hideNetworkNav {
|
&.hideNetworkNav {
|
||||||
grid-template-columns: 1fr;
|
grid-template-columns: 1fr;
|
||||||
|
|
||||||
@@ -38,7 +22,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.category {
|
.category {
|
||||||
background: var(--tui-background-base-alt);
|
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 15px;
|
padding: 15px;
|
||||||
|
|
||||||
@@ -46,6 +29,31 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
justify-content: start;
|
justify-content: start;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.channels {
|
||||||
|
position: relative;
|
||||||
|
padding-left: 24px; /* Space for the line and spacing */
|
||||||
|
border-left: 2px solid var(--tui-background-neutral-1-hover); /* Main vertical track */
|
||||||
|
margin-left: 8px; /* Shifts child tracks slightly right */
|
||||||
|
|
||||||
|
.channel {
|
||||||
|
height: 50px;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.channel::before {
|
||||||
|
content: "";
|
||||||
|
position: absolute;
|
||||||
|
left: -26px; /* Reaches backward to snap to the parent track */
|
||||||
|
top: 10px; /* Aligns horizontally with the center of the user header */
|
||||||
|
width: 22px; /* Defines width of the horizontal curve */
|
||||||
|
height: 14px; /* Defines height of the vertical curve drop */
|
||||||
|
|
||||||
|
border-left: 2px solid var(--tui-background-neutral-1-hover);
|
||||||
|
border-bottom: 2px solid var(--tui-background-neutral-1-hover);
|
||||||
|
border-bottom-left-radius: 8px; /* Creates the smooth curved bend */
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#settings {
|
#settings {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import {Component, inject, OnInit, signal} from '@angular/core';
|
import { Component, effect, inject, input, OnInit, signal } from '@angular/core';
|
||||||
import {ActivatedRoute, Router, RouterLink, RouterOutlet} from '@angular/router';
|
import {ActivatedRoute, Router, RouterLink, RouterOutlet} from '@angular/router';
|
||||||
import {Chat} from '@chatenium/chatenium-sdk/domain/chatService.schema';
|
import {Chat} from '@chatenium/chatenium-sdk/domain/chatService.schema';
|
||||||
import {Message} from '@chatenium/chatenium-sdk/domain/dmService.schema';
|
import {Message} from '@chatenium/chatenium-sdk/domain/dmService.schema';
|
||||||
@@ -15,9 +15,10 @@ import {TuiTab, TuiTabsHorizontal, TuiTabsWithMore} from '@taiga-ui/kit';
|
|||||||
import {TuiItem} from '@taiga-ui/cdk';
|
import {TuiItem} from '@taiga-ui/cdk';
|
||||||
import {TranslatePipe} from '@ngx-translate/core';
|
import {TranslatePipe} from '@ngx-translate/core';
|
||||||
import {Settings} from './settings/settings';
|
import {Settings} from './settings/settings';
|
||||||
|
import { toObservable } from '@angular/core/rxjs-interop';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-network',
|
selector: 'network',
|
||||||
imports: [
|
imports: [
|
||||||
RouterOutlet,
|
RouterOutlet,
|
||||||
Navbar,
|
Navbar,
|
||||||
@@ -31,59 +32,61 @@ import {Settings} from './settings/settings';
|
|||||||
TuiTab,
|
TuiTab,
|
||||||
TranslatePipe,
|
TranslatePipe,
|
||||||
TuiTabsHorizontal,
|
TuiTabsHorizontal,
|
||||||
Settings
|
Settings,
|
||||||
],
|
],
|
||||||
templateUrl: './network.html',
|
templateUrl: './network.html',
|
||||||
styleUrl: './network.scss',
|
styleUrl: './network.scss',
|
||||||
})
|
})
|
||||||
export class Network implements OnInit {
|
export class Network {
|
||||||
serviceManager = inject(ServiceManager)
|
serviceManager = inject(ServiceManager);
|
||||||
route = inject(ActivatedRoute)
|
route = inject(ActivatedRoute);
|
||||||
indexedDb = inject(IndexedDB)
|
indexedDb = inject(IndexedDB);
|
||||||
breakpoint = inject(TUI_BREAKPOINT)
|
breakpoint = inject(TUI_BREAKPOINT);
|
||||||
router = inject(Router)
|
router = inject(Router);
|
||||||
|
|
||||||
tabActiveIndex = 2
|
constructor() {
|
||||||
|
effect(() => {
|
||||||
routerOutletActive = signal(false)
|
if (this.network()) {
|
||||||
|
this.setupNetwork();
|
||||||
networkId = ""
|
|
||||||
get store() {
|
|
||||||
return this.serviceManager.networkServices()[this.networkId]
|
|
||||||
}
|
|
||||||
|
|
||||||
ngOnInit() {
|
|
||||||
this.route.params.subscribe(async params => {
|
|
||||||
console.log("Loading network...")
|
|
||||||
const networkId = params['networkId'];
|
|
||||||
this.networkId = networkId;
|
|
||||||
|
|
||||||
const session = this.serviceManager.currentSession();
|
|
||||||
const networkData = this.serviceManager.networks().find(c => c.networkId === networkId);
|
|
||||||
|
|
||||||
if (!session || !networkData) {
|
|
||||||
console.warn(`Initialization deferred for ${networkId}: Session or NetworkData missing.`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this.serviceManager.networkServices()[networkId]) {
|
|
||||||
const newStore = {
|
|
||||||
networkData: signal<NetworkData>(networkData),
|
|
||||||
textChannels: signal({}),
|
|
||||||
wsListener: (action, data) => {
|
|
||||||
},
|
|
||||||
} as NetworkStorage;
|
|
||||||
|
|
||||||
newStore.service = new NetworkService(
|
|
||||||
session.userData.userid,
|
|
||||||
session.token,
|
|
||||||
networkId,
|
|
||||||
this.indexedDb.getApi(),
|
|
||||||
(action, data) => newStore.wsListener(action, data)
|
|
||||||
);
|
|
||||||
|
|
||||||
this.serviceManager.networkServices()[networkId] = newStore;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
network = input.required<NetworkData>();
|
||||||
|
|
||||||
|
routerOutletActive = signal(false);
|
||||||
|
|
||||||
|
get store() {
|
||||||
|
return this.serviceManager.networkServices()[this.network().networkId];
|
||||||
|
}
|
||||||
|
|
||||||
|
setupNetwork() {
|
||||||
|
console.log(`Setting up NetworkView for ${this.network().networkId}`);
|
||||||
|
const session = this.serviceManager.currentSession();
|
||||||
|
|
||||||
|
if (!session) {
|
||||||
|
console.warn(
|
||||||
|
`Initialization deferred for ${this.network().networkId}: Session or NetworkData missing.`,
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.serviceManager.networkServices()[this.network().networkId]) {
|
||||||
|
const newStore = {
|
||||||
|
networkData: signal<NetworkData>(this.network()),
|
||||||
|
textChannels: signal({}),
|
||||||
|
wsListener: (action, data) => {},
|
||||||
|
} as NetworkStorage;
|
||||||
|
|
||||||
|
newStore.service = new NetworkService(
|
||||||
|
session.userData.userid,
|
||||||
|
session.token,
|
||||||
|
this.network().networkId,
|
||||||
|
this.indexedDb.getApi(),
|
||||||
|
(action, data) => newStore.wsListener(action, data),
|
||||||
|
);
|
||||||
|
|
||||||
|
this.serviceManager.networkServices()[this.network().networkId] = newStore;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
100
src/app/chat/user-settings/security/email/email.html
Normal file
100
src/app/chat/user-settings/security/email/email.html
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
<div class="option" [class.mobile]="breakpoint() == 'mobile'">
|
||||||
|
<ng-template [(tuiDialog)]="changeEmailDialogOpen"
|
||||||
|
[tuiDialogOptions]="{label: ('chat.userSettingsDialog.security.changeEmailDialog.'+ (changeEmailRemoveMode() ? 'labelRemove' : serviceManager.currentSession()!.userData.emailSet ? 'label' : 'labelSet'))|translate}">
|
||||||
|
<p>{{ "chat.userSettingsDialog.security.changeEmailDialog.warn"|translate }}</p>
|
||||||
|
@if (step() == 0) {
|
||||||
|
<form [formGroup]="changeEmailForm" style="display: flex; flex-direction: column; gap: 10px">
|
||||||
|
@if (!changeEmailRemoveMode()) {
|
||||||
|
<tui-textfield iconStart="@tui.mail">
|
||||||
|
<label
|
||||||
|
tuiLabel>{{ "chat.userSettingsDialog.security.changeEmailDialog.newMail"|translate }}</label>
|
||||||
|
<input formControlName="newAddress" tuiInput type="email">
|
||||||
|
</tui-textfield>
|
||||||
|
}
|
||||||
|
|
||||||
|
<tui-textfield iconStart="@tui.key">
|
||||||
|
<label tuiLabel>{{ "chat.userSettingsDialog.security.changeEmailDialog.currentPassword"|translate }}</label>
|
||||||
|
<input formControlName="currentPassword" tuiInput type="password">
|
||||||
|
</tui-textfield>
|
||||||
|
|
||||||
|
@if (changeEmailForm.controls['currentPassword'].dirty) {
|
||||||
|
@if (changeEmailForm.controls['currentPassword'].hasError("required")) {
|
||||||
|
<tui-error
|
||||||
|
[error]="'chat.userSettingsDialog.security.changeEmailDialog.errors.currentPasswordRequired'|translate"></tui-error>
|
||||||
|
}
|
||||||
|
|
||||||
|
@if (changeEmailForm.controls['currentPassword'].hasError("incorrect")) {
|
||||||
|
<tui-error
|
||||||
|
[error]="'chat.userSettingsDialog.security.changeEmailDialog.errors.incorrectPassword'|translate"></tui-error>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<button tuiButton iconStart="@tui.check" [loading]="changeEmailPending()"
|
||||||
|
[disabled]="changeEmailPending()"
|
||||||
|
(click)="changeEmail(changeEmailForm.controls['currentPassword'].value, changeEmailForm.controls['newAddress'].value)">
|
||||||
|
{{ ('chat.userSettingsDialog.security.changeEmailDialog.' + (changeEmailRemoveMode() ? 'labelRemove' : serviceManager.currentSession()!.userData.passwordSet ? 'label' : 'labelSet'))|translate }}
|
||||||
|
</button>
|
||||||
|
</footer>
|
||||||
|
} @else {
|
||||||
|
<form style="display: flex; flex-direction: column; gap: 10px" [formGroup]="verifyEmailForm">
|
||||||
|
@if (serviceManager.currentSession()!.userData.emailSet) {
|
||||||
|
<tui-textfield iconStart="@tui.mail">
|
||||||
|
<label tuiLabel>{{ "chat.userSettingsDialog.security.changeEmailDialog.oldCode"|translate }}</label>
|
||||||
|
<input tuiInput type="number" [step]="1" formControlName="oldCode">
|
||||||
|
</tui-textfield>
|
||||||
|
}
|
||||||
|
|
||||||
|
@if (!changeEmailRemoveMode()) {
|
||||||
|
<tui-textfield iconStart="@tui.badge-plus">
|
||||||
|
<label tuiLabel>{{ "chat.userSettingsDialog.security.changeEmailDialog.newCode"|translate }}</label>
|
||||||
|
<input tuiInput type="number" [step]="1" formControlName="newCode">
|
||||||
|
</tui-textfield>
|
||||||
|
}
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<button tuiButton iconStart="@tui.check" [loading]="verifyEmailPending()"
|
||||||
|
[disabled]="verifyEmailForm.invalid || verifyEmailPending()"
|
||||||
|
(click)="verifyEmail(verifyEmailForm.controls['newCode'].value, verifyEmailForm.controls['oldCode'].value)">
|
||||||
|
{{ ('chat.userSettingsDialog.security.changeEmailDialog.' + (changeEmailRemoveMode() ? 'labelRemove' : serviceManager.currentSession()!.userData.passwordSet ? 'label' : 'labelSet'))|translate }}
|
||||||
|
</button>
|
||||||
|
</footer>
|
||||||
|
}
|
||||||
|
</ng-template>
|
||||||
|
|
||||||
|
<header>
|
||||||
|
<tui-icon icon="@tui.mail"/>
|
||||||
|
<span>{{ "chat.userSettingsDialog.security.email"|translate }}</span>
|
||||||
|
|
||||||
|
@if (serviceManager.currentSession()!.userData.emailSet) {
|
||||||
|
<div tuiBadge appearance="positive"
|
||||||
|
iconStart="@tui.check">{{ 'chat.userSettingsDialog.security.set'|translate }}
|
||||||
|
</div>
|
||||||
|
} @else {
|
||||||
|
<div tuiBadge appearance="negative"
|
||||||
|
iconStart="@tui.x">{{ 'chat.userSettingsDialog.security.notSet'|translate }}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<button tuiButton appearance="outline" (click)="openChangeEmailDialog(false)"
|
||||||
|
[iconStart]="serviceManager.currentSession()!.userData.emailSet ? '@tui.pencil' : '@tui.plus'">
|
||||||
|
@if (serviceManager.currentSession()!.userData.phoneSet) {
|
||||||
|
{{ "chat.userSettingsDialog.security.changeMail"|translate }}
|
||||||
|
} @else {
|
||||||
|
{{ "chat.userSettingsDialog.security.setMail"|translate }}
|
||||||
|
}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
@if (serviceManager.currentSession()!.userData.emailSet) {
|
||||||
|
<button tuiButton appearance="outline" tuiAppearanceMode="invalid" iconStart="@tui.x" [disabled]="!serviceManager.currentSession()!.userData.phoneSet && !serviceManager.currentSession()!.userData.passwordSet"
|
||||||
|
(click)="openChangeEmailDialog(true)"
|
||||||
|
style="color: var(--tui-text-negative)">
|
||||||
|
{{ "chat.userSettingsDialog.security.removeMail"|translate }}
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
22
src/app/chat/user-settings/security/email/email.spec.ts
Normal file
22
src/app/chat/user-settings/security/email/email.spec.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { Email } from './email';
|
||||||
|
|
||||||
|
describe('Email', () => {
|
||||||
|
let component: Email;
|
||||||
|
let fixture: ComponentFixture<Email>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
imports: [Email],
|
||||||
|
}).compileComponents();
|
||||||
|
|
||||||
|
fixture = TestBed.createComponent(Email);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
await fixture.whenStable();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
112
src/app/chat/user-settings/security/email/email.ts
Normal file
112
src/app/chat/user-settings/security/email/email.ts
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
import {Component, inject, signal} from '@angular/core';
|
||||||
|
import {TranslatePipe} from '@ngx-translate/core';
|
||||||
|
import {TuiBadge, TuiButtonLoading, TuiInputNumber} from '@taiga-ui/kit';
|
||||||
|
import {
|
||||||
|
TUI_BREAKPOINT,
|
||||||
|
TuiButton,
|
||||||
|
TuiDialog,
|
||||||
|
TuiErrorComponent,
|
||||||
|
TuiIcon,
|
||||||
|
TuiInputDirective,
|
||||||
|
TuiLabel,
|
||||||
|
TuiTextfieldComponent
|
||||||
|
} from '@taiga-ui/core';
|
||||||
|
import {ServiceManager} from '../../../../service-manager';
|
||||||
|
import {
|
||||||
|
AbstractControl,
|
||||||
|
FormControl,
|
||||||
|
FormGroup,
|
||||||
|
ReactiveFormsModule,
|
||||||
|
ValidationErrors,
|
||||||
|
Validators
|
||||||
|
} from '@angular/forms';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'user-settings-security-email',
|
||||||
|
imports: [
|
||||||
|
TranslatePipe,
|
||||||
|
TuiBadge,
|
||||||
|
TuiButton,
|
||||||
|
TuiIcon,
|
||||||
|
ReactiveFormsModule,
|
||||||
|
TuiButtonLoading,
|
||||||
|
TuiDialog,
|
||||||
|
TuiErrorComponent,
|
||||||
|
TuiInputDirective,
|
||||||
|
TuiLabel,
|
||||||
|
TuiTextfieldComponent,
|
||||||
|
TuiInputNumber,
|
||||||
|
],
|
||||||
|
templateUrl: './email.html',
|
||||||
|
styleUrl: './email.scss',
|
||||||
|
})
|
||||||
|
export class Email {
|
||||||
|
serviceManager = inject(ServiceManager)
|
||||||
|
breakpoint = inject(TUI_BREAKPOINT)
|
||||||
|
|
||||||
|
step = signal(0)
|
||||||
|
changeEmailDialogOpen = signal(false)
|
||||||
|
changeEmailRemoveMode = signal(false)
|
||||||
|
changeEmailPending = signal(false)
|
||||||
|
verifyEmailPending = signal(false)
|
||||||
|
newAddress = ""
|
||||||
|
|
||||||
|
changeEmailForm = new FormGroup({
|
||||||
|
newAddress: new FormControl(""),
|
||||||
|
currentPassword: new FormControl(""),
|
||||||
|
})
|
||||||
|
|
||||||
|
verifyEmailForm = new FormGroup({
|
||||||
|
oldCode: new FormControl(0),
|
||||||
|
newCode: new FormControl(0, {validators: [Validators.required]})
|
||||||
|
})
|
||||||
|
|
||||||
|
openChangeEmailDialog(modeRemove: boolean) {
|
||||||
|
this.changeEmailDialogOpen.set(true)
|
||||||
|
this.changeEmailRemoveMode.set(modeRemove)
|
||||||
|
this.changeEmailForm.controls["currentPassword"].clearValidators()
|
||||||
|
this.changeEmailForm.controls["newAddress"].clearValidators()
|
||||||
|
if (!modeRemove) {
|
||||||
|
this.changeEmailForm.controls["newAddress"].setValidators([Validators.required])
|
||||||
|
this.changeEmailForm.controls["newAddress"].updateValueAndValidity()
|
||||||
|
}
|
||||||
|
|
||||||
|
this.changeEmailForm.controls["currentPassword"].setValidators([Validators.required])
|
||||||
|
this.changeEmailForm.controls["currentPassword"].updateValueAndValidity()
|
||||||
|
}
|
||||||
|
|
||||||
|
async changeEmail(currentPassword: string | null, newMail: string | null) {
|
||||||
|
if (this.changeEmailRemoveMode()) {
|
||||||
|
newMail = "remove"
|
||||||
|
}
|
||||||
|
this.changeEmailPending.set(true)
|
||||||
|
const service = this.serviceManager.currentSessionHandler
|
||||||
|
if (service) {
|
||||||
|
try {
|
||||||
|
await service.changeEmail(newMail ?? "", currentPassword ?? "")
|
||||||
|
this.step.set(1)
|
||||||
|
this.newAddress = newMail ?? ""
|
||||||
|
if (!this.changeEmailRemoveMode()) {
|
||||||
|
this.verifyEmailForm.controls["oldCode"].setValidators([Validators.required])
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
this.changeEmailForm.controls["currentPassword"].setErrors({incorrect: true})
|
||||||
|
this.changeEmailPending.set(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async verifyEmail(newCode: number | null, oldCode: number | null) {
|
||||||
|
this.verifyEmailPending.set(true)
|
||||||
|
const service = this.serviceManager.currentSessionHandler
|
||||||
|
if (service) {
|
||||||
|
try {
|
||||||
|
await service.verifyEmailChange(oldCode ?? 0, newCode ?? 0, this.newAddress)
|
||||||
|
this.changeEmailDialogOpen.set(false)
|
||||||
|
} catch (e) {
|
||||||
|
this.verifyEmailForm.controls["newCode"].setErrors({incorrect: true})
|
||||||
|
this.verifyEmailPending.set(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
81
src/app/chat/user-settings/security/password/password.html
Normal file
81
src/app/chat/user-settings/security/password/password.html
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
<div class="option" [class.mobile]="breakpoint() == 'mobile'">
|
||||||
|
<ng-template [(tuiDialog)]="changePasswordDialogOpen"
|
||||||
|
[tuiDialogOptions]="{label: ('chat.userSettingsDialog.security.changePasswordDialog.'+ (changePasswordRemoveMode() ? 'labelRemove' : serviceManager.currentSession()!.userData.passwordSet ? 'label' : 'labelSet'))|translate}">
|
||||||
|
<p>{{"chat.userSettingsDialog.security.changePasswordDialog.warn"|translate}}</p>
|
||||||
|
<form [formGroup]="changeEmailForm" style="display: flex; flex-direction: column; gap: 10px">
|
||||||
|
@if (serviceManager.currentSession()!.userData.passwordSet) {
|
||||||
|
<tui-textfield iconStart="@tui.key">
|
||||||
|
<label
|
||||||
|
tuiLabel>{{ "chat.userSettingsDialog.security.changePasswordDialog.currentPassword"|translate }}</label>
|
||||||
|
<input formControlName="currentPassword" tuiInput type="password">
|
||||||
|
</tui-textfield>
|
||||||
|
|
||||||
|
@if (changeEmailForm.controls['currentPassword'].dirty) {
|
||||||
|
@if (changeEmailForm.controls['currentPassword'].hasError("required")) {
|
||||||
|
<tui-error
|
||||||
|
[error]="'chat.userSettingsDialog.security.changePasswordDialog.errors.currentPasswordRequired'|translate"></tui-error>
|
||||||
|
}
|
||||||
|
|
||||||
|
@if (changeEmailForm.controls['currentPassword'].hasError("incorrect")) {
|
||||||
|
<tui-error
|
||||||
|
[error]="'chat.userSettingsDialog.security.changePasswordDialog.errors.incorrectPassword'|translate"></tui-error>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@if (!changePasswordRemoveMode()) {
|
||||||
|
<tui-textfield iconStart="@tui.badge-plus">
|
||||||
|
<label tuiLabel>{{ "chat.userSettingsDialog.security.changePasswordDialog.newPassword"|translate }}</label>
|
||||||
|
<input formControlName="newPassword" tuiInput type="password">
|
||||||
|
</tui-textfield>
|
||||||
|
|
||||||
|
<tui-textfield iconStart="@tui.badge-plus">
|
||||||
|
<label
|
||||||
|
tuiLabel>{{ "chat.userSettingsDialog.security.changePasswordDialog.newPasswordRepeat"|translate }}</label>
|
||||||
|
<input formControlName="newPasswordRepeat" tuiInput type="password">
|
||||||
|
</tui-textfield>
|
||||||
|
}
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<button tuiButton iconStart="@tui.check" [loading]="changePasswordPending()"
|
||||||
|
[disabled]="changeEmailForm.invalid || changePasswordPending()"
|
||||||
|
(click)="changePassword(changeEmailForm.controls['currentPassword'].value, changeEmailForm.controls['newPassword'].value)">
|
||||||
|
{{ ('chat.userSettingsDialog.security.changePasswordDialog.' + (changePasswordRemoveMode() ? 'labelRemove' : serviceManager.currentSession()!.userData.passwordSet ? 'label' : 'labelSet'))|translate }}
|
||||||
|
</button>
|
||||||
|
</footer>
|
||||||
|
</ng-template>
|
||||||
|
|
||||||
|
<header>
|
||||||
|
<tui-icon icon="@tui.key"/>
|
||||||
|
<span>{{ "chat.userSettingsDialog.security.password"|translate }}</span>
|
||||||
|
|
||||||
|
@if (serviceManager.currentSession()!.userData.passwordSet) {
|
||||||
|
<div tuiBadge appearance="positive"
|
||||||
|
iconStart="@tui.check">{{ 'chat.userSettingsDialog.security.set'|translate }}
|
||||||
|
</div>
|
||||||
|
} @else {
|
||||||
|
<div tuiBadge appearance="negative"
|
||||||
|
iconStart="@tui.x">{{ 'chat.userSettingsDialog.security.notSet'|translate }}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<button tuiButton appearance="outline" (click)="openChangePasswordDialog(false)"
|
||||||
|
[iconStart]="serviceManager.currentSession()!.userData.passwordSet ? '@tui.pencil' : '@tui.plus'">
|
||||||
|
@if (serviceManager.currentSession()!.userData.passwordSet) {
|
||||||
|
{{ "chat.userSettingsDialog.security.changePassword"|translate }}
|
||||||
|
} @else {
|
||||||
|
{{ "chat.userSettingsDialog.security.setPassword"|translate }}
|
||||||
|
}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
@if (serviceManager.currentSession()!.userData.passwordSet) {
|
||||||
|
<button tuiButton appearance="outline" tuiAppearanceMode="invalid" iconStart="@tui.x" [disabled]="!serviceManager.currentSession()!.userData.phoneSet && !serviceManager.currentSession()!.userData.emailSet"
|
||||||
|
style="color: var(--tui-text-negative)" (click)="openChangePasswordDialog(true)">
|
||||||
|
{{ "chat.userSettingsDialog.security.removePassword"|translate }}
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
:host {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { Password } from './password';
|
||||||
|
|
||||||
|
describe('Password', () => {
|
||||||
|
let component: Password;
|
||||||
|
let fixture: ComponentFixture<Password>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
imports: [Password],
|
||||||
|
}).compileComponents();
|
||||||
|
|
||||||
|
fixture = TestBed.createComponent(Password);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
await fixture.whenStable();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
93
src/app/chat/user-settings/security/password/password.ts
Normal file
93
src/app/chat/user-settings/security/password/password.ts
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
import {Component, inject, signal} from '@angular/core';
|
||||||
|
import {ServiceManager} from '../../../../service-manager';
|
||||||
|
import {
|
||||||
|
AbstractControl,
|
||||||
|
FormControl,
|
||||||
|
FormGroup,
|
||||||
|
FormsModule,
|
||||||
|
ReactiveFormsModule,
|
||||||
|
ValidationErrors,
|
||||||
|
Validators
|
||||||
|
} from '@angular/forms';
|
||||||
|
import {TranslatePipe} from '@ngx-translate/core';
|
||||||
|
import {TuiBadge, TuiButtonLoading} from '@taiga-ui/kit';
|
||||||
|
import {
|
||||||
|
TUI_BREAKPOINT,
|
||||||
|
TuiButton,
|
||||||
|
TuiDialog,
|
||||||
|
TuiErrorComponent,
|
||||||
|
TuiIcon,
|
||||||
|
TuiInputDirective,
|
||||||
|
TuiLabel,
|
||||||
|
TuiTextfieldComponent
|
||||||
|
} from '@taiga-ui/core';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'user-settings-security-password',
|
||||||
|
imports: [
|
||||||
|
FormsModule,
|
||||||
|
ReactiveFormsModule,
|
||||||
|
TranslatePipe,
|
||||||
|
TuiBadge,
|
||||||
|
TuiButton,
|
||||||
|
TuiButtonLoading,
|
||||||
|
TuiDialog,
|
||||||
|
TuiErrorComponent,
|
||||||
|
TuiIcon,
|
||||||
|
TuiInputDirective,
|
||||||
|
TuiLabel,
|
||||||
|
TuiTextfieldComponent
|
||||||
|
],
|
||||||
|
templateUrl: './password.html',
|
||||||
|
styleUrl: './password.scss',
|
||||||
|
})
|
||||||
|
export class Password {
|
||||||
|
serviceManager = inject(ServiceManager)
|
||||||
|
breakpoint = inject(TUI_BREAKPOINT)
|
||||||
|
|
||||||
|
changePasswordDialogOpen = signal(false)
|
||||||
|
changePasswordRemoveMode = signal(false)
|
||||||
|
changePasswordPending = signal(false)
|
||||||
|
|
||||||
|
changeEmailForm = new FormGroup({
|
||||||
|
currentPassword: new FormControl(""),
|
||||||
|
newPassword: new FormControl(""),
|
||||||
|
newPasswordRepeat: new FormControl("")
|
||||||
|
}, {
|
||||||
|
validators: [(group) => this.chkPassMatch(group)]
|
||||||
|
})
|
||||||
|
|
||||||
|
openChangePasswordDialog(modeRemove: boolean) {
|
||||||
|
this.changePasswordDialogOpen.set(true)
|
||||||
|
this.changePasswordRemoveMode.set(modeRemove)
|
||||||
|
this.changeEmailForm.controls["currentPassword"].clearValidators()
|
||||||
|
this.changeEmailForm.controls["newPassword"].clearValidators()
|
||||||
|
this.changeEmailForm.controls["newPasswordRepeat"].clearValidators()
|
||||||
|
if (!modeRemove) {
|
||||||
|
this.changeEmailForm.controls["newPassword"].setValidators([Validators.required])
|
||||||
|
this.changeEmailForm.controls["newPasswordRepeat"].setValidators([Validators.required])
|
||||||
|
this.changeEmailForm.controls["newPassword"].updateValueAndValidity()
|
||||||
|
this.changeEmailForm.controls["newPasswordRepeat"].updateValueAndValidity()
|
||||||
|
}
|
||||||
|
|
||||||
|
this.changeEmailForm.controls["currentPassword"].setValidators([Validators.required])
|
||||||
|
this.changeEmailForm.controls["currentPassword"].updateValueAndValidity()
|
||||||
|
}
|
||||||
|
|
||||||
|
async changePassword(currentPassword: string | null, newPassword: string | null) {
|
||||||
|
this.changePasswordPending.set(true)
|
||||||
|
const service = this.serviceManager.currentSessionHandler
|
||||||
|
if (service) {
|
||||||
|
try {
|
||||||
|
await service.changePassword(newPassword ?? "", currentPassword ?? "")
|
||||||
|
} catch (e) {
|
||||||
|
this.changeEmailForm.controls["currentPassword"].setErrors({incorrect: true})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
chkPassMatch(group: AbstractControl): ValidationErrors | null {
|
||||||
|
return this.changePasswordRemoveMode() ? null : group.value.newPassword == group.value.newPasswordRepeat
|
||||||
|
? null : {passMatchError: true};
|
||||||
|
}
|
||||||
|
}
|
||||||
99
src/app/chat/user-settings/security/phone/phone.html
Normal file
99
src/app/chat/user-settings/security/phone/phone.html
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
<div class="option" [class.mobile]="breakpoint() == 'mobile'">
|
||||||
|
<ng-template [(tuiDialog)]="changePhoneDialogOpen"
|
||||||
|
[tuiDialogOptions]="{label: ('chat.userSettingsDialog.security.changePhoneDialog.'+ (changePhoneRemoveMode() ? 'labelRemove' : serviceManager.currentSession()!.userData.phoneSet ? 'label' : 'labelSet'))|translate}">
|
||||||
|
<p>{{ "chat.userSettingsDialog.security.changePhoneDialog.warn"|translate }}</p>
|
||||||
|
@if (step() == 0) {
|
||||||
|
<form [formGroup]="changePhoneForm" style="display: flex; flex-direction: column; gap: 10px">
|
||||||
|
@if (!changePhoneRemoveMode()) {
|
||||||
|
<tui-textfield>
|
||||||
|
<label
|
||||||
|
tuiLabel>{{ "chat.userSettingsDialog.security.changePhoneDialog.newPhone"|translate }}</label>
|
||||||
|
<input formControlName="newNumber" tuiInputPhoneInternational [countrySearch]="true" [countries]="countries | tuiSortCountries" [(countryIsoCode)]="countryIsoCode">
|
||||||
|
</tui-textfield>
|
||||||
|
}
|
||||||
|
|
||||||
|
<tui-textfield iconStart="@tui.key">
|
||||||
|
<label tuiLabel>{{ "chat.userSettingsDialog.security.changePhoneDialog.currentPassword"|translate }}</label>
|
||||||
|
<input formControlName="currentPassword" tuiInput type="password">
|
||||||
|
</tui-textfield>
|
||||||
|
|
||||||
|
@if (changePhoneForm.controls['currentPassword'].dirty) {
|
||||||
|
@if (changePhoneForm.controls['currentPassword'].hasError("required")) {
|
||||||
|
<tui-error
|
||||||
|
[error]="'chat.userSettingsDialog.security.changePhoneDialog.errors.currentPasswordRequired'|translate"></tui-error>
|
||||||
|
}
|
||||||
|
|
||||||
|
@if (changePhoneForm.controls['currentPassword'].hasError("incorrect")) {
|
||||||
|
<tui-error
|
||||||
|
[error]="'chat.userSettingsDialog.security.changePhoneDialog.errors.incorrectPassword'|translate"></tui-error>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<button tuiButton iconStart="@tui.check" [loading]="changePhonePending()"
|
||||||
|
[disabled]="changePhonePending()"
|
||||||
|
(click)="changePhone(changePhoneForm.controls['currentPassword'].value, changePhoneForm.controls['newNumber'].value)">
|
||||||
|
{{ ('chat.userSettingsDialog.security.changePhoneDialog.' + (changePhoneRemoveMode() ? 'labelRemove' : serviceManager.currentSession()!.userData.passwordSet ? 'label' : 'labelSet'))|translate }}
|
||||||
|
</button>
|
||||||
|
</footer>
|
||||||
|
} @else {
|
||||||
|
<form style="display: flex; flex-direction: column; gap: 10px" [formGroup]="verifyPhoneForm">
|
||||||
|
@if (serviceManager.currentSession()!.userData.phoneSet) {
|
||||||
|
<tui-textfield iconStart="@tui.phone">
|
||||||
|
<label tuiLabel>{{ "chat.userSettingsDialog.security.changePhoneDialog.oldCode"|translate }}</label>
|
||||||
|
<input tuiInput type="number" [step]="1" formControlName="oldCode">
|
||||||
|
</tui-textfield>
|
||||||
|
}
|
||||||
|
|
||||||
|
@if (!changePhoneRemoveMode()) {
|
||||||
|
<tui-textfield iconStart="@tui.badge-plus">
|
||||||
|
<label tuiLabel>{{ "chat.userSettingsDialog.security.changePhoneDialog.newCode"|translate }}</label>
|
||||||
|
<input tuiInput type="number" [step]="1" formControlName="newCode">
|
||||||
|
</tui-textfield>
|
||||||
|
}
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<button tuiButton iconStart="@tui.check" [loading]="verifyPhonePending()"
|
||||||
|
[disabled]="verifyPhoneForm.invalid || verifyPhonePending()"
|
||||||
|
(click)="verifyPhone(verifyPhoneForm.controls['newCode'].value, verifyPhoneForm.controls['oldCode'].value)">
|
||||||
|
{{ ('chat.userSettingsDialog.security.changePhoneDialog.' + (changePhoneRemoveMode() ? 'labelRemove' : serviceManager.currentSession()!.userData.passwordSet ? 'label' : 'labelSet'))|translate }}
|
||||||
|
</button>
|
||||||
|
</footer>
|
||||||
|
}
|
||||||
|
</ng-template>
|
||||||
|
|
||||||
|
<header>
|
||||||
|
<tui-icon icon="@tui.phone"/>
|
||||||
|
<span>{{ "chat.userSettingsDialog.security.phoneNumber"|translate }}</span>
|
||||||
|
|
||||||
|
@if (serviceManager.currentSession()!.userData.phoneSet) {
|
||||||
|
<div tuiBadge appearance="positive"
|
||||||
|
iconStart="@tui.check">{{ 'chat.userSettingsDialog.security.set'|translate }}
|
||||||
|
</div>
|
||||||
|
} @else {
|
||||||
|
<div tuiBadge appearance="negative"
|
||||||
|
iconStart="@tui.x">{{ 'chat.userSettingsDialog.security.notSet'|translate }}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<button tuiButton appearance="outline" (click)="openChangePhoneDialog(false)"
|
||||||
|
[iconStart]="serviceManager.currentSession()!.userData.phoneSet ? '@tui.pencil' : '@tui.plus'">
|
||||||
|
@if (serviceManager.currentSession()!.userData.phoneSet) {
|
||||||
|
{{ "chat.userSettingsDialog.security.changePhone"|translate }}
|
||||||
|
} @else {
|
||||||
|
{{ "chat.userSettingsDialog.security.setPhone"|translate }}
|
||||||
|
}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
@if (serviceManager.currentSession()!.userData.phoneSet) {
|
||||||
|
<button [disabled]="!serviceManager.currentSession()!.userData.passwordSet && !serviceManager.currentSession()!.userData.emailSet" tuiButton appearance="outline" tuiAppearanceMode="invalid" iconStart="@tui.x" (click)="openChangePhoneDialog(true)"
|
||||||
|
style="color: var(--tui-text-negative)">
|
||||||
|
{{ "chat.userSettingsDialog.security.removePhone"|translate }}
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
22
src/app/chat/user-settings/security/phone/phone.spec.ts
Normal file
22
src/app/chat/user-settings/security/phone/phone.spec.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { Phone } from './phone';
|
||||||
|
|
||||||
|
describe('Phone', () => {
|
||||||
|
let component: Phone;
|
||||||
|
let fixture: ComponentFixture<Phone>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
imports: [Phone],
|
||||||
|
}).compileComponents();
|
||||||
|
|
||||||
|
fixture = TestBed.createComponent(Phone);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
await fixture.whenStable();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
111
src/app/chat/user-settings/security/phone/phone.ts
Normal file
111
src/app/chat/user-settings/security/phone/phone.ts
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
import {Component, inject, signal} from '@angular/core';
|
||||||
|
import {FormControl, FormGroup, ReactiveFormsModule, Validators} from '@angular/forms';
|
||||||
|
import {TranslatePipe} from '@ngx-translate/core';
|
||||||
|
import {TuiBadge, TuiButtonLoading, TuiInputPhoneInternationalComponent, TuiSortCountriesPipe} from '@taiga-ui/kit';
|
||||||
|
import {
|
||||||
|
TUI_BREAKPOINT,
|
||||||
|
TuiButton,
|
||||||
|
TuiDialog,
|
||||||
|
TuiErrorComponent,
|
||||||
|
TuiIcon,
|
||||||
|
TuiInputDirective,
|
||||||
|
TuiLabel,
|
||||||
|
TuiTextfieldComponent
|
||||||
|
} from '@taiga-ui/core';
|
||||||
|
import {ServiceManager} from '../../../../service-manager';
|
||||||
|
import {getCountries} from 'libphonenumber-js';
|
||||||
|
import {TuiCountryIsoCode} from '@taiga-ui/i18n';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'user-settings-security-phone',
|
||||||
|
imports: [
|
||||||
|
ReactiveFormsModule,
|
||||||
|
TranslatePipe,
|
||||||
|
TuiBadge,
|
||||||
|
TuiButton,
|
||||||
|
TuiButtonLoading,
|
||||||
|
TuiDialog,
|
||||||
|
TuiErrorComponent,
|
||||||
|
TuiIcon,
|
||||||
|
TuiInputDirective,
|
||||||
|
TuiLabel,
|
||||||
|
TuiTextfieldComponent,
|
||||||
|
TuiInputPhoneInternationalComponent,
|
||||||
|
TuiSortCountriesPipe
|
||||||
|
],
|
||||||
|
templateUrl: './phone.html',
|
||||||
|
styleUrl: './phone.scss',
|
||||||
|
})
|
||||||
|
export class Phone {
|
||||||
|
protected readonly countries = getCountries();
|
||||||
|
protected countryIsoCode: TuiCountryIsoCode = 'HU';
|
||||||
|
breakpoint = inject(TUI_BREAKPOINT)
|
||||||
|
|
||||||
|
serviceManager = inject(ServiceManager)
|
||||||
|
|
||||||
|
step = signal(0)
|
||||||
|
changePhoneDialogOpen = signal(false)
|
||||||
|
changePhoneRemoveMode = signal(false)
|
||||||
|
changePhonePending = signal(false)
|
||||||
|
verifyPhonePending = signal(false)
|
||||||
|
newNumber = ""
|
||||||
|
|
||||||
|
changePhoneForm = new FormGroup({
|
||||||
|
newNumber: new FormControl(""),
|
||||||
|
currentPassword: new FormControl(""),
|
||||||
|
})
|
||||||
|
|
||||||
|
verifyPhoneForm = new FormGroup({
|
||||||
|
oldCode: new FormControl(0),
|
||||||
|
newCode: new FormControl(0, {validators: [Validators.required]})
|
||||||
|
})
|
||||||
|
|
||||||
|
openChangePhoneDialog(modeRemove: boolean) {
|
||||||
|
this.changePhoneDialogOpen.set(true)
|
||||||
|
this.changePhoneRemoveMode.set(modeRemove)
|
||||||
|
this.changePhoneForm.controls["currentPassword"].clearValidators()
|
||||||
|
this.changePhoneForm.controls["newNumber"].clearValidators()
|
||||||
|
if (!modeRemove) {
|
||||||
|
this.changePhoneForm.controls["newNumber"].setValidators([Validators.required])
|
||||||
|
this.changePhoneForm.controls["newNumber"].updateValueAndValidity()
|
||||||
|
}
|
||||||
|
|
||||||
|
this.changePhoneForm.controls["currentPassword"].setValidators([Validators.required])
|
||||||
|
this.changePhoneForm.controls["currentPassword"].updateValueAndValidity()
|
||||||
|
}
|
||||||
|
|
||||||
|
async changePhone(currentPassword: string | null, newNumber: string | null) {
|
||||||
|
if (this.changePhoneRemoveMode()) {
|
||||||
|
newNumber = "remove"
|
||||||
|
}
|
||||||
|
this.changePhonePending.set(true)
|
||||||
|
const service = this.serviceManager.currentSessionHandler
|
||||||
|
if (service) {
|
||||||
|
try {
|
||||||
|
await service.changePhoneNumber(currentPassword ?? "", newNumber ?? "")
|
||||||
|
this.step.set(1)
|
||||||
|
this.newNumber = newNumber ?? ""
|
||||||
|
if (!this.changePhoneRemoveMode()) {
|
||||||
|
this.verifyPhoneForm.controls["oldCode"].setValidators([Validators.required])
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
this.changePhoneForm.controls["currentPassword"].setErrors({incorrect: true})
|
||||||
|
this.changePhonePending.set(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async verifyPhone(newCode: number | null, oldCode: number | null) {
|
||||||
|
this.verifyPhonePending.set(true)
|
||||||
|
const service = this.serviceManager.currentSessionHandler
|
||||||
|
if (service) {
|
||||||
|
try {
|
||||||
|
await service.verifyPhoneNumberChange(this.newNumber, oldCode ?? 0, newCode ?? 0)
|
||||||
|
this.changePhoneDialogOpen.set(false)
|
||||||
|
} catch (e) {
|
||||||
|
this.verifyPhoneForm.controls["newCode"].setErrors({incorrect: true})
|
||||||
|
this.verifyPhonePending.set(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
9
src/app/chat/user-settings/security/security.html
Normal file
9
src/app/chat/user-settings/security/security.html
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<p>
|
||||||
|
<tui-icon icon="@tui.info"/>
|
||||||
|
{{ "chat.userSettingsDialog.security.label"|translate }}
|
||||||
|
</p>
|
||||||
|
<div id="options" tuiGroup orientation="vertical">
|
||||||
|
<user-settings-security-password style="overflow: hidden"/>
|
||||||
|
<user-settings-security-email style="overflow: hidden"/>
|
||||||
|
<user-settings-security-phone style="overflow: hidden"/>
|
||||||
|
</div>
|
||||||
45
src/app/chat/user-settings/security/security.scss
Normal file
45
src/app/chat/user-settings/security/security.scss
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
#options {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
|
||||||
|
::ng-deep .option {
|
||||||
|
width: 100%;
|
||||||
|
height: 60px;
|
||||||
|
background: var(--tui-background-base-alt);
|
||||||
|
padding: 15px;
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
|
||||||
|
&.mobile {
|
||||||
|
grid-template-rows: 50px 50px;
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
height: 150px;
|
||||||
|
|
||||||
|
main {
|
||||||
|
display: flex;
|
||||||
|
justify-content: start;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
::ng-deep header {
|
||||||
|
display: flex;
|
||||||
|
gap: 5px;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
::ng-deep main {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: end;
|
||||||
|
display: flex;
|
||||||
|
gap: 5px;
|
||||||
|
|
||||||
|
button {
|
||||||
|
height: 35px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
22
src/app/chat/user-settings/security/security.spec.ts
Normal file
22
src/app/chat/user-settings/security/security.spec.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { Security } from './security';
|
||||||
|
|
||||||
|
describe('Security', () => {
|
||||||
|
let component: Security;
|
||||||
|
let fixture: ComponentFixture<Security>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
imports: [Security],
|
||||||
|
}).compileComponents();
|
||||||
|
|
||||||
|
fixture = TestBed.createComponent(Security);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
await fixture.whenStable();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
43
src/app/chat/user-settings/security/security.ts
Normal file
43
src/app/chat/user-settings/security/security.ts
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
import {Component, inject, signal} from '@angular/core';
|
||||||
|
import {TuiButton, TuiDialog, TuiErrorComponent, TuiGroup, TuiIcon, TuiInputDirective} from '@taiga-ui/core';
|
||||||
|
import {TranslatePipe} from '@ngx-translate/core';
|
||||||
|
import {ServiceManager} from '../../../service-manager';
|
||||||
|
import {JsonPipe} from '@angular/common';
|
||||||
|
import {TuiBadge, TuiButtonLoading, TuiInputColor} from '@taiga-ui/kit';
|
||||||
|
import {
|
||||||
|
AbstractControl,
|
||||||
|
FormControl,
|
||||||
|
FormGroup,
|
||||||
|
ReactiveFormsModule,
|
||||||
|
ValidationErrors,
|
||||||
|
Validators
|
||||||
|
} from '@angular/forms';
|
||||||
|
import {Password} from './password/password';
|
||||||
|
import {Email} from './email/email';
|
||||||
|
import {Phone} from './phone/phone';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'user-settings-security',
|
||||||
|
imports: [
|
||||||
|
TuiGroup,
|
||||||
|
TranslatePipe,
|
||||||
|
TuiIcon,
|
||||||
|
JsonPipe,
|
||||||
|
TuiBadge,
|
||||||
|
TuiButton,
|
||||||
|
TuiDialog,
|
||||||
|
ReactiveFormsModule,
|
||||||
|
TuiInputColor,
|
||||||
|
TuiInputDirective,
|
||||||
|
TuiButtonLoading,
|
||||||
|
TuiErrorComponent,
|
||||||
|
Password,
|
||||||
|
Email,
|
||||||
|
Phone
|
||||||
|
],
|
||||||
|
templateUrl: './security.html',
|
||||||
|
styleUrl: './security.scss',
|
||||||
|
})
|
||||||
|
export class Security {
|
||||||
|
serviceManager = inject(ServiceManager)
|
||||||
|
}
|
||||||
38
src/app/chat/user-settings/user-settings.html
Normal file
38
src/app/chat/user-settings/user-settings.html
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<div id="layout" [class.mobile]="breakpoint() != 'desktopLarge'">
|
||||||
|
@if (breakpoint() == "desktopLarge" || selectedOption == "") {
|
||||||
|
<aside>
|
||||||
|
<header>
|
||||||
|
<tui-icon icon="@tui.cog"/>
|
||||||
|
<h2>{{ "chat.userSettingsDialog.label"|translate }}</h2>
|
||||||
|
|
||||||
|
@if (breakpoint() != "mobile") {
|
||||||
|
<button tuiButtonX (click)="close.emit()"></button>
|
||||||
|
}
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div id="options">
|
||||||
|
@for (option of options; track option) {
|
||||||
|
<button [disabled]="!option.implemented" tuiButton [iconStart]="'@tui.'+option.icon" [appearance]="selectedOption == option.name ? 'primary' : 'flat'" (click)="selectedOption = option.name">
|
||||||
|
{{"chat.userSettingsDialog.options."+option.name|translate}}
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</aside>
|
||||||
|
}
|
||||||
|
|
||||||
|
@if (breakpoint() == "desktopLarge" || selectedOption != "") {
|
||||||
|
<main>
|
||||||
|
@if (breakpoint() != "desktopLarge") {
|
||||||
|
<div style="display: flex; align-items: center; gap: 1rem;">
|
||||||
|
<button tuiButton appearance="flat" iconStart="@tui.arrow-left" (click)="selectedOption = ''"></button>
|
||||||
|
<h3>{{"chat.userSettingsDialog.options."+selectedOption|translate}}</h3>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
@switch (selectedOption) {
|
||||||
|
@case ("security") {
|
||||||
|
<user-settings-security/>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</main>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
59
src/app/chat/user-settings/user-settings.scss
Normal file
59
src/app/chat/user-settings/user-settings.scss
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
#layout {
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 300px 1fr;
|
||||||
|
|
||||||
|
&.mobile {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
|
||||||
|
aside, main {
|
||||||
|
border-radius: 1.5rem;
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
aside {
|
||||||
|
background-color: var(--tui-background-base-alt);
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
border-radius: 1.5rem 0 0 1.5rem;
|
||||||
|
|
||||||
|
header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
gap: 5px;
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
tui-icon {
|
||||||
|
font-size: 35px;
|
||||||
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
position: absolute;
|
||||||
|
right: 25px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#options {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 1px;
|
||||||
|
padding: 15px;
|
||||||
|
|
||||||
|
button {
|
||||||
|
width: 100%;
|
||||||
|
display: flex;
|
||||||
|
justify-content: start;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main {
|
||||||
|
background: var(--tui-background-neutral-2);
|
||||||
|
width: 100%;
|
||||||
|
border-radius: 0 1.5rem 1.5rem 0;
|
||||||
|
padding: 15px;
|
||||||
|
}
|
||||||
|
}
|
||||||
22
src/app/chat/user-settings/user-settings.spec.ts
Normal file
22
src/app/chat/user-settings/user-settings.spec.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { UserSettings } from './user-settings';
|
||||||
|
|
||||||
|
describe('UserSettings', () => {
|
||||||
|
let component: UserSettings;
|
||||||
|
let fixture: ComponentFixture<UserSettings>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
imports: [UserSettings],
|
||||||
|
}).compileComponents();
|
||||||
|
|
||||||
|
fixture = TestBed.createComponent(UserSettings);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
await fixture.whenStable();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
57
src/app/chat/user-settings/user-settings.ts
Normal file
57
src/app/chat/user-settings/user-settings.ts
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
import {Component, EventEmitter, inject, OnInit, Output} from '@angular/core';
|
||||||
|
import {TranslatePipe} from '@ngx-translate/core';
|
||||||
|
import {TUI_BREAKPOINT, TuiButton, TuiButtonX, TuiIcon} from '@taiga-ui/core';
|
||||||
|
import {Security} from './security/security';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'user-settings',
|
||||||
|
imports: [
|
||||||
|
TranslatePipe,
|
||||||
|
TuiIcon,
|
||||||
|
TuiButtonX,
|
||||||
|
TuiButton,
|
||||||
|
Security
|
||||||
|
],
|
||||||
|
templateUrl: './user-settings.html',
|
||||||
|
styleUrl: './user-settings.scss',
|
||||||
|
})
|
||||||
|
export class UserSettings implements OnInit {
|
||||||
|
breakpoint = inject(TUI_BREAKPOINT)
|
||||||
|
|
||||||
|
@Output() close = new EventEmitter<void>()
|
||||||
|
|
||||||
|
selectedOption = "security"
|
||||||
|
options = [
|
||||||
|
{
|
||||||
|
icon: "shield",
|
||||||
|
name: "security",
|
||||||
|
implemented: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: "users",
|
||||||
|
name: "profile",
|
||||||
|
implemented: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: "paint-roller",
|
||||||
|
name: "themes",
|
||||||
|
implemented: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: "computer",
|
||||||
|
name: "sessions",
|
||||||
|
implemented: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: "hard-drive",
|
||||||
|
name: "storage",
|
||||||
|
implemented: false,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
if (this.breakpoint() != "desktopLarge") {
|
||||||
|
this.selectedOption = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
12
src/app/chatenium.token.ts
Normal file
12
src/app/chatenium.token.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import { InjectionToken } from '@angular/core';
|
||||||
|
import { environment } from '../environments/environment';
|
||||||
|
import { ChateniumClient } from 'chatenium-sdk-preview';
|
||||||
|
|
||||||
|
export const CHATENIUM_SDK = new InjectionToken<ChateniumClient>('CHATENIUM_SDK', {
|
||||||
|
providedIn: 'root',
|
||||||
|
factory: () => {
|
||||||
|
return new ChateniumClient({
|
||||||
|
baseUrl: environment.api_url,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
16
src/app/google-oauth.spec.ts
Normal file
16
src/app/google-oauth.spec.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { GoogleOAuth } from './google-oauth';
|
||||||
|
|
||||||
|
describe('GoogleOAuth', () => {
|
||||||
|
let service: GoogleOAuth;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({});
|
||||||
|
service = TestBed.inject(GoogleOAuth);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be created', () => {
|
||||||
|
expect(service).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
30
src/app/google-oauth.ts
Normal file
30
src/app/google-oauth.ts
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import { inject, Injectable, NgZone } from '@angular/core';
|
||||||
|
import { Subject } from 'rxjs';
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root',
|
||||||
|
})
|
||||||
|
export class GoogleOAuth {
|
||||||
|
private ngZone = inject(NgZone);
|
||||||
|
private codeClient?: google.accounts.oauth2.CodeClient;
|
||||||
|
private codeSubject = new Subject<string>();
|
||||||
|
|
||||||
|
readonly code$ = this.codeSubject.asObservable();
|
||||||
|
|
||||||
|
init(clientId: string): void {
|
||||||
|
this.codeClient = google.accounts.oauth2.initCodeClient({
|
||||||
|
client_id: clientId,
|
||||||
|
scope: 'openid email profile',
|
||||||
|
ux_mode: 'popup',
|
||||||
|
callback: (response) => {
|
||||||
|
if (response.code) {
|
||||||
|
this.ngZone.run(() => this.codeSubject.next(response.code));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
openSignIn(): void {
|
||||||
|
this.codeClient?.requestCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,24 +1,18 @@
|
|||||||
import {CanActivateFn, Router} from '@angular/router';
|
import {CanActivateFn, Router} from '@angular/router';
|
||||||
import {inject} from '@angular/core';
|
import {inject} from '@angular/core';
|
||||||
import {IndexedDB} from '../storage/indexed-db';
|
import {IndexedDB} from '../storage/indexed-db';
|
||||||
import {Keyring} from '../storage/keyring';
|
import { SessionManager } from '../session-manager';
|
||||||
import {KeyValue} from '../storage/key-value';
|
|
||||||
import {SessionManager} from '@chatenium/chatenium-sdk/services/sessionManager';
|
|
||||||
|
|
||||||
export const authNeededGuard: CanActivateFn = (route, state) => {
|
export const authNeededGuard: CanActivateFn = (route, state) => {
|
||||||
const indexedDb = inject(IndexedDB)
|
const sessionManager = inject(SessionManager);
|
||||||
const keyring = inject(Keyring)
|
const idb = inject(IndexedDB);
|
||||||
const keyValue = inject(KeyValue)
|
const router = inject(Router);
|
||||||
const router = inject(Router)
|
|
||||||
|
|
||||||
indexedDb.openDatabase().then(async () => {
|
idb.openDatabase().then(async () => {
|
||||||
const sessionManager = new SessionManager(indexedDb.getApi(), keyring.getApi(), keyValue.getApi());
|
if (!sessionManager.quickSignInCheck()) {
|
||||||
const sessions = await sessionManager.loadSessions()
|
await router.navigate(['/chat']);
|
||||||
|
|
||||||
if (sessions.length == 0) {
|
|
||||||
router.navigate(['/signin'])
|
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,22 +1,16 @@
|
|||||||
import {CanActivateFn, Router} from '@angular/router';
|
import {CanActivateFn, Router} from '@angular/router';
|
||||||
import {SessionManager} from '@chatenium/chatenium-sdk/services/sessionManager';
|
|
||||||
import {inject} from '@angular/core';
|
import {inject} from '@angular/core';
|
||||||
import {IndexedDB} from '../storage/indexed-db';
|
import {IndexedDB} from '../storage/indexed-db';
|
||||||
import {Keyring} from '../storage/keyring';
|
import { SessionManager } from '../session-manager';
|
||||||
import {KeyValue} from '../storage/key-value';
|
|
||||||
|
|
||||||
export const noAuthGuard: CanActivateFn = async (route, state) => {
|
export const noAuthGuard: CanActivateFn = async (route, state) => {
|
||||||
const indexedDb = inject(IndexedDB)
|
const sessionManager = inject(SessionManager);
|
||||||
const keyring = inject(Keyring)
|
const idb = inject(IndexedDB);
|
||||||
const keyValue = inject(KeyValue)
|
|
||||||
const router = inject(Router)
|
const router = inject(Router)
|
||||||
|
|
||||||
indexedDb.openDatabase().then(async () => {
|
idb.openDatabase().then(async () => {
|
||||||
const sessionManager = new SessionManager(indexedDb.getApi(), keyring.getApi(), keyValue.getApi());
|
if (sessionManager.quickSignInCheck()) {
|
||||||
const sessions = await sessionManager.loadSessions()
|
await router.navigate(['/chat'])
|
||||||
|
|
||||||
if (sessions.length != 0) {
|
|
||||||
router.navigate(['/chat'])
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ import {PictureService} from '@chatenium/chatenium-sdk/services/pictureService';
|
|||||||
import {Album} from '@chatenium/chatenium-sdk/domain/pictureService.schema';
|
import {Album} from '@chatenium/chatenium-sdk/domain/pictureService.schema';
|
||||||
import {PublicUserData} from '@chatenium/chatenium-sdk/domain/common.schema';
|
import {PublicUserData} from '@chatenium/chatenium-sdk/domain/common.schema';
|
||||||
import {MessagesViewModel} from './chat/elements/messages/messages-viewmodel';
|
import {MessagesViewModel} from './chat/elements/messages/messages-viewmodel';
|
||||||
|
import {AuthService} from '@chatenium/chatenium-sdk/services/authService';
|
||||||
|
import {UserService} from '@chatenium/chatenium-sdk/services/userService';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root',
|
providedIn: 'root',
|
||||||
@@ -28,6 +30,7 @@ export class ServiceManager {
|
|||||||
|
|
||||||
sessionManager = new SessionManager(this.database.getApi(), this.keyring.getApi(), this.keyValue.getApi())
|
sessionManager = new SessionManager(this.database.getApi(), this.keyring.getApi(), this.keyValue.getApi())
|
||||||
currentSession = signal<Session | null>(null)
|
currentSession = signal<Session | null>(null)
|
||||||
|
currentSessionHandler: UserService | null = null
|
||||||
|
|
||||||
chatService: ChatService | null = null // Initialized in picture-list.ts
|
chatService: ChatService | null = null // Initialized in picture-list.ts
|
||||||
chatsStatus = signal<LoadStatus>(LoadStatus.loading)
|
chatsStatus = signal<LoadStatus>(LoadStatus.loading)
|
||||||
|
|||||||
16
src/app/session-manager.spec.ts
Normal file
16
src/app/session-manager.spec.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { SessionManager } from './session-manager';
|
||||||
|
|
||||||
|
describe('SessionManager', () => {
|
||||||
|
let service: SessionManager;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({});
|
||||||
|
service = TestBed.inject(SessionManager);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be created', () => {
|
||||||
|
expect(service).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
103
src/app/session-manager.ts
Normal file
103
src/app/session-manager.ts
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
import { inject, Injectable, signal } from '@angular/core';
|
||||||
|
import { IndexedDB } from './storage/indexed-db';
|
||||||
|
import { CookieService } from 'ngx-cookie-service';
|
||||||
|
import { CHATENIUM_SDK } from './chatenium.token';
|
||||||
|
import { PersonalUserData, SuccessfulAuthResp } from 'chatenium-sdk-preview';
|
||||||
|
import { TuiNotificationService } from '@taiga-ui/core';
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root',
|
||||||
|
})
|
||||||
|
export class SessionManager {
|
||||||
|
private SDK = inject(CHATENIUM_SDK);
|
||||||
|
private idb = inject(IndexedDB);
|
||||||
|
private cookie = inject(CookieService);
|
||||||
|
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();
|
||||||
|
date.setFullYear(date.getFullYear() + 5);
|
||||||
|
this.cookie.set(`token_${userId}`, refreshToken, {
|
||||||
|
expires: date,
|
||||||
|
path: '/',
|
||||||
|
secure: true,
|
||||||
|
sameSite: 'Strict',
|
||||||
|
});
|
||||||
|
|
||||||
|
this.SDK.addHeader('Authorization', accessToken);
|
||||||
|
try {
|
||||||
|
const resp = await this.SDK.account.getPersonalUserData();
|
||||||
|
const data = resp.data as PersonalUserData;
|
||||||
|
this.idb.putObject('userData', data, data.userId);
|
||||||
|
} catch (error) {
|
||||||
|
this.notification
|
||||||
|
.open('PersonalUserData fetch failed. Did header refresh fail?', { appearance: 'negative' })
|
||||||
|
.subscribe();
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async loadSessions() {
|
||||||
|
const cookies = this.cookie.getAll();
|
||||||
|
for (const [key, value] of Object.entries(cookies)) {
|
||||||
|
if (key.startsWith('token')) {
|
||||||
|
const userId = key.split('_')[1];
|
||||||
|
const userData = (await this.idb.get('userData', userId)) as PersonalUserData;
|
||||||
|
console.log(`Found saved session for ID: ${userId} Username: ${userData.displayName}`);
|
||||||
|
this.userData.set(userData);
|
||||||
|
await this.rotateTokenPair();
|
||||||
|
break; // For the moment, the client just loads the first session saved
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Quickly checks saved cookies and determines if the user is signed-in or not
|
||||||
|
*/
|
||||||
|
quickSignInCheck(): boolean {
|
||||||
|
const cookies = this.cookie.getAll();
|
||||||
|
for (const [key, value] of Object.entries(cookies)) {
|
||||||
|
if (key.startsWith('token')) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
async rotateTokenPair() {
|
||||||
|
const userData = this.userData();
|
||||||
|
|
||||||
|
if (userData != undefined) {
|
||||||
|
const refreshToken = this.cookie.get(`token_${userData.userId}`);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const resp = await this.SDK.auth.rotateTokenPair(refreshToken);
|
||||||
|
const data = resp.data as SuccessfulAuthResp;
|
||||||
|
|
||||||
|
const date = new Date();
|
||||||
|
date.setFullYear(date.getFullYear() + 5);
|
||||||
|
this.cookie.set(`token_${data.userId}`, data.refreshToken, {
|
||||||
|
expires: date,
|
||||||
|
path: '/',
|
||||||
|
secure: true,
|
||||||
|
sameSite: 'Strict',
|
||||||
|
});
|
||||||
|
|
||||||
|
this.SDK.addHeader('Authorization', data.accessToken);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.error('Token refresh failed - No user data loaded');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,44 +1,163 @@
|
|||||||
<main id="holder">
|
<main id="holder">
|
||||||
<form [formGroup]="signInForm" tuiAppearance="floating">
|
@switch (page()) {
|
||||||
<header>
|
@case ('initial') {
|
||||||
<h1>{{"signIn.formTitle"|translate}}</h1>
|
<form [formGroup]="signInForm" tuiAppearance="floating" id="initial" animate.enter="slide-in-right"
|
||||||
</header>
|
animate.leave="slide-out-left">
|
||||||
|
<header>
|
||||||
|
<h1>{{ "signIn.initial.formTitle"|translate }}</h1>
|
||||||
|
<span>{{ "signIn.initial.formSubtitle"|translate }}</span>
|
||||||
|
</header>
|
||||||
|
|
||||||
<main>
|
<main>
|
||||||
<tui-textfield iconStart="@tui.user">
|
<tui-textfield iconStart="@tui.user">
|
||||||
<label tuiLabel>{{"signIn.mainInput.label"|translate}}</label>
|
<label tuiLabel>{{ "signIn.initial.mainInput.label"|translate }}</label>
|
||||||
|
|
||||||
<input (input)="checkAuthMethods(signInForm.controls['unameMailPhone'].value)" formControlName="unameMailPhone" tuiInput placeholder="{{'signIn.mainInput.placeholder'|translate}}">
|
<input (input)="checkAuthMethods(signInForm.controls['unameMailPhone'].value)"
|
||||||
</tui-textfield>
|
formControlName="unameMailPhone" tuiInput
|
||||||
@if (signInForm.controls["unameMailPhone"].dirty) {
|
placeholder="{{'signIn.initial.mainInput.placeholder'|translate}}">
|
||||||
@if (signInForm.controls["unameMailPhone"].hasError("required")) {
|
</tui-textfield>
|
||||||
<tui-error [error]="'signIn.errors.unameMailPhoneRequired'|translate"></tui-error>
|
@if (signInForm.controls["unameMailPhone"].dirty) {
|
||||||
}
|
@if (signInForm.controls["unameMailPhone"].hasError("required")) {
|
||||||
}
|
<tui-error [error]="'signIn.errors.unameMailPhoneRequired'|translate"></tui-error>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</main>
|
||||||
|
|
||||||
<tui-textfield iconStart="@tui.key">
|
<footer>
|
||||||
<label tuiLabel>{{"signIn.password.label"|translate}}</label>
|
<button (click)="startChallenge(signInForm.controls['unameMailPhone'].value)"
|
||||||
<input formControlName="password" [disabled]="!methods().password" type="password" tuiInput>
|
[disabled]="signInForm.invalid && false || pendingAction()" tuiButton>
|
||||||
<tui-icon tuiPassword></tui-icon>
|
{{ 'signIn.initial.signInButton'|translate }}
|
||||||
</tui-textfield>
|
</button>
|
||||||
@if (signInForm.controls["password"].dirty) {
|
</footer>
|
||||||
@if (signInForm.controls["password"].hasError("required")) {
|
</form>
|
||||||
<tui-error [error]="'signIn.errors.passwordRequired'|translate"></tui-error>
|
}
|
||||||
} @else if (signInForm.controls["password"].hasError("incorrect")) {
|
@case ('methodChoose') {
|
||||||
<tui-error [error]="'signIn.errors.passwordIncorrect'|translate"></tui-error>
|
<form id="methodChoose" animate.enter="slide-in-right" animate.leave="slide-out-left">
|
||||||
}
|
<header>
|
||||||
}
|
@if (isMultistep()) {
|
||||||
|
<h1>{{ "signIn.methodChoose.formTitleAlt"|translate }}</h1>
|
||||||
|
<span>{{ "signIn.methodChoose.formSubtitleAlt"|translate }}</span>
|
||||||
|
} @else {
|
||||||
|
<h1>{{ "signIn.methodChoose.formTitle"|translate }}</h1>
|
||||||
|
<span>{{ "signIn.methodChoose.formSubtitle"|translate }}</span>
|
||||||
|
}
|
||||||
|
</header>
|
||||||
|
|
||||||
<div id="methods">
|
<main tuiGroup orientation="vertical" style="gap: 0">
|
||||||
<button [disabled]="!methods().email" iconStart="@tui.mail-open" appearance="secondary" tuiButton disabled>{{'signIn.emailButton'|translate}}</button>
|
@if (challenge != null) {
|
||||||
<button [disabled]="!methods().sms" iconStart="@tui.phone" appearance="secondary" tuiButton disabled>{{'signIn.smsButton'|translate}}</button>
|
@if (challenge()!.factorsTracker["PASSWORD"] != null) {
|
||||||
</div>
|
<button [disabled]="challenge()!.factorsTracker['PASSWORD'].status == 'SUCCESS'" type="button" tuiButton
|
||||||
</main>
|
appearance="secondary" class="method" (click)="this.page.set('passwordAuth')">
|
||||||
|
<tui-icon icon="@tui.key"></tui-icon>
|
||||||
|
<div>
|
||||||
|
<span class="title">{{ "signIn.methodChoose.methods.password.title"|translate }}</span>
|
||||||
|
<span class="desc">{{ "signIn.methodChoose.methods.password.desc"|translate }}</span>
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
@if (challenge()!.factorsTracker["EMAIL"] != null) {
|
||||||
|
<button type="button"
|
||||||
|
[disabled]="challenge()!.factorsTracker['EMAIL'].status == 'SUCCESS' || pendingAction()" tuiButton
|
||||||
|
appearance="secondary" class="method" (click)="this.requestCredential('EMAIL')">
|
||||||
|
<tui-icon icon="@tui.mail"></tui-icon>
|
||||||
|
<div>
|
||||||
|
<span class="title">{{ "signIn.methodChoose.methods.mail.title"|translate }}</span>
|
||||||
|
<span class="desc">{{ "signIn.methodChoose.methods.mail.desc"|translate }}</span>
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
<button tuiButton appearance="secondary" class="method">
|
||||||
|
<tui-icon icon="@tui.phone"></tui-icon>
|
||||||
|
<div>
|
||||||
|
<span class="title">{{ "signIn.methodChoose.methods.sms.title"|translate }}</span>
|
||||||
|
<span class="desc">{{ "signIn.methodChoose.methods.sms.desc"|translate }}</span>
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
@if (challenge()!.factorsTracker["GOOGLE"] != null) {
|
||||||
|
<button type="button" tuiButton appearance="secondary" class="method"
|
||||||
|
(click)="this.googleOAuth.openSignIn();" [disabled]="challenge()!.factorsTracker['GOOGLE'].status == 'SUCCESS' || pendingAction()">
|
||||||
|
<fa-icon [icon]="faGoogle" style="font-size: 25px; margin-left: -5px"></fa-icon>
|
||||||
|
|
||||||
<footer>
|
<div>
|
||||||
<button (click)="passwordSignIn(signInForm.controls['unameMailPhone'].value, signInForm.controls['password'].value)" [disabled]="signInForm.invalid || !methods().password" tuiButton>
|
<span class="title">{{ "signIn.methodChoose.methods.google.title"|translate }}</span>
|
||||||
{{'signIn.signInButton'|translate}}
|
<span class="desc">{{ "signIn.methodChoose.methods.google.desc"|translate }}</span>
|
||||||
</button>
|
</div>
|
||||||
</footer>
|
</button>
|
||||||
</form>
|
}
|
||||||
|
<button tuiButton appearance="secondary" class="method">
|
||||||
|
<fa-icon [icon]="faApple" style="font-size: 30px; margin-left: -7px"></fa-icon>
|
||||||
|
<div>
|
||||||
|
<span class="title">{{ "signIn.methodChoose.methods.apple.title"|translate }}</span>
|
||||||
|
<span class="desc">{{ "signIn.methodChoose.methods.apple.desc"|translate }}</span>
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
</main>
|
||||||
|
</form>
|
||||||
|
}
|
||||||
|
@case ('passwordAuth') {
|
||||||
|
<form [formGroup]="authForm" tuiAppearance="floating" id="passwordAuth" animate.enter="slide-in-right"
|
||||||
|
animate.leave="slide-out-left">
|
||||||
|
<header>
|
||||||
|
<h1>{{ "signIn.passwordAuth.formTitle"|translate }}</h1>
|
||||||
|
<span>{{ "signIn.passwordAuth.formSubtitle"|translate }}</span>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<tui-textfield iconStart="@tui.key">
|
||||||
|
<label tuiLabel>{{ "signIn.initial.password.label"|translate }}</label>
|
||||||
|
<input formControlName="method" type="password" tuiInput>
|
||||||
|
<tui-icon tuiPassword></tui-icon>
|
||||||
|
</tui-textfield>
|
||||||
|
@if (authForm.controls["method"].dirty) {
|
||||||
|
@if (authForm.controls["method"].hasError("required")) {
|
||||||
|
<tui-error [error]="'signIn.passwordAuth.errors.passwordRequired'|translate"></tui-error>
|
||||||
|
} @else if (authForm.controls["method"].hasError("incorrect")) {
|
||||||
|
<tui-error [error]="'signIn.passwordAuth.errors.passwordIncorrect'|translate"></tui-error>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<button (click)="verifyMethod('PASSWORD', authForm.controls['method'].value)"
|
||||||
|
[disabled]="authForm.invalid && false || pendingAction()" tuiButton>
|
||||||
|
{{ 'signIn.anyAuth.verifyButton'|translate }}
|
||||||
|
</button>
|
||||||
|
</footer>
|
||||||
|
</form>
|
||||||
|
}
|
||||||
|
@case ('emailAuth') {
|
||||||
|
<form [formGroup]="authForm" tuiAppearance="floating" id="emailAuth" animate.enter="slide-in-right"
|
||||||
|
animate.leave="slide-out-left">
|
||||||
|
<header>
|
||||||
|
<h1>{{ "signIn.emailAuth.formTitle"|translate }}</h1>
|
||||||
|
<span>{{ "signIn.emailAuth.formSubtitle"|translate }}</span>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<tui-textfield iconStart="@tui.mail">
|
||||||
|
<label tuiLabel>{{ "signIn.emailAuth.emailCode.label"|translate }}</label>
|
||||||
|
<input formControlName="method" type="number" tuiInput>
|
||||||
|
</tui-textfield>
|
||||||
|
@if (authForm.controls["method"].dirty) {
|
||||||
|
@if (authForm.controls["method"].hasError("required")) {
|
||||||
|
<tui-error [error]="'signIn.emailAuth.errors.passwordRequired'|translate"></tui-error>
|
||||||
|
} @else if (authForm.controls["method"].hasError("incorrect")) {
|
||||||
|
<tui-error [error]="'signIn.emailAuth.errors.passwordIncorrect'|translate"></tui-error>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<button (click)="verifyMethod('EMAIL', authForm.controls['method'].value)"
|
||||||
|
[disabled]="authForm.invalid && false || pendingAction()" tuiButton>
|
||||||
|
{{ 'signIn.anyAuth.verifyButton'|translate }}
|
||||||
|
</button>
|
||||||
|
</footer>
|
||||||
|
</form>
|
||||||
|
}
|
||||||
|
@case ('ok') {
|
||||||
|
<h1>Received Chtn identity token, auth flow finished</h1>
|
||||||
|
}
|
||||||
|
}
|
||||||
</main>
|
</main>
|
||||||
|
|||||||
@@ -4,9 +4,28 @@
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
|
|
||||||
|
.slide-in-right {
|
||||||
|
animation: slideInRight 250ms ease-out forwards;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slide-out-left {
|
||||||
|
animation: slideOutLeft 200ms ease-in forwards;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes slideInRight {
|
||||||
|
from { opacity: 0; transform: translateX(-8px); }
|
||||||
|
to { opacity: 1; transform: translateX(0); }
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes slideOutLeft {
|
||||||
|
from { opacity: 1; transform: translateX(0); }
|
||||||
|
to { opacity: 0; transform: translateX(8px); }
|
||||||
|
}
|
||||||
|
|
||||||
form {
|
form {
|
||||||
width: 50%;
|
position: absolute;
|
||||||
height: 45%;
|
width: 35%;
|
||||||
|
max-height: 65%;
|
||||||
border-radius: 35px;
|
border-radius: 35px;
|
||||||
background: var(--tui-background-base-alt);
|
background: var(--tui-background-base-alt);
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
@@ -14,21 +33,51 @@
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
|
||||||
main {
|
header {
|
||||||
|
align-self: center;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 10px;
|
align-items: center;
|
||||||
|
margin-bottom: 35px;
|
||||||
|
margin-top: 25px;
|
||||||
|
|
||||||
#methods {
|
h1 {
|
||||||
width: 100%;
|
margin: 0;
|
||||||
display: grid;
|
padding: 0;
|
||||||
grid-template-columns: repeat(2, 1fr);
|
|
||||||
gap: 10px;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
footer {
|
footer {
|
||||||
margin-top: 30px;
|
margin-top: 10px;
|
||||||
|
|
||||||
|
button {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#initial main {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#methodChoose main .method {
|
||||||
|
width: 100%;
|
||||||
|
height: 65px;
|
||||||
|
display: flex;
|
||||||
|
gap: 15px;
|
||||||
|
justify-content: start;
|
||||||
|
|
||||||
|
.title {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 5px;
|
||||||
|
align-items: start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.desc {
|
||||||
|
font-weight: normal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,37 @@
|
|||||||
import {Component, inject, OnInit, signal} from '@angular/core';
|
import { Component, computed, inject, OnInit, signal } from '@angular/core';
|
||||||
import {TuiAppearance, TuiButton, TuiError, TuiErrorDirective, TuiIcon, TuiInput, TuiTextfield} from '@taiga-ui/core';
|
import {
|
||||||
|
TuiAlertService,
|
||||||
|
TuiAppearance,
|
||||||
|
TuiButton,
|
||||||
|
TuiError,
|
||||||
|
TuiErrorDirective,
|
||||||
|
TuiGroup,
|
||||||
|
TuiIcon,
|
||||||
|
TuiInput,
|
||||||
|
TuiNotificationService,
|
||||||
|
TuiTextfield,
|
||||||
|
} from '@taiga-ui/core';
|
||||||
import {TranslatePipe} from '@ngx-translate/core';
|
import {TranslatePipe} from '@ngx-translate/core';
|
||||||
import {TuiButtonGroup, TuiPassword} from '@taiga-ui/kit';
|
import {TuiButtonGroup, TuiPassword} from '@taiga-ui/kit';
|
||||||
import {FormControl, FormGroup, ReactiveFormsModule, Validators} from '@angular/forms';
|
import {FormControl, FormGroup, ReactiveFormsModule, Validators} from '@angular/forms';
|
||||||
import {AuthService} from '@chatenium/chatenium-sdk/services/authService';
|
import {AuthService} from '@chatenium/chatenium-sdk/services/authService';
|
||||||
import {AuthMethods} from '@chatenium/chatenium-sdk/domain/authService.schema';
|
import {AuthMethods} from '@chatenium/chatenium-sdk/domain/authService.schema';
|
||||||
import {SessionManager} from '@chatenium/chatenium-sdk/services/sessionManager';
|
|
||||||
import {ServiceManager} from '../service-manager';
|
import {ServiceManager} from '../service-manager';
|
||||||
import {IndexedDB} from '../storage/indexed-db';
|
import {IndexedDB} from '../storage/indexed-db';
|
||||||
import {PublicUserData} from '@chatenium/chatenium-sdk/domain/common.schema';
|
import {PublicUserData} from '@chatenium/chatenium-sdk/domain/common.schema';
|
||||||
import {Router} from '@angular/router';
|
import {Router} from '@angular/router';
|
||||||
|
import { CHATENIUM_SDK } from '../chatenium.token';
|
||||||
|
import { AuthChallenge, Challenge, SignInReq, SuccessfulAuthResp } from 'chatenium-sdk-preview';
|
||||||
|
import { TuiItemGroup } from '@taiga-ui/layout';
|
||||||
|
import { faApple, faGoogle } from '@fortawesome/free-brands-svg-icons';
|
||||||
|
import { FaIconComponent } from '@fortawesome/angular-fontawesome';
|
||||||
|
import { JsonPipe } from '@angular/common';
|
||||||
|
import { Subscription } from 'rxjs';
|
||||||
|
import { GoogleOAuth } from '../google-oauth';
|
||||||
|
import { environment } from '../../environments/environment';
|
||||||
|
import { SessionManager } from '../session-manager';
|
||||||
|
import { Platform } from '@angular/cdk/platform';
|
||||||
|
import { DeviceDetectorService } from 'ngx-device-detector';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-signin',
|
selector: 'app-signin',
|
||||||
@@ -19,49 +41,77 @@ import {Router} from '@angular/router';
|
|||||||
TuiTextfield,
|
TuiTextfield,
|
||||||
TuiInput,
|
TuiInput,
|
||||||
TuiButton,
|
TuiButton,
|
||||||
TuiButtonGroup,
|
|
||||||
TuiPassword,
|
TuiPassword,
|
||||||
TuiIcon,
|
TuiIcon,
|
||||||
ReactiveFormsModule,
|
ReactiveFormsModule,
|
||||||
TuiErrorDirective,
|
TuiError,
|
||||||
TuiError
|
TuiGroup,
|
||||||
|
FaIconComponent,
|
||||||
|
JsonPipe,
|
||||||
],
|
],
|
||||||
templateUrl: './signin.html',
|
templateUrl: './signin.html',
|
||||||
styleUrl: './signin.scss',
|
styleUrl: './signin.scss',
|
||||||
})
|
})
|
||||||
export class SignIn implements OnInit {
|
export class SignIn implements OnInit {
|
||||||
indexedDb = inject(IndexedDB)
|
SDK = inject(CHATENIUM_SDK);
|
||||||
router = inject(Router)
|
googleOAuth = inject(GoogleOAuth);
|
||||||
|
sessionManager = inject(SessionManager);
|
||||||
|
device = inject(DeviceDetectorService);
|
||||||
|
notification = inject(TuiNotificationService);
|
||||||
|
|
||||||
service = new AuthService()
|
private googleSub?: Subscription;
|
||||||
serviceManager = new ServiceManager()
|
|
||||||
methods = signal<AuthMethods>({sms: false, email: false, password: false})
|
|
||||||
|
|
||||||
private clickEvent = signal(0)
|
challengeApi: AuthChallenge | null = null;
|
||||||
|
challenge = signal<Challenge | null>(null);
|
||||||
|
|
||||||
|
indexedDb = inject(IndexedDB);
|
||||||
|
router = inject(Router);
|
||||||
|
|
||||||
|
service = new AuthService();
|
||||||
|
serviceManager = new ServiceManager();
|
||||||
|
methods = signal<AuthMethods>({ sms: false, email: false, password: false });
|
||||||
|
|
||||||
|
pendingAction = signal(false);
|
||||||
|
page = signal<'initial' | 'methodChoose' | 'passwordAuth' | 'emailAuth' | 'smsAuth' | 'ok'>(
|
||||||
|
'initial',
|
||||||
|
);
|
||||||
|
isMultistep = signal(false);
|
||||||
|
|
||||||
signInForm = new FormGroup({
|
signInForm = new FormGroup({
|
||||||
unameMailPhone: new FormControl('', {
|
unameMailPhone: new FormControl('', {
|
||||||
validators: [Validators.required]
|
validators: [Validators.required],
|
||||||
}),
|
}),
|
||||||
password: new FormControl('', {
|
});
|
||||||
validators: [Validators.required]
|
|
||||||
})
|
authForm = new FormGroup({
|
||||||
})
|
method: new FormControl('', {
|
||||||
|
validators: [Validators.required],
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
timeoutId: any;
|
timeoutId: any;
|
||||||
|
|
||||||
async checkAuthMethods(unameMailPhone: string | null) {
|
async checkAuthMethods(unameMailPhone: string | null) {
|
||||||
console.log("Called")
|
console.log('Called');
|
||||||
clearTimeout(this.timeoutId);
|
clearTimeout(this.timeoutId);
|
||||||
|
|
||||||
this.timeoutId = setTimeout(async () => {
|
this.timeoutId = setTimeout(async () => {
|
||||||
this.methods.set({sms: false, password: false, email: false})
|
this.methods.set({ sms: false, password: false, email: false });
|
||||||
this.methods.set(await this.service.getAuthMethods(unameMailPhone ?? ""))
|
this.methods.set(await this.service.getAuthMethods(unameMailPhone ?? ''));
|
||||||
}, 500)
|
}, 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
async passwordSignIn(unameMailPhone: string | null, password: string | null) {
|
async startChallenge(identity: string | null) {
|
||||||
|
this.pendingAction.set(true);
|
||||||
try {
|
try {
|
||||||
|
const fetchResp = await this.SDK.auth.getIdFromIdentity(identity ?? '');
|
||||||
|
const challenge = new AuthChallenge(this.SDK.auth);
|
||||||
|
const resp = await challenge.start('AUTH:SIGNIN', fetchResp.data.userId);
|
||||||
|
this.challenge.set(resp);
|
||||||
|
this.challengeApi = challenge;
|
||||||
|
this.pendingAction.set(false);
|
||||||
|
this.page.set('methodChoose');
|
||||||
|
/*
|
||||||
const resp = await this.service.loginPasswordAuth(unameMailPhone ?? "", password ?? "")
|
const resp = await this.service.loginPasswordAuth(unameMailPhone ?? "", password ?? "")
|
||||||
this.serviceManager.sessionManager.addSession(<PublicUserData>{
|
this.serviceManager.sessionManager.addSession(<PublicUserData>{
|
||||||
pfp: resp.pfp,
|
pfp: resp.pfp,
|
||||||
@@ -71,13 +121,101 @@ export class SignIn implements OnInit {
|
|||||||
}, resp.token)
|
}, resp.token)
|
||||||
console.log("Logged in")
|
console.log("Logged in")
|
||||||
this.router.navigate(["/chat"])
|
this.router.navigate(["/chat"])
|
||||||
|
*/
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e);
|
||||||
this.signInForm.controls['password'].setErrors({incorrect: true})
|
this.signInForm.controls['unameMailPhone'].setErrors({ incorrect: true });
|
||||||
|
this.pendingAction.set(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
async verifyMethod(methodName: string, credential: string | null) {
|
||||||
this.indexedDb.openDatabase()
|
this.pendingAction.set(true);
|
||||||
|
if (this.challengeApi != null) {
|
||||||
|
try {
|
||||||
|
const resp = await this.challengeApi.verifyFactor(methodName, String(credential) ?? '');
|
||||||
|
this.challenge.set(resp);
|
||||||
|
this.pendingAction.set(false);
|
||||||
|
if (resp.authIdentityToken == null) {
|
||||||
|
this.isMultistep.set(true);
|
||||||
|
this.page.set('methodChoose');
|
||||||
|
this.authForm.reset();
|
||||||
|
} else {
|
||||||
|
await this.signIn(resp.authIdentityToken);
|
||||||
|
this.page.set('ok');
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
this.pendingAction.set(false);
|
||||||
|
this.authForm.controls['method'].setErrors({ incorrect: true });
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async signIn(authIdentityToken: string) {
|
||||||
|
try {
|
||||||
|
const resp = await this.SDK.auth.signIn(authIdentityToken, {
|
||||||
|
os: this.device.deviceInfo().os,
|
||||||
|
frontend: "nexum"
|
||||||
|
})
|
||||||
|
const data = resp.data as SuccessfulAuthResp;
|
||||||
|
await this.sessionManager.addSession(data.refreshToken, data.accessToken, data.userId);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
this.notification.open('SignIn Failed', { appearance: "negative" }).subscribe();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async requestCredential(methodName: string) {
|
||||||
|
this.pendingAction.set(true);
|
||||||
|
if (this.challengeApi != null) {
|
||||||
|
try {
|
||||||
|
const resp = await this.challengeApi.requestCredential(methodName);
|
||||||
|
this.challenge.set(resp);
|
||||||
|
this.pendingAction.set(false);
|
||||||
|
if (resp.authIdentityToken == null) {
|
||||||
|
this.isMultistep.set(true);
|
||||||
|
this.page.set(methodName == 'EMAIL' ? 'emailAuth' : 'smsAuth');
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
this.pendingAction.set(false);
|
||||||
|
this.authForm.controls['method'].setErrors({ incorrect: true });
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async ngOnInit(): Promise<void> {
|
||||||
|
this.indexedDb.openDatabase();
|
||||||
|
|
||||||
|
this.googleSub = this.googleOAuth.code$.subscribe((code) => {
|
||||||
|
this.verifyMethod("GOOGLE", code);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.waitForGoogle().then(() => {
|
||||||
|
this.googleOAuth.init(environment.google_client_id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnDestroy(): void {
|
||||||
|
this.googleSub?.unsubscribe();
|
||||||
|
}
|
||||||
|
|
||||||
|
private waitForGoogle(): Promise<void> {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
if (typeof google !== 'undefined' && google.accounts?.oauth2) {
|
||||||
|
resolve();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const timer = setInterval(() => {
|
||||||
|
if (typeof google !== 'undefined' && google.accounts?.oauth2) {
|
||||||
|
clearInterval(timer);
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
}, 50);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected readonly faGoogle = faGoogle;
|
||||||
|
protected readonly faApple = faApple;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {DatabaseAPI} from '@chatenium/chatenium-sdk/storage/database';
|
|||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class IndexedDB {
|
export class IndexedDB {
|
||||||
private dbVersion = 3
|
private dbVersion = 4
|
||||||
private db: IDBDatabase | null = null
|
private db: IDBDatabase | null = null
|
||||||
|
|
||||||
getApi(): DatabaseAPI {
|
getApi(): DatabaseAPI {
|
||||||
@@ -30,12 +30,12 @@ export class IndexedDB {
|
|||||||
|
|
||||||
request.onupgradeneeded = (e: IDBVersionChangeEvent) => {
|
request.onupgradeneeded = (e: IDBVersionChangeEvent) => {
|
||||||
const db = (e.target as IDBOpenDBRequest).result;
|
const db = (e.target as IDBOpenDBRequest).result;
|
||||||
db.createObjectStore('sessions', { keyPath: 'id' })
|
db.createObjectStore('userData', { keyPath: 'id' })
|
||||||
db.createObjectStore('chats', { keyPath: 'id' })
|
db.createObjectStore('contacts', { keyPath: 'id' })
|
||||||
db.createObjectStore('networks', { keyPath: 'id' })
|
db.createObjectStore('cascades', { keyPath: 'id' })
|
||||||
db.createObjectStore('files', { keyPath: 'id' })
|
db.createObjectStore('files', { keyPath: 'id' })
|
||||||
db.createObjectStore('messages', { keyPath: 'id' })
|
db.createObjectStore('messages', { keyPath: 'id' })
|
||||||
db.createObjectStore('networkmessages', { keyPath: 'id' })
|
db.createObjectStore('threadMessages', { keyPath: 'id' })
|
||||||
db.createObjectStore('pictures', { keyPath: 'id' })
|
db.createObjectStore('pictures', { keyPath: 'id' })
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,7 +123,7 @@ export class IndexedDB {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
get(storeName: string, key: string): Promise<string> {
|
get(storeName: string, key: string): Promise<any> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (this.db) {
|
if (this.db) {
|
||||||
const transaction = this.db.transaction([storeName], "readonly");
|
const transaction = this.db.transaction([storeName], "readonly");
|
||||||
@@ -147,7 +147,7 @@ export class IndexedDB {
|
|||||||
delete(storeName: string, key: string): Promise<void> {
|
delete(storeName: string, key: string): Promise<void> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (this.db) {
|
if (this.db) {
|
||||||
const transaction = this.db.transaction([storeName], "readonly");
|
const transaction = this.db.transaction([storeName], "readwrite");
|
||||||
const store = transaction.objectStore(storeName);
|
const store = transaction.objectStore(storeName);
|
||||||
const request = store.delete(key);
|
const request = store.delete(key);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
export const environment = {
|
export const environment = {
|
||||||
version: "3.0-beta8",
|
version: '3.0-beta11',
|
||||||
api_url: "http://localhost:3000",
|
api_url: 'http://localhost:3000',
|
||||||
cdn_url: "http://localhost:4000",
|
cdn_url: 'http://localhost:4000',
|
||||||
ws_url: "ws://localhost:3000",
|
ws_url: 'ws://localhost:3000',
|
||||||
|
// Google OAuth
|
||||||
|
google_client_id: '21430884719-vjmecc7ofnfp82hmb22hba323gr4r7p7.apps.googleusercontent.com',
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
export const environment = {
|
export const environment = {
|
||||||
version: "3.0-beta8",
|
version: '3.0-beta11',
|
||||||
api_url: "https://api.chatenium.hu",
|
api_url: 'https://api.chatenium.hu',
|
||||||
cdn_url: "https://cdn.chatenium.hu",
|
cdn_url: 'https://cdn.chatenium.hu',
|
||||||
ws_url: "wss://api.chatenium.hu",
|
ws_url: 'wss://api.chatenium.hu',
|
||||||
|
// Google OAuth
|
||||||
|
google_client_id: '21430884719-vjmecc7ofnfp82hmb22hba323gr4r7p7.apps.googleusercontent.com',
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css">
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css">
|
||||||
<link rel="icon" type="image/x-icon" href="favicon.ico">
|
<link rel="icon" type="image/x-icon" href="favicon.ico">
|
||||||
<link rel="manifest" href="manifest.webmanifest">
|
<link rel="manifest" href="manifest.webmanifest">
|
||||||
|
<script src="https://accounts.google.com/gsi/client" async defer></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<app-root></app-root>
|
<app-root></app-root>
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
/* You can add global styles to this file, and also import other style files */
|
/* You can add global styles to this file, and also import other style files */
|
||||||
|
|
||||||
.drag-active * {
|
.drag-active * {
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
"extends": "./tsconfig.json",
|
"extends": "./tsconfig.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"outDir": "./out-tsc/app",
|
"outDir": "./out-tsc/app",
|
||||||
"types": []
|
"types": ["google.accounts"]
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"src/**/*.ts"
|
"src/**/*.ts"
|
||||||
|
|||||||
Reference in New Issue
Block a user