Spaces:
Running
Running
Download index.html from sldshr/Client_Less: direct link, hf CLI and curl.
- Browser
- Download file 79.1 kB
-
https://huggingface.co/spaces/sldshr/Client_Less/resolve/main/index.html
- Command line
-
hf download hf://spaces/sldshr/Client_Less/index.html
-
curl -L -o index.html https://huggingface.co/spaces/sldshr/Client_Less/resolve/main/index.html
79.1 kB
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Matrix Hydrogen Client</title>
<style>
:root {
/* Hydrogen Minimal Palette */
--bg-dark: #0d131a;
--bg-sidebar: #151d28;
--bg-card: #1c2636;
--bg-hover: #243246;
--bg-input: #090e14;
--border-color: #212c3d;
--accent: #0dbd8b;
--accent-hover: #0aa378;
--accent-glow: rgba(13, 189, 139, 0.15);
--text-main: #e6edf3;
--text-muted: #8b9bb4;
--danger: #f85149;
--danger-hover: #da3633;
--radius-lg: 10px;
--radius-md: 6px;
--radius-sm: 4px;
--font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}
.theme-matrix {
--bg-dark: #040d06;
--bg-sidebar: #09170b;
--bg-card: #0f2412;
--bg-hover: #16361b;
--bg-input: #030804;
--border-color: #173d1c;
--accent: #00e676;
--accent-hover: #00c853;
--accent-glow: rgba(0, 230, 118, 0.2);
--text-main: #00ff66;
--text-muted: #00aa44;
}
.theme-light {
--bg-dark: #f6f8fa;
--bg-sidebar: #ffffff;
--bg-card: #f3f4f6;
--bg-hover: #e5e7eb;
--bg-input: #ffffff;
--border-color: #d0d7de;
--accent: #0969da;
--accent-hover: #0451a5;
--accent-glow: rgba(9, 105, 218, 0.15);
--text-main: #1f2328;
--text-muted: #656d76;
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
font-family: var(--font-family);
overflow-wrap: anywhere;
word-break: break-word;
/* Disable text selection everywhere in UI */
user-select: none;
-webkit-user-select: none;
}
/* Allow selection only inside actual message contents */
.message-bubble, .form-input, .search-input, .chat-input {
user-select: text;
-webkit-user-select: text;
}
body, html {
height: 100%;
width: 100%;
background-color: var(--bg-dark);
color: var(--text-main);
overflow: hidden;
}
/* SVG Icon styling */
.svg-icon {
width: 18px;
height: 18px;
fill: currentColor;
display: inline-block;
vertical-align: middle;
flex-shrink: 0;
}
.svg-icon.sm {
width: 15px;
height: 15px;
}
/* App Layout */
#appContainer {
display: flex;
height: 100vh;
width: 100vw;
}
.nav-bar {
width: 58px;
background: var(--bg-sidebar);
border-right: 1px solid var(--border-color);
display: flex;
flex-direction: column;
align-items: center;
padding: 12px 0;
gap: 12px;
z-index: 20;
flex-shrink: 0;
}
.nav-logo {
width: 38px;
height: 38px;
background: var(--accent-glow);
color: var(--accent);
border-radius: var(--radius-md);
display: flex;
align-items: center;
justify-content: center;
font-weight: 700;
font-size: 18px;
border: 1px solid var(--accent);
}
.nav-btn {
width: 40px;
height: 40px;
border-radius: var(--radius-md);
background: transparent;
border: none;
color: var(--text-muted);
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
position: relative;
transition: all 0.15s ease;
}
.nav-btn:hover {
background: var(--bg-hover);
color: var(--text-main);
}
.nav-btn.active {
color: var(--accent);
background: var(--bg-card);
border-left: 3px solid var(--accent);
border-radius: 0 var(--radius-md) var(--radius-md) 0;
}
.badge {
position: absolute;
top: 2px;
right: 2px;
background: var(--accent);
color: #000;
font-size: 10px;
font-weight: 700;
border-radius: 8px;
padding: 1px 5px;
}
.list-sidebar {
width: 300px;
background: var(--bg-sidebar);
border-right: 1px solid var(--border-color);
display: flex;
flex-direction: column;
flex-shrink: 0;
}
.sidebar-header {
padding: 14px;
border-bottom: 1px solid var(--border-color);
display: flex;
flex-direction: column;
gap: 10px;
}
.sidebar-title-row {
display: flex;
align-items: center;
justify-content: space-between;
height: 32px;
}
.sidebar-title {
font-size: 16px;
font-weight: 700;
letter-spacing: -0.2px;
}
.action-btns {
display: flex;
gap: 6px;
}
.btn-sm {
padding: 6px 10px;
font-size: 12px;
font-weight: 600;
border-radius: var(--radius-sm);
border: 1px solid transparent;
cursor: pointer;
background: var(--accent);
color: #000;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 5px;
transition: background 0.15s;
white-space: nowrap;
}
.btn-sm:hover {
background: var(--accent-hover);
}
.btn-secondary {
background: var(--bg-card);
color: var(--text-main);
border: 1px solid var(--border-color);
}
.btn-secondary:hover {
background: var(--bg-hover);
}
.search-input {
width: 100%;
padding: 7px 10px;
background: var(--bg-input);
border: 1px solid var(--border-color);
border-radius: var(--radius-md);
color: var(--text-main);
font-size: 13px;
outline: none;
}
.search-input:focus {
border-color: var(--accent);
}
.room-list {
flex: 1;
overflow-y: auto;
padding: 6px;
display: flex;
flex-direction: column;
gap: 2px;
}
.room-item {
display: flex;
align-items: center;
gap: 10px;
padding: 8px 10px;
border-radius: var(--radius-md);
cursor: pointer;
transition: background 0.15s;
min-width: 0;
}
.room-item:hover {
background: var(--bg-hover);
}
.room-item.active {
background: var(--bg-card);
border: 1px solid var(--border-color);
}
.avatar {
width: 36px;
height: 36px;
border-radius: var(--radius-md);
object-fit: cover;
background: var(--bg-card);
display: flex;
align-items: center;
justify-content: center;
font-weight: 700;
color: var(--accent);
border: 1px solid var(--border-color);
flex-shrink: 0;
overflow: hidden;
font-size: 14px;
}
.avatar img {
width: 100%;
height: 100%;
object-fit: cover;
}
.room-info {
flex: 1;
min-width: 0;
}
.room-name-row {
display: flex;
justify-content: space-between;
align-items: center;
gap: 6px;
}
.room-name {
font-size: 13.5px;
font-weight: 600;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.room-topic {
font-size: 11.5px;
color: var(--text-muted);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
margin-top: 1px;
}
.workspace {
flex: 1;
display: flex;
background: var(--bg-dark);
min-width: 0;
position: relative;
}
.chat-container {
flex: 1;
display: flex;
flex-direction: column;
min-width: 0;
height: 100%;
}
.chat-header {
height: 56px;
padding: 0 16px;
border-bottom: 1px solid var(--border-color);
display: flex;
align-items: center;
justify-content: space-between;
background: var(--bg-sidebar);
min-width: 0;
}
.chat-header-info {
display: flex;
align-items: center;
gap: 10px;
min-width: 0;
}
.chat-title-group {
min-width: 0;
}
.chat-title {
font-size: 15px;
font-weight: 700;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.chat-subtitle {
font-size: 11px;
color: var(--text-muted);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.timeline {
flex: 1;
overflow-y: auto;
padding: 16px 20px;
display: flex;
flex-direction: column;
gap: 10px;
}
.message-group {
display: flex;
flex-direction: column;
max-width: 75%;
word-break: break-word;
overflow-wrap: anywhere;
}
.message-group.me {
align-self: flex-end;
align-items: flex-end;
}
.message-group.other {
align-self: flex-start;
align-items: flex-start;
}
.message-header {
display: flex;
align-items: center;
gap: 6px;
margin-bottom: 3px;
font-size: 11px;
}
.sender-name {
font-weight: 600;
color: var(--accent);
}
.message-time {
color: var(--text-muted);
}
.message-bubble {
padding: 8px 12px;
border-radius: var(--radius-lg);
font-size: 13.5px;
line-height: 1.45;
position: relative;
max-width: 100%;
}
.message-group.me .message-bubble {
background: var(--accent);
color: #041009;
border-top-right-radius: 2px;
font-weight: 500;
}
.message-group.other .message-bubble {
background: var(--bg-card);
border: 1px solid var(--border-color);
color: var(--text-main);
border-top-left-radius: 2px;
}
.reactions-row {
display: flex;
flex-wrap: wrap;
gap: 4px;
margin-top: 4px;
}
.reaction-chip {
background: var(--bg-card);
border: 1px solid var(--border-color);
border-radius: 12px;
padding: 2px 7px;
font-size: 11px;
cursor: pointer;
display: flex;
align-items: center;
gap: 4px;
color: var(--text-main);
}
.reaction-chip:hover {
border-color: var(--accent);
}
/* Input Footer */
.chat-footer {
padding: 12px 16px;
border-top: 1px solid var(--border-color);
background: var(--bg-sidebar);
display: flex;
flex-direction: column;
gap: 6px;
}
.reply-banner {
display: flex;
align-items: center;
justify-content: space-between;
background: var(--bg-card);
padding: 6px 10px;
border-radius: var(--radius-sm);
border-left: 3px solid var(--accent);
font-size: 12px;
}
.input-row {
display: flex;
align-items: center;
gap: 8px;
}
.chat-input {
flex: 1;
padding: 10px 14px;
background: var(--bg-input);
border: 1px solid var(--border-color);
border-radius: var(--radius-md);
color: var(--text-main);
font-size: 13.5px;
outline: none;
}
.chat-input:focus {
border-color: var(--accent);
}
.icon-btn {
padding: 8px;
background: var(--bg-card);
border: 1px solid var(--border-color);
border-radius: var(--radius-md);
color: var(--text-main);
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.15s;
}
.icon-btn:hover {
background: var(--bg-hover);
}
.members-sidebar {
width: 240px;
background: var(--bg-sidebar);
border-left: 1px solid var(--border-color);
display: flex;
flex-direction: column;
padding: 14px;
gap: 10px;
overflow-y: auto;
}
.member-item {
display: flex;
align-items: center;
gap: 8px;
padding: 4px 0;
min-width: 0;
}
.member-name {
font-size: 12.5px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
/* Modals & Overlays */
.modal-overlay {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.7);
backdrop-filter: blur(2px);
z-index: 100;
display: flex;
align-items: center;
justify-content: center;
padding: 16px;
}
.modal-card {
background: var(--bg-sidebar);
border: 1px solid var(--border-color);
border-radius: var(--radius-lg);
width: 100%;
max-width: 440px;
padding: 20px;
display: flex;
flex-direction: column;
gap: 14px;
box-shadow: 0 16px 32px rgba(0, 0, 0, 0.5);
max-height: 90vh;
overflow-y: auto;
}
.modal-header {
display: flex;
justify-content: space-between;
align-items: center;
font-size: 16px;
font-weight: 700;
gap: 10px;
}
.form-group {
display: flex;
flex-direction: column;
gap: 5px;
}
.form-label {
font-size: 11px;
font-weight: 700;
color: var(--text-muted);
text-transform: uppercase;
letter-spacing: 0.5px;
}
.form-input, .form-select {
padding: 9px 12px;
background: var(--bg-input);
border: 1px solid var(--border-color);
border-radius: var(--radius-md);
color: var(--text-main);
font-size: 13.5px;
outline: none;
width: 100%;
}
.form-input:focus, .form-select:focus {
border-color: var(--accent);
}
.context-menu {
position: fixed;
background: var(--bg-card);
border: 1px solid var(--border-color);
border-radius: var(--radius-md);
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
padding: 4px;
z-index: 200;
display: flex;
flex-direction: column;
gap: 2px;
min-width: 160px;
}
.context-item {
padding: 7px 10px;
font-size: 12.5px;
border-radius: var(--radius-sm);
cursor: pointer;
color: var(--text-main);
display: flex;
align-items: center;
gap: 8px;
transition: background 0.1s;
}
.context-item:hover {
background: var(--bg-hover);
}
.context-item.danger {
color: var(--danger);
}
.context-item.danger:hover {
background: rgba(248, 81, 73, 0.12);
}
/* Media Previews */
.media-img {
max-width: 280px;
max-height: 220px;
border-radius: var(--radius-md);
cursor: pointer;
margin-top: 4px;
object-fit: cover;
}
.media-video {
max-width: 300px;
border-radius: var(--radius-md);
margin-top: 4px;
}
.code-block {
background: var(--bg-dark);
border: 1px solid var(--border-color);
padding: 6px 10px;
border-radius: 4px;
font-family: monospace;
font-size: 12px;
margin-top: 4px;
overflow-x: auto;
}
.hidden { display: none !important; }
</style>
</head>
<body id="appBody">
<svg style="display: none;">
<symbol id="icon-chat" viewBox="0 0 24 24">
<path d="M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm0 14H5.2L4 17.2V4h16v12z"/>
</symbol>
<symbol id="icon-user" viewBox="0 0 24 24">
<path d="M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z"/>
</symbol>
<symbol id="icon-add-user" viewBox="0 0 24 24">
<path d="M15 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm-9-2V7H4v3H1v2h3v3h2v-3h3v-2H6zm9 4c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z"/>
</symbol>
<symbol id="icon-inbox" viewBox="0 0 24 24">
<path d="M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H5v-3h3.58c.77 1.19 2.08 2 3.58 2s2.81-.81 3.58-2H19v3zm0-5h-4.17c-.41 1.16-1.52 2-2.83 2s-2.42-.84-2.83-2H5V5h14v9z"/>
</symbol>
<symbol id="icon-settings" viewBox="0 0 24 24">
<path d="M19.43 12.98c.04-.32.07-.64.07-.98s-.03-.66-.07-.98l2.11-1.65c.19-.15.24-.42.12-.64l-2-3.46c-.12-.22-.39-.3-.61-.22l-2.49 1c-.52-.4-1.08-.73-1.69-.98l-.38-2.65C14.46 2.18 14.25 2 14 2h-4c-.25 0-.46.18-.49.42l-.38 2.65c-.61.25-1.17.59-1.69.98l-2.49-1c-.23-.09-.49 0-.61.22l-2 3.46c-.13.22-.07.49.12.64l2.11 1.65c-.04.32-.07.65-.07.98s.03.66.07.98l-2.11 1.65c-.19.15-.24.42-.12.64l2 3.46c.12.22.39.3.61.22l2.49-1c.52.4 1.08.73 1.69.98l.38 2.65c.03.24.24.42.49.42h4c.25 0 .46-.18.49-.42l.38-2.65c.61-.25 1.17-.59 1.69-.98l2.49 1c.23.09.49 0 .61-.22l2-3.46c.12-.22.07-.49-.12-.64l-2.11-1.65zM12 15.5c-1.93 0-3.5-1.57-3.5-3.5s1.57-3.5 3.5-3.5 3.5 1.57 3.5 3.5-1.57 3.5-3.5 3.5z"/>
</symbol>
<symbol id="icon-logout" viewBox="0 0 24 24">
<path d="M17 7l-1.41 1.41L18.17 11H8v2h10.17l-2.58 2.58L17 17l5-5zM4 5h8V3H4c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h8v-2H4V5z"/>
</symbol>
<symbol id="icon-plus" viewBox="0 0 24 24">
<path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
</symbol>
<symbol id="icon-link" viewBox="0 0 24 24">
<path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"/>
</symbol>
<symbol id="icon-attach" viewBox="0 0 24 24">
<path d="M16.5 6v11.5c0 2.21-1.79 4-4 4s-4-1.79-4-4V5c0-1.38 1.12-2.5 2.5-2.5s2.5 1.12 2.5 2.5v10.5c0 .55-.45 1-1 1s-1-.45-1-1V6H10v9.5c0 1.38 1.12 2.5 2.5 2.5s2.5-1.12 2.5-2.5V5c0-2.21-1.79-4-4-4S7 2.79 7 5v12.5c0 3.04 2.46 5.5 5.5 5.5s5.5-2.46 5.5-5.5V6h-1.5z"/>
</symbol>
<symbol id="icon-send" viewBox="0 0 24 24">
<path d="M2.01 21L23 12 2.01 3 2 10l15 2-15 2z"/>
</symbol>
<symbol id="icon-close" viewBox="0 0 24 24">
<path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/>
</symbol>
<symbol id="icon-info" viewBox="0 0 24 24">
<path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z"/>
</symbol>
<symbol id="icon-members" viewBox="0 0 24 24">
<path d="M16 11c1.66 0 2.99-1.34 2.99-3S17.66 5 16 5c-1.66 0-3 1.34-3 3zm-8 0c1.66 0 2.99-1.34 2.99-3S9.66 5 8 5C6.34 5 5 6.34 5 8s1.34 3 3 3zm0 2c-2.33 0-7 1.17-7 3.5V19h14v-2.5c0-2.33-4.67-3.5-7-3.5zm8 0c-.29 0-.62.02-.97.05 1.16.84 1.97 1.97 1.97 3.45V19h6v-2.5c0-2.33-4.67-3.5-7-3.5z"/>
</symbol>
<symbol id="icon-reply" viewBox="0 0 24 24">
<path d="M10 9V5l-7 7 7 7v-4.1c5 0 8.5 1.6 11 5.1-1-5-4-10-11-11z"/>
</symbol>
<symbol id="icon-like" viewBox="0 0 24 24">
<path d="M1 21h4V9H1v12zm22-11c0-1.1-.9-2-2-2h-6.31l.95-4.57.03-.32c0-.41-.17-.79-.44-1.06L14.17 1 7.58 7.59C7.22 7.95 7 8.45 7 9v10c0 1.1.9 2 2 2h9c.83 0 1.54-.5 1.84-1.22l3.02-7.05c.09-.23.14-.47.14-.73v-2z"/>
</symbol>
<symbol id="icon-heart" viewBox="0 0 24 24">
<path d="M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z"/>
</symbol>
<symbol id="icon-trash" viewBox="0 0 24 24">
<path d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"/>
</symbol>
</svg>
<div id="toastContainer" style="position: fixed; top: 16px; right: 16px; z-index: 300; display: flex; flex-direction: column; gap: 8px;"></div>
<!-- Right Click Context Menu -->
<div id="customContextMenu" class="context-menu hidden"></div>
<!-- LOGIN SCREEN -->
<div id="loginView" style="height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;">
<div class="modal-card" style="max-width: 380px;">
<div style="text-align: center; margin-bottom: 4px;">
<div class="nav-logo" style="margin: 0 auto 10px auto; width: 48px; height: 48px; font-size: 24px;">H</div>
<h1 style="font-size: 20px;">Matrix Hydrogen</h1>
<p style="font-size: 12px; color: var(--text-muted); margin-top: 2px;">Вход в аккаунт Matrix</p>
</div>
<form onsubmit="handleLogin(event)" style="display: flex; flex-direction: column; gap: 12px;">
<div class="form-group">
<label class="form-label">Сервер (Homeserver)</label>
<select id="hsSelect" class="form-select" onchange="toggleCustomServerInput()">
<option value="https://matrix.org">matrix.org</option>
<option value="https://matrix.unredacted.org">matrix.unredacted.org</option>
<option value="https://matrix.envs.net">matrix.envs.net</option>
<option value="custom">Свой сервер...</option>
</select>
<input type="url" id="hsCustomInput" class="form-input hidden" style="margin-top: 6px;" placeholder="https://your-homeserver.com">
</div>
<div class="form-group">
<label class="form-label">Способ входа</label>
<select id="authTypeSelect" class="form-select" onchange="toggleAuthFields()">
<option value="password">Логин и Пароль</option>
<option value="token">Access Token</option>
</select>
</div>
<div id="passAuthFields" class="form-group" style="gap: 10px;">
<div class="form-group">
<label class="form-label">Никнейм / MXID</label>
<input type="text" id="userInput" class="form-input" placeholder="username или @user:server.org">
</div>
<div class="form-group">
<label class="form-label">Пароль</label>
<input type="password" id="passInput" class="form-input" placeholder="••••••••">
</div>
</div>
<div id="tokenAuthFields" class="form-group hidden">
<label class="form-label">Access Token</label>
<input type="password" id="tokenInput" class="form-input" placeholder="syt_...">
</div>
<button type="submit" id="loginBtn" class="btn-sm" style="padding: 10px; font-size: 13px; margin-top: 4px;">Войти</button>
</form>
</div>
</div>
<!-- MAIN APP INTERFACE -->
<div id="mainView" class="hidden" style="height: 100vh; width: 100vw; display: flex;">
<!-- Left Nav Sidebar -->
<div class="nav-bar">
<div class="nav-logo">H</div>
<button onclick="switchTab('chats')" id="tabBtn-chats" class="nav-btn active" title="Чаты">
<svg class="svg-icon"><use href="#icon-chat"/></svg>
</button>
<button onclick="switchTab('dms')" id="tabBtn-dms" class="nav-btn" title="Личные сообщения">
<svg class="svg-icon"><use href="#icon-user"/></svg>
</button>
<button onclick="switchTab('inbox')" id="tabBtn-inbox" class="nav-btn" title="Приглашения">
<svg class="svg-icon"><use href="#icon-inbox"/></svg>
<span id="inboxBadge" class="badge hidden">0</span>
</button>
<button onclick="switchTab('settings')" id="tabBtn-settings" class="nav-btn" title="Настройки">
<svg class="svg-icon"><use href="#icon-settings"/></svg>
</button>
<button onclick="logout()" class="nav-btn" style="margin-top: auto; color: var(--danger);" title="Выйти">
<svg class="svg-icon"><use href="#icon-logout"/></svg>
</button>
</div>
<!-- Secondary List Sidebar -->
<div class="list-sidebar">
<div class="sidebar-header">
<div class="sidebar-title-row">
<h2 id="sidebarTitle" class="sidebar-title">Чаты</h2>
<!-- Contextual Actions per tab -->
<div id="chatActionBtns" class="action-btns">
<!-- Visible ONLY in DMs tab -->
<button onclick="openModal('createDmModal')" id="btnActionDm" class="btn-sm btn-secondary hidden" title="Начать ЛС">
<svg class="svg-icon sm"><use href="#icon-add-user"/></svg> Добавить друга
</button>
<!-- Visible ONLY in Rooms/Chats tab -->
<button onclick="openModal('createRoomModal')" id="btnActionCreateRoom" class="btn-sm" title="Создать комнату">
<svg class="svg-icon sm"><use href="#icon-plus"/></svg>
</button>
<button onclick="openModal('joinRoomModal')" id="btnActionJoinRoom" class="btn-sm btn-secondary" title="Присоединиться">
<svg class="svg-icon sm"><use href="#icon-link"/></svg>
</button>
</div>
</div>
<input type="text" id="searchInput" class="search-input" oninput="filterRooms()" placeholder="Поиск...">
</div>
<div id="listContainer" class="room-list"></div>
</div>
<!-- Main Workspace -->
<div class="workspace">
<!-- Chat View -->
<div id="chatView" class="chat-container">
<div class="chat-header">
<div class="chat-header-info">
<div id="currentRoomAvatar" class="avatar">#</div>
<div class="chat-title-group">
<h3 id="currentRoomName" class="chat-title">Выберите чат</h3>
<p id="currentRoomTopic" class="chat-subtitle">Hydrogen Matrix Client</p>
</div>
</div>
<div style="display: flex; gap: 6px;">
<button onclick="toggleMembersSidebar()" class="btn-sm btn-secondary" title="Участники">
<svg class="svg-icon sm"><use href="#icon-members"/></svg>
</button>
<button onclick="openCurrentRoomDetails()" class="btn-sm btn-secondary" title="Инфо">
<svg class="svg-icon sm"><use href="#icon-info"/></svg>
</button>
</div>
</div>
<div id="messageTimeline" class="timeline">
<div style="margin: auto; color: var(--text-muted); text-align: center; font-size: 13px;">
Выберите комнату или личное сообщение из списка слева
</div>
</div>
<div class="chat-footer">
<div id="replyBanner" class="reply-banner hidden">
<span id="replyText">Ответ на сообщение...</span>
<button onclick="cancelReply()" style="background:none; border:none; color:var(--text-muted); cursor:pointer;">
<svg class="svg-icon sm"><use href="#icon-close"/></svg>
</button>
</div>
<form onsubmit="sendMessage(event)" class="input-row">
<label class="icon-btn" title="Отправить файл">
<svg class="svg-icon"><use href="#icon-attach"/></svg>
<input type="file" id="fileInput" onchange="sendFile(this)" style="display: none;">
</label>
<input type="text" id="msgInput" class="chat-input" placeholder="Написать сообщение (**bold**, *italic*, `code`)..." autocomplete="off">
<button type="submit" class="btn-sm" style="padding: 9px 14px;">
<svg class="svg-icon"><use href="#icon-send"/></svg>
</button>
</form>
</div>
</div>
<!-- Members Sidebar Panel -->
<div id="membersSidebar" class="members-sidebar hidden">
<h4 style="font-size: 13px; font-weight:700;">Участники</h4>
<div id="membersList" style="display: flex; flex-direction: column; gap: 6px;"></div>
</div>
<!-- Settings View -->
<div id="settingsView" class="hidden" style="flex: 1; padding: 30px; overflow-y: auto;">
<div style="max-width: 460px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px;">
<h2 style="font-size:18px;">Настройки профиля</h2>
<div class="modal-card">
<div style="display: flex; align-items: center; gap: 16px;">
<div id="settingsAvatarPreview" class="avatar" style="width: 60px; height: 60px; font-size: 20px;">?</div>
<label class="btn-sm btn-secondary" style="cursor: pointer;">
Изменить аватар
<input type="file" accept="image/*" onchange="uploadProfileAvatar(this)" style="display: none;">
</label>
</div>
<div class="form-group">
<label class="form-label">Отображаемое имя</label>
<div style="display: flex; gap: 8px;">
<input type="text" id="settingsDisplayName" class="form-input" style="flex:1;">
<button onclick="saveDisplayName()" class="btn-sm">Сохранить</button>
</div>
</div>
<div class="form-group">
<label class="form-label">Мой User ID</label>
<input type="text" id="settingsUserId" class="form-input" readonly style="opacity: 0.7;">
</div>
</div>
<div class="modal-card">
<h3 style="font-size:14px;">Тема оформления</h3>
<div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 6px;">
<button onclick="setAppTheme('dark')" class="btn-sm btn-secondary" style="padding: 12px;">Dark</button>
<button onclick="setAppTheme('matrix')" class="btn-sm btn-secondary" style="padding: 12px; color:#00ff66;">Matrix</button>
<button onclick="setAppTheme('light')" class="btn-sm btn-secondary" style="padding: 12px; color:#1f2328;">Light</button>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- MODALS -->
<!-- Create Room Modal -->
<div id="createRoomModal" class="modal-overlay hidden">
<div class="modal-card">
<div class="modal-header">
<span>Создать комнату</span>
<button onclick="closeModal('createRoomModal')" style="background:none; border:none; color:var(--text-main); cursor:pointer;">
<svg class="svg-icon"><use href="#icon-close"/></svg>
</button>
</div>
<form onsubmit="handleCreateRoom(event)" style="display: flex; flex-direction: column; gap: 10px;">
<div class="form-group">
<label class="form-label">Название *</label>
<input type="text" id="newRoomName" class="form-input" required>
</div>
<div class="form-group">
<label class="form-label">Тема (Topic)</label>
<input type="text" id="newRoomTopic" class="form-input">
</div>
<div class="form-group">
<label class="form-label">Аватарка комнаты</label>
<input type="file" id="newRoomAvatarFile" accept="image/*" class="form-input">
</div>
<div class="form-group">
<label class="form-label">Алиас (Ссылка)</label>
<input type="text" id="newRoomAlias" class="form-input" placeholder="my-room">
</div>
<div style="display: flex; align-items: center; gap: 8px;">
<input type="checkbox" id="newRoomPublic">
<label for="newRoomPublic" style="font-size: 13px;">Публичная комната</label>
</div>
<button type="submit" class="btn-sm" style="padding: 10px; margin-top: 6px;">Создать</button>
</form>
</div>
</div>
<!-- Start DM Modal -->
<div id="createDmModal" class="modal-overlay hidden">
<div class="modal-card">
<div class="modal-header">
<span>Добавить друга (Начать ЛС)</span>
<button onclick="closeModal('createDmModal')" style="background:none; border:none; color:var(--text-main); cursor:pointer;">
<svg class="svg-icon"><use href="#icon-close"/></svg>
</button>
</div>
<form onsubmit="handleStartDm(event)" style="display: flex; flex-direction: column; gap: 10px;">
<div class="form-group">
<label class="form-label">Matrix ID пользователя *</label>
<input type="text" id="dmUserIdInput" class="form-input" required placeholder="@user:matrix.org">
</div>
<button type="submit" class="btn-sm" style="padding: 10px; margin-top: 6px;">Начать чат</button>
</form>
</div>
</div>
<!-- Join Room Modal -->
<div id="joinRoomModal" class="modal-overlay hidden">
<div class="modal-card">
<div class="modal-header">
<span>Присоединиться к комнате</span>
<button onclick="closeModal('joinRoomModal')" style="background:none; border:none; color:var(--text-main); cursor:pointer;">
<svg class="svg-icon"><use href="#icon-close"/></svg>
</button>
</div>
<form onsubmit="handleJoinRoom(event)" style="display: flex; flex-direction: column; gap: 10px;">
<div class="form-group">
<label class="form-label">ID или Алиас комнаты *</label>
<input type="text" id="joinRoomInput" class="form-input" required placeholder="#room:matrix.org или !id:matrix.org">
</div>
<button type="submit" class="btn-sm" style="padding: 10px; margin-top: 6px;">Войти</button>
</form>
</div>
</div>
<!-- Room Info Modal -->
<div id="roomDetailsModal" class="modal-overlay hidden">
<div class="modal-card">
<div class="modal-header">
<span>Информация о комнате</span>
<button onclick="closeModal('roomDetailsModal')" style="background:none; border:none; color:var(--text-main); cursor:pointer;">
<svg class="svg-icon"><use href="#icon-close"/></svg>
</button>
</div>
<div style="display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center;">
<div id="infoModalAvatar" class="avatar" style="width: 56px; height: 56px; font-size: 20px;">#</div>
<h3 id="infoModalName" style="max-width: 100%; font-size:15px;"></h3>
<p id="infoModalTopic" style="font-size: 12px; color: var(--text-muted);"></p>
<div class="form-group" style="text-align: left; width: 100%; margin-top: 8px;">
<label class="form-label">ROOM ID</label>
<input type="text" id="infoModalId" class="form-input" readonly>
</div>
<button onclick="leaveCurrentRoom()" class="btn-sm" style="background: var(--danger); color: white; width: 100%; margin-top: 8px;">Выйти из комнаты</button>
</div>
</div>
</div>
<!-- Image Preview Modal -->
<div id="imageViewerModal" class="modal-overlay hidden" onclick="closeModal('imageViewerModal')">
<img id="fullImageView" src="" style="max-width: 90vw; max-height: 90vh; border-radius: var(--radius-md); object-fit: contain;">
</div>
<script>
const state = {
hsUrl: '',
accessToken: '',
userId: '',
nextBatch: '',
rooms: {},
invites: {},
currentRoomId: null,
activeTab: 'chats',
syncing: false,
replyToEvent: null,
showMembers: false
};
function showToast(msg, isError = false) {
const container = document.getElementById('toastContainer');
const toast = document.createElement('div');
toast.style.cssText = `
padding: 10px 14px;
border-radius: 6px;
background: ${isError ? '#f85149' : '#1c2636'};
color: #fff;
font-size: 12.5px;
border: 1px solid var(--border-color);
box-shadow: 0 8px 16px rgba(0,0,0,0.4);
transition: opacity 0.25s;
`;
toast.innerText = msg;
container.appendChild(toast);
setTimeout(() => {
toast.style.opacity = '0';
setTimeout(() => toast.remove(), 250);
}, 3000);
}
function mxcToHttp(mxcUrl) {
if (!mxcUrl || typeof mxcUrl !== 'string' || !mxcUrl.startsWith('mxc://')) return null;
const parts = mxcUrl.substring(6).split('/');
if (parts.length < 2) return null;
return `${state.hsUrl}/_matrix/media/v3/download/${parts[0]}/${parts[1]}`;
}
async function apiReq(endpoint, method = 'GET', body = null, isRaw = false) {
const headers = {};
if (state.accessToken) headers['Authorization'] = `Bearer ${state.accessToken}`;
if (body && !isRaw) headers['Content-Type'] = 'application/json';
const opts = { method, headers };
if (body) opts.body = isRaw ? body : JSON.stringify(body);
try {
const res = await fetch(`${state.hsUrl}/_matrix/${endpoint}`, opts);
const data = await res.json();
if (!res.ok) throw new Error(data.error || data.errcode || 'API Error');
return data;
} catch (err) {
console.error(`API Error [${endpoint}]:`, err);
throw err;
}
}
function toggleCustomServerInput() {
const select = document.getElementById('hsSelect');
const customInput = document.getElementById('hsCustomInput');
if (select.value === 'custom') {
customInput.classList.remove('hidden');
} else {
customInput.classList.add('hidden');
}
}
function toggleAuthFields() {
const type = document.getElementById('authTypeSelect').value;
if (type === 'password') {
document.getElementById('passAuthFields').classList.remove('hidden');
document.getElementById('tokenAuthFields').classList.add('hidden');
} else {
document.getElementById('passAuthFields').classList.add('hidden');
document.getElementById('tokenAuthFields').classList.remove('hidden');
}
}
async function handleLogin(e) {
e.preventDefault();
const selectVal = document.getElementById('hsSelect').value;
state.hsUrl = (selectVal === 'custom' ? document.getElementById('hsCustomInput').value : selectVal).trim().replace(/\/$/, '');
if (!state.hsUrl) return showToast('Укажите корректный URL сервера', true);
const authType = document.getElementById('authTypeSelect').value;
try {
document.getElementById('loginBtn').innerText = 'Подключение...';
if (authType === 'token') {
const token = document.getElementById('tokenInput').value.trim();
if (!token) return showToast('Введите Access Token', true);
state.accessToken = token;
const res = await apiReq('client/v3/account/whoami');
state.userId = res.user_id;
} else {
const user = document.getElementById('userInput').value.trim();
const pass = document.getElementById('passInput').value;
const res = await apiReq('client/v3/login', 'POST', {
type: 'm.login.password',
identifier: { type: 'm.id.user', user: user },
password: pass
});
state.accessToken = res.access_token;
state.userId = res.user_id;
}
localStorage.setItem('matrix_hs', state.hsUrl);
localStorage.setItem('matrix_token', state.accessToken);
localStorage.setItem('matrix_user', state.userId);
initClient();
showToast('Успешный вход!');
} catch (err) {
showToast(`Ошибка входа: ${err.message}`, true);
} finally {
document.getElementById('loginBtn').innerText = 'Войти';
}
}
function checkSavedSession() {
const hs = localStorage.getItem('matrix_hs');
const token = localStorage.getItem('matrix_token');
const user = localStorage.getItem('matrix_user');
if (hs && token && user) {
state.hsUrl = hs;
state.accessToken = token;
state.userId = user;
initClient();
}
}
function logout() {
localStorage.clear();
location.reload();
}
function initClient() {
document.getElementById('loginView').classList.add('hidden');
document.getElementById('mainView').classList.remove('hidden');
document.getElementById('settingsUserId').value = state.userId;
loadUserProfile();
startSync();
switchTab('chats');
}
async function loadUserProfile() {
try {
const data = await apiReq(`client/v3/profile/${encodeURIComponent(state.userId)}`);
if (data.displayname) document.getElementById('settingsDisplayName').value = data.displayname;
if (data.avatar_url) {
const httpUrl = mxcToHttp(data.avatar_url);
if (httpUrl) document.getElementById('settingsAvatarPreview').innerHTML = `<img src="${httpUrl}">`;
}
} catch(e){}
}
async function startSync() {
if (state.syncing) return;
state.syncing = true;
while (state.accessToken) {
try {
const timeout = state.nextBatch ? 30000 : 0;
const endpoint = `client/v3/sync?timeout=${timeout}${state.nextBatch ? `&since=${state.nextBatch}` : ''}`;
const data = await apiReq(endpoint);
state.nextBatch = data.next_batch;
processSyncData(data);
} catch (err) {
await new Promise(r => setTimeout(r, 5000));
}
}
}
function processSyncData(data) {
if (data.rooms?.join) {
for (const [roomId, roomData] of Object.entries(data.rooms.join)) {
if (!state.rooms[roomId]) {
state.rooms[roomId] = {
id: roomId,
name: null,
topic: '',
avatar: null,
events: [],
reactions: {},
members: {},
unread: 0,
isDirect: false
};
}
const room = state.rooms[roomId];
const allEvents = [...(roomData.state?.events || []), ...(roomData.timeline?.events || [])];
for (const ev of allEvents) {
if (ev.type === 'm.room.name' && ev.content?.name) room.name = ev.content.name;
if (ev.type === 'm.room.canonical_alias' && ev.content?.alias && !room.name) room.name = ev.content.alias;
if (ev.type === 'm.room.topic' && ev.content?.topic) room.topic = ev.content.topic;
if (ev.type === 'm.room.avatar' && ev.content?.url) room.avatar = mxcToHttp(ev.content.url);
if (ev.type === 'm.direct') room.isDirect = true;
if (ev.type === 'm.room.member') {
const sender = ev.state_key || ev.sender;
const memberAvatar = mxcToHttp(ev.content?.avatar_url);
const displayName = ev.content?.displayname || sender;
room.members[sender] = {
userId: sender,
name: displayName,
avatar: memberAvatar
};
}
if (ev.type === 'm.room.message') {
if (!room.events.some(e => e.event_id === ev.event_id)) {
room.events.push(ev);
if (roomId !== state.currentRoomId) room.unread++;
}
}
if (ev.type === 'm.reaction' && ev.content?.['m.relates_to']) {
const rel = ev.content['m.relates_to'];
const targetId = rel.event_id;
const emojiKey = rel.key;
if (targetId && emojiKey) {
if (!room.reactions[targetId]) room.reactions[targetId] = {};
if (!room.reactions[targetId][emojiKey]) room.reactions[targetId][emojiKey] = 0;
room.reactions[targetId][emojiKey]++;
}
}
}
computeRoomNameAndAvatar(room);
}
}
if (data.rooms?.invite) {
state.invites = {};
for (const [roomId, inviteData] of Object.entries(data.rooms.invite)) {
let name = roomId;
let inviter = 'Неизвестно';
for (const ev of (inviteData.invite_state?.events || [])) {
if (ev.type === 'm.room.name') name = ev.content.name;
if (ev.type === 'm.room.member' && ev.state_key === state.userId) inviter = ev.sender;
}
state.invites[roomId] = { roomId, name, inviter };
}
}
updateUI();
}
function computeRoomNameAndAvatar(room) {
const memberKeys = Object.keys(room.members).filter(id => id !== state.userId);
if (memberKeys.length === 1) {
room.isDirect = true;
const partner = room.members[memberKeys[0]];
if (!room.name) room.name = partner.name || partner.userId;
if (!room.avatar) room.avatar = partner.avatar;
} else if (!room.name) {
if (memberKeys.length > 1) {
const names = memberKeys.slice(0, 3).map(k => room.members[k]?.name || k);
room.name = names.join(', ');
} else {
room.name = room.id;
}
}
}
function updateUI() {
const inviteCount = Object.keys(state.invites).length;
const badge = document.getElementById('inboxBadge');
badge.innerText = inviteCount;
if (inviteCount > 0) badge.classList.remove('hidden'); else badge.classList.add('hidden');
renderSidebarList();
if (state.currentRoomId) {
renderTimeline();
renderMembersList();
}
}
function switchTab(tab) {
state.activeTab = tab;
['chats', 'dms', 'inbox', 'settings'].forEach(t => {
const btn = document.getElementById(`tabBtn-${t}`);
if (btn) btn.classList.toggle('active', t === tab);
});
document.getElementById('chatView').classList.toggle('hidden', tab === 'settings');
document.getElementById('settingsView').classList.toggle('hidden', tab !== 'settings');
const titleMap = { chats: 'Чаты', dms: 'Личные сообщения', inbox: 'Приглашения', settings: 'Настройки' };
document.getElementById('sidebarTitle').innerText = titleMap[tab] || 'Чаты';
// Show/Hide Contextual Action Buttons in sidebar header
const btnDm = document.getElementById('btnActionDm');
const btnCreate = document.getElementById('btnActionCreateRoom');
const btnJoin = document.getElementById('btnActionJoinRoom');
if (tab === 'dms') {
btnDm.classList.remove('hidden');
btnCreate.classList.add('hidden');
btnJoin.classList.add('hidden');
} else if (tab === 'chats') {
btnDm.classList.add('hidden');
btnCreate.classList.remove('hidden');
btnJoin.classList.remove('hidden');
} else {
btnDm.classList.add('hidden');
btnCreate.classList.add('hidden');
btnJoin.classList.add('hidden');
}
renderSidebarList();
}
function renderSidebarList() {
const list = document.getElementById('listContainer');
list.innerHTML = '';
if (state.activeTab === 'chats' || state.activeTab === 'dms') {
const isDmTab = state.activeTab === 'dms';
const entries = Object.entries(state.rooms).filter(([_, room]) => isDmTab ? room.isDirect : !room.isDirect);
if (entries.length === 0) {
list.innerHTML = `<div style="text-align:center; padding:20px; font-size:12px; color:var(--text-muted);">${isDmTab ? 'Нет личных сообщений' : 'Нет комнат'}</div>`;
return;
}
entries.forEach(([id, room]) => {
const item = document.createElement('div');
item.className = `room-item ${id === state.currentRoomId ? 'active' : ''}`;
item.onclick = () => selectRoom(id);
item.oncontextmenu = (e) => showRoomContextMenu(e, id);
const avatarHtml = room.avatar
? `<img src="${room.avatar}" onerror="this.onerror=null; this.parentElement.innerText='${(room.name[0] || '#').toUpperCase()}';">`
: (room.name[0] || '#').toUpperCase();
item.innerHTML = `
<div class="avatar">${avatarHtml}</div>
<div class="room-info">
<div class="room-name-row">
<span class="room-name">${escapeHtml(room.name)}</span>
${room.unread > 0 ? `<span class="badge" style="position:static;">${room.unread}</span>` : ''}
</div>
<div class="room-topic">${escapeHtml(room.topic || 'Без описания')}</div>
</div>
`;
list.appendChild(item);
});
} else if (state.activeTab === 'inbox') {
const invites = Object.values(state.invites);
if (invites.length === 0) {
list.innerHTML = `<div style="text-align:center; padding:20px; font-size:12px; color:var(--text-muted);">Входящих приглашений нет</div>`;
return;
}
invites.forEach(inv => {
const card = document.createElement('div');
card.className = 'modal-card';
card.style.padding = '12px';
card.innerHTML = `
<div style="font-weight:bold; font-size:13px;">${escapeHtml(inv.name)}</div>
<div style="font-size:11px; color:var(--text-muted);">От: ${escapeHtml(inv.inviter)}</div>
<div style="display:flex; gap:6px; margin-top:6px;">
<button onclick="acceptInvite('${inv.roomId}')" class="btn-sm" style="flex:1;">Принять</button>
<button onclick="rejectInvite('${inv.roomId}')" class="btn-sm btn-secondary" style="flex:1;">Отклонить</button>
</div>
`;
list.appendChild(card);
});
}
}
function selectRoom(roomId) {
state.currentRoomId = roomId;
if (state.rooms[roomId]) state.rooms[roomId].unread = 0;
const room = state.rooms[roomId];
document.getElementById('currentRoomName').innerText = room ? room.name : roomId;
document.getElementById('currentRoomTopic').innerText = room ? (room.topic || 'Без темы') : '';
const avatarEl = document.getElementById('currentRoomAvatar');
if (room && room.avatar) {
avatarEl.innerHTML = `<img src="${room.avatar}" onerror="this.onerror=null; this.parentElement.innerText='${(room.name[0] || '#').toUpperCase()}';">`;
} else {
avatarEl.innerText = room ? (room.name[0] || '#').toUpperCase() : '#';
}
renderSidebarList();
renderTimeline();
renderMembersList();
}
function formatMessageContent(text) {
let html = escapeHtml(text);
html = html.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>');
html = html.replace(/\*(.*?)\*/g, '<em>$1</em>');
html = html.replace(/`(.*?)`/g, '<code class="code-block">$1</code>');
return html;
}
function renderTimeline() {
const container = document.getElementById('messageTimeline');
container.innerHTML = '';
const room = state.rooms[state.currentRoomId];
if (!room || room.events.length === 0) {
container.innerHTML = `<div style="margin:auto; color:var(--text-muted); font-size:13px;">В этой комнате нет сообщений</div>`;
return;
}
room.events.forEach(ev => {
const isMe = ev.sender === state.userId;
const body = ev.content?.body || '';
const time = new Date(ev.origin_server_ts).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
const group = document.createElement('div');
group.className = `message-group ${isMe ? 'me' : 'other'}`;
group.oncontextmenu = (e) => showMessageContextMenu(e, ev);
let contentHtml = formatMessageContent(body);
if (ev.content?.msgtype === 'm.image' && ev.content.url) {
const imgUrl = mxcToHttp(ev.content.url);
contentHtml = `<img src="${imgUrl}" class="media-img" onclick="openImageViewer('${imgUrl}')"><br>` + contentHtml;
} else if (ev.content?.msgtype === 'm.video' && ev.content.url) {
const videoUrl = mxcToHttp(ev.content.url);
contentHtml = `<video src="${videoUrl}" controls class="media-video"></video><br>` + contentHtml;
}
let reactionsHtml = '';
const evReactions = room.reactions[ev.event_id];
if (evReactions) {
reactionsHtml = '<div class="reactions-row">';
for (const [emoji, count] of Object.entries(evReactions)) {
reactionsHtml += `<div class="reaction-chip" onclick="sendReaction('${ev.event_id}', '${emoji}')">${emoji} ${count}</div>`;
}
reactionsHtml += '</div>';
}
const senderMember = room.members[ev.sender];
const displayName = senderMember?.name || ev.sender;
group.innerHTML = `
<div class="message-header">
<span class="sender-name">${escapeHtml(displayName)}</span>
<span class="message-time">${time}</span>
</div>
<div class="message-bubble">${contentHtml}</div>
${reactionsHtml}
`;
container.appendChild(group);
});
container.scrollTop = container.scrollHeight;
}
function toggleMembersSidebar() {
state.showMembers = !state.showMembers;
document.getElementById('membersSidebar').classList.toggle('hidden', !state.showMembers);
}
function renderMembersList() {
const container = document.getElementById('membersList');
container.innerHTML = '';
const room = state.rooms[state.currentRoomId];
if (!room) return;
Object.values(room.members).forEach(m => {
const item = document.createElement('div');
item.className = 'member-item';
const avatarHtml = m.avatar
? `<img src="${m.avatar}" onerror="this.onerror=null; this.parentElement.innerText='${(m.name[0] || '?').toUpperCase()}';">`
: (m.name[0] || '?').toUpperCase();
item.innerHTML = `
<div class="avatar" style="width:26px; height:26px; font-size:11px;">${avatarHtml}</div>
<span class="member-name">${escapeHtml(m.name)}</span>
`;
container.appendChild(item);
});
}
function showRoomContextMenu(e, roomId) {
e.preventDefault();
closeContextMenu();
const menu = document.getElementById('customContextMenu');
menu.innerHTML = `
<div class="context-item" onclick="openRoomDetailsModal('${roomId}')">
<svg class="svg-icon sm"><use href="#icon-info"/></svg> Информация
</div>
<div class="context-item danger" onclick="leaveRoom('${roomId}')">
<svg class="svg-icon sm"><use href="#icon-logout"/></svg> Выйти из комнаты
</div>
`;
menu.classList.remove('hidden');
positionContextMenu(e, menu);
}
function showMessageContextMenu(e, ev) {
e.preventDefault();
closeContextMenu();
const menu = document.getElementById('customContextMenu');
const bodyEscaped = escapeHtml(ev.content?.body || '');
menu.innerHTML = `
<div class="context-item" onclick="setReply('${ev.event_id}', '${bodyEscaped}')">
<svg class="svg-icon sm"><use href="#icon-reply"/></svg> Ответить
</div>
<div class="context-item" onclick="sendReaction('${ev.event_id}', '👍')">
<svg class="svg-icon sm"><use href="#icon-like"/></svg> Лайк
</div>
<div class="context-item" onclick="sendReaction('${ev.event_id}', '❤️')">
<svg class="svg-icon sm"><use href="#icon-heart"/></svg> Сердце
</div>
<div class="context-item danger" onclick="deleteMessageLocally('${ev.event_id}')">
<svg class="svg-icon sm"><use href="#icon-trash"/></svg> Удалить у себя
</div>
`;
menu.classList.remove('hidden');
positionContextMenu(e, menu);
}
// Position context menu with boundary safety
function positionContextMenu(e, menu) {
const menuWidth = menu.offsetWidth || 170;
const menuHeight = menu.offsetHeight || 140;
let posX = e.clientX;
let posY = e.clientY;
if (posX + menuWidth > window.innerWidth) {
posX = Math.max(10, window.innerWidth - menuWidth - 10);
}
if (posY + menuHeight > window.innerHeight) {
posY = Math.max(10, window.innerHeight - menuHeight - 10);
}
menu.style.left = `${posX}px`;
menu.style.top = `${posY}px`;
}
function closeContextMenu() {
document.getElementById('customContextMenu').classList.add('hidden');
}
document.addEventListener('click', closeContextMenu);
function setReply(eventId, text) {
state.replyToEvent = eventId;
document.getElementById('replyText').innerText = `Ответ: ${text}`;
document.getElementById('replyBanner').classList.remove('hidden');
}
function cancelReply() {
state.replyToEvent = null;
document.getElementById('replyBanner').classList.add('hidden');
}
function deleteMessageLocally(eventId) {
if (!state.currentRoomId) return;
const room = state.rooms[state.currentRoomId];
if (room) {
room.events = room.events.filter(e => e.event_id !== eventId);
renderTimeline();
showToast('Сообщение удалено');
}
}
async function sendReaction(eventId, emoji) {
if (!state.currentRoomId) return;
const txnId = 'm' + Date.now();
try {
await apiReq(`client/v3/rooms/${encodeURIComponent(state.currentRoomId)}/send/m.reaction/${txnId}`, 'PUT', {
'm.relates_to': {
rel_type: 'm.annotation',
event_id: eventId,
key: emoji
}
});
} catch (err) {
showToast(`Ошибка реакции: ${err.message}`, true);
}
}
async function sendMessage(e) {
e.preventDefault();
if (!state.currentRoomId) return;
const input = document.getElementById('msgInput');
const body = input.value.trim();
if (!body) return;
input.value = '';
const txnId = 'm' + Date.now();
const payload = { msgtype: 'm.text', body };
if (state.replyToEvent) {
payload['m.relates_to'] = { 'm.in_reply_to': { event_id: state.replyToEvent } };
cancelReply();
}
try {
await apiReq(`client/v3/rooms/${encodeURIComponent(state.currentRoomId)}/send/m.room.message/${txnId}`, 'PUT', payload);
} catch (err) {
showToast(`Ошибка отправки: ${err.message}`, true);
}
}
async function uploadMediaFile(file) {
const res = await fetch(`${state.hsUrl}/_matrix/media/v3/upload`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${state.accessToken}`,
'Content-Type': file.type || 'application/octet-stream'
},
body: file
});
const data = await res.json();
if (!res.ok) throw new Error(data.error || 'Upload error');
return data.content_uri;
}
async function sendFile(input) {
if (!input.files?.[0] || !state.currentRoomId) return;
const file = input.files[0];
try {
showToast('Загрузка файла...');
const mxcUrl = await uploadMediaFile(file);
const txnId = 'm' + Date.now();
const isImg = file.type.startsWith('image/');
const isVid = file.type.startsWith('video/');
await apiReq(`client/v3/rooms/${encodeURIComponent(state.currentRoomId)}/send/m.room.message/${txnId}`, 'PUT', {
msgtype: isImg ? 'm.image' : isVid ? 'm.video' : 'm.file',
body: file.name,
url: mxcUrl
});
showToast('Файл отправлен');
} catch (err) {
showToast(`Ошибка отправки файла: ${err.message}`, true);
}
}
async function handleStartDm(e) {
e.preventDefault();
const targetUser = document.getElementById('dmUserIdInput').value.trim();
if (!targetUser) return;
try {
const res = await apiReq('client/v3/createRoom', 'POST', {
is_direct: true,
invite: [targetUser],
preset: 'trusted_private_chat'
});
closeModal('createDmModal');
if (res.room_id) {
if (!state.rooms[res.room_id]) state.rooms[res.room_id] = { id: res.room_id, name: targetUser, topic: '', avatar: null, events: [], reactions: {}, members: {}, unread: 0, isDirect: true };
else state.rooms[res.room_id].isDirect = true;
selectRoom(res.room_id);
}
showToast('Чат создан');
} catch (err) {
showToast(`Ошибка: ${err.message}`, true);
}
}
async function handleCreateRoom(e) {
e.preventDefault();
const name = document.getElementById('newRoomName').value.trim();
const topic = document.getElementById('newRoomTopic').value.trim();
const alias = document.getElementById('newRoomAlias').value.trim();
const isPublic = document.getElementById('newRoomPublic').checked;
const avatarFile = document.getElementById('newRoomAvatarFile').files[0];
try {
let avatarMxc = null;
if (avatarFile) avatarMxc = await uploadMediaFile(avatarFile);
const initialState = [];
if (avatarMxc) initialState.push({ type: 'm.room.avatar', content: { url: avatarMxc } });
const body = {
name, topic,
preset: isPublic ? 'public_chat' : 'private_chat',
visibility: isPublic ? 'public' : 'private',
initial_state: initialState
};
if (alias) body.room_alias_name = alias;
const res = await apiReq('client/v3/createRoom', 'POST', body);
closeModal('createRoomModal');
if (res.room_id) selectRoom(res.room_id);
showToast('Комната создана');
} catch (err) {
showToast(`Ошибка: ${err.message}`, true);
}
}
async function handleJoinRoom(e) {
e.preventDefault();
const input = document.getElementById('joinRoomInput').value.trim();
try {
const res = await apiReq(`client/v3/join/${encodeURIComponent(input)}`, 'POST', {});
closeModal('joinRoomModal');
if (res.room_id) selectRoom(res.room_id);
showToast('Вы присоединились!');
} catch (err) {
showToast(`Ошибка входа: ${err.message}`, true);
}
}
async function leaveRoom(roomId) {
try {
await apiReq(`client/v3/rooms/${encodeURIComponent(roomId)}/leave`, 'POST', {});
delete state.rooms[roomId];
if (state.currentRoomId === roomId) state.currentRoomId = null;
updateUI();
showToast('Вы вышли из комнаты');
} catch (err) {
showToast(`Ошибка: ${err.message}`, true);
}
}
function openRoomDetailsModal(roomId) {
const room = state.rooms[roomId];
if (!room) return;
document.getElementById('infoModalName').innerText = room.name || roomId;
document.getElementById('infoModalTopic').innerText = room.topic || 'Без темы';
document.getElementById('infoModalId').value = roomId;
const avatarEl = document.getElementById('infoModalAvatar');
if (room.avatar) avatarEl.innerHTML = `<img src="${room.avatar}">`;
else avatarEl.innerText = (room.name[0] || '#').toUpperCase();
openModal('roomDetailsModal');
}
function openCurrentRoomDetails() {
if (state.currentRoomId) openRoomDetailsModal(state.currentRoomId);
}
function leaveCurrentRoom() {
if (state.currentRoomId) {
leaveRoom(state.currentRoomId);
closeModal('roomDetailsModal');
}
}
async function acceptInvite(roomId) {
try {
await apiReq(`client/v3/join/${encodeURIComponent(roomId)}`, 'POST', {});
delete state.invites[roomId];
updateUI();
selectRoom(roomId);
} catch (err) { showToast(`Ошибка: ${err.message}`, true); }
}
async function rejectInvite(roomId) {
try {
await apiReq(`client/v3/rooms/${encodeURIComponent(roomId)}/leave`, 'POST', {});
delete state.invites[roomId];
updateUI();
} catch (err) { showToast(`Ошибка: ${err.message}`, true); }
}
async function uploadProfileAvatar(input) {
if (!input.files?.[0]) return;
try {
showToast('Загрузка аватара...');
const mxcUrl = await uploadMediaFile(input.files[0]);
await apiReq(`client/v3/profile/${encodeURIComponent(state.userId)}/avatar_url`, 'PUT', { avatar_url: mxcUrl });
loadUserProfile();
showToast('Аватар обновлен!');
} catch (err) { showToast(`Ошибка: ${err.message}`, true); }
}
async function saveDisplayName() {
const name = document.getElementById('settingsDisplayName').value.trim();
if (!name) return;
try {
await apiReq(`client/v3/profile/${encodeURIComponent(state.userId)}/displayname`, 'PUT', { displayname: name });
showToast('Имя изменено!');
} catch (err) { showToast(`Ошибка: ${err.message}`, true); }
}
function setAppTheme(theme) {
document.body.className = theme === 'matrix' ? 'theme-matrix' : theme === 'light' ? 'theme-light' : '';
}
function filterRooms() {
const query = document.getElementById('searchInput').value.toLowerCase();
const items = document.querySelectorAll('#listContainer .room-item');
items.forEach(el => el.style.display = el.innerText.toLowerCase().includes(query) ? 'flex' : 'none');
}
function openImageViewer(url) {
document.getElementById('fullImageView').src = url;
openModal('imageViewerModal');
}
function openModal(id) { document.getElementById(id).classList.remove('hidden'); }
function closeModal(id) { document.getElementById(id).classList.add('hidden'); }
function escapeHtml(str) {
if (!str) return '';
return str.replace(/[&<>"']/g, m => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[m]));
}
window.onload = checkSavedSession;
</script>
</body>
</html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Matrix Hydrogen Client</title>
<style>
:root {
/* Hydrogen Minimal Palette */
--bg-dark: #0d131a;
--bg-sidebar: #151d28;
--bg-card: #1c2636;
--bg-hover: #243246;
--bg-input: #090e14;
--border-color: #212c3d;
--accent: #0dbd8b;
--accent-hover: #0aa378;
--accent-glow: rgba(13, 189, 139, 0.15);
--text-main: #e6edf3;
--text-muted: #8b9bb4;
--danger: #f85149;
--danger-hover: #da3633;
--radius-lg: 10px;
--radius-md: 6px;
--radius-sm: 4px;
--font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}
.theme-matrix {
--bg-dark: #040d06;
--bg-sidebar: #09170b;
--bg-card: #0f2412;
--bg-hover: #16361b;
--bg-input: #030804;
--border-color: #173d1c;
--accent: #00e676;
--accent-hover: #00c853;
--accent-glow: rgba(0, 230, 118, 0.2);
--text-main: #00ff66;
--text-muted: #00aa44;
}
.theme-light {
--bg-dark: #f6f8fa;
--bg-sidebar: #ffffff;
--bg-card: #f3f4f6;
--bg-hover: #e5e7eb;
--bg-input: #ffffff;
--border-color: #d0d7de;
--accent: #0969da;
--accent-hover: #0451a5;
--accent-glow: rgba(9, 105, 218, 0.15);
--text-main: #1f2328;
--text-muted: #656d76;
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
font-family: var(--font-family);
overflow-wrap: anywhere;
word-break: break-word;
/* Disable text selection everywhere in UI */
user-select: none;
-webkit-user-select: none;
}
/* Allow selection only inside actual message contents */
.message-bubble, .form-input, .search-input, .chat-input {
user-select: text;
-webkit-user-select: text;
}
body, html {
height: 100%;
width: 100%;
background-color: var(--bg-dark);
color: var(--text-main);
overflow: hidden;
}
/* SVG Icon styling */
.svg-icon {
width: 18px;
height: 18px;
fill: currentColor;
display: inline-block;
vertical-align: middle;
flex-shrink: 0;
}
.svg-icon.sm {
width: 15px;
height: 15px;
}
/* App Layout */
#appContainer {
display: flex;