Compare commits
27 Commits
3.0-beta3
...
34752b446c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
34752b446c | ||
|
|
c18a8c14ca | ||
|
|
bc8501d74c | ||
|
|
76d96067d0 | ||
|
|
aa3494eac0 | ||
|
|
e386608e59 | ||
|
|
56d6065eef | ||
|
|
aa811bff1b | ||
|
|
b4ff8356ab | ||
|
|
f836df391b | ||
|
|
1988c0a61e | ||
|
|
043a97ada5 | ||
|
|
3ef5387b8d | ||
|
|
086d27c9a4 | ||
|
|
eeee9d5154 | ||
| aa3e1de412 | |||
| f9518a9164 | |||
| 3ed025ee61 | |||
| 5f032c5098 | |||
| 20e67ecd85 | |||
| 4eaaacac2c | |||
| 8afd4a81b0 | |||
| a0a6fdaf55 | |||
| 0dc1e15e59 | |||
| 931ac91526 | |||
| c56b0aab8a | |||
| 62bc82f158 |
@@ -1,2 +1,2 @@
|
|||||||
# Chatenium On Web
|
# Chatenium Nexum
|
||||||
A modern web application for Chatenium compatible with a wide range of devices.
|
The next generation Web application for Chatenium, built on modern standards powered by Chatenium SDK (TypeScript).
|
||||||
|
|||||||
@@ -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",
|
||||||
@@ -42,12 +47,12 @@
|
|||||||
{
|
{
|
||||||
"type": "initial",
|
"type": "initial",
|
||||||
"maximumWarning": "500kB",
|
"maximumWarning": "500kB",
|
||||||
"maximumError": "1MB"
|
"maximumError": "100MB"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "anyComponentStyle",
|
"type": "anyComponentStyle",
|
||||||
"maximumWarning": "4kB",
|
"maximumWarning": "4kB",
|
||||||
"maximumError": "8kB"
|
"maximumError": "100MB"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"outputHashing": "all",
|
"outputHashing": "all",
|
||||||
|
|||||||
30
ngsw-config.json
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
"$schema": "./node_modules/@angular/service-worker/config/schema.json",
|
||||||
|
"index": "/index.html",
|
||||||
|
"assetGroups": [
|
||||||
|
{
|
||||||
|
"name": "app",
|
||||||
|
"installMode": "prefetch",
|
||||||
|
"resources": {
|
||||||
|
"files": [
|
||||||
|
"/favicon.ico",
|
||||||
|
"/index.csr.html",
|
||||||
|
"/index.html",
|
||||||
|
"/manifest.webmanifest",
|
||||||
|
"/*.css",
|
||||||
|
"/*.js"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "assets",
|
||||||
|
"installMode": "lazy",
|
||||||
|
"updateMode": "prefetch",
|
||||||
|
"resources": {
|
||||||
|
"files": [
|
||||||
|
"/**/*.(svg|cur|jpg|jpeg|png|apng|webp|avif|gif|otf|ttf|woff|woff2)"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
4612
package-lock.json
generated
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.1.5",
|
"@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.7",
|
||||||
|
"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": "3.0 Beta 3 (April 11, 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.",
|
||||||
@@ -8,14 +8,16 @@
|
|||||||
"independent": "Independent",
|
"independent": "Independent",
|
||||||
"scrollDownForMore": "Scroll down for more",
|
"scrollDownForMore": "Scroll down for more",
|
||||||
"whatIsChtn": "Chatenium is a chat platform aiming to provide a secure, well integrated fast chatting experience across any devices. You can create a new account for free and start chatting and broadcasting messages.",
|
"whatIsChtn": "Chatenium is a chat platform aiming to provide a secure, well integrated fast chatting experience across any devices. You can create a new account for free and start chatting and broadcasting messages.",
|
||||||
|
"updating": "Updating...",
|
||||||
"home": {
|
"home": {
|
||||||
|
"soon": "Coming soon...",
|
||||||
"chtn": "Chatenium ",
|
"chtn": "Chatenium ",
|
||||||
"chtnIs": "Chatenium is ",
|
"chtnIs": "Chatenium is ",
|
||||||
"help": "Help",
|
"help": "Help",
|
||||||
"blog": "Blog",
|
"blog": "Blog",
|
||||||
"apiSpecs": "API specifications",
|
"apiSpecs": "API specifications",
|
||||||
"adaptsToYou": "adapts to you",
|
"adaptsTo": "Chatenium adapts to ",
|
||||||
"adaptsToYouDesc": "We actively work on bringing Chatenium to every device, but not the fast way, the good way by developing a native application for each platform.",
|
"adaptsToYouDesc": "Choose your platform:",
|
||||||
"chtnOnWeb": "Chatenium On Web",
|
"chtnOnWeb": "Chatenium On Web",
|
||||||
"chtnOnWebDesc": "Built for maximum compatibility. The Web will work on every device you have.",
|
"chtnOnWebDesc": "Built for maximum compatibility. The Web will work on every device you have.",
|
||||||
"chtnOnAndroid": "Chatenium On Android™",
|
"chtnOnAndroid": "Chatenium On Android™",
|
||||||
@@ -77,7 +79,9 @@
|
|||||||
"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": {
|
||||||
|
"formTitle": "Welcome back!",
|
||||||
|
"formSubtitle": "Sign in with your Chatenium account.",
|
||||||
"mainInput": {
|
"mainInput": {
|
||||||
"label": "Username, email or phone number",
|
"label": "Username, email or phone number",
|
||||||
"placeholder": "bob, bob@example.com, +36201234567"
|
"placeholder": "bob, bob@example.com, +36201234567"
|
||||||
@@ -85,31 +89,189 @@
|
|||||||
"password": {
|
"password": {
|
||||||
"label": "Password"
|
"label": "Password"
|
||||||
},
|
},
|
||||||
"emailButton": "Sign in with email code",
|
"signInButton": "Sign in"
|
||||||
"smsButton": "Sign in with SMS code",
|
},
|
||||||
"signInButton": "Sign in",
|
"methodChoose": {
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"anyAuth": {
|
||||||
|
"verifyButton": "Verify identity"
|
||||||
|
},
|
||||||
|
"passwordAuth": {
|
||||||
|
"formTitle": "Password authentication",
|
||||||
|
"formSubtitle": "Enter your password below",
|
||||||
"errors": {
|
"errors": {
|
||||||
"unameMailPhoneRequired": "Username, email or phone number is required",
|
|
||||||
"passwordRequired": "Password is required",
|
"passwordRequired": "Password is required",
|
||||||
"passwordIncorrect": "Password is incorrect"
|
"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",
|
||||||
"tab3": "Pictures",
|
"tab3": "Pictures",
|
||||||
"tab4": "Settings"
|
"tab4": "Settings"
|
||||||
},
|
},
|
||||||
|
"network": {
|
||||||
|
"tabs": {
|
||||||
|
"channels": "Channels",
|
||||||
|
"members": "Members",
|
||||||
|
"settings": "Settings"
|
||||||
|
},
|
||||||
|
"settings": {
|
||||||
|
"options": {
|
||||||
|
"categories": {
|
||||||
|
"apps": "Apps",
|
||||||
|
"moderation": "Moderation",
|
||||||
|
"community": "Community"
|
||||||
|
},
|
||||||
|
"overview": "Overview",
|
||||||
|
"rank": "Ranks",
|
||||||
|
"emoji": "Emojis",
|
||||||
|
"embed": "Embed",
|
||||||
|
"invite": "Invites",
|
||||||
|
"webhook": "Webhooks",
|
||||||
|
"bots": "Bots",
|
||||||
|
"activityHistory": "Activity history",
|
||||||
|
"bans": "Bans",
|
||||||
|
"communityChannels": "Community channels",
|
||||||
|
"networkIntroducer": "Network introducer",
|
||||||
|
"members": "Members"
|
||||||
|
},
|
||||||
|
"overviewPage": {
|
||||||
|
"networkPicture": "Network picture",
|
||||||
|
"networkName": "Network name",
|
||||||
|
"networkVisibility": "Network visibility",
|
||||||
|
"uploadNewPicture": "Upload new picture",
|
||||||
|
"setNewName": "Set new name",
|
||||||
|
"changeToPrivate": "Change to private",
|
||||||
|
"changeToPrivateDialog": {
|
||||||
|
"label": "You are about to make your network private",
|
||||||
|
"warn": {
|
||||||
|
"1": "Your network will be delisted from Network Discovery.",
|
||||||
|
"2": "Users will no longer be able to freely join your network without an invite.",
|
||||||
|
"3": "Your broadcasts may be unavailable to users outside your network."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"changeToPublic": "Change to public",
|
||||||
|
"changeToPublicDialog": {
|
||||||
|
"label": "You are about to make your network public",
|
||||||
|
"warn": {
|
||||||
|
"1": "Your network will be listed in Network Discovery.",
|
||||||
|
"2": "Users will be able to freely join your network without an invite.",
|
||||||
|
"3": "Your broadcasts will be available to users outside your network."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"setNewNameDialog": {
|
||||||
|
"label": "New name"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"changeLogDialog": {
|
"changeLogDialog": {
|
||||||
"label": "Chatenium has been updated",
|
"label": "Chatenium has been updated",
|
||||||
"changeLog": {
|
"changeLog": {
|
||||||
"1": "Fixed WebSocket connection issues",
|
"1": "The network UI have been merged with the left side navigation panel.",
|
||||||
"2": "The web is now mobile-friendly",
|
"2": "Categories and channels now have a threaded UI to align with recent changes"
|
||||||
"3": "The web is now a PWA. You can now install it on your home screen"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"chatnav": {
|
"chatnav": {
|
||||||
|
"pictureList": {
|
||||||
|
"myPictures": "My pictures"
|
||||||
|
},
|
||||||
"dmList": {
|
"dmList": {
|
||||||
"newChat": "Start new chat",
|
"newChat": "Start new chat",
|
||||||
"messageBox": {
|
"messageBox": {
|
||||||
@@ -117,6 +279,14 @@
|
|||||||
"you": "You: "
|
"you": "You: "
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"networkList": {
|
||||||
|
"newNetwork": "Start new network"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"pictures": {
|
||||||
|
"albumList": {
|
||||||
|
"noAlbum": "This user has no albums published"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"elements": {
|
"elements": {
|
||||||
|
|||||||
BIN
public/icons/icon-128x128.png
Normal file
|
After Width: | Height: | Size: 635 B |
BIN
public/icons/icon-144x144.png
Normal file
|
After Width: | Height: | Size: 658 B |
BIN
public/icons/icon-152x152.png
Normal file
|
After Width: | Height: | Size: 769 B |
BIN
public/icons/icon-192x192.png
Normal file
|
After Width: | Height: | Size: 836 B |
BIN
public/icons/icon-384x384.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
public/icons/icon-512x512.png
Normal file
|
After Width: | Height: | Size: 7.4 KiB |
BIN
public/icons/icon-72x72.png
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
public/icons/icon-96x96.png
Normal file
|
After Width: | Height: | Size: 487 B |
57
public/manifest.webmanifest
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
{
|
||||||
|
"name": "Chatenium",
|
||||||
|
"short_name": "Chtn",
|
||||||
|
"display": "standalone",
|
||||||
|
"scope": "./",
|
||||||
|
"start_url": "./",
|
||||||
|
"icons": [
|
||||||
|
{
|
||||||
|
"src": "icons/icon-72x72.png",
|
||||||
|
"sizes": "72x72",
|
||||||
|
"type": "image/png",
|
||||||
|
"purpose": "maskable any"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "icons/icon-96x96.png",
|
||||||
|
"sizes": "96x96",
|
||||||
|
"type": "image/png",
|
||||||
|
"purpose": "maskable any"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "icons/icon-128x128.png",
|
||||||
|
"sizes": "128x128",
|
||||||
|
"type": "image/png",
|
||||||
|
"purpose": "maskable any"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "icons/icon-144x144.png",
|
||||||
|
"sizes": "144x144",
|
||||||
|
"type": "image/png",
|
||||||
|
"purpose": "maskable any"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "icons/icon-152x152.png",
|
||||||
|
"sizes": "152x152",
|
||||||
|
"type": "image/png",
|
||||||
|
"purpose": "maskable any"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "icons/icon-192x192.png",
|
||||||
|
"sizes": "192x192",
|
||||||
|
"type": "image/png",
|
||||||
|
"purpose": "maskable any"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "icons/icon-384x384.png",
|
||||||
|
"sizes": "384x384",
|
||||||
|
"type": "image/png",
|
||||||
|
"purpose": "maskable any"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "icons/icon-512x512.png",
|
||||||
|
"sizes": "512x512",
|
||||||
|
"type": "image/png",
|
||||||
|
"purpose": "maskable any"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -1,27 +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} 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),
|
provideRouter(
|
||||||
|
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,21 +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 { Text } from './chat/network/channel/text/text';
|
||||||
|
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,
|
||||||
]
|
canActivate: [authNeededGuard],
|
||||||
|
children: [
|
||||||
|
{ path: 'dm/:contactId', component: Dm },
|
||||||
|
{ 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
@@ -0,0 +1,16 @@
|
|||||||
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { CacheService } from './cache';
|
||||||
|
|
||||||
|
describe('Cache', () => {
|
||||||
|
let service: CacheService;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({});
|
||||||
|
service = TestBed.inject(CacheService);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be created', () => {
|
||||||
|
expect(service).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
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 CacheService {
|
||||||
|
contacts = signal<Contact[]>([])
|
||||||
|
contactsState = signal<LoadState>(LoadState.CLEAN_LOADING)
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum LoadState {
|
||||||
|
CLEAN_LOADING,
|
||||||
|
CACHE_UPDATING,
|
||||||
|
LOADED,
|
||||||
|
ERROR
|
||||||
|
}
|
||||||
@@ -4,7 +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>
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<button tuiButton iconStart="@tui.check"
|
<button tuiButton iconStart="@tui.check"
|
||||||
@@ -12,42 +11,70 @@
|
|||||||
</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">
|
<tui-segmented id="mode_switcher" [(activeItemIndex)]="navigationActiveIndex">
|
||||||
|
<button (click)="expandedSidenav.set(false)">
|
||||||
|
<tui-icon icon="@tui.message-circle" />
|
||||||
|
</button>
|
||||||
<button>
|
<button>
|
||||||
<tui-icon icon="@tui.message-circle"/>
|
<tui-icon icon="@tui.network" />
|
||||||
</button>
|
</button>
|
||||||
<button disabled style="pointer-events: none; opacity: 0.5">
|
<button (click)="expandedSidenav.set(false)">
|
||||||
<tui-icon icon="@tui.network"/>
|
<tui-icon icon="@tui.image" />
|
||||||
</button>
|
|
||||||
<button disabled style="pointer-events: none; opacity: 0.5">
|
|
||||||
<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>
|
||||||
<app-dm-list [token]="serviceManager.currentSession()!.token"
|
@switch (navigationActiveIndex) {
|
||||||
[userid]="serviceManager.currentSession()!.userData.userid"></app-dm-list>
|
@case (0) {
|
||||||
|
<app-contact-list></app-contact-list>
|
||||||
|
} <!--
|
||||||
|
@case (1) {
|
||||||
|
<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>
|
||||||
|
}-->
|
||||||
|
}
|
||||||
</main>
|
</main>
|
||||||
</aside>
|
</aside>
|
||||||
|
|
||||||
<main id="content">
|
<main id="content">
|
||||||
<div id="content_tint">
|
<div id="content_tint">
|
||||||
@defer (when serviceManager.chatsStatus() != LoadStatus.loading) {
|
@if (router.url.startsWith("/chat/dm") || router.url.startsWith("/chat/picture")) {
|
||||||
<router-outlet/>
|
<!-- To ensure data is loaded -->
|
||||||
|
@defer (when cache.contactsState() != LoadState.CLEAN_LOADING) {
|
||||||
|
<router-outlet />
|
||||||
|
}
|
||||||
|
} @else if (router.url.startsWith("/chat/network")) {
|
||||||
|
@defer (when serviceManager.networksStatus() != LoadStatus.loading) {
|
||||||
|
<router-outlet />
|
||||||
|
}
|
||||||
|
} @else {
|
||||||
|
<router-outlet />
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
@@ -57,12 +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) {
|
||||||
|
<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">
|
||||||
@@ -82,8 +124,17 @@
|
|||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@if (router.url.startsWith("/chat/dm") || router.url.startsWith("/chat/picture")) {
|
||||||
|
<!-- 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")) {
|
||||||
|
@defer (when serviceManager.networksStatus() != LoadStatus.loading) {
|
||||||
|
<router-outlet (activate)="routerOutletActive.set(true)" (deactivate)="routerOutletActive.set(false)" />
|
||||||
|
}
|
||||||
|
} @else {
|
||||||
|
<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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +66,6 @@
|
|||||||
border-radius: 0 20px 20px 0;
|
border-radius: 0 20px 20px 0;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
background: var(--tui-background-neutral-2);
|
background: var(--tui-background-neutral-2);
|
||||||
padding: 15px;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -80,8 +84,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
#navigation_content {
|
#navigation_content {
|
||||||
|
overflow-y: scroll;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
::ng-deep tui-dialog[data-appearance~=big] {
|
||||||
|
height: 90svh;
|
||||||
|
width: 90svw !important;
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,15 +2,21 @@ 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';
|
||||||
import {environment} from '../../environments/environment';
|
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 {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';
|
||||||
|
import { CacheService, LoadState } from '../cache';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-chat',
|
selector: 'app-chat',
|
||||||
@@ -20,25 +26,33 @@ import {TuiTabBarComponent, TuiTabBarItem} from '@taiga-ui/addon-mobile';
|
|||||||
TuiIcon,
|
TuiIcon,
|
||||||
TuiButton,
|
TuiButton,
|
||||||
TuiLoader,
|
TuiLoader,
|
||||||
DmList,
|
ContactList,
|
||||||
JsonPipe,
|
JsonPipe,
|
||||||
TuiAppearance,
|
TuiAppearance,
|
||||||
TuiGroup,
|
TuiGroup,
|
||||||
TuiDialog,
|
TuiDialog,
|
||||||
TranslatePipe,
|
TranslatePipe,
|
||||||
TuiTabBarComponent,
|
TuiTabBarComponent,
|
||||||
TuiTabBarItem
|
TuiTabBarItem,
|
||||||
|
NetworkList,
|
||||||
|
PictureList,
|
||||||
|
UserSettings
|
||||||
],
|
],
|
||||||
templateUrl: './chat.html',
|
templateUrl: './chat.html',
|
||||||
styleUrl: './chat.scss',
|
styleUrl: './chat.scss',
|
||||||
})
|
})
|
||||||
export class Chat implements OnInit {
|
export class Chat implements OnInit {
|
||||||
serviceManager = inject(ServiceManager)
|
sessionManager = inject(SessionManager);
|
||||||
indexedDb = inject(IndexedDB)
|
serviceManager = inject(ServiceManager);
|
||||||
breakpoint = inject(TUI_BREAKPOINT)
|
cache = inject(CacheService);
|
||||||
router = inject(Router)
|
indexedDb = inject(IndexedDB);
|
||||||
|
breakpoint = inject(TUI_BREAKPOINT);
|
||||||
|
router = inject(Router);
|
||||||
|
|
||||||
|
expandedSidenav = signal(false)
|
||||||
|
|
||||||
routerOutletActive = signal(false)
|
routerOutletActive = signal(false)
|
||||||
|
userSettingsOpen = signal(false)
|
||||||
|
|
||||||
navigationActiveIndex = 0
|
navigationActiveIndex = 0
|
||||||
// Mobile navigation //
|
// Mobile navigation //
|
||||||
@@ -51,28 +65,28 @@ export class Chat implements OnInit {
|
|||||||
{
|
{
|
||||||
text: "chat.tabBar.tab2",
|
text: "chat.tabBar.tab2",
|
||||||
icon: '@tui.network',
|
icon: '@tui.network',
|
||||||
implemented: false,
|
implemented: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
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,
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
changeLogOpen = signal(false)
|
changeLogOpen = signal(false)
|
||||||
|
|
||||||
async ngOnInit() {
|
async ngOnInit() {
|
||||||
this.indexedDb.openDatabase().then(async () => {
|
if (this.router.url.startsWith("/chat/network")) {
|
||||||
const session = await this.serviceManager.sessionManager.loadPreferredSession()
|
this.navigationActiveIndex = 1
|
||||||
this.serviceManager.currentSession.set(session)
|
} else if (this.router.url.startsWith("/chat/picture")) {
|
||||||
await WebSocketHandler.getInstance().connect(session.userData.userid, session.token)
|
this.navigationActiveIndex = 2
|
||||||
})
|
}
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const latestRead = localStorage.getItem("changeLogLastRead")
|
const latestRead = localStorage.getItem("changeLogLastRead")
|
||||||
@@ -85,4 +99,5 @@ export class Chat implements OnInit {
|
|||||||
protected readonly LoadStatus = LoadStatus;
|
protected readonly LoadStatus = LoadStatus;
|
||||||
protected readonly localStorage = localStorage;
|
protected readonly localStorage = localStorage;
|
||||||
protected readonly environment = environment;
|
protected readonly environment = environment;
|
||||||
|
protected readonly LoadState = LoadState;
|
||||||
}
|
}
|
||||||
|
|||||||
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>
|
||||||
|
}
|
||||||
36
src/app/chat/contact-list/contact-list.scss
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
:host {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 5px;
|
||||||
|
|
||||||
|
#loader {
|
||||||
|
width: 100%;
|
||||||
|
display: flex;
|
||||||
|
justify-content: start;
|
||||||
|
padding: 5px;
|
||||||
|
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%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
22
src/app/chat/contact-list/contact-list.spec.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { ContactList } from './contact-list';
|
||||||
|
|
||||||
|
describe('PictureList', () => {
|
||||||
|
let component: ContactList;
|
||||||
|
let fixture: ComponentFixture<ContactList>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
imports: [ContactList],
|
||||||
|
}).compileComponents();
|
||||||
|
|
||||||
|
fixture = TestBed.createComponent(ContactList);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
await fixture.whenStable();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
65
src/app/chat/contact-list/contact-list.ts
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
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 } from 'chatenium-sdk-preview';
|
||||||
|
import { CHATENIUM_SDK } from '../../chatenium.token';
|
||||||
|
import { CacheService, 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(CacheService);
|
||||||
|
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[];
|
||||||
|
if (contacts.length > 0) {
|
||||||
|
this.cache.contacts.set(contacts);
|
||||||
|
this.cache.contactsState.set(LoadState.CACHE_UPDATING);
|
||||||
|
} else {
|
||||||
|
console.log("Found no contacts in cache")
|
||||||
|
}
|
||||||
|
} 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);
|
||||||
|
console.log(`Successfully fetched ${data.length} contacts`);
|
||||||
|
this.cache.contactsState.set(LoadState.LOADED);
|
||||||
|
} 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,24 +0,0 @@
|
|||||||
<button disabled tuiButton appearance="secondary" iconStart="@tui.mail-plus">
|
|
||||||
{{"chat.chatnav.dmList.newChat"|translate}}
|
|
||||||
</button>
|
|
||||||
|
|
||||||
@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,28 +1,32 @@
|
|||||||
<main [class.mobile]="breakpoint() == 'mobile'">
|
<main [class.mobile]="breakpoint() == 'mobile'">
|
||||||
@defer (when store) {
|
@defer (when handler) {
|
||||||
|
@if (chatData != null) {
|
||||||
<navbar backButtonDest="/chat">
|
<navbar backButtonDest="/chat">
|
||||||
<div class="items-left">
|
<div class="data">
|
||||||
<oimg [src]="store.chatData().pfp" height="50px" width="50px" [radius]="15"></oimg>
|
<avatar [src]="chatData.pfp" height="50px" width="50px" [radius]="15" [name]="chatData.username"></avatar>
|
||||||
<div class="chat-data">
|
<div class="chat-data">
|
||||||
@if (store.chatData().displayName == "") {
|
@if (chatData.displayName == "") {
|
||||||
<span class="main-name">{{'@'+store.chatData().username}}</span>
|
<span class="main-name">{{ '@' + chatData.username }}</span>
|
||||||
} @else {
|
} @else {
|
||||||
<span class="main-name">{{store.chatData().displayName}}</span>
|
<span class="main-name">{{ chatData.displayName }}</span>
|
||||||
<span class="alt-name">{{'@'+store.chatData().username}}</span>
|
<span class="alt-name">{{ '@' + chatData.username }}</span>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="items-right">
|
<div class="items-right">
|
||||||
<button tuiButton appearance="flat" disabled>
|
<button tuiButton appearance="flat" disabled>
|
||||||
<tui-icon icon="@tui.phone"/>
|
<tui-icon icon="@tui.phone" />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</navbar>
|
</navbar>
|
||||||
|
|
||||||
<messages [messageBoxViewModel]="store.messageBox" [messages]="store.messages()" id="scrollContainer" (onDelete)="deleteMessage($event)"/>
|
<!--<messages (scrollend)="handleMessagesScroll($event)" [loading]="store.messagesStatus() == LoadStatus.loading"
|
||||||
|
[messageBoxViewModel]="store.messageBox" [messages]="store.messages()" id="scrollContainer"
|
||||||
|
(onDelete)="deleteMessage($event)" />
|
||||||
|
|
||||||
<message-box [viewModel]="store.messageBox"/>
|
<message-box [viewModel]="store.messageBox" />-->
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
</main>
|
</main>
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
main {
|
main {
|
||||||
height: 95svh;
|
height: 98svh;
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-rows: 70px minmax(0, 1fr) auto;
|
grid-template-rows: 70px minmax(0, 1fr) auto;
|
||||||
|
padding: 15px;
|
||||||
|
|
||||||
&.mobile {
|
&.mobile {
|
||||||
height: 100svh;
|
height: 100svh;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import {Component, inject, OnInit, signal} from '@angular/core';
|
import {Component, inject, OnInit, signal} from '@angular/core';
|
||||||
import {DmStorage, ServiceManager} from '../../service-manager';
|
import {DmStorage, LoadStatus, ServiceManager} from '../../service-manager';
|
||||||
import {ActivatedRoute} from '@angular/router';
|
import {ActivatedRoute} from '@angular/router';
|
||||||
import {DMService} from '@chatenium/chatenium-sdk/services/dmService';
|
import {DMService} from '@chatenium/chatenium-sdk/services/dmService';
|
||||||
import {IndexedDB} from '../../storage/indexed-db';
|
import {IndexedDB} from '../../storage/indexed-db';
|
||||||
@@ -11,65 +11,70 @@ import {Messages} from '../elements/messages/messages';
|
|||||||
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';
|
||||||
import {MessageBoxViewModel} from '../elements/message-box/message-box-viewmodel';
|
import {MessageBoxViewModel} from '../elements/message-box/message-box-viewmodel';
|
||||||
import {WebSocketHandler} from '@chatenium/chatenium-sdk/core/webSocketHandler';
|
import {FileUploadProgressListener} from '@chatenium/chatenium-sdk/domain/fileUploadService.schema';
|
||||||
import {FileData, FileUploadProgressListener} from '@chatenium/chatenium-sdk/domain/fileUploadService.schema';
|
|
||||||
import {Attachment} from '@chatenium/chatenium-sdk/domain/common.schema';
|
import {Attachment} from '@chatenium/chatenium-sdk/domain/common.schema';
|
||||||
|
import {MessagesViewModel} from '../elements/messages/messages-viewmodel';
|
||||||
|
import {v4 as uuidv4} from 'uuid';
|
||||||
|
import { CHATENIUM_SDK } from '../../chatenium.token';
|
||||||
|
import { Contact, createDMWrapper, DirectMessagingApi, WrappedDMHandler } from 'chatenium-sdk-preview';
|
||||||
|
import { CacheService } from '../../cache';
|
||||||
|
import { Avatar } from '../elements/avatar/avatar';
|
||||||
|
import { JsonPipe } from '@angular/common';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-dm',
|
selector: 'app-dm',
|
||||||
imports: [
|
imports: [Navbar, Oimg, TuiButton, TuiIcon, MessageBox, Messages, Avatar, JsonPipe],
|
||||||
Navbar,
|
|
||||||
Oimg,
|
|
||||||
TuiButton,
|
|
||||||
TuiIcon,
|
|
||||||
MessageBox,
|
|
||||||
Messages
|
|
||||||
],
|
|
||||||
templateUrl: './dm.html',
|
templateUrl: './dm.html',
|
||||||
styleUrl: './dm.scss',
|
styleUrl: './dm.scss',
|
||||||
})
|
})
|
||||||
export class Dm implements OnInit {
|
export class Dm implements OnInit {
|
||||||
serviceManager = inject(ServiceManager)
|
SDK = inject(CHATENIUM_SDK);
|
||||||
route = inject(ActivatedRoute)
|
cache = inject(CacheService);
|
||||||
indexedDb = inject(IndexedDB)
|
serviceManager = inject(ServiceManager);
|
||||||
breakpoint = inject(TUI_BREAKPOINT)
|
route = inject(ActivatedRoute);
|
||||||
|
indexedDb = inject(IndexedDB);
|
||||||
|
breakpoint = inject(TUI_BREAKPOINT);
|
||||||
|
|
||||||
chatid = ""
|
handler: WrappedDMHandler<DirectMessagingApi> | null = null;
|
||||||
|
chatData: Contact | null = null;
|
||||||
|
|
||||||
|
chatid = '';
|
||||||
|
|
||||||
get store(): DmStorage {
|
get store(): DmStorage {
|
||||||
return this.serviceManager.dmServices()[this.chatid]
|
return this.serviceManager.dmServices()[this.chatid];
|
||||||
}
|
}
|
||||||
|
|
||||||
async sendMessage(message: string, files: FileDataWithPreview[] | null) {
|
async sendMessage(message: string, files: FileDataWithPreview[] | null) {
|
||||||
if (!files && message.trim() == "") return
|
if (!files && message.trim() == '') return;
|
||||||
|
|
||||||
const session = this.serviceManager.currentSession();
|
const session = this.serviceManager.currentSession();
|
||||||
if (session != null) {
|
if (session != null) {
|
||||||
const editedMessage = this.store.messageBox.editingMessage()
|
const editedMessage = this.store.messageBox.editingMessage();
|
||||||
if (editedMessage) {
|
if (editedMessage) {
|
||||||
const storedMsg = this.store.messages().find(m => m.msgid == editedMessage.messageId)
|
const storedMsg = this.store.messages().find((m) => m.msgid == editedMessage.messageId);
|
||||||
const originalMessage: Message = JSON.parse(JSON.stringify(storedMsg))
|
const originalMessage: Message = JSON.parse(JSON.stringify(storedMsg));
|
||||||
if (storedMsg) {
|
if (storedMsg) {
|
||||||
storedMsg.message = message
|
storedMsg.message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.store.service.editMessage(editedMessage.messageId, message)
|
await this.store.service.editMessage(editedMessage.messageId, message);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (storedMsg) {
|
if (storedMsg) {
|
||||||
storedMsg.message = originalMessage.message
|
storedMsg.message = originalMessage.message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.store.messageBox.editingMessage.set(null)
|
return;
|
||||||
this.store.messageBox.message.set("")
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let attachments: Attachment[] = []
|
let attachments: Attachment[] = [];
|
||||||
files?.forEach(file => {
|
files?.forEach((file) => {
|
||||||
const extraMetaData: Record<string, string> = {}
|
const extraMetaData: Record<string, any> = {};
|
||||||
extraMetaData["thumbnailMetaData"] = file.videoThumbnail ?? ""
|
extraMetaData['thumbnailMetaData'] = file.videoThumbnail ?? '';
|
||||||
|
extraMetaData['progressShown'] = true;
|
||||||
|
extraMetaData['totalChunks'] = 0;
|
||||||
|
extraMetaData['uploadedChunks'] = 0;
|
||||||
|
|
||||||
attachments.push({
|
attachments.push({
|
||||||
fileName: file.name,
|
fileName: file.name,
|
||||||
@@ -79,63 +84,132 @@ export class Dm implements OnInit {
|
|||||||
path: file.blob,
|
path: file.blob,
|
||||||
height: file.height,
|
height: file.height,
|
||||||
width: file.width,
|
width: file.width,
|
||||||
extraMetaData: extraMetaData
|
extraMetaData: extraMetaData,
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
this.store.messages.update(value => [...value, {
|
const tempMsgId = uuidv4();
|
||||||
|
this.store.messages.update((value) => [
|
||||||
|
...value,
|
||||||
|
{
|
||||||
message: message,
|
message: message,
|
||||||
chatid: this.chatid,
|
chatid: this.chatid,
|
||||||
files: attachments,
|
files: attachments,
|
||||||
replyTo: "",
|
replyTo: '',
|
||||||
author: session.userData.userid,
|
author: session.userData.userid,
|
||||||
seen: false,
|
seen: false,
|
||||||
msgid: "",
|
msgid: tempMsgId,
|
||||||
forwardedFrom: "",
|
forwardedFrom: '',
|
||||||
isEdited: false,
|
isEdited: false,
|
||||||
sent_at: {T: 0, I: 0},
|
sent_at: { T: 0, I: 0 },
|
||||||
replyToId: "",
|
replyToId: '',
|
||||||
forwardedFromName: ""
|
forwardedFromName: '',
|
||||||
}])
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
this.scrollToBottom("smooth")
|
const respMessage = await this.store.service.sendMessage(
|
||||||
|
tempMsgId,
|
||||||
await this.store.service.sendMessage("", message, null, null, files, <FileUploadProgressListener>{
|
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.scrollToBottom('smooth');
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
this.store.messageBox.message.set("")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteMessage(messageId: string) {
|
async deleteMessage(messageId: string) {
|
||||||
const i = this.store.messages().findIndex(m => m.msgid == messageId)
|
const i = this.store.messages().findIndex((m) => m.msgid == messageId);
|
||||||
if (i != -1) {
|
if (i != -1) {
|
||||||
const originalMessage: Message = JSON.parse(JSON.stringify(this.store.messages()[i]))
|
const originalMessage: Message = JSON.parse(JSON.stringify(this.store.messages()[i]));
|
||||||
this.store.messages().splice(i, 1)
|
this.store.messages().splice(i, 1);
|
||||||
try {
|
try {
|
||||||
await this.store.service.deleteMessages([messageId])
|
await this.store.service.deleteMessages([messageId]);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.store.messages().splice(i, 0, originalMessage)
|
this.store.messages().splice(i, 0, originalMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
restoreScrollState(): void {
|
||||||
|
setTimeout(() => {
|
||||||
|
const scrollContainer = <HTMLDivElement>document.querySelector('#scrollContainer');
|
||||||
|
scrollContainer.scroll({
|
||||||
|
top:
|
||||||
|
this.store.messagesVm.scrollBarStatus() == -1
|
||||||
|
? scrollContainer.scrollHeight
|
||||||
|
: this.store.messagesVm.scrollBarStatus(),
|
||||||
|
left: 0,
|
||||||
|
behavior: 'instant',
|
||||||
|
});
|
||||||
|
|
||||||
|
if (this.store.messagesVm.scrollBarStatus() == -1) {
|
||||||
|
this.store.messagesVm.scrollBarStatus.set(scrollContainer.scrollHeight);
|
||||||
|
}
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
|
|
||||||
scrollToBottom(anim: 'instant' | 'smooth'): void {
|
scrollToBottom(anim: 'instant' | 'smooth'): void {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const scrollContainer = <HTMLDivElement>document.querySelector("#scrollContainer")
|
const scrollContainer = <HTMLDivElement>document.querySelector('#scrollContainer');
|
||||||
scrollContainer.scroll({
|
scrollContainer.scroll({
|
||||||
top: scrollContainer.scrollHeight,
|
top: scrollContainer.scrollHeight,
|
||||||
left: 0,
|
left: 0,
|
||||||
behavior: anim
|
behavior: anim,
|
||||||
});
|
});
|
||||||
}, 0)
|
}, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleMessagesScroll(e: any) {
|
||||||
|
this.store.messagesVm.scrollBarStatus.set(e.target.scrollTop);
|
||||||
}
|
}
|
||||||
|
|
||||||
uploadProgressUpdate(tempMsgId: string, fileId: string, allChunks: number, chunksDone: number) {
|
uploadProgressUpdate(tempMsgId: string, fileId: string, allChunks: number, chunksDone: number) {
|
||||||
console.log(fileId, allChunks, chunksDone)
|
console.log(tempMsgId, fileId, allChunks, chunksDone);
|
||||||
|
this.store.messages.update((messages) =>
|
||||||
|
messages.map((m) => {
|
||||||
|
if (m.msgid !== tempMsgId) return m;
|
||||||
|
|
||||||
|
return {
|
||||||
|
...m,
|
||||||
|
files: m.files.map((f) => {
|
||||||
|
if (f.fileId !== fileId) return f;
|
||||||
|
return {
|
||||||
|
...f,
|
||||||
|
extraMetaData: {
|
||||||
|
...f.extraMetaData,
|
||||||
|
totalChunks: allChunks,
|
||||||
|
uploadedChunks: chunksDone,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateTempMessage(tempMsgId: string, message: Message) {
|
||||||
|
this.store.messages.update((messages) =>
|
||||||
|
messages.map((m) => {
|
||||||
|
if (m.msgid !== tempMsgId) return m;
|
||||||
|
|
||||||
|
return {
|
||||||
|
...m,
|
||||||
|
msgid: message.msgid,
|
||||||
|
sent_at: message.sent_at,
|
||||||
|
files: m.files.map((f) => {
|
||||||
|
f.extraMetaData['progressShown'] = false;
|
||||||
|
return f;
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The chatid parameter ensures isolation
|
// The chatid parameter ensures isolation
|
||||||
@@ -145,9 +219,9 @@ export class Dm implements OnInit {
|
|||||||
const targetStore = this.serviceManager.dmServices()[chatid];
|
const targetStore = this.serviceManager.dmServices()[chatid];
|
||||||
if (targetStore) {
|
if (targetStore) {
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case "newMessage":
|
case 'newMessage':
|
||||||
targetStore.messages.update(messages => [...messages, data]);
|
targetStore.messages.update((messages) => [...messages, data]);
|
||||||
this.scrollToBottom("smooth")
|
this.scrollToBottom('smooth');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -155,43 +229,64 @@ export class Dm implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.route.params.subscribe(async params => {
|
this.route.params.subscribe(async (params) => {
|
||||||
const chatid = params['chatid'];
|
const contactId = params['contactId'];
|
||||||
this.chatid = chatid;
|
this.chatid = contactId;
|
||||||
|
console.log(`Loading DM chat ${contactId}...`);
|
||||||
|
|
||||||
const session = this.serviceManager.currentSession();
|
const chatData = this.cache.contacts().find((c) => c.contactId === contactId);
|
||||||
const chatData = this.serviceManager.chats().find(c => c.chatid === chatid);
|
|
||||||
|
|
||||||
if (!session || !chatData) {
|
if (!chatData) {
|
||||||
console.warn(`Initialization deferred for ${chatid}: Session or ChatData missing.`);
|
console.warn(
|
||||||
|
`Unable to find chat data with the provided contactId: ${contactId}, skipping load.`,
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.serviceManager.dmServices()[chatid]) {
|
this.chatData = chatData;
|
||||||
|
this.handler = createDMWrapper(this.SDK.directMessaging, chatData.contactId);
|
||||||
|
console.log(`Finished initializing chat: ${contactId}`);
|
||||||
|
|
||||||
|
/*if (!this.serviceManager.dmServices()[contactId]) {
|
||||||
const newStore = {
|
const newStore = {
|
||||||
chatData: signal<Chat>(chatData),
|
chatData: signal<Chat>(chatData),
|
||||||
messages: signal<Message[]>([]),
|
messages: signal<Message[]>([]),
|
||||||
|
messagesStatus: signal<LoadStatus>(LoadStatus.loading),
|
||||||
messageBox: new MessageBoxViewModel((msg, files) => this.sendMessage(msg, files)),
|
messageBox: new MessageBoxViewModel((msg, files) => this.sendMessage(msg, files)),
|
||||||
wsListener: (action, data) => this.onWsListen(action, data, chatid),
|
messagesVm: new MessagesViewModel(),
|
||||||
|
wsListener: (action, data) => this.onWsListen(action, data, contactId),
|
||||||
} as DmStorage;
|
} as DmStorage;
|
||||||
|
|
||||||
newStore.service = new DMService(
|
newStore.service = new DMService(
|
||||||
session.userData.userid,
|
session.userData.userid,
|
||||||
session.token,
|
session.token,
|
||||||
chatid,
|
contactId,
|
||||||
this.indexedDb.getApi(),
|
this.indexedDb.getApi(),
|
||||||
(action, data) => newStore.wsListener(action, data)
|
(action, data) => newStore.wsListener(action, data)
|
||||||
);
|
);
|
||||||
|
|
||||||
this.serviceManager.dmServices()[chatid] = newStore;
|
this.serviceManager.dmServices()[contactId] = newStore;
|
||||||
|
|
||||||
const currentStore = this.serviceManager.dmServices()[chatid];
|
const currentStore = this.serviceManager.dmServices()[contactId];
|
||||||
const history = await currentStore.service.get();
|
try {
|
||||||
currentStore.messages.set(history);
|
const messagesCache = await currentStore.service.getQuick();
|
||||||
this.scrollToBottom("instant")
|
currentStore.messages.set(messagesCache);
|
||||||
|
this.store.messagesStatus.set(LoadStatus.updating)
|
||||||
|
this.restoreScrollState()
|
||||||
|
} catch (e) {
|
||||||
|
console.warn(`Cache load failed: ${e}. Skipping cache load...`)
|
||||||
|
}
|
||||||
|
const messages = await currentStore.service.get();
|
||||||
|
currentStore.messages.set(messages);
|
||||||
|
this.store.messagesStatus.set(LoadStatus.loaded)
|
||||||
|
this.restoreScrollState()
|
||||||
|
|
||||||
await currentStore.service.joinWebSocketRoom();
|
await currentStore.service.joinWebSocketRoom();
|
||||||
}
|
} else {
|
||||||
|
this.restoreScrollState()
|
||||||
|
}*/
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected readonly LoadStatus = LoadStatus;
|
||||||
}
|
}
|
||||||
|
|||||||
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
@@ -0,0 +1,6 @@
|
|||||||
|
.avatar {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
@@ -1,17 +1,17 @@
|
|||||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
import { DmList } from './dm-list';
|
import { Avatar } from './avatar';
|
||||||
|
|
||||||
describe('DmList', () => {
|
describe('Avatar', () => {
|
||||||
let component: DmList;
|
let component: Avatar;
|
||||||
let fixture: ComponentFixture<DmList>;
|
let fixture: ComponentFixture<Avatar>;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await TestBed.configureTestingModule({
|
await TestBed.configureTestingModule({
|
||||||
imports: [DmList],
|
imports: [Avatar],
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
|
|
||||||
fixture = TestBed.createComponent(DmList);
|
fixture = TestBed.createComponent(Avatar);
|
||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
await fixture.whenStable();
|
await fixture.whenStable();
|
||||||
});
|
});
|
||||||
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,9 +1,8 @@
|
|||||||
:host {
|
:host {
|
||||||
display: grid;
|
display: grid;
|
||||||
gap: 4px;
|
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
|
||||||
img {
|
::ng-deep img {
|
||||||
display: block;
|
display: block;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|||||||
@@ -50,7 +50,7 @@
|
|||||||
</ng-template>
|
</ng-template>
|
||||||
|
|
||||||
<main>
|
<main>
|
||||||
<div id="message-box-extension" tuiAppearance="floating" [class.shown]="viewModel().editingMessage()">
|
<div id="message-box-extension" tuiAppearance="floating" [class.shown]="viewModel().editingMessage()" [class.fullWidth]="breakpoint() != 'desktopLarge'">
|
||||||
<div id="content">
|
<div id="content">
|
||||||
@if (viewModel().editingMessage()) {
|
@if (viewModel().editingMessage()) {
|
||||||
<tui-icon icon="@tui.pencil"></tui-icon>
|
<tui-icon icon="@tui.pencil"></tui-icon>
|
||||||
@@ -59,7 +59,7 @@
|
|||||||
<tui-icon icon="@tui.paperclip"></tui-icon>
|
<tui-icon icon="@tui.paperclip"></tui-icon>
|
||||||
<span>{{"chat.elements.messageBox.attachments"|translate}}</span>
|
<span>{{"chat.elements.messageBox.attachments"|translate}}</span>
|
||||||
} @else {
|
} @else {
|
||||||
{{viewModel().editingMessage()!.message}}
|
<span style="width: 300px" tuiScrollable tuiFade>{{viewModel().editingMessage()!.message}}</span>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
@@ -80,12 +80,12 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="items-middle">
|
<div class="items-middle">
|
||||||
<textarea (keydown.enter)="handleEnterKeydown($event); viewModel().onMessageSend(message.value, null)" [style]="'height:'+textareaHeight+'px;'" #message (input)="onTextAreaInput(message)" [(ngModel)]="viewModel().message"></textarea>
|
<textarea (keydown.enter)="viewModel().onMessageSend(message.value, null); viewModel().message.set(''); viewModel().editingMessage.set(null); handleEnterKeydown($event)" [style]="'height:'+textareaHeight+'px;'" #message (input)="onTextAreaInput(message)" [(ngModel)]="viewModel().message"></textarea>
|
||||||
<span class="placeholder"
|
<span class="placeholder"
|
||||||
[class.hidden]="message.value != ''">{{ "chat.elements.messageBox.placeholder"|translate }}</span>
|
[class.hidden]="message.value != ''">{{ "chat.elements.messageBox.placeholder"|translate }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="items-right">
|
<div class="items-right">
|
||||||
<button [disabled]="message.value.trim() == ''" tuiButton appearance="flat" (click)="viewModel().onMessageSend(message.value, null)">
|
<button [disabled]="message.value.trim() == ''" tuiButton appearance="flat" (click)="viewModel().onMessageSend(message.value, null); viewModel().message.set(''); viewModel().editingMessage.set(null);">
|
||||||
<tui-icon icon="@tui.send"/>
|
<tui-icon icon="@tui.send"/>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -67,6 +67,10 @@
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
height: 0;
|
height: 0;
|
||||||
|
|
||||||
|
&.fullWidth {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
#content {
|
#content {
|
||||||
padding-left: 10px;
|
padding-left: 10px;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
TuiButton,
|
TuiButton,
|
||||||
TuiDialog,
|
TuiDialog,
|
||||||
TuiGroup,
|
TuiGroup,
|
||||||
TuiIcon,
|
TuiIcon, TuiScrollable,
|
||||||
TuiScrollbarDirective,
|
TuiScrollbarDirective,
|
||||||
TuiTextfield
|
TuiTextfield
|
||||||
} from '@taiga-ui/core';
|
} from '@taiga-ui/core';
|
||||||
@@ -17,7 +17,7 @@ import {v4 as uuidv4} from 'uuid';
|
|||||||
import {Masonry} from '../masonry/masonry';
|
import {Masonry} from '../masonry/masonry';
|
||||||
import {Oimg} from '../oimg/oimg';
|
import {Oimg} from '../oimg/oimg';
|
||||||
import {FileData} from '@chatenium/chatenium-sdk/domain/fileUploadService.schema';
|
import {FileData} from '@chatenium/chatenium-sdk/domain/fileUploadService.schema';
|
||||||
import {TuiTextarea, TuiTextareaComponent} from '@taiga-ui/kit';
|
import {TuiFade, TuiTextarea, TuiTextareaComponent} from '@taiga-ui/kit';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'message-box',
|
selector: 'message-box',
|
||||||
@@ -33,7 +33,9 @@ import {TuiTextarea, TuiTextareaComponent} from '@taiga-ui/kit';
|
|||||||
Oimg,
|
Oimg,
|
||||||
Masonry,
|
Masonry,
|
||||||
TuiTextfield,
|
TuiTextfield,
|
||||||
TuiTextarea
|
TuiTextarea,
|
||||||
|
TuiScrollable,
|
||||||
|
TuiFade
|
||||||
],
|
],
|
||||||
templateUrl: './message-box.html',
|
templateUrl: './message-box.html',
|
||||||
styleUrl: './message-box.scss',
|
styleUrl: './message-box.scss',
|
||||||
@@ -101,8 +103,10 @@ export class MessageBox {
|
|||||||
|
|
||||||
sendMessageWithCaption() {
|
sendMessageWithCaption() {
|
||||||
this.viewModel().onMessageSend(this.viewModel().message(), this.viewModel().files())
|
this.viewModel().onMessageSend(this.viewModel().message(), this.viewModel().files())
|
||||||
|
this.viewModel().message.set("")
|
||||||
this.viewModel().files.set([])
|
this.viewModel().files.set([])
|
||||||
this.viewModel().dialogOpen.set(false)
|
this.viewModel().dialogOpen.set(false)
|
||||||
|
this.viewModel().editingMessage.set(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
handleEnterKeydown(e: any) {
|
handleEnterKeydown(e: any) {
|
||||||
|
|||||||
6
src/app/chat/elements/messages/messages-viewmodel.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import {signal} from '@angular/core';
|
||||||
|
|
||||||
|
export class MessagesViewModel {
|
||||||
|
// Saves scrolling state. First value initialized when scrolling to bottom on the message load
|
||||||
|
scrollBarStatus = signal<number>(-1)
|
||||||
|
}
|
||||||
@@ -1,8 +1,25 @@
|
|||||||
@if (serviceManager.currentSession != null) {
|
@if (loading()) {
|
||||||
|
@for (_ of [{}, {}, {}, {}, {}, {}, {}, {}, {}, {}]; track _; let i = $index) {
|
||||||
|
<div class="message"
|
||||||
|
[class.chained_start]="i == 0 || i == 3 || i == 6"
|
||||||
|
[class.chained_end]="i == 2 || i == 5 || i == 9"
|
||||||
|
[class.chained_middle]="i != 0 && i != 3 && i != 6 && i != 2 && i != 5 && i != 9"
|
||||||
|
[class.author]="i == 3 || i == 4 || i == 5"
|
||||||
|
>
|
||||||
|
<div class="bubble" [tuiSkeleton]="true">
|
||||||
|
{{i}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
} @else {
|
||||||
|
@if (serviceManager.currentSession != null) {
|
||||||
@for (message of messages(); track message.msgid; let i = $index) {
|
@for (message of messages(); track message.msgid; let i = $index) {
|
||||||
<div
|
<div
|
||||||
class="message"
|
class="message"
|
||||||
[class.author]="message.author == serviceManager.currentSession()!.userData.userid"
|
[class.author]="
|
||||||
|
messageAsDm(message).author == serviceManager.currentSession()!.userData.userid ||
|
||||||
|
messageAsNetwork(message).author.userid == serviceManager.currentSession()!.userData.userid
|
||||||
|
"
|
||||||
[class.chained_start]="isMessageStartOfChain(i)"
|
[class.chained_start]="isMessageStartOfChain(i)"
|
||||||
[class.chained_middle]="isMessageMiddleInChain(i)"
|
[class.chained_middle]="isMessageMiddleInChain(i)"
|
||||||
[class.chained_end]="isMessageEndOfChain(i)"
|
[class.chained_end]="isMessageEndOfChain(i)"
|
||||||
@@ -14,6 +31,16 @@
|
|||||||
<span class="message-text">{{ message.message }}</span>
|
<span class="message-text">{{ message.message }}</span>
|
||||||
<masonry style="max-height: 300px">
|
<masonry style="max-height: 300px">
|
||||||
@for (file of filterExpressedMedia(message.files); track file) {
|
@for (file of filterExpressedMedia(message.files); track file) {
|
||||||
|
<div style="position:relative;">
|
||||||
|
@if (file.extraMetaData && Object.keys(file.extraMetaData).length > 0) {
|
||||||
|
@if (file.extraMetaData['progressShown']) {
|
||||||
|
<tui-progress-circle
|
||||||
|
style="position: absolute; top: 0; right: 0; z-index: 10; transform: translate(-50%, -50%)"
|
||||||
|
[max]="file.extraMetaData['totalChunks']"
|
||||||
|
[value]="file.extraMetaData['uploadedChunks']"
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
}
|
||||||
@if (file.type == "image") {
|
@if (file.type == "image") {
|
||||||
<img [src]="file.path"
|
<img [src]="file.path"
|
||||||
style="width: 100%; height: 100%; max-height: 300px; object-fit: cover; border-radius: 25px"/>
|
style="width: 100%; height: 100%; max-height: 300px; object-fit: cover; border-radius: 25px"/>
|
||||||
@@ -25,13 +52,26 @@
|
|||||||
<video-player maxHeight="300px" maxWidth="300px" [src]="file.path"></video-player>
|
<video-player maxHeight="300px" maxWidth="300px" [src]="file.path"></video-player>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
</div>
|
||||||
}
|
}
|
||||||
</masonry>
|
</masonry>
|
||||||
|
|
||||||
<div tuiGroup orientation="vertical" style="width: 100%">
|
<div tuiGroup orientation="vertical" style="width: 100%">
|
||||||
@for (file of filterNonExpressedMedia(message.files); track file) {
|
@for (file of filterNonExpressedMedia(message.files); track file) {
|
||||||
<div style="width: 100%; height: 50px; display: flex; align-items: center; padding: 0 10px; background: var(--tui-background-accent-1); gap: 5px">
|
<div style="width: 100%; height: 50px; display: flex; align-items: center; padding: 0 10px; background: var(--tui-background-base-alt); gap: 5px">
|
||||||
|
@if (file.extraMetaData && Object.keys(file.extraMetaData).length > 0) {
|
||||||
|
@if (file.extraMetaData['progressShown']) {
|
||||||
|
<tui-progress-circle
|
||||||
|
size="xs"
|
||||||
|
[max]="file.extraMetaData['totalChunks']"
|
||||||
|
[value]="file.extraMetaData['uploadedChunks']"
|
||||||
|
/>
|
||||||
|
} @else {
|
||||||
<tui-icon icon="@tui.file"/>
|
<tui-icon icon="@tui.file"/>
|
||||||
|
}
|
||||||
|
} @else {
|
||||||
|
<tui-icon icon="@tui.file"/>
|
||||||
|
}
|
||||||
<span>{{ file.fileName }}</span>
|
<span>{{ file.fileName }}</span>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
@@ -63,4 +103,6 @@
|
|||||||
</ng-template>
|
</ng-template>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
.message {
|
.message {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
align-items: start;
|
||||||
|
|
||||||
&.author {
|
&.author {
|
||||||
align-items: end;
|
align-items: end;
|
||||||
@@ -16,6 +17,24 @@
|
|||||||
.bubble {
|
.bubble {
|
||||||
background: var(--tui-background-accent-1-hover);
|
background: var(--tui-background-accent-1-hover);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&.chained_start {
|
||||||
|
.bubble {
|
||||||
|
border-radius: 10px 25px 10px 10px !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&.chained_middle {
|
||||||
|
.bubble {
|
||||||
|
border-radius: 10px !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&.chained_end {
|
||||||
|
.bubble {
|
||||||
|
border-radius: 10px 10px 25px 10px !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&.chained_start {
|
&.chained_start {
|
||||||
@@ -64,7 +83,7 @@
|
|||||||
padding: 10px;
|
padding: 10px;
|
||||||
|
|
||||||
.message-text {
|
.message-text {
|
||||||
white-space: none;
|
white-space: break-spaces;
|
||||||
overflow-wrap: anywhere;
|
overflow-wrap: anywhere;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import {TranslatePipe} from '@ngx-translate/core';
|
|||||||
import {MessageBoxViewModel} from '../message-box/message-box-viewmodel';
|
import {MessageBoxViewModel} from '../message-box/message-box-viewmodel';
|
||||||
import {FileDataWithPreview} from '../message-box/message-box';
|
import {FileDataWithPreview} from '../message-box/message-box';
|
||||||
import {Attachment} from '@chatenium/chatenium-sdk/domain/common.schema';
|
import {Attachment} from '@chatenium/chatenium-sdk/domain/common.schema';
|
||||||
|
import {TuiProgressCircle, TuiSkeleton} from '@taiga-ui/kit';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'messages',
|
selector: 'messages',
|
||||||
@@ -32,7 +33,9 @@ import {Attachment} from '@chatenium/chatenium-sdk/domain/common.schema';
|
|||||||
TranslatePipe,
|
TranslatePipe,
|
||||||
TuiDataListComponent,
|
TuiDataListComponent,
|
||||||
TuiGroup,
|
TuiGroup,
|
||||||
TuiIcon
|
TuiIcon,
|
||||||
|
TuiProgressCircle,
|
||||||
|
TuiSkeleton
|
||||||
],
|
],
|
||||||
templateUrl: './messages.html',
|
templateUrl: './messages.html',
|
||||||
styleUrl: './messages.scss',
|
styleUrl: './messages.scss',
|
||||||
@@ -42,6 +45,7 @@ export class Messages {
|
|||||||
|
|
||||||
messages = input.required<Message[] | NetworkMessage[]>()
|
messages = input.required<Message[] | NetworkMessage[]>()
|
||||||
messageBoxViewModel = input.required<MessageBoxViewModel>()
|
messageBoxViewModel = input.required<MessageBoxViewModel>()
|
||||||
|
loading = input(false)
|
||||||
|
|
||||||
@Output() onDelete = new EventEmitter<string>()
|
@Output() onDelete = new EventEmitter<string>()
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
<nav [class.mobile]="breakpoint() == 'mobile'">
|
<nav [class.includeBackButton]="breakpoint() == showBackButtonAt()" [class.mobile]="breakpoint() == 'mobile'" [class.alignCenter]="dataAlignment() == 'center'">
|
||||||
@if (breakpoint() == "mobile") {
|
@if (breakpoint() == showBackButtonAt()) {
|
||||||
<div>
|
<div>
|
||||||
<button (click)="router.navigate([backButtonDest()])" tuiButton appearance="flat" iconStart="@tui.chevron-left">
|
<button (click)="router.navigate([backButtonDest()])" tuiButton appearance="flat" iconStart="@tui.chevron-left">
|
||||||
{{"back"|translate}}
|
{{"back"|translate}}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
@if (dataAlignment() == "center" && breakpoint() != showBackButtonAt()) {
|
||||||
|
<div></div> <!-- filler to align data to center -->
|
||||||
|
}
|
||||||
<ng-content></ng-content>
|
<ng-content></ng-content>
|
||||||
</nav>
|
</nav>
|
||||||
|
|||||||
@@ -2,18 +2,31 @@ nav {
|
|||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 1fr 1fr;
|
grid-template-columns: 1fr 1fr;
|
||||||
|
|
||||||
&.mobile {
|
&.includeBackButton {
|
||||||
zoom: 0.85;
|
|
||||||
grid-template-columns: 1fr 1fr 1fr;
|
grid-template-columns: 1fr 1fr 1fr;
|
||||||
|
|
||||||
::ng-deep .items-left {
|
::ng-deep .data {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
::ng-deep .items-right, ::ng-deep .items-left {
|
&.mobile {
|
||||||
|
zoom: 0.85;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.alignCenter {
|
||||||
|
grid-template-columns: 1fr 1fr 1fr;
|
||||||
|
|
||||||
|
::ng-deep .data {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
::ng-deep .items-right, ::ng-deep .data {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 10px;
|
gap: 10px;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|||||||
@@ -22,4 +22,6 @@ export class Navbar {
|
|||||||
breakpoint = inject(TUI_BREAKPOINT)
|
breakpoint = inject(TUI_BREAKPOINT)
|
||||||
router = inject(Router)
|
router = inject(Router)
|
||||||
backButtonDest = input.required<string>()
|
backButtonDest = input.required<string>()
|
||||||
|
showBackButtonAt = input<"desktopSmall"|"mobile">("mobile")
|
||||||
|
dataAlignment = input<"left"|"center">("left")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
img {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|||||||
35
src/app/chat/network-list/network-list.html
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<div id="holder" [class.networkActive]="selectedNetwork() != null">
|
||||||
|
<div id="networks">
|
||||||
|
<button disabled tuiButton appearance="secondary" iconStart="@tui.plus">
|
||||||
|
{{ "chat.chatnav.networkList.newNetwork"|translate }}
|
||||||
|
</button>
|
||||||
|
@if (serviceManager.networksStatus() == LoadStatus.updating) {
|
||||||
|
<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 id="network">
|
||||||
|
<div style="display: flex; align-items: center; gap: 1rem;">
|
||||||
|
<button tuiButton appearance="secondary" iconStart="@tui.arrow-left" (click)="selectNetwork(null)"></button>
|
||||||
|
@if (selectedNetwork() != null) {
|
||||||
|
<oimg [src]="selectedNetwork()!.picture" height="35px" width="35px" [radius]="15"></oimg>
|
||||||
|
<h3>{{ selectedNetwork()!.name }}</h3>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
<network [network]="selectedNetwork()!"></network>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
68
src/app/chat/network-list/network-list.scss
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
#holder {
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
&.networkActive {
|
||||||
|
#networks {
|
||||||
|
transform: translateX(100px);
|
||||||
|
opacity: 0;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
#network {
|
||||||
|
pointer-events: all;
|
||||||
|
transform: translateX(0);
|
||||||
|
opacity: 1;
|
||||||
|
|
||||||
|
network {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#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%;
|
||||||
|
}
|
||||||
|
}
|
||||||
22
src/app/chat/network-list/network-list.spec.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { NetworkList } from './network-list';
|
||||||
|
|
||||||
|
describe('NetworkList', () => {
|
||||||
|
let component: NetworkList;
|
||||||
|
let fixture: ComponentFixture<NetworkList>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
imports: [NetworkList],
|
||||||
|
}).compileComponents();
|
||||||
|
|
||||||
|
fixture = TestBed.createComponent(NetworkList);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
await fixture.whenStable();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
61
src/app/chat/network-list/network-list.ts
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
import { Component, inject, input, model, OnInit, signal } from '@angular/core';
|
||||||
|
import {IndexedDB} from '../../storage/indexed-db';
|
||||||
|
import {Router, RouterLink} from '@angular/router';
|
||||||
|
import {LoadStatus, ServiceManager} from '../../service-manager';
|
||||||
|
import {TUI_BREAKPOINT, TuiButton, TuiLoader} from '@taiga-ui/core';
|
||||||
|
import {NetworkService} from '@chatenium/chatenium-sdk/services/networkService';
|
||||||
|
import {Oimg} from '../elements/oimg/oimg';
|
||||||
|
import {TranslatePipe} from '@ngx-translate/core';
|
||||||
|
import { Network as NetworkData } from '@chatenium/chatenium-sdk/domain/networkService.schema';
|
||||||
|
import { Network } from '../network/network';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'network-list',
|
||||||
|
imports: [Oimg, TranslatePipe, TuiButton, TuiLoader, Network],
|
||||||
|
templateUrl: './network-list.html',
|
||||||
|
styleUrl: './network-list.scss',
|
||||||
|
})
|
||||||
|
export class NetworkList implements OnInit {
|
||||||
|
userid = input<string>('');
|
||||||
|
token = input<string>('');
|
||||||
|
expandedSidenav = model.required<boolean>();
|
||||||
|
|
||||||
|
selectedNetwork = signal<NetworkData | null>(null);
|
||||||
|
|
||||||
|
indexedDb = inject(IndexedDB);
|
||||||
|
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() {
|
||||||
|
this.serviceManager.networkService = new NetworkService(
|
||||||
|
this.userid(),
|
||||||
|
this.token(),
|
||||||
|
'',
|
||||||
|
this.indexedDb.getApi(),
|
||||||
|
() => {},
|
||||||
|
);
|
||||||
|
if (this.serviceManager.networksStatus() != LoadStatus.loaded) {
|
||||||
|
try {
|
||||||
|
this.serviceManager.networks.set(await this.serviceManager.networkService.getQuick());
|
||||||
|
this.serviceManager.networksStatus.set(LoadStatus.updating);
|
||||||
|
} catch (e) {
|
||||||
|
console.warn(`Cache load failed: ${e}. Skipping cache load...`);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
this.serviceManager.networks.set(await this.serviceManager.networkService.get());
|
||||||
|
this.serviceManager.networksStatus.set(LoadStatus.loaded);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
this.serviceManager.networksStatus.set(LoadStatus.error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected readonly LoadStatus = LoadStatus;
|
||||||
|
}
|
||||||
34
src/app/chat/network/channel/text/text.html
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<main [class.mobile]="breakpoint() == 'mobile'">
|
||||||
|
@defer (when store) {
|
||||||
|
<navbar backButtonDest="/chat/network/{{networkId}}" showBackButtonAt="desktopSmall">
|
||||||
|
<div class="data">
|
||||||
|
<div class="chat-data">
|
||||||
|
@switch (store!.channelData().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 class="main-name">{{ store!.channelData().name }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="items-right">
|
||||||
|
<button tuiButton appearance="flat" disabled>
|
||||||
|
<tui-icon icon="@tui.phone"/>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</navbar>
|
||||||
|
|
||||||
|
<messages [loading]="store!.messagesStatus() == LoadStatus.loading" (scrollend)="handleMessagesScroll($event)" [messageBoxViewModel]="store!.messageBox" [messages]="store!.messages()" id="scrollContainer"
|
||||||
|
(onDelete)="deleteMessage($event)"/>
|
||||||
|
|
||||||
|
<message-box [viewModel]="store!.messageBox"/>
|
||||||
|
}
|
||||||
|
|
||||||
|
</main>
|
||||||
43
src/app/chat/network/channel/text/text.scss
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
main {
|
||||||
|
height: 98svh;
|
||||||
|
display: grid;
|
||||||
|
grid-template-rows: 70px minmax(0, 1fr) auto;
|
||||||
|
padding: 15px;
|
||||||
|
|
||||||
|
&.mobile {
|
||||||
|
height: 100svh;
|
||||||
|
padding: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mobile {
|
||||||
|
height: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
navbar {
|
||||||
|
.chat-data {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 5px;
|
||||||
|
|
||||||
|
.main-name {
|
||||||
|
font-size: 18px;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.alt-name {
|
||||||
|
margin-top: -5px;
|
||||||
|
color: gray;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.items-right {
|
||||||
|
margin-top: -10px;
|
||||||
|
|
||||||
|
button {
|
||||||
|
width: 35px;
|
||||||
|
height: 35px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
22
src/app/chat/network/channel/text/text.spec.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { Text } from './text';
|
||||||
|
|
||||||
|
describe('Text', () => {
|
||||||
|
let component: Text;
|
||||||
|
let fixture: ComponentFixture<Text>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
imports: [Text],
|
||||||
|
}).compileComponents();
|
||||||
|
|
||||||
|
fixture = TestBed.createComponent(Text);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
await fixture.whenStable();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
313
src/app/chat/network/channel/text/text.ts
Normal file
@@ -0,0 +1,313 @@
|
|||||||
|
import {Component, inject, signal} from '@angular/core';
|
||||||
|
import {DmStorage, LoadStatus, ServiceManager, TextChannelStorage} from '../../../../service-manager';
|
||||||
|
import {ActivatedRoute} from '@angular/router';
|
||||||
|
import {IndexedDB} from '../../../../storage/indexed-db';
|
||||||
|
import {TUI_BREAKPOINT, TuiButton, TuiIcon} from '@taiga-ui/core';
|
||||||
|
import {FileDataWithPreview, MessageBox} from '../../../elements/message-box/message-box';
|
||||||
|
import {Attachment} from '@chatenium/chatenium-sdk/domain/common.schema';
|
||||||
|
import {FileUploadProgressListener} from '@chatenium/chatenium-sdk/domain/fileUploadService.schema';
|
||||||
|
import {MessageBoxViewModel} from '../../../elements/message-box/message-box-viewmodel';
|
||||||
|
import {TextChannelServiceService} from '@chatenium/chatenium-sdk/services/textChannelService';
|
||||||
|
import {Message} from '@chatenium/chatenium-sdk/domain/textChannelService.schema';
|
||||||
|
import {Messages} from '../../../elements/messages/messages';
|
||||||
|
import {Navbar} from '../../../elements/navbar/navbar';
|
||||||
|
import {Oimg} from '../../../elements/oimg/oimg';
|
||||||
|
import {MessagesViewModel} from '../../../elements/messages/messages-viewmodel';
|
||||||
|
import {v4 as uuidv4} from 'uuid';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-text',
|
||||||
|
imports: [
|
||||||
|
MessageBox,
|
||||||
|
Messages,
|
||||||
|
Navbar,
|
||||||
|
Oimg,
|
||||||
|
TuiButton,
|
||||||
|
TuiIcon
|
||||||
|
],
|
||||||
|
templateUrl: './text.html',
|
||||||
|
styleUrl: './text.scss',
|
||||||
|
})
|
||||||
|
export class Text {
|
||||||
|
serviceManager = inject(ServiceManager)
|
||||||
|
route = inject(ActivatedRoute)
|
||||||
|
indexedDb = inject(IndexedDB)
|
||||||
|
breakpoint = inject(TUI_BREAKPOINT)
|
||||||
|
|
||||||
|
networkId = ""
|
||||||
|
channelId = ""
|
||||||
|
categoryId = ""
|
||||||
|
|
||||||
|
get store(): TextChannelStorage | null {
|
||||||
|
if (!this.serviceManager.networkServices()[this.networkId]) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
return this.serviceManager.networkServices()[this.networkId].textChannels()[this.channelId]
|
||||||
|
}
|
||||||
|
|
||||||
|
async sendMessage(message: string, files: FileDataWithPreview[] | null) {
|
||||||
|
if (!this.store) return
|
||||||
|
if (!files && message.trim() == "") return
|
||||||
|
|
||||||
|
const session = this.serviceManager.currentSession();
|
||||||
|
if (session != null) {
|
||||||
|
const editedMessage = this.store.messageBox.editingMessage()
|
||||||
|
if (editedMessage) {
|
||||||
|
const storedMsg = this.store.messages().find(m => m.msgid == editedMessage.messageId)
|
||||||
|
const originalMessage: Message = JSON.parse(JSON.stringify(storedMsg))
|
||||||
|
if (storedMsg) {
|
||||||
|
storedMsg.message = message
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await this.store.service.editMessage(editedMessage.messageId, message)
|
||||||
|
} catch (e) {
|
||||||
|
if (storedMsg) {
|
||||||
|
storedMsg.message = originalMessage.message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let attachments: Attachment[] = []
|
||||||
|
files?.forEach(file => {
|
||||||
|
const extraMetaData: Record<string, any> = {}
|
||||||
|
extraMetaData["thumbnailMetaData"] = file.videoThumbnail ?? ""
|
||||||
|
extraMetaData["progressShown"] = true
|
||||||
|
extraMetaData["totalChunks"] = 0
|
||||||
|
extraMetaData["uploadedChunks"] = 0
|
||||||
|
|
||||||
|
attachments.push({
|
||||||
|
fileName: file.name,
|
||||||
|
fileId: file.fileId,
|
||||||
|
type: file.type,
|
||||||
|
format: file.extension,
|
||||||
|
path: file.blob,
|
||||||
|
height: file.height,
|
||||||
|
width: file.width,
|
||||||
|
extraMetaData: extraMetaData
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
const tempMsgId = uuidv4()
|
||||||
|
this.store.messages.update(value => [...value, {
|
||||||
|
author: {
|
||||||
|
userid: session.userData.userid,
|
||||||
|
pfp: session.userData.pfp,
|
||||||
|
username: session.userData.username,
|
||||||
|
displayName: session.userData.displayName
|
||||||
|
},
|
||||||
|
msgid: tempMsgId,
|
||||||
|
message: message,
|
||||||
|
sent_at: {
|
||||||
|
T: 0,
|
||||||
|
I: 0
|
||||||
|
},
|
||||||
|
isEdited: false,
|
||||||
|
channelId: "",
|
||||||
|
networkId: "",
|
||||||
|
categoryId: "",
|
||||||
|
files: attachments,
|
||||||
|
seen: false,
|
||||||
|
replyTo: "",
|
||||||
|
replyToId: "",
|
||||||
|
forwardedFrom: "",
|
||||||
|
forwardedFromName: ""
|
||||||
|
}])
|
||||||
|
|
||||||
|
const respMessage = await this.store.service.sendMessage(tempMsgId, message, null, null, files, <FileUploadProgressListener>{
|
||||||
|
fileProgressUpdate: (tempMsgId, fileId, allChunks, chunksDone) => {
|
||||||
|
this.uploadProgressUpdate(tempMsgId, fileId, allChunks, chunksDone)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
this.updateTempMessage(tempMsgId, respMessage)
|
||||||
|
this.scrollToBottom("smooth")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async deleteMessage(messageId: string) {
|
||||||
|
if (!this.store) return
|
||||||
|
const i = this.store.messages().findIndex(m => m.msgid == messageId)
|
||||||
|
if (i != -1) {
|
||||||
|
const originalMessage: Message = JSON.parse(JSON.stringify(this.store.messages()[i]))
|
||||||
|
this.store.messages().splice(i, 1)
|
||||||
|
try {
|
||||||
|
await this.store.service.deleteMessages([messageId])
|
||||||
|
} catch (e) {
|
||||||
|
this.store.messages().splice(i, 0, originalMessage)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
restoreScrollState() {
|
||||||
|
setTimeout(() => {
|
||||||
|
if (!this.store) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const scrollContainer = <HTMLDivElement>document.querySelector("#scrollContainer")
|
||||||
|
scrollContainer.scroll({
|
||||||
|
top: this.store.messagesVm.scrollBarStatus() == -1 ? scrollContainer.scrollHeight : this.store.messagesVm.scrollBarStatus(),
|
||||||
|
left: 0,
|
||||||
|
behavior: "instant"
|
||||||
|
});
|
||||||
|
|
||||||
|
if (this.store.messagesVm.scrollBarStatus() == -1) {
|
||||||
|
this.store.messagesVm.scrollBarStatus.set(scrollContainer.scrollHeight)
|
||||||
|
}
|
||||||
|
}, 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) {
|
||||||
|
if (!this.store) return
|
||||||
|
this.store.messagesVm.scrollBarStatus.set(e.target.scrollTop)
|
||||||
|
}
|
||||||
|
|
||||||
|
uploadProgressUpdate(tempMsgId: string, fileId: string, allChunks: number, chunksDone: number) {
|
||||||
|
if (!this.store) return
|
||||||
|
this.store.messages.update(messages =>
|
||||||
|
messages.map(m => {
|
||||||
|
if (m.msgid !== tempMsgId) return m;
|
||||||
|
|
||||||
|
return {
|
||||||
|
...m,
|
||||||
|
files: m.files.map(f => {
|
||||||
|
if (f.fileId !== fileId) return f;
|
||||||
|
return {
|
||||||
|
...f,
|
||||||
|
extraMetaData: {
|
||||||
|
...f.extraMetaData,
|
||||||
|
totalChunks: allChunks,
|
||||||
|
uploadedChunks: chunksDone
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})
|
||||||
|
};
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateTempMessage(tempMsgId: string, message: Message) {
|
||||||
|
if (!this.store) return
|
||||||
|
this.store.messages.update(messages =>
|
||||||
|
messages.map(m => {
|
||||||
|
if (m.msgid !== tempMsgId) return m;
|
||||||
|
|
||||||
|
return {
|
||||||
|
...m,
|
||||||
|
msgid: message.msgid,
|
||||||
|
sent_at: message.sent_at,
|
||||||
|
files: m.files.map(f => {
|
||||||
|
f.extraMetaData["progressShown"] = false
|
||||||
|
return f
|
||||||
|
})
|
||||||
|
};
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// The chatid parameter ensures isolation
|
||||||
|
onWsListen(action: string, message: string, networkId: string, channelId: string) {
|
||||||
|
const data = JSON.parse(message);
|
||||||
|
if (data.channelId === channelId) {
|
||||||
|
const targetStore = this.serviceManager.networkServices()[networkId].textChannels()[channelId];
|
||||||
|
if (targetStore) {
|
||||||
|
switch (action) {
|
||||||
|
case "newMessage":
|
||||||
|
targetStore.messages.update(messages => [...messages, data]);
|
||||||
|
this.scrollToBottom("smooth")
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
this.route.params.subscribe(async params => {
|
||||||
|
const networkId = params['networkId'];
|
||||||
|
const categoryId = params['categoryId'];
|
||||||
|
const channelId = params['channelId'];
|
||||||
|
this.networkId = networkId;
|
||||||
|
this.categoryId = categoryId;
|
||||||
|
this.channelId = channelId;
|
||||||
|
|
||||||
|
const session = this.serviceManager.currentSession();
|
||||||
|
const networkData = this.serviceManager.networks().find(c => c.networkId === networkId);
|
||||||
|
|
||||||
|
if (!session || !networkData) {
|
||||||
|
console.warn("No network data")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const categoryData = networkData.categories.find(c => c.categoryId === categoryId);
|
||||||
|
if (!categoryData) {
|
||||||
|
console.warn("No category data")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const channelData = categoryData.channels.find(c => c.channelId === channelId);
|
||||||
|
if (!channelData) {
|
||||||
|
console.warn("No channel data")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!this.serviceManager.networkServices()[networkId]) {
|
||||||
|
console.warn("No networkService")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
console.log(this.serviceManager.networkServices())
|
||||||
|
console.log(this.serviceManager.networkServices()[networkId])
|
||||||
|
if (!this.serviceManager.networkServices()[networkId].textChannels()[channelId]) {
|
||||||
|
const newStore = {
|
||||||
|
categoryData: signal(categoryData),
|
||||||
|
channelData: signal(channelData),
|
||||||
|
messages: signal<Message[]>([]),
|
||||||
|
messagesVm: new MessagesViewModel(),
|
||||||
|
messagesStatus: signal<LoadStatus>(LoadStatus.loading),
|
||||||
|
messageBox: new MessageBoxViewModel((msg, files) => this.sendMessage(msg, files)),
|
||||||
|
wsListener: (action, data) => this.onWsListen(action, data, networkId, categoryId),
|
||||||
|
} as TextChannelStorage;
|
||||||
|
|
||||||
|
newStore.service = new TextChannelServiceService(
|
||||||
|
session.userData.userid,
|
||||||
|
session.token,
|
||||||
|
networkId,
|
||||||
|
categoryId,
|
||||||
|
channelId,
|
||||||
|
this.indexedDb.getApi(),
|
||||||
|
(action, data) => newStore.wsListener(action, data)
|
||||||
|
);
|
||||||
|
|
||||||
|
this.serviceManager.networkServices()[networkId].textChannels()[channelId] = newStore;
|
||||||
|
|
||||||
|
const currentStore = this.serviceManager.networkServices()[networkId].textChannels()[channelId]
|
||||||
|
try {
|
||||||
|
const messagesCache = await currentStore.service.getQuick();
|
||||||
|
currentStore.messages.set(messagesCache);
|
||||||
|
this.restoreScrollState()
|
||||||
|
currentStore.messagesStatus.set(LoadStatus.updating)
|
||||||
|
} catch (e) {
|
||||||
|
console.warn(`Cache load failed: ${e}. Skipping cache load...`)
|
||||||
|
}
|
||||||
|
const messages = await currentStore.service.get();
|
||||||
|
currentStore.messages.set(messages);
|
||||||
|
currentStore.messagesStatus.set(LoadStatus.loaded)
|
||||||
|
this.restoreScrollState()
|
||||||
|
|
||||||
|
await currentStore.service.joinWebSocketRoom();
|
||||||
|
} else {
|
||||||
|
this.restoreScrollState()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected readonly LoadStatus = LoadStatus;
|
||||||
|
}
|
||||||
43
src/app/chat/network/network.html
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
@defer (when store) {
|
||||||
|
<div id="layout" [class.routerOutletActive]="routerOutletActive()"
|
||||||
|
[class.hideNetworkNav]="routerOutletActive() && breakpoint() == 'desktopSmall'">
|
||||||
|
<div id="network-data">
|
||||||
|
<main tuiGroup orientation="vertical" style="width: 100%; height: 80svh">
|
||||||
|
@for (category of store.networkData().categories; track category) {
|
||||||
|
<div class="category">
|
||||||
|
<h2>{{ category.name }}</h2>
|
||||||
|
|
||||||
|
<div class="channels">
|
||||||
|
@for (channel of category.channels; track channel) {
|
||||||
|
<div class="channel">
|
||||||
|
<button tuiButton
|
||||||
|
[appearance]="router.url.endsWith(channel.channelId) ? 'secondary' : 'flat'"
|
||||||
|
[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>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</main>
|
||||||
|
<!-- @case (2) {
|
||||||
|
<main id="settings">
|
||||||
|
<network-settings [networkStore]="this.store"></network-settings>
|
||||||
|
</main>
|
||||||
|
}-->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
65
src/app/chat/network/network.scss
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
#layout {
|
||||||
|
overflow-y: scroll;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
overflow-x: hidden;
|
||||||
|
padding: 15px;
|
||||||
|
transition: 0.2s;
|
||||||
|
|
||||||
|
#network-data {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.hideNetworkNav {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
|
||||||
|
#network-data {
|
||||||
|
&.hidden {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.category {
|
||||||
|
width: 100%;
|
||||||
|
padding: 15px;
|
||||||
|
|
||||||
|
.channel {
|
||||||
|
display: flex;
|
||||||
|
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 {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
background: var(--tui-background-base-alt);
|
||||||
|
border-radius: 20px;
|
||||||
|
}
|
||||||
|
}
|
||||||
22
src/app/chat/network/network.spec.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { Network } from './network';
|
||||||
|
|
||||||
|
describe('Network', () => {
|
||||||
|
let component: Network;
|
||||||
|
let fixture: ComponentFixture<Network>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
imports: [Network],
|
||||||
|
}).compileComponents();
|
||||||
|
|
||||||
|
fixture = TestBed.createComponent(Network);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
await fixture.whenStable();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
92
src/app/chat/network/network.ts
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
import { Component, effect, inject, input, OnInit, signal } from '@angular/core';
|
||||||
|
import {ActivatedRoute, Router, RouterLink, RouterOutlet} from '@angular/router';
|
||||||
|
import {Chat} from '@chatenium/chatenium-sdk/domain/chatService.schema';
|
||||||
|
import {Message} from '@chatenium/chatenium-sdk/domain/dmService.schema';
|
||||||
|
import {MessageBoxViewModel} from '../elements/message-box/message-box-viewmodel';
|
||||||
|
import {DmStorage, NetworkStorage, ServiceManager} from '../../service-manager';
|
||||||
|
import {DMService} from '@chatenium/chatenium-sdk/services/dmService';
|
||||||
|
import {Network as NetworkData} from "@chatenium/chatenium-sdk/domain/networkService.schema"
|
||||||
|
import {NetworkService} from '@chatenium/chatenium-sdk/services/networkService';
|
||||||
|
import {IndexedDB} from '../../storage/indexed-db';
|
||||||
|
import {Navbar} from '../elements/navbar/navbar';
|
||||||
|
import {Oimg} from '../elements/oimg/oimg';
|
||||||
|
import {TUI_BREAKPOINT, TuiButton, TuiGroup, TuiIcon} from '@taiga-ui/core';
|
||||||
|
import {TuiTab, TuiTabsHorizontal, TuiTabsWithMore} from '@taiga-ui/kit';
|
||||||
|
import {TuiItem} from '@taiga-ui/cdk';
|
||||||
|
import {TranslatePipe} from '@ngx-translate/core';
|
||||||
|
import {Settings} from './settings/settings';
|
||||||
|
import { toObservable } from '@angular/core/rxjs-interop';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'network',
|
||||||
|
imports: [
|
||||||
|
RouterOutlet,
|
||||||
|
Navbar,
|
||||||
|
Oimg,
|
||||||
|
TuiGroup,
|
||||||
|
TuiButton,
|
||||||
|
TuiIcon,
|
||||||
|
RouterLink,
|
||||||
|
TuiTabsWithMore,
|
||||||
|
TuiItem,
|
||||||
|
TuiTab,
|
||||||
|
TranslatePipe,
|
||||||
|
TuiTabsHorizontal,
|
||||||
|
Settings,
|
||||||
|
],
|
||||||
|
templateUrl: './network.html',
|
||||||
|
styleUrl: './network.scss',
|
||||||
|
})
|
||||||
|
export class Network {
|
||||||
|
serviceManager = inject(ServiceManager);
|
||||||
|
route = inject(ActivatedRoute);
|
||||||
|
indexedDb = inject(IndexedDB);
|
||||||
|
breakpoint = inject(TUI_BREAKPOINT);
|
||||||
|
router = inject(Router);
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
effect(() => {
|
||||||
|
if (this.network()) {
|
||||||
|
this.setupNetwork();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
114
src/app/chat/network/settings/overview/overview.html
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
<div tuiGroup id="options" orientation="vertical">
|
||||||
|
<div>
|
||||||
|
<header>
|
||||||
|
<tui-icon icon="@tui.image"></tui-icon>
|
||||||
|
{{ "chat.network.settings.overviewPage.networkPicture"|translate }}
|
||||||
|
<oimg [src]="networkStore().networkData().picture" height="25px" width="25px" [radius]="6"/>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<button tuiButton appearance="outline" disabled iconEnd="@tui.file-up">
|
||||||
|
{{ "chat.network.settings.overviewPage.uploadNewPicture"|translate }}
|
||||||
|
</button>
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<ng-template [(tuiDialog)]="setNewNameDialogOpen"
|
||||||
|
[tuiDialogOptions]="{label: 'chat.network.settings.overviewPage.setNewName'|translate}">
|
||||||
|
|
||||||
|
<tui-textfield #newName iconStart="@tui.signature">
|
||||||
|
<label tuiLabel>{{"chat.network.settings.overviewPage.setNewNameDialog.label"|translate}}</label>
|
||||||
|
<input type="text" tuiInput>
|
||||||
|
</tui-textfield>
|
||||||
|
@if (setNewNameError() != "") {
|
||||||
|
<tui-error [error]="setNewNameError()"></tui-error>
|
||||||
|
}
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<button tuiButton iconStart="@tui.check" [loading]="setNewNamePending()" [disabled]="setNewNamePending()" (click)="setNewName(newName.value())">
|
||||||
|
{{'chat.network.settings.overviewPage.setNewName'|translate}}
|
||||||
|
</button>
|
||||||
|
</footer>
|
||||||
|
</ng-template>
|
||||||
|
|
||||||
|
<header>
|
||||||
|
<tui-icon icon="@tui.network"></tui-icon>
|
||||||
|
{{ "chat.network.settings.overviewPage.networkName"|translate }}
|
||||||
|
<b style="color: gray">{{ networkStore().networkData().name }}</b>
|
||||||
|
</header>
|
||||||
|
<main>
|
||||||
|
<button (click)="setNewNameDialogOpen.set(true)" tuiButton appearance="outline" iconEnd="@tui.pencil">
|
||||||
|
{{ "chat.network.settings.overviewPage.setNewName"|translate }}
|
||||||
|
</button>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<ng-template [(tuiDialog)]="makeNetworkPrivateWarnDialogOpen"
|
||||||
|
[tuiDialogOptions]="{label: 'chat.network.settings.overviewPage.changeToPrivateDialog.label'|translate}">
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<tui-icon icon="@tui.eye-off"/>
|
||||||
|
{{ "chat.network.settings.overviewPage.changeToPrivateDialog.warn.1"|translate }}
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<tui-icon icon="@tui.ticket"/>
|
||||||
|
{{ "chat.network.settings.overviewPage.changeToPrivateDialog.warn.2"|translate }}
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<tui-icon icon="@tui.radio"/>
|
||||||
|
{{ "chat.network.settings.overviewPage.changeToPrivateDialog.warn.3"|translate }}
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<footer>
|
||||||
|
<button tuiButton iconStart="@tui.eye-off" [loading]="networkVisChangePending()" [disabled]="networkVisChangePending()" (click)="changeVisibility('private')">
|
||||||
|
{{'chat.network.settings.overviewPage.changeToPrivate'|translate}}
|
||||||
|
</button>
|
||||||
|
</footer>
|
||||||
|
</ng-template>
|
||||||
|
|
||||||
|
<ng-template [(tuiDialog)]="makeNetworkPublicWarnDialogOpen"
|
||||||
|
[tuiDialogOptions]="{label: 'chat.network.settings.overviewPage.changeToPublicDialog.label'|translate}">
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<tui-icon icon="@tui.eye"/>
|
||||||
|
{{ "chat.network.settings.overviewPage.changeToPublicDialog.warn.1"|translate }}
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<tui-icon icon="@tui.ticket"/>
|
||||||
|
{{ "chat.network.settings.overviewPage.changeToPublicDialog.warn.2"|translate }}
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<tui-icon icon="@tui.radio"/>
|
||||||
|
{{ "chat.network.settings.overviewPage.changeToPublicDialog.warn.3"|translate }}
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<footer>
|
||||||
|
<button tuiButton iconStart="@tui.eye" [loading]="networkVisChangePending()" [disabled]="networkVisChangePending()" (click)="changeVisibility('public')">
|
||||||
|
{{'chat.network.settings.overviewPage.changeToPublic'|translate}}
|
||||||
|
</button>
|
||||||
|
</footer>
|
||||||
|
</ng-template>
|
||||||
|
|
||||||
|
<header>
|
||||||
|
@if (networkStore().networkData().visibility == "public") {
|
||||||
|
<tui-icon icon="@tui.eye"></tui-icon>
|
||||||
|
} @else {
|
||||||
|
<tui-icon icon="@tui.eye-off"></tui-icon>
|
||||||
|
}
|
||||||
|
{{ "chat.network.settings.overviewPage.networkVisibility"|translate }}
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
@if (networkStore().networkData().visibility == "public") {
|
||||||
|
<button tuiButton appearance="outline" iconEnd="@tui.eye-off" (click)="makeNetworkPrivateWarnDialogOpen.set(true)">
|
||||||
|
{{ "chat.network.settings.overviewPage.changeToPrivate"|translate }}
|
||||||
|
</button>
|
||||||
|
} @else {
|
||||||
|
<button tuiButton appearance="outline" iconEnd="@tui.eye" (click)="makeNetworkPublicWarnDialogOpen.set(true)">
|
||||||
|
{{ "chat.network.settings.overviewPage.changeToPublic"|translate }}
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
31
src/app/chat/network/settings/overview/overview.scss
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#options {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
|
||||||
|
div {
|
||||||
|
width: 100%;
|
||||||
|
height: 60px;
|
||||||
|
background: var(--tui-background-base-alt);
|
||||||
|
padding: 15px;
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
|
||||||
|
header {
|
||||||
|
display: flex;
|
||||||
|
gap: 5px;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
main {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: end;
|
||||||
|
|
||||||
|
button {
|
||||||
|
height: 35px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
22
src/app/chat/network/settings/overview/overview.spec.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { Overview } from './overview';
|
||||||
|
|
||||||
|
describe('Overview', () => {
|
||||||
|
let component: Overview;
|
||||||
|
let fixture: ComponentFixture<Overview>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
imports: [Overview],
|
||||||
|
}).compileComponents();
|
||||||
|
|
||||||
|
fixture = TestBed.createComponent(Overview);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
await fixture.whenStable();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
79
src/app/chat/network/settings/overview/overview.ts
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
import {Component, inject, input, signal} from '@angular/core';
|
||||||
|
import {NetworkStorage} from '../../../../service-manager';
|
||||||
|
import {
|
||||||
|
TuiAlertService,
|
||||||
|
TuiButton,
|
||||||
|
TuiDialog,
|
||||||
|
TuiErrorComponent,
|
||||||
|
TuiGroup,
|
||||||
|
TuiIcon,
|
||||||
|
TuiInputDirective
|
||||||
|
} from '@taiga-ui/core';
|
||||||
|
import {TranslatePipe} from '@ngx-translate/core';
|
||||||
|
import {Oimg} from '../../../elements/oimg/oimg';
|
||||||
|
import {environment} from '../../../../../environments/environment';
|
||||||
|
import {TuiButtonLoading, TuiComboBox} from '@taiga-ui/kit';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'network-settings-overview',
|
||||||
|
imports: [
|
||||||
|
TuiGroup,
|
||||||
|
TranslatePipe,
|
||||||
|
TuiIcon,
|
||||||
|
Oimg,
|
||||||
|
TuiButton,
|
||||||
|
TuiDialog,
|
||||||
|
TuiComboBox,
|
||||||
|
TuiInputDirective,
|
||||||
|
TuiButtonLoading,
|
||||||
|
TuiErrorComponent
|
||||||
|
],
|
||||||
|
templateUrl: './overview.html',
|
||||||
|
styleUrl: './overview.scss',
|
||||||
|
})
|
||||||
|
export class Overview {
|
||||||
|
networkStore = input.required<NetworkStorage>()
|
||||||
|
protected readonly environment = environment;
|
||||||
|
protected readonly localStorage = localStorage;
|
||||||
|
|
||||||
|
setNewNameDialogOpen = signal(false)
|
||||||
|
setNewNamePending = signal(false)
|
||||||
|
setNewNameError = signal("")
|
||||||
|
|
||||||
|
makeNetworkPrivateWarnDialogOpen = signal(false)
|
||||||
|
makeNetworkPublicWarnDialogOpen = signal(false)
|
||||||
|
networkVisChangePending = signal(false)
|
||||||
|
|
||||||
|
async setNewName(name: string) {
|
||||||
|
this.setNewNameError.set("")
|
||||||
|
this.setNewNamePending.set(true)
|
||||||
|
try {
|
||||||
|
await this.networkStore().service.editName(name)
|
||||||
|
this.setNewNamePending.set(false)
|
||||||
|
this.setNewNameDialogOpen.set(false)
|
||||||
|
this.networkStore().networkData.update(
|
||||||
|
value => {
|
||||||
|
value.name = name
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
)
|
||||||
|
} catch (e) {
|
||||||
|
this.setNewNamePending.set(false)
|
||||||
|
this.setNewNameError.set(e as string)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async changeVisibility(newVisibility: "public" | "private") {
|
||||||
|
this.networkVisChangePending.set(true)
|
||||||
|
await this.networkStore().service.changeVisibility(newVisibility)
|
||||||
|
this.networkStore().networkData.update(
|
||||||
|
value => {
|
||||||
|
value.visibility = newVisibility
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
)
|
||||||
|
this.networkVisChangePending.set(false)
|
||||||
|
this.makeNetworkPrivateWarnDialogOpen.set(false)
|
||||||
|
this.makeNetworkPublicWarnDialogOpen.set(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
29
src/app/chat/network/settings/settings.html
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<aside>
|
||||||
|
@for (category of networkSettingsOptions; track category) {
|
||||||
|
<header>
|
||||||
|
<tui-icon [icon]="'@tui.'+category.icon"></tui-icon>
|
||||||
|
@if (category.name == "networkName") {
|
||||||
|
{{networkStore().networkData().name}}
|
||||||
|
} @else {
|
||||||
|
{{'chat.network.settings.options.categories.'+category.name|translate}}
|
||||||
|
}
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="optionList">
|
||||||
|
@for (option of category.options; track option;) {
|
||||||
|
<button (click)="selectedOption = option.name" [appearance]="selectedOption == option.name ? 'primary' : 'flat'" tuiButton [disabled]="!option.implemented || !optionRequiredPermissionsGranted(networkStore().networkData().permissions, option.requiredAtLeastOneOf ?? [])">
|
||||||
|
<tui-icon [icon]="'@tui.'+option.icon"></tui-icon>
|
||||||
|
{{'chat.network.settings.options.'+option.name|translate}}
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</aside>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
@switch (selectedOption) {
|
||||||
|
@case ("overview") {
|
||||||
|
<network-settings-overview [networkStore]="networkStore()"/>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</main>
|
||||||
37
src/app/chat/network/settings/settings.scss
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
:host {
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 300px 1fr;
|
||||||
|
|
||||||
|
aside {
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
border-radius: 20px 0 0 20px;
|
||||||
|
padding: 15px;
|
||||||
|
|
||||||
|
header {
|
||||||
|
display: flex;
|
||||||
|
gap: 5px;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
div {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 1px;
|
||||||
|
padding: 5px;
|
||||||
|
|
||||||
|
button {
|
||||||
|
height: 40px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: start;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main {
|
||||||
|
background: var(--tui-background-neutral-2);
|
||||||
|
border-radius: 0 20px 20px 0;
|
||||||
|
padding: 15px;
|
||||||
|
}
|
||||||
|
}
|
||||||
22
src/app/chat/network/settings/settings.spec.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { Settings } from './settings';
|
||||||
|
|
||||||
|
describe('Settings', () => {
|
||||||
|
let component: Settings;
|
||||||
|
let fixture: ComponentFixture<Settings>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
imports: [Settings],
|
||||||
|
}).compileComponents();
|
||||||
|
|
||||||
|
fixture = TestBed.createComponent(Settings);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
await fixture.whenStable();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
150
src/app/chat/network/settings/settings.ts
Normal file
@@ -0,0 +1,150 @@
|
|||||||
|
import {Component, inject, input} from '@angular/core';
|
||||||
|
import {TuiButton, TuiGroup, TuiIcon} from '@taiga-ui/core';
|
||||||
|
import {permissionGranted, permissions} from '@chatenium/chatenium-sdk/core/permissions';
|
||||||
|
import {NetworkStorage, ServiceManager} from '../../../service-manager';
|
||||||
|
import {Session} from '@chatenium/chatenium-sdk/domain/sessionManager.schema';
|
||||||
|
import {SessionManager} from '@chatenium/chatenium-sdk/services/sessionManager';
|
||||||
|
import {TranslatePipe} from '@ngx-translate/core';
|
||||||
|
import {Overview} from './overview/overview';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'network-settings',
|
||||||
|
imports: [
|
||||||
|
TuiGroup,
|
||||||
|
TuiIcon,
|
||||||
|
TranslatePipe,
|
||||||
|
TuiButton,
|
||||||
|
Overview
|
||||||
|
],
|
||||||
|
templateUrl: './settings.html',
|
||||||
|
styleUrl: './settings.scss',
|
||||||
|
})
|
||||||
|
export class Settings {
|
||||||
|
serviceManager = inject(ServiceManager)
|
||||||
|
networkStore = input.required<NetworkStorage>()
|
||||||
|
|
||||||
|
selectedOption = "overview"
|
||||||
|
|
||||||
|
optionRequiredPermissionsGranted(permissions: number, required: number[]) {
|
||||||
|
if (!this.serviceManager.currentSession) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
let granted = false;
|
||||||
|
|
||||||
|
if (this.networkStore().networkData().createdBy == this.serviceManager.currentSession()!.userData.userid) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
required.forEach((permission) => {
|
||||||
|
if (permissionGranted(permissions, permission)) {
|
||||||
|
granted = true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return granted
|
||||||
|
}
|
||||||
|
|
||||||
|
networkSettingsOptions: {
|
||||||
|
name: string,
|
||||||
|
icon: string,
|
||||||
|
options: {
|
||||||
|
name: string, // ? channel.settings.[name]
|
||||||
|
icon: string // ? Class name
|
||||||
|
requiredAtLeastOneOf?: number[],
|
||||||
|
implemented: boolean
|
||||||
|
}[]
|
||||||
|
}[] = [
|
||||||
|
{
|
||||||
|
name: "networkName", // ? UI Will show network name
|
||||||
|
icon: "network",
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
icon: "eye",
|
||||||
|
name: "overview",
|
||||||
|
implemented: true,
|
||||||
|
requiredAtLeastOneOf: [permissions.changeNetworkNamePictureAndVisibility]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "rank",
|
||||||
|
icon: "book",
|
||||||
|
requiredAtLeastOneOf: [permissions.createAndEditRanks, permissions.deleteRanks],
|
||||||
|
implemented: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "emoji",
|
||||||
|
icon: "smile",
|
||||||
|
implemented: false,
|
||||||
|
requiredAtLeastOneOf: [permissions.createEmojis]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "embed",
|
||||||
|
icon: "code",
|
||||||
|
implemented: false,
|
||||||
|
requiredAtLeastOneOf: [permissions.manageEmbed]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "invite",
|
||||||
|
icon: "ticket",
|
||||||
|
implemented: false,
|
||||||
|
requiredAtLeastOneOf: [permissions.createInvites, permissions.deleteInvites]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "apps",
|
||||||
|
icon: "layout-panel-left",
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: "webhook",
|
||||||
|
icon: "globe",
|
||||||
|
implemented: false,
|
||||||
|
requiredAtLeastOneOf: [permissions.deleteWebhooks, permissions.createWebhooks]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "bots",
|
||||||
|
icon: "bot",
|
||||||
|
implemented: false,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "moderation",
|
||||||
|
icon: "shield-half",
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: "activityHistory",
|
||||||
|
icon: "scroll-text",
|
||||||
|
implemented: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "bans",
|
||||||
|
icon: "gavel",
|
||||||
|
implemented: false,
|
||||||
|
requiredAtLeastOneOf: [permissions.banMembers]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "community",
|
||||||
|
icon: "users",
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: "communityChannels",
|
||||||
|
icon: "hash",
|
||||||
|
implemented: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "networkIntroducer",
|
||||||
|
icon: "network",
|
||||||
|
implemented: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "members",
|
||||||
|
icon: "users",
|
||||||
|
implemented: false,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
16
src/app/chat/picture-list/picture-list.html
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<button (click)="router.navigate(['/chat/picture/'+serviceManager.currentSession()!.userData.userid])" tuiButton [appearance]="router.url == '/chat/picture/' + serviceManager.currentSession()!.userData.userid ? 'primary' : 'secondary'" iconStart="@tui.user">
|
||||||
|
{{"chat.chatnav.pictureList.myPictures"|translate}}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
@for (chat of serviceManager.chats(); track chat.chatid) {
|
||||||
|
<button [class.enlarge]="breakpoint() == 'mobile'" tuiButton [appearance]="router.url == '/chat/picture/' + chat.userid ? 'primary' : 'flat'" [routerLink]="'/chat/picture/' + chat.userid">
|
||||||
|
<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>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
}
|
||||||
22
src/app/chat/picture-list/picture-list.spec.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { PictureList } from './picture-list';
|
||||||
|
|
||||||
|
describe('PictureList', () => {
|
||||||
|
let component: PictureList;
|
||||||
|
let fixture: ComponentFixture<PictureList>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
imports: [PictureList],
|
||||||
|
}).compileComponents();
|
||||||
|
|
||||||
|
fixture = TestBed.createComponent(PictureList);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
await fixture.whenStable();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -9,17 +9,17 @@ import {TranslatePipe} from '@ngx-translate/core';
|
|||||||
import {LoadStatus, ServiceManager} from '../../service-manager';
|
import {LoadStatus, ServiceManager} from '../../service-manager';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-dm-list',
|
selector: 'app-picture-list',
|
||||||
imports: [
|
imports: [
|
||||||
TuiButton,
|
TuiButton,
|
||||||
Oimg,
|
Oimg,
|
||||||
RouterLink,
|
RouterLink,
|
||||||
TranslatePipe
|
TranslatePipe
|
||||||
],
|
],
|
||||||
templateUrl: './dm-list.html',
|
templateUrl: './picture-list.html',
|
||||||
styleUrl: './dm-list.scss',
|
styleUrl: './picture-list.scss',
|
||||||
})
|
})
|
||||||
export class DmList implements OnInit {
|
export class PictureList implements OnInit {
|
||||||
userid = input<string>("")
|
userid = input<string>("")
|
||||||
token = input<string>("")
|
token = input<string>("")
|
||||||
|
|
||||||
@@ -30,6 +30,13 @@ export class DmList implements OnInit {
|
|||||||
|
|
||||||
async ngOnInit() {
|
async ngOnInit() {
|
||||||
this.serviceManager.chatService = new ChatService(this.userid(), this.token(), this.indexedDb.getApi(), () => {})
|
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 {
|
try {
|
||||||
this.serviceManager.chats.set(await this.serviceManager.chatService.get())
|
this.serviceManager.chats.set(await this.serviceManager.chatService.get())
|
||||||
this.serviceManager.chatsStatus.set(LoadStatus.loaded)
|
this.serviceManager.chatsStatus.set(LoadStatus.loaded)
|
||||||
@@ -38,4 +45,5 @@ export class DmList implements OnInit {
|
|||||||
this.serviceManager.chatsStatus.set(LoadStatus.error)
|
this.serviceManager.chatsStatus.set(LoadStatus.error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
61
src/app/chat/picture/see/see.html
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
<ng-template [(tuiDialog)]="viewerOpen">
|
||||||
|
<oimg [src]="viewedPicture!.path" height="100%" width="100%" [radius]="0"></oimg>
|
||||||
|
</ng-template>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
@defer (when store) {
|
||||||
|
<navbar backButtonDest="/chat">
|
||||||
|
<div class="data">
|
||||||
|
<oimg [src]="store.uploaderData().pfp" height="50px" width="50px" [radius]="15"></oimg>
|
||||||
|
<div class="uploader-data">
|
||||||
|
@if (!store.uploaderData().displayName) {
|
||||||
|
<span class="main-name">{{'@'+store.uploaderData().username}}</span>
|
||||||
|
} @else {
|
||||||
|
<span class="main-name">{{store.uploaderData().displayName}}</span>
|
||||||
|
<span class="alt-name">{{'@'+store.uploaderData().username}}</span>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="items-right">
|
||||||
|
</div>
|
||||||
|
</navbar>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
@if (openedAlbum) {
|
||||||
|
<div style="display: flex; align-items: center; gap: 10px">
|
||||||
|
<button tuiButton appearance="flat" iconStart="@tui.chevron-left" (click)="exitAlbum()"></button>
|
||||||
|
<h1 style="padding: 0; margin: 0">{{openedAlbum.name}}</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="pictureList">
|
||||||
|
@for (picture of openedAlbum.images; track picture) {
|
||||||
|
<oimg (click)="viewPicture(picture)" [src]="picture.path" height="200px" width="200px" [radius]="25" objectFit="none"></oimg>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
} @else {
|
||||||
|
@if (store.albums().length == 0) {
|
||||||
|
<tui-block-status style="height: 300px">
|
||||||
|
<tui-icon icon="@tui.frown" tuiSlot="top" style="font-size: 150px"></tui-icon>
|
||||||
|
<h4>{{"chat.pictures.albumList.noAlbum"|translate}}</h4>
|
||||||
|
</tui-block-status>
|
||||||
|
} @else {
|
||||||
|
<div id="albumList">
|
||||||
|
@for (album of store.albums(); track album) {
|
||||||
|
<div class="album" (click)="enterAlbum(album.albumId)">
|
||||||
|
<masonry [maxColSize]="3" style="height: 300px; pointer-events: none;">
|
||||||
|
@for (file of album.images; track file) {
|
||||||
|
<img [src]="file.path+'_thumbnail.png'" style="filter: blur(5px)"/>
|
||||||
|
}
|
||||||
|
</masonry>
|
||||||
|
<div class="album-name">
|
||||||
|
<h2>{{album.name}}</h2>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</main>
|
||||||
|
}
|
||||||
|
</main>
|
||||||
85
src/app/chat/picture/see/see.scss
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
main {
|
||||||
|
height: 98svh;
|
||||||
|
display: grid;
|
||||||
|
grid-template-rows: 70px minmax(0, 1fr) auto;
|
||||||
|
padding: 15px;
|
||||||
|
|
||||||
|
navbar {
|
||||||
|
.uploader-data {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
|
||||||
|
.main-name {
|
||||||
|
font-size: 18px;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.alt-name {
|
||||||
|
margin-top: -5px;
|
||||||
|
color: gray;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.items-right {
|
||||||
|
margin-top: -10px;
|
||||||
|
|
||||||
|
button {
|
||||||
|
width: 35px;
|
||||||
|
height: 35px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#albumList {
|
||||||
|
display: flex;
|
||||||
|
gap: 10px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
align-content: flex-start;
|
||||||
|
|
||||||
|
.album {
|
||||||
|
width: 300px;
|
||||||
|
height: 300px;
|
||||||
|
background: var(--tui-background-base-alt);
|
||||||
|
border: 2px solid var(--tui-border-normal);
|
||||||
|
border-radius: 30px;
|
||||||
|
overflow: hidden;
|
||||||
|
position: relative;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
.album-name {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
background: color-mix(in srgb, var(--tui-background-base) 50%, transparent);
|
||||||
|
padding: 10px;
|
||||||
|
font-size: 18px;
|
||||||
|
font-weight: bold;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#pictureList {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 10px;
|
||||||
|
align-content: flex-start;
|
||||||
|
overflow-y: scroll;
|
||||||
|
|
||||||
|
oimg {
|
||||||
|
background: var(--tui-background-base-alt);
|
||||||
|
height: 200px;
|
||||||
|
border-radius: 25px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
22
src/app/chat/picture/see/see.spec.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { See } from './see';
|
||||||
|
|
||||||
|
describe('See', () => {
|
||||||
|
let component: See;
|
||||||
|
let fixture: ComponentFixture<See>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
imports: [See],
|
||||||
|
}).compileComponents();
|
||||||
|
|
||||||
|
fixture = TestBed.createComponent(See);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
await fixture.whenStable();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
133
src/app/chat/picture/see/see.ts
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
import {Component, inject, signal} from '@angular/core';
|
||||||
|
import {DmStorage, PictureStorage, ServiceManager} from '../../../service-manager';
|
||||||
|
import {ActivatedRoute, Router} from '@angular/router';
|
||||||
|
import {IndexedDB} from '../../../storage/indexed-db';
|
||||||
|
import {TUI_BREAKPOINT, TuiButton, TuiDialog, TuiIcon} from '@taiga-ui/core';
|
||||||
|
import {PictureService} from '@chatenium/chatenium-sdk/services/pictureService';
|
||||||
|
import {Navbar} from '../../elements/navbar/navbar';
|
||||||
|
import {Oimg} from '../../elements/oimg/oimg';
|
||||||
|
import {Masonry} from '../../elements/masonry/masonry';
|
||||||
|
import {Album, Image} from '@chatenium/chatenium-sdk/domain/pictureService.schema';
|
||||||
|
import {pictureHandlers} from '@chatenium/chatenium-sdk/mocks/handlers/picture.http';
|
||||||
|
import {TuiBlockStatusComponent} from '@taiga-ui/layout';
|
||||||
|
import {TranslatePipe} from '@ngx-translate/core';
|
||||||
|
import {TuiBadgedContentDirective} from '@taiga-ui/kit';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-see',
|
||||||
|
imports: [
|
||||||
|
Navbar,
|
||||||
|
Oimg,
|
||||||
|
TuiButton,
|
||||||
|
TuiIcon,
|
||||||
|
Masonry,
|
||||||
|
TuiDialog,
|
||||||
|
TuiBlockStatusComponent,
|
||||||
|
TranslatePipe,
|
||||||
|
TuiBadgedContentDirective
|
||||||
|
],
|
||||||
|
templateUrl: './see.html',
|
||||||
|
styleUrl: './see.scss',
|
||||||
|
})
|
||||||
|
export class See {
|
||||||
|
serviceManager = inject(ServiceManager)
|
||||||
|
route = inject(ActivatedRoute)
|
||||||
|
indexedDb = inject(IndexedDB)
|
||||||
|
breakpoint = inject(TUI_BREAKPOINT)
|
||||||
|
router = inject(Router)
|
||||||
|
|
||||||
|
uploaderId = ""
|
||||||
|
openedAlbum: Album | null = null
|
||||||
|
|
||||||
|
viewedPicture: Image | null = null
|
||||||
|
get viewerOpen() {
|
||||||
|
return this.viewedPicture != null
|
||||||
|
}
|
||||||
|
set viewerOpen(_: any) {
|
||||||
|
this.viewedPicture = null
|
||||||
|
this.router.navigate([], {
|
||||||
|
queryParams: { pictureId: null },
|
||||||
|
queryParamsHandling: "merge"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
get store(): PictureStorage {
|
||||||
|
return this.serviceManager.pictureServices()[this.uploaderId]
|
||||||
|
}
|
||||||
|
|
||||||
|
enterAlbum(albumId: string) {
|
||||||
|
this.router.navigate([], {
|
||||||
|
queryParams: { albumId: albumId },
|
||||||
|
queryParamsHandling: "merge"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
exitAlbum() {
|
||||||
|
this.openedAlbum = null
|
||||||
|
this.router.navigate([], {
|
||||||
|
queryParams: { albumId: null },
|
||||||
|
queryParamsHandling: "merge"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
viewPicture(picture: Image) {
|
||||||
|
this.viewedPicture = picture
|
||||||
|
this.router.navigate([], {
|
||||||
|
queryParams: { pictureId: picture.imageId },
|
||||||
|
queryParamsHandling: "merge"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
this.route.params.subscribe(async params => {
|
||||||
|
const uploaderId = params['uploaderId'];
|
||||||
|
this.uploaderId = uploaderId;
|
||||||
|
|
||||||
|
const session = this.serviceManager.currentSession();
|
||||||
|
if (!session) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.serviceManager.pictureServices()[uploaderId]) {
|
||||||
|
const newService = new PictureService(
|
||||||
|
session.token,
|
||||||
|
uploaderId,
|
||||||
|
session.userData.userid,
|
||||||
|
this.indexedDb.getApi(),
|
||||||
|
);
|
||||||
|
|
||||||
|
const uploaderInfo = await newService.get()
|
||||||
|
|
||||||
|
this.serviceManager.pictureServices.update(services => ({
|
||||||
|
...services,
|
||||||
|
[uploaderId]: {
|
||||||
|
albums: signal(uploaderInfo.pictures),
|
||||||
|
uploaderData: signal(uploaderInfo.userData),
|
||||||
|
service: newService,
|
||||||
|
} as PictureStorage
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Show album
|
||||||
|
this.route.queryParams.subscribe(params => {
|
||||||
|
const albumId = params['albumId'];
|
||||||
|
if (albumId) {
|
||||||
|
const album = uploaderInfo.pictures.find(a => a.albumId === albumId)
|
||||||
|
if (album) {
|
||||||
|
this.openedAlbum = album
|
||||||
|
|
||||||
|
const pictureId = params['pictureId'];
|
||||||
|
if (pictureId) {
|
||||||
|
const picture = album.images.find(img => img.imageId === pictureId)
|
||||||
|
if (picture) {
|
||||||
|
this.viewedPicture = picture
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected readonly pictureHandlers = pictureHandlers;
|
||||||
|
}
|
||||||
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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'])
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||