Add user page with profile picture, number and about. change font to Selawik.

This commit is contained in:
天クマ 2026-07-18 12:02:20 -03:00
commit cce7b74068
12 changed files with 219 additions and 29 deletions

BIN
fonts/selawk.ttf Normal file

Binary file not shown.

BIN
fonts/selawkb.ttf Normal file

Binary file not shown.

BIN
fonts/selawkl.ttf Normal file

Binary file not shown.

BIN
fonts/selawksb.ttf Normal file

Binary file not shown.

BIN
fonts/selawksl.ttf Normal file

Binary file not shown.

View file

@ -16,6 +16,7 @@
<body> <body>
<div class="app-container no-active-chat"> <div class="app-container no-active-chat">
<aside id="desktop-aside"> <aside id="desktop-aside">
<button id="profile-sidebar-btn" class="icon-btn mif-person mif-2x" data-page="profile-page"></button>
<button id="chats-sidebar-btn" class="icon-btn mif-qa mif-2x" data-page="chat-page"></button> <button id="chats-sidebar-btn" class="icon-btn mif-qa mif-2x" data-page="chat-page"></button>
<button id="settings-sidebar-btn" class="icon-btn mif-cog mif-2x" data-page="settings-page"></button> <button id="settings-sidebar-btn" class="icon-btn mif-cog mif-2x" data-page="settings-page"></button>
</aside> </aside>
@ -27,7 +28,7 @@
<div class="user-profile"> <div class="user-profile">
<!-- <div id="pandora-user-icon" class="avatar user-avatar">P</div> --> <!-- <div id="pandora-user-icon" class="avatar user-avatar">P</div> -->
<div class="user-info"> <div class="user-info">
<h3 id="pandora-username">Pandora User</h3> <h3 id="pandora-username" data-content="app-user">Pandora User</h3>
</div> </div>
</div> </div>
</header> </header>
@ -54,13 +55,6 @@
<!-- Chats will be dynamically injected here --> <!-- Chats will be dynamically injected here -->
</ul> </ul>
</div> </div>
<div class="sidebar-footer">
<div class="api-status-badge">
<span class="pulse-dot"></span>
<span id="backend-status-text">Backend connected</span>
</div>
</div>
</aside> </aside>
<div class="extra-page" id="chat-page"> <div class="extra-page" id="chat-page">
@ -119,6 +113,17 @@
</main> </main>
</div> </div>
<section class="extra-page" id="profile-page">
<h2 data-content="app-user">Pandora User</h2>
<div class="content">
<img id="profile-page-picture" data-resource="app-user-image">
<div id="profile-page-user-info">
<p id="profile-page-user-number" data-content="app-user-number">Pandora User</p>
<input id="profile-page-status-input" placeholder="enter your status" data-value="app-user-status">
</div>
</div>
</section>
<section class="extra-page" id="settings-page"> <section class="extra-page" id="settings-page">
<div class="modal-content"> <div class="modal-content">
<header class="modal-header"> <header class="modal-header">
@ -152,6 +157,12 @@
<footer class="modal-footer"> <footer class="modal-footer">
<button class="btn primary-btn" id="save-settings">Save</button> <button class="btn primary-btn" id="save-settings">Save</button>
</footer> </footer>
<div class="sidebar-footer">
<div class="api-status-badge">
<span class="pulse-dot"></span>
<span id="backend-status-text">Backend connected</span>
</div>
</div>
</div> </div>
</section> </section>
</div> </div>

View file

@ -2,8 +2,8 @@ import { config } from "./config.js";
import { waha } from "./waha.js"; import { waha } from "./waha.js";
import { ui, elements } from "./ui.js"; import { ui, elements } from "./ui.js";
import { websocket } from "./websocket.js"; import { websocket } from "./websocket.js";
import { compensateMessageOrdering, formatTime, normalizeId } from "./utils.js"; import { compensateMessageOrdering, debounce, formatTime, normalizeId } from "./utils.js";
import { fetchChats, getAppUser, getChatMessages, getChats, updateOnlineStatus } from "./storage.js"; import { fetchChats, getAppUser, getChatMessages, getChatPicture, getChats, getUser, getUserAbout, sendStatus, updateOnlineStatus } from "./storage.js";
import { upsertMessages } from "./db.js"; import { upsertMessages } from "./db.js";
let activeChatState = null; let activeChatState = null;
@ -20,7 +20,7 @@ document.addEventListener('DOMContentLoaded', async () => {
await updateOnlineStatus(); await updateOnlineStatus();
setupEventListeners(); setupEventListeners();
try { try {
elements.loggedUserName.textContent = (await getAppUser()).pushName; setupElementsData();
loadChats(); loadChats();
checkWahaStatus(); checkWahaStatus();
initWebSocket(); initWebSocket();
@ -29,6 +29,25 @@ document.addEventListener('DOMContentLoaded', async () => {
} }
}); });
async function setupElementsData() {
const usr = await getAppUser();
const usrPic = (await getChatPicture(usr.id))?.url;
const usrInfo = await getUser(usr.id);
const usrAbout = (await getUserAbout(usr.id)).about;
elements.contentUserName.forEach(e => {
e.innerHTML = usr.pushName;
})
elements.contentUserNumber.forEach(async e => {
e.innerHTML = usrInfo.number;
})
elements.resourceUserPic.forEach(async e => {
e.src = usrPic;
})
elements.valueUserStatus.forEach(async e => {
e.value = usrAbout.trim();
})
}
function loadChats() { function loadChats() {
elements.chatsLoader.classList.remove('hidden'); elements.chatsLoader.classList.remove('hidden');
try { try {
@ -168,6 +187,17 @@ function setupEventListeners() {
}) })
elements.saveSettingsBtn.addEventListener('click', saveSettings); elements.saveSettingsBtn.addEventListener('click', saveSettings);
elements.inputUserStatus.addEventListener('input', debounce(async function() {
const result = await sendStatus(elements.inputUserStatus.value);
console.log(result);
}, 2000))
// elements.selectable.forEach(e => {
// e.addEventListener('pointerdown', () => {
// })
// })
} }
function initWebSocket() { function initWebSocket() {

View file

@ -43,8 +43,20 @@ export function getGroups() {
return chats.filter(c => c.id.endsWith("@g.us")); return chats.filter(c => c.id.endsWith("@g.us"));
} }
export function getUser(number) { export async function getUser(number) {
return users.find(user => user.id === number); if (online) {
return await waha.getUser(number);
} else {
return;
}
}
export async function getUserAbout(userId) {
if (online) {
return await waha.getUserAbout(userId);
} else {
return;
}
} }
export function getChats() { export function getChats() {
@ -126,3 +138,13 @@ export async function getChatPicture(chatId) {
export function isOnline() { export function isOnline() {
return online; return online;
} }
export async function sendStatus(text) {
if (online) {
return await waha.setStatus(text);
} else {
return {
success: false
}
}
}

View file

@ -33,7 +33,13 @@ export const elements = {
attachmentInput: document.getElementById('attachment-input'), attachmentInput: document.getElementById('attachment-input'),
attachmentBtn: document.getElementById('attachment-btn'), attachmentBtn: document.getElementById('attachment-btn'),
extraPages: document.querySelectorAll('.extra-page'), extraPages: document.querySelectorAll('.extra-page'),
desktopSidebarButtons: document.querySelectorAll("#desktop-aside button") desktopSidebarButtons: document.querySelectorAll("#desktop-aside button"),
contentUserName: document.querySelectorAll('[data-content="app-user"]'),
contentUserNumber: document.querySelectorAll('[data-content="app-user-number"]'),
resourceUserPic: document.querySelectorAll('[data-resource="app-user-image"]'),
valueUserStatus: document.querySelectorAll('[data-value="app-user-status"]'),
inputUserStatus: document.getElementById('profile-page-status-input'),
selectable: document.querySelectorAll('.selectable'),
}; };
export const ui = { export const ui = {
@ -92,7 +98,7 @@ export const ui = {
for (const chat of chats) { for (const chat of chats) {
const li = document.createElement('li'); const li = document.createElement('li');
li.className = `chat-item ${activeChat && activeChat.id === chat.id ? 'active' : ''}`; li.className = `chat-item selectable ${activeChat && activeChat.id === chat.id ? 'active' : ''}`;
li.dataset.id = chat.id; li.dataset.id = chat.id;
const initials = chat.name ? chat.name.substring(0, 1).toUpperCase() : '?'; const initials = chat.name ? chat.name.substring(0, 1).toUpperCase() : '?';
@ -235,7 +241,7 @@ export const ui = {
const prevMsgEl = getPrevMessageElem(); const prevMsgEl = getPrevMessageElem();
const groupDiv = document.createElement('div'); const groupDiv = document.createElement('div');
groupDiv.className = `message-group ${isOutgoing ? 'outgoing' : 'incoming'}`; groupDiv.className = `message-group selectable ${isOutgoing ? 'outgoing' : 'incoming'}`;
groupDiv.id = normalizeId(msg._serialized ? msg : msg.id); groupDiv.id = normalizeId(msg._serialized ? msg : msg.id);
groupDiv.dataset.timestamp = msg.timestamp; groupDiv.dataset.timestamp = msg.timestamp;
groupDiv.dataset.from = msg.participant || msg.from; groupDiv.dataset.from = msg.participant || msg.from;

View file

@ -113,3 +113,11 @@ export function normalizeId(raw) {
} }
return raw; return raw;
} }
export function debounce(func, delay) {
let timeoutId;
return function() {
clearTimeout(timeoutId);
timeoutId = setTimeout(func, delay);
};
}

View file

@ -102,6 +102,14 @@ export const waha = {
return request(`/api/${config.session}/chats/${chatId}/picture`); return request(`/api/${config.session}/chats/${chatId}/picture`);
}, },
async getUser(chatId) {
return request(`/api/${config.session}/contacts/${chatId}`);
},
async getUserAbout(chatId) {
return request(`/api/contacts/about?contactId=${chatId}&session=${config.session}`);
},
async readChat(chatId) { async readChat(chatId) {
return request('/api/sendSeen', { return request('/api/sendSeen', {
method: 'POST', method: 'POST',
@ -143,6 +151,15 @@ export const waha = {
}); });
}, },
async setStatus(text) {
return request(`/api/${config.session}/profile/status`, {
method: 'PUT',
body: JSON.stringify({
status: text
})
});
},
async sendFileMessage(chatId, file) { async sendFileMessage(chatId, file) {
const fileBase64 = await getBase64(file); const fileBase64 = await getBase64(file);
const body = { const body = {

120
style.css
View file

@ -1,3 +1,33 @@
@font-face {
font-family: Selawik;
src: url(./fonts/selawk.ttf);
font-weight: normal;
}
@font-face {
font-family: Selawik;
src: url(./fonts/selawkl.ttf);
font-weight: 200;
}
@font-face {
font-family: Selawik;
src: url(./fonts/selawksl.ttf);
font-weight: 300;
}
@font-face {
font-family: Selawik;
src: url(./fonts/selawkb.ttf);
font-weight: bold;
}
@font-face {
font-family: Selawik;
src: url(./fonts/selawkb.ttf);
font-weight: 800;
}
:root { :root {
--bg-main: black; --bg-main: black;
--bg-secondary: #242424; --bg-secondary: #242424;
@ -44,7 +74,7 @@ body.light {
margin: 0; margin: 0;
padding: 0; padding: 0;
box-sizing: border-box; box-sizing: border-box;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; font-family: Selawik, 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
user-select: none; user-select: none;
} }
@ -106,7 +136,7 @@ input:focus {
} }
.app-name { .app-name {
font-weight: bolder; font-weight: bold;
} }
/* Sidebar Styling */ /* Sidebar Styling */
@ -299,15 +329,28 @@ input:focus {
border: 1px solid transparent; border: 1px solid transparent;
} }
.selected {
background: rgba(255, 255, 255, 0.04);
transform: scale(0.98) skewX(10deg);
filter: blur(.1px);
opacity: .6;
}
@media (hover: hover) { @media (hover: hover) {
.chat-item:hover { .selectable:hover {
background: rgba(255, 255, 255, 0.04); transform: scale(0.98) skewX(10deg); filter: blur(.1px); opacity: .6; background: rgba(255, 255, 255, 0.04);
transform: scale(0.98) skewX(10deg);
filter: blur(.1px);
opacity: .6;
} }
} }
@media (hover: none) { @media (hover: none) {
.chat-item:active { .selectable:active {
background: rgba(255, 255, 255, 0.04); transform: scale(0.98) skewX(10deg); filter: blur(.1px); opacity: .6; background: rgba(255, 255, 255, 0.04);
transform: scale(0.98) skewX(10deg);
filter: blur(.1px);
opacity: .6;
} }
} }
@ -351,6 +394,7 @@ input:focus {
white-space: nowrap; white-space: nowrap;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
font-weight: 300;
flex: 1; flex: 1;
} }
@ -403,11 +447,6 @@ input:focus {
} }
/* Sidebar Footer */ /* Sidebar Footer */
.sidebar-footer {
padding: 14px 20px;
background: var(--bg-secondary);
}
.api-status-badge { .api-status-badge {
display: flex; display: flex;
align-items: center; align-items: center;
@ -555,7 +594,7 @@ input:focus {
.active-contact-info h3 { .active-contact-info h3 {
font-size: 1rem; font-size: 1rem;
font-weight: bolder; font-weight: bold;
} }
.contact-status { .contact-status {
@ -604,6 +643,7 @@ input:focus {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
max-width: 65%; max-width: 65%;
transition: .1s;
} }
.message-group.incoming { .message-group.incoming {
@ -826,6 +866,49 @@ input:focus {
display: flex; display: flex;
} }
#profile-page {
flex-direction: column;
background-color: var(--bg-main);
}
#profile-page .content {
padding: 1.4rem;
display: flex;
gap: 1em;
}
#profile-page-user-info {
flex: 1;
}
#profile-page h2 {
padding: 1.4rem;
font-size: 5rem;
text-wrap-mode: nowrap;
overflow: hidden;
font-weight: 200;
}
#profile-page-picture {
width: 100%;
max-width: 10%;
height: auto;
aspect-ratio: 1/1;
}
#profile-page-status-input {
width: 100%;
background-color: var(--bg-main);
font-size: xx-large;
border-bottom: medium solid transparent;
padding: 0;
}
#profile-page-status-input:focus {
color: var(--text-primary);
border-bottom-color: var(--text-primary);
}
@media (max-width: 768px) { @media (max-width: 768px) {
.app-container { .app-container {
width: 100%; width: 100%;
@ -901,6 +984,19 @@ input:focus {
#desktop-aside { #desktop-aside {
display: none; display: none;
} }
#profile-page .content {
flex-direction: column;
}
#profile-page-picture {
max-width: 50%;
margin: auto;
}
#profile-page-user-number {
text-align: center;
}
} }
/* Modal Styling */ /* Modal Styling */