sldshr commited on
Commit
abfeec4
·
verified ·
1 Parent(s): 75fbf32

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +1469 -152
index.html CHANGED
@@ -1,176 +1,1493 @@
1
  <!DOCTYPE html>
2
- <html lang="en">
3
  <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>Matrix Web Client</title>
7
- <link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'><rect width='32' height='32' rx='7' fill='%230dbd8b'/><text x='16' y='23' font-family='Arial' font-size='20' font-weight='bold' text-anchor='middle' fill='white'>M</text></svg>">
8
- <link rel="preconnect" href="https://fonts.googleapis.com">
9
- <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
10
- <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
11
- <link rel="stylesheet" href="styles.css">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  </head>
13
- <body>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
- <!-- ===================== LOGIN VIEW ===================== -->
16
- <div id="login-view" class="login-view">
17
- <div class="login-card">
18
- <div class="login-logo">M</div>
19
- <h1>Matrix Web Client</h1>
20
- <p class="login-subtitle">Connect to your Matrix homeserver</p>
21
 
22
- <div class="login-tabs">
23
- <button type="button" class="tab-btn active" data-tab="password">Password</button>
24
- <button type="button" class="tab-btn" data-tab="token">Access Token</button>
25
- </div>
 
 
 
 
 
 
 
 
 
26
 
27
- <form id="login-password-form" class="login-form">
28
- <label for="homeserver-input">Homeserver URL</label>
29
- <input type="url" id="homeserver-input" placeholder="https://matrix.org" spellcheck="false" required>
 
 
 
 
 
 
 
 
 
 
30
 
31
- <label for="username-input">Username</label>
32
- <input type="text" id="username-input" placeholder="@user:server.com" autocomplete="username" spellcheck="false" required>
33
 
34
- <label for="password-input">Password</label>
35
- <input type="password" id="password-input" placeholder="••••••••" autocomplete="current-password" required>
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
- <button type="submit" class="btn-primary" id="login-password-submit">Sign In</button>
38
- </form>
 
 
 
39
 
40
- <form id="login-token-form" class="login-form hidden">
41
- <label for="token-homeserver-input">Homeserver URL</label>
42
- <input type="url" id="token-homeserver-input" placeholder="https://matrix.org" spellcheck="false" required>
 
 
 
 
 
 
 
 
 
 
 
43
 
44
- <label for="token-user-input">User ID</label>
45
- <input type="text" id="token-user-input" placeholder="@user:server.com" spellcheck="false" required>
 
 
 
 
 
 
 
 
 
 
 
46
 
47
- <label for="token-input">Access Token</label>
48
- <input type="password" id="token-input" placeholder="syt_..." autocomplete="off" required>
 
 
 
 
 
49
 
50
- <button type="submit" class="btn-primary" id="login-token-submit">Sign In</button>
51
- </form>
 
 
 
52
 
53
- <div id="login-error" class="login-error hidden"></div>
 
 
 
 
 
 
 
 
 
54
 
55
- <p class="login-hint">
56
- Your credentials are sent directly to your homeserver over HTTPS.
57
- This client does <strong>not</strong> support end-to-end encryption —
58
- use <a href="https://element.io" target="_blank" rel="noopener">Element</a>
59
- for encrypted rooms.
60
- </p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  </div>
62
- </div>
63
-
64
- <!-- ===================== APP VIEW ===================== -->
65
- <div id="app-view" class="app-view hidden">
66
-
67
- <!-- Sidebar -->
68
- <aside class="sidebar">
69
- <div class="sidebar-user">
70
- <div class="avatar" id="user-avatar"></div>
71
- <div class="user-info">
72
- <div class="user-name" id="user-name"></div>
73
- <div class="user-id" id="user-id"></div>
 
 
 
74
  </div>
75
- <button class="icon-btn" id="logout-btn" title="Sign out" aria-label="Sign out">
76
- <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18.36 6.64a9 9 0 1 1-12.73 0"/><line x1="12" y1="2" x2="12" y2="12"/></svg>
77
- </button>
78
- </div>
79
-
80
- <div class="sidebar-actions">
81
- <button class="action-btn" id="create-room-btn">+ New Room</button>
82
- <button class="action-btn secondary" id="join-room-btn">Join Room</button>
83
- </div>
84
-
85
- <div class="room-search">
86
- <input type="text" id="room-search-input" placeholder="Filter rooms…" autocomplete="off">
87
- </div>
88
-
89
- <div class="room-list" id="room-list"></div>
90
-
91
- <div class="sidebar-status connecting" id="sync-status">
92
- <span class="status-dot"></span>
93
- <span class="status-text">Starting…</span>
94
- </div>
95
- </aside>
96
-
97
- <!-- Main panel -->
98
- <main class="main-panel">
99
- <div id="empty-state" class="empty-state">
100
- <div class="empty-logo">M</div>
101
- <h2>Select a room</h2>
102
- <p>Choose a room from the list on the left, or create / join a new one.</p>
103
- </div>
104
-
105
- <div id="chat-panel" class="chat-panel hidden">
106
- <header class="chat-header">
107
- <div class="avatar" id="chat-room-avatar"></div>
108
- <div class="chat-room-meta">
109
- <div class="chat-room-name" id="chat-room-name"></div>
110
- <div class="chat-room-topic" id="chat-room-topic"></div>
111
- </div>
112
- <div class="chat-room-count" id="chat-room-count"></div>
113
- <button class="icon-btn" id="leave-room-btn" title="Leave room" aria-label="Leave room">
114
- <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"/><polyline points="16 17 21 12 16 7"/><line x1="21" y1="12" x2="9" y2="12"/></svg>
115
- </button>
116
- </header>
117
-
118
- <div class="timeline" id="timeline"></div>
119
-
120
- <div class="composer">
121
- <button class="icon-btn attach-btn" id="attach-btn" title="Attach file" aria-label="Attach file">
122
- <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"/></svg>
123
- </button>
124
- <input type="file" id="file-input" class="hidden" multiple>
125
- <textarea id="composer-input" rows="1" placeholder="Send a message… (Enter to send, Shift+Enter for a new line)"></textarea>
126
- <button class="send-btn" id="send-btn" title="Send" aria-label="Send">
127
- <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="19" x2="12" y2="5"/><polyline points="5 12 12 5 19 12"/></svg>
128
- </button>
129
  </div>
130
- </div>
131
- </main>
132
- </div>
133
-
134
- <!-- ===================== CREATE ROOM MODAL ===================== -->
135
- <div id="create-room-modal" class="modal-overlay hidden">
136
- <div class="modal">
137
- <h2>Create Room</h2>
138
- <label for="create-room-name">Room name</label>
139
- <input type="text" id="create-room-name" placeholder="My room" autocomplete="off">
140
- <label for="create-room-alias">Room alias (optional)</label>
141
- <input type="text" id="create-room-alias" placeholder="#alias:server.com" autocomplete="off" spellcheck="false">
142
- <label for="create-room-visibility">Visibility</label>
143
- <select id="create-room-visibility">
144
- <option value="private">Private (invite only)</option>
145
- <option value="public">Public</option>
146
- </select>
147
- <div class="modal-actions">
148
- <button type="button" class="btn-ghost" data-close-modal>Cancel</button>
149
- <button type="button" class="btn-primary" id="create-room-confirm">Create</button>
150
- </div>
151
- <div id="create-room-error" class="modal-error hidden"></div>
152
  </div>
153
- </div>
154
-
155
- <!-- ===================== JOIN ROOM MODAL ===================== -->
156
- <div id="join-room-modal" class="modal-overlay hidden">
157
- <div class="modal">
158
- <h2>Join Room</h2>
159
- <label for="join-room-input">Room ID or alias</label>
160
- <input type="text" id="join-room-input" placeholder="#room:server.com" autocomplete="off" spellcheck="false">
161
- <div class="modal-actions">
162
- <button type="button" class="btn-ghost" data-close-modal>Cancel</button>
163
- <button type="button" class="btn-primary" id="join-room-confirm">Join</button>
164
- </div>
165
- <div id="join-room-error" class="modal-error hidden"></div>
166
  </div>
167
- </div>
168
 
169
- <div id="toast-container" class="toast-container"></div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
 
171
- <!-- matrix-js-sdk (UMD browser build) -->
172
- <script src="https://unpkg.com/matrix-js-sdk@latest/browser-matrix.js"></script>
173
- <script src="js/matrix-service.js"></script>
174
- <script src="js/app.js"></script>
175
  </body>
176
  </html>
 
1
  <!DOCTYPE html>
2
+ <html lang="ru">
3
  <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Matrix Web Client</title>
7
+ <style>
8
+ :root {
9
+ --bg-dark: #090d12;
10
+ --bg-sidebar: #111720;
11
+ --bg-card: #182230;
12
+ --bg-hover: #222e40;
13
+ --bg-input: #0d131c;
14
+ --border-color: #212e40;
15
+ --accent: #10b981;
16
+ --accent-hover: #059669;
17
+ --accent-glow: rgba(16, 185, 129, 0.2);
18
+ --text-main: #f1f5f9;
19
+ --text-muted: #8b9bb4;
20
+ --danger: #ef4444;
21
+ --danger-hover: #dc2626;
22
+ --radius-lg: 14px;
23
+ --radius-md: 10px;
24
+ --radius-sm: 6px;
25
+ --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
26
+ }
27
+
28
+ .theme-matrix {
29
+ --bg-dark: #040a05;
30
+ --bg-sidebar: #0a140b;
31
+ --bg-card: #0e1f10;
32
+ --bg-hover: #152e18;
33
+ --bg-input: #060e07;
34
+ --border-color: #17381b;
35
+ --accent: #00ff66;
36
+ --accent-hover: #00cc52;
37
+ --accent-glow: rgba(0, 255, 102, 0.2);
38
+ --text-main: #00ff66;
39
+ --text-muted: #00aa44;
40
+ }
41
+
42
+ .theme-light {
43
+ --bg-dark: #f1f5f9;
44
+ --bg-sidebar: #ffffff;
45
+ --bg-card: #f8fafc;
46
+ --bg-hover: #e2e8f0;
47
+ --bg-input: #ffffff;
48
+ --border-color: #cbd5e1;
49
+ --accent: #2563eb;
50
+ --accent-hover: #1d4ed8;
51
+ --accent-glow: rgba(37, 99, 235, 0.2);
52
+ --text-main: #0f172a;
53
+ --text-muted: #64748b;
54
+ }
55
+
56
+ * {
57
+ box-sizing: border-box;
58
+ margin: 0;
59
+ padding: 0;
60
+ font-family: var(--font-family);
61
+ }
62
+
63
+ body, html {
64
+ height: 100%;
65
+ width: 100%;
66
+ background-color: var(--bg-dark);
67
+ color: var(--text-main);
68
+ overflow: hidden;
69
+ }
70
+
71
+ /* App Layout */
72
+ #appContainer {
73
+ display: flex;
74
+ height: 100vh;
75
+ width: 100vw;
76
+ }
77
+
78
+ /* Nav Sidebar */
79
+ .nav-bar {
80
+ width: 64px;
81
+ background: var(--bg-sidebar);
82
+ border-right: 1px solid var(--border-color);
83
+ display: flex;
84
+ flex-direction: column;
85
+ align-items: center;
86
+ padding: 16px 0;
87
+ gap: 16px;
88
+ z-index: 20;
89
+ flex-shrink: 0;
90
+ }
91
+
92
+ .nav-logo {
93
+ width: 42px;
94
+ height: 42px;
95
+ background: var(--accent-glow);
96
+ color: var(--accent);
97
+ border-radius: var(--radius-md);
98
+ display: flex;
99
+ align-items: center;
100
+ justify-content: center;
101
+ font-weight: bold;
102
+ font-size: 20px;
103
+ }
104
+
105
+ .nav-btn {
106
+ width: 44px;
107
+ height: 44px;
108
+ border-radius: var(--radius-md);
109
+ background: transparent;
110
+ border: none;
111
+ color: var(--text-muted);
112
+ cursor: pointer;
113
+ display: flex;
114
+ align-items: center;
115
+ justify-content: center;
116
+ position: relative;
117
+ transition: all 0.2s;
118
+ }
119
+
120
+ .nav-btn:hover, .nav-btn.active {
121
+ background: var(--bg-hover);
122
+ color: var(--text-main);
123
+ }
124
+
125
+ .nav-btn.active {
126
+ color: var(--accent);
127
+ border-left: 3px solid var(--accent);
128
+ border-radius: 0 var(--radius-md) var(--radius-md) 0;
129
+ }
130
+
131
+ .badge {
132
+ position: absolute;
133
+ top: 4px;
134
+ right: 4px;
135
+ background: var(--accent);
136
+ color: #000;
137
+ font-size: 10px;
138
+ font-weight: bold;
139
+ border-radius: 10px;
140
+ padding: 2px 6px;
141
+ }
142
+
143
+ /* List Sidebar */
144
+ .list-sidebar {
145
+ width: 320px;
146
+ background: var(--bg-sidebar);
147
+ border-right: 1px solid var(--border-color);
148
+ display: flex;
149
+ flex-direction: column;
150
+ flex-shrink: 0;
151
+ }
152
+
153
+ .sidebar-header {
154
+ padding: 16px;
155
+ border-bottom: 1px solid var(--border-color);
156
+ display: flex;
157
+ flex-direction: column;
158
+ gap: 12px;
159
+ }
160
+
161
+ .sidebar-title-row {
162
+ display: flex;
163
+ align-items: center;
164
+ justify-content: space-between;
165
+ }
166
+
167
+ .sidebar-title {
168
+ font-size: 18px;
169
+ font-weight: 700;
170
+ }
171
+
172
+ .action-btns {
173
+ display: flex;
174
+ gap: 6px;
175
+ }
176
+
177
+ .btn-sm {
178
+ padding: 6px 10px;
179
+ font-size: 12px;
180
+ font-weight: 600;
181
+ border-radius: var(--radius-sm);
182
+ border: none;
183
+ cursor: pointer;
184
+ background: var(--accent);
185
+ color: #000;
186
+ transition: background 0.2s;
187
+ }
188
+
189
+ .btn-sm:hover {
190
+ background: var(--accent-hover);
191
+ }
192
+
193
+ .btn-secondary {
194
+ background: var(--bg-card);
195
+ color: var(--text-main);
196
+ border: 1px solid var(--border-color);
197
+ }
198
+
199
+ .btn-secondary:hover {
200
+ background: var(--bg-hover);
201
+ }
202
+
203
+ .search-input {
204
+ width: 100%;
205
+ padding: 8px 12px;
206
+ background: var(--bg-input);
207
+ border: 1px solid var(--border-color);
208
+ border-radius: var(--radius-md);
209
+ color: var(--text-main);
210
+ font-size: 13px;
211
+ outline: none;
212
+ }
213
+
214
+ .search-input:focus {
215
+ border-color: var(--accent);
216
+ }
217
+
218
+ .room-list {
219
+ flex: 1;
220
+ overflow-y: auto;
221
+ padding: 8px;
222
+ display: flex;
223
+ flex-direction: column;
224
+ gap: 4px;
225
+ }
226
+
227
+ .room-item {
228
+ display: flex;
229
+ align-items: center;
230
+ gap: 12px;
231
+ padding: 10px 12px;
232
+ border-radius: var(--radius-md);
233
+ cursor: pointer;
234
+ transition: background 0.15s;
235
+ user-select: none;
236
+ }
237
+
238
+ .room-item:hover {
239
+ background: var(--bg-hover);
240
+ }
241
+
242
+ .room-item.active {
243
+ background: var(--bg-card);
244
+ border: 1px solid var(--border-color);
245
+ }
246
+
247
+ .avatar {
248
+ width: 40px;
249
+ height: 40px;
250
+ border-radius: var(--radius-md);
251
+ object-fit: cover;
252
+ background: var(--bg-card);
253
+ display: flex;
254
+ align-items: center;
255
+ justify-content: center;
256
+ font-weight: bold;
257
+ color: var(--accent);
258
+ border: 1px solid var(--border-color);
259
+ flex-shrink: 0;
260
+ }
261
+
262
+ .room-info {
263
+ flex: 1;
264
+ min-width: 0;
265
+ }
266
+
267
+ .room-name-row {
268
+ display: flex;
269
+ justify-content: space-between;
270
+ align-items: center;
271
+ }
272
+
273
+ .room-name {
274
+ font-size: 14px;
275
+ font-weight: 600;
276
+ white-space: nowrap;
277
+ overflow: hidden;
278
+ text-overflow: ellipsis;
279
+ }
280
+
281
+ .room-topic {
282
+ font-size: 12px;
283
+ color: var(--text-muted);
284
+ white-space: nowrap;
285
+ overflow: hidden;
286
+ text-overflow: ellipsis;
287
+ margin-top: 2px;
288
+ }
289
+
290
+ /* Workspace Main */
291
+ .workspace {
292
+ flex: 1;
293
+ display: flex;
294
+ flex-direction: column;
295
+ background: var(--bg-dark);
296
+ min-width: 0;
297
+ position: relative;
298
+ }
299
+
300
+ .chat-header {
301
+ height: 64px;
302
+ padding: 0 20px;
303
+ border-bottom: 1px solid var(--border-color);
304
+ display: flex;
305
+ align-items: center;
306
+ justify-content: space-between;
307
+ background: var(--bg-sidebar);
308
+ min-width: 0;
309
+ }
310
+
311
+ .chat-header-info {
312
+ display: flex;
313
+ align-items: center;
314
+ gap: 12px;
315
+ min-width: 0;
316
+ }
317
+
318
+ .chat-title-group {
319
+ min-width: 0;
320
+ }
321
+
322
+ .chat-title {
323
+ font-size: 16px;
324
+ font-weight: 700;
325
+ white-space: nowrap;
326
+ overflow: hidden;
327
+ text-overflow: ellipsis;
328
+ }
329
+
330
+ .chat-subtitle {
331
+ font-size: 12px;
332
+ color: var(--text-muted);
333
+ white-space: nowrap;
334
+ overflow: hidden;
335
+ text-overflow: ellipsis;
336
+ }
337
+
338
+ .timeline {
339
+ flex: 1;
340
+ overflow-y: auto;
341
+ padding: 20px;
342
+ display: flex;
343
+ flex-direction: column;
344
+ gap: 12px;
345
+ }
346
+
347
+ .message-group {
348
+ display: flex;
349
+ flex-direction: column;
350
+ max-width: 75%;
351
+ }
352
+
353
+ .message-group.me {
354
+ align-self: flex-end;
355
+ align-items: flex-end;
356
+ }
357
+
358
+ .message-group.other {
359
+ align-self: flex-start;
360
+ align-items: flex-start;
361
+ }
362
+
363
+ .message-header {
364
+ display: flex;
365
+ align-items: center;
366
+ gap: 8px;
367
+ margin-bottom: 4px;
368
+ font-size: 11px;
369
+ }
370
+
371
+ .sender-name {
372
+ font-weight: 600;
373
+ color: var(--accent);
374
+ }
375
+
376
+ .message-time {
377
+ color: var(--text-muted);
378
+ }
379
+
380
+ .message-bubble {
381
+ padding: 10px 14px;
382
+ border-radius: 14px;
383
+ font-size: 14px;
384
+ line-height: 1.4;
385
+ word-break: break-word;
386
+ white-space: pre-wrap;
387
+ position: relative;
388
+ }
389
+
390
+ .message-group.me .message-bubble {
391
+ background: var(--accent);
392
+ color: #000;
393
+ border-top-right-radius: 2px;
394
+ }
395
+
396
+ .message-group.other .message-bubble {
397
+ background: var(--bg-card);
398
+ border: 1px solid var(--border-color);
399
+ color: var(--text-main);
400
+ border-top-left-radius: 2px;
401
+ }
402
+
403
+ .reply-quote {
404
+ background: rgba(0, 0, 0, 0.15);
405
+ border-left: 3px solid var(--accent);
406
+ padding: 6px 10px;
407
+ border-radius: 4px;
408
+ font-size: 12px;
409
+ margin-bottom: 6px;
410
+ }
411
+
412
+ /* Input Footer */
413
+ .chat-footer {
414
+ padding: 16px;
415
+ border-top: 1px solid var(--border-color);
416
+ background: var(--bg-sidebar);
417
+ display: flex;
418
+ flex-direction: column;
419
+ gap: 8px;
420
+ }
421
+
422
+ .reply-banner {
423
+ display: flex;
424
+ align-items: center;
425
+ justify-content: space-between;
426
+ background: var(--bg-card);
427
+ padding: 6px 12px;
428
+ border-radius: var(--radius-sm);
429
+ border-left: 3px solid var(--accent);
430
+ font-size: 12px;
431
+ }
432
+
433
+ .input-row {
434
+ display: flex;
435
+ align-items: center;
436
+ gap: 8px;
437
+ }
438
+
439
+ .chat-input {
440
+ flex: 1;
441
+ padding: 12px 16px;
442
+ background: var(--bg-input);
443
+ border: 1px solid var(--border-color);
444
+ border-radius: var(--radius-md);
445
+ color: var(--text-main);
446
+ font-size: 14px;
447
+ outline: none;
448
+ }
449
+
450
+ .chat-input:focus {
451
+ border-color: var(--accent);
452
+ }
453
+
454
+ .icon-btn {
455
+ padding: 10px;
456
+ background: var(--bg-card);
457
+ border: 1px solid var(--border-color);
458
+ border-radius: var(--radius-md);
459
+ color: var(--text-main);
460
+ cursor: pointer;
461
+ display: flex;
462
+ align-items: center;
463
+ justify-content: center;
464
+ }
465
+
466
+ .icon-btn:hover {
467
+ background: var(--bg-hover);
468
+ }
469
+
470
+ /* Modals & Overlays */
471
+ .modal-overlay {
472
+ position: fixed;
473
+ inset: 0;
474
+ background: rgba(0, 0, 0, 0.75);
475
+ backdrop-filter: blur(4px);
476
+ z-index: 100;
477
+ display: flex;
478
+ align-items: center;
479
+ justify-content: center;
480
+ padding: 20px;
481
+ }
482
+
483
+ .modal-card {
484
+ background: var(--bg-sidebar);
485
+ border: 1px solid var(--border-color);
486
+ border-radius: var(--radius-lg);
487
+ width: 100%;
488
+ max-width: 480px;
489
+ padding: 24px;
490
+ display: flex;
491
+ flex-direction: column;
492
+ gap: 16px;
493
+ box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
494
+ }
495
+
496
+ .modal-header {
497
+ display: flex;
498
+ justify-content: space-between;
499
+ align-items: center;
500
+ font-size: 18px;
501
+ font-weight: bold;
502
+ }
503
+
504
+ .form-group {
505
+ display: flex;
506
+ flex-direction: column;
507
+ gap: 6px;
508
+ }
509
+
510
+ .form-label {
511
+ font-size: 12px;
512
+ font-weight: 600;
513
+ color: var(--text-muted);
514
+ text-transform: uppercase;
515
+ }
516
+
517
+ .form-input, .form-select {
518
+ padding: 10px 14px;
519
+ background: var(--bg-input);
520
+ border: 1px solid var(--border-color);
521
+ border-radius: var(--radius-md);
522
+ color: var(--text-main);
523
+ font-size: 14px;
524
+ outline: none;
525
+ }
526
+
527
+ .form-input:focus, .form-select:focus {
528
+ border-color: var(--accent);
529
+ }
530
+
531
+ /* Custom Context Menu */
532
+ .context-menu {
533
+ position: fixed;
534
+ background: var(--bg-card);
535
+ border: 1px solid var(--border-color);
536
+ border-radius: var(--radius-md);
537
+ box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
538
+ padding: 6px;
539
+ z-index: 200;
540
+ display: flex;
541
+ flex-direction: column;
542
+ gap: 2px;
543
+ min-width: 160px;
544
+ }
545
+
546
+ .context-item {
547
+ padding: 8px 12px;
548
+ font-size: 13px;
549
+ border-radius: var(--radius-sm);
550
+ cursor: pointer;
551
+ color: var(--text-main);
552
+ display: flex;
553
+ align-items: center;
554
+ gap: 8px;
555
+ }
556
+
557
+ .context-item:hover {
558
+ background: var(--bg-hover);
559
+ }
560
+
561
+ .context-item.danger {
562
+ color: var(--danger);
563
+ }
564
+
565
+ .context-item.danger:hover {
566
+ background: rgba(239, 68, 68, 0.1);
567
+ }
568
+
569
+ /* Media Previews */
570
+ .media-img {
571
+ max-width: 320px;
572
+ max-height: 240px;
573
+ border-radius: var(--radius-md);
574
+ cursor: pointer;
575
+ margin-top: 4px;
576
+ object-fit: cover;
577
+ }
578
+
579
+ .media-video {
580
+ max-width: 340px;
581
+ border-radius: var(--radius-md);
582
+ margin-top: 4px;
583
+ }
584
+
585
+ .hidden { display: none !important; }
586
+ </style>
587
  </head>
588
+ <body id="appBody">
589
+
590
+ <!-- Toast Notifications Container -->
591
+ <div id="toastContainer" style="position: fixed; top: 20px; right: 20px; z-index: 300; display: flex; flex-direction: column; gap: 8px;"></div>
592
+
593
+ <!-- Right Click Context Menu -->
594
+ <div id="customContextMenu" class="context-menu hidden"></div>
595
+
596
+ <!-- LOGIN SCREEN -->
597
+ <div id="loginView" style="height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;">
598
+ <div class="modal-card" style="max-width: 400px;">
599
+ <div style="text-align: center; margin-bottom: 8px;">
600
+ <div class="nav-logo" style="margin: 0 auto 12px auto; width: 56px; height: 56px; font-size: 28px;">M</div>
601
+ <h1 style="font-size: 22px;">Вход в Matrix</h1>
602
+ <p style="font-size: 13px; color: var(--text-muted); margin-top: 4px;">Выберите сервер и войдите в систему</p>
603
+ </div>
604
+
605
+ <form onsubmit="handleLogin(event)" style="display: flex; flex-direction: column; gap: 14px;">
606
+ <div class="form-group">
607
+ <label class="form-label">Сервер (Homeserver)</label>
608
+ <select id="hsSelect" class="form-select" onchange="toggleCustomServerInput()">
609
+ <option value="https://matrix.org">matrix.org</option>
610
+ <option value="https://matrix.unredacted.org">matrix.unredacted.org</option>
611
+ <option value="https://matrix.envs.net">matrix.envs.net</option>
612
+ <option value="https://mozilla.org">mozilla.org</option>
613
+ <option value="custom">Свой сервер...</option>
614
+ </select>
615
+ <input type="url" id="hsCustomInput" class="form-input hidden" style="margin-top: 6px;" placeholder="https://your-homeserver.com">
616
+ </div>
617
+
618
+ <div class="form-group">
619
+ <label class="form-label">Способ входа</label>
620
+ <select id="authTypeSelect" class="form-select" onchange="toggleAuthFields()">
621
+ <option value="password">Логин и Пароль</option>
622
+ <option value="token">Access Token</option>
623
+ </select>
624
+ </div>
625
+
626
+ <div id="passAuthFields" class="form-group" style="gap: 12px;">
627
+ <div class="form-group">
628
+ <label class="form-label">Никнейм / MXID</label>
629
+ <input type="text" id="userInput" class="form-input" placeholder="username или @user:server.org">
630
+ </div>
631
+ <div class="form-group">
632
+ <label class="form-label">Пароль</label>
633
+ <input type="password" id="passInput" class="form-input" placeholder="••••••••">
634
+ </div>
635
+ </div>
636
+
637
+ <div id="tokenAuthFields" class="form-group hidden">
638
+ <label class="form-label">Access Token</label>
639
+ <input type="password" id="tokenInput" class="form-input" placeholder="syt_...">
640
+ </div>
641
 
642
+ <button type="submit" id="loginBtn" class="btn-sm" style="padding: 12px; font-size: 14px; margin-top: 8px;">Войти</button>
643
+ </form>
644
+ </div>
645
+ </div>
 
 
646
 
647
+ <!-- MAIN APP INTERFACE -->
648
+ <div id="mainView" class="hidden" style="height: 100vh; width: 100vw; display: flex;">
649
+ <!-- Left Nav Sidebar -->
650
+ <div class="nav-bar">
651
+ <div class="nav-logo">M</div>
652
+ <button onclick="switchTab('chats')" id="tabBtn-chats" class="nav-btn active" title="Чаты">💬</button>
653
+ <button onclick="switchTab('dms')" id="tabBtn-dms" class="nav-btn" title="Личные сообщения">👤</button>
654
+ <button onclick="switchTab('inbox')" id="tabBtn-inbox" class="nav-btn" title="Приглашения">
655
+ 📥 <span id="inboxBadge" class="badge hidden">0</span>
656
+ </button>
657
+ <button onclick="switchTab('settings')" id="tabBtn-settings" class="nav-btn" title="Настройки">⚙️</button>
658
+ <button onclick="logout()" class="nav-btn" style="margin-top: auto; color: var(--danger);" title="Выйти">🚪</button>
659
+ </div>
660
 
661
+ <!-- Secondary List Sidebar -->
662
+ <div class="list-sidebar">
663
+ <div class="sidebar-header">
664
+ <div class="sidebar-title-row">
665
+ <h2 id="sidebarTitle" class="sidebar-title">Чаты</h2>
666
+ <div id="chatActionBtns" class="action-btns">
667
+ <button onclick="openModal('createDmModal')" class="btn-sm btn-secondary" title="Начать ЛС">👤 +</button>
668
+ <button onclick="openModal('createRoomModal')" class="btn-sm" title="Создать комнату">+</button>
669
+ <button onclick="openModal('joinRoomModal')" class="btn-sm btn-secondary" title="Присоединиться">🔗</button>
670
+ </div>
671
+ </div>
672
+ <input type="text" id="searchInput" class="search-input" oninput="filterRooms()" placeholder="Поиск...">
673
+ </div>
674
 
675
+ <div id="listContainer" class="room-list"></div>
676
+ </div>
677
 
678
+ <!-- Main Workspace -->
679
+ <div class="workspace">
680
+
681
+ <!-- Chat View -->
682
+ <div id="chatView" style="height: 100%; display: flex; flex-direction: column;">
683
+ <div class="chat-header">
684
+ <div class="chat-header-info">
685
+ <div id="currentRoomAvatar" class="avatar">#</div>
686
+ <div class="chat-title-group">
687
+ <h3 id="currentRoomName" class="chat-title">Выберите чат</h3>
688
+ <p id="currentRoomTopic" class="chat-subtitle">Matrix Client</p>
689
+ </div>
690
+ </div>
691
+ <button onclick="openCurrentRoomDetails()" class="btn-sm btn-secondary">Инфо</button>
692
+ </div>
693
 
694
+ <div id="messageTimeline" class="timeline">
695
+ <div style="margin: auto; color: var(--text-muted); text-align: center; font-size: 14px;">
696
+ Выберите комнату или личное сообщение из списка слева
697
+ </div>
698
+ </div>
699
 
700
+ <div class="chat-footer">
701
+ <div id="replyBanner" class="reply-banner hidden">
702
+ <span id="replyText">Ответ на сообщение...</span>
703
+ <button onclick="cancelReply()" style="background:none; border:none; color:var(--text-muted); cursor:pointer;">✕</button>
704
+ </div>
705
+ <form onsubmit="sendMessage(event)" class="input-row">
706
+ <label class="icon-btn" title="Отправить файл">
707
+ 📎 <input type="file" id="fileInput" onchange="sendFile(this)" style="display: none;">
708
+ </label>
709
+ <input type="text" id="msgInput" class="chat-input" placeholder="Написать сообщение..." autocomplete="off">
710
+ <button type="submit" class="btn-sm" style="padding: 12px 20px;">Отправить</button>
711
+ </form>
712
+ </div>
713
+ </div>
714
 
715
+ <!-- Settings View -->
716
+ <div id="settingsView" class="hidden" style="padding: 40px; overflow-y: auto;">
717
+ <div style="max-width: 500px; margin: 0 auto; display: flex; flex-direction: column; gap: 24px;">
718
+ <h2>Настройки профиля</h2>
719
+
720
+ <div class="modal-card">
721
+ <div style="display: flex; align-items: center; gap: 20px;">
722
+ <div id="settingsAvatarPreview" class="avatar" style="width: 72px; height: 72px; font-size: 24px;">?</div>
723
+ <label class="btn-sm btn-secondary" style="cursor: pointer;">
724
+ Изменить аватар
725
+ <input type="file" accept="image/*" onchange="uploadProfileAvatar(this)" style="display: none;">
726
+ </label>
727
+ </div>
728
 
729
+ <div class="form-group">
730
+ <label class="form-label">Отображаемое имя</label>
731
+ <div style="display: flex; gap: 8px;">
732
+ <input type="text" id="settingsDisplayName" class="form-input" style="flex:1;">
733
+ <button onclick="saveDisplayName()" class="btn-sm">Сохранить</button>
734
+ </div>
735
+ </div>
736
 
737
+ <div class="form-group">
738
+ <label class="form-label">Мой User ID</label>
739
+ <input type="text" id="settingsUserId" class="form-input" readonly style="opacity: 0.7;">
740
+ </div>
741
+ </div>
742
 
743
+ <div class="modal-card">
744
+ <h3>Тема оформления</h3>
745
+ <div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 10px;">
746
+ <button onclick="setAppTheme('dark')" class="btn-sm btn-secondary" style="padding: 16px;">Dark</button>
747
+ <button onclick="setAppTheme('matrix')" class="btn-sm btn-secondary" style="padding: 16px; color:#00ff66;">Matrix</button>
748
+ <button onclick="setAppTheme('light')" class="btn-sm btn-secondary" style="padding: 16px; color:#0f172a;">Light</button>
749
+ </div>
750
+ </div>
751
+ </div>
752
+ </div>
753
 
754
+ </div>
755
+ </div>
756
+
757
+ <!-- MODALS -->
758
+ <!-- Create Room Modal -->
759
+ <div id="createRoomModal" class="modal-overlay hidden">
760
+ <div class="modal-card">
761
+ <div class="modal-header">
762
+ <span>Создать комнату</span>
763
+ <button onclick="closeModal('createRoomModal')" style="background:none; border:none; color:var(--text-main); cursor:pointer;">✕</button>
764
+ </div>
765
+ <form onsubmit="handleCreateRoom(event)" style="display: flex; flex-direction: column; gap: 12px;">
766
+ <div class="form-group">
767
+ <label class="form-label">Название *</label>
768
+ <input type="text" id="newRoomName" class="form-input" required>
769
+ </div>
770
+ <div class="form-group">
771
+ <label class="form-label">Тема (Topic)</label>
772
+ <input type="text" id="newRoomTopic" class="form-input">
773
+ </div>
774
+ <div class="form-group">
775
+ <label class="form-label">Аватарка комнаты</label>
776
+ <input type="file" id="newRoomAvatarFile" accept="image/*" class="form-input">
777
+ </div>
778
+ <div class="form-group">
779
+ <label class="form-label">Алиас (Ссылка)</label>
780
+ <input type="text" id="newRoomAlias" class="form-input" placeholder="my-room">
781
+ </div>
782
+ <div style="display: flex; align-items: center; gap: 8px;">
783
+ <input type="checkbox" id="newRoomPublic">
784
+ <label for="newRoomPublic" style="font-size: 13px;">Публичная комната</label>
785
+ </div>
786
+ <button type="submit" class="btn-sm" style="padding: 12px; margin-top: 8px;">Создать</button>
787
+ </form>
788
+ </div>
789
+ </div>
790
+
791
+ <!-- Start DM Modal -->
792
+ <div id="createDmModal" class="modal-overlay hidden">
793
+ <div class="modal-card">
794
+ <div class="modal-header">
795
+ <span>Написать пользователю (ЛС)</span>
796
+ <button onclick="closeModal('createDmModal')" style="background:none; border:none; color:var(--text-main); cursor:pointer;">✕</button>
797
+ </div>
798
+ <form onsubmit="handleStartDm(event)" style="display: flex; flex-direction: column; gap: 12px;">
799
+ <div class="form-group">
800
+ <label class="form-label">Matrix ID пользователя *</label>
801
+ <input type="text" id="dmUserIdInput" class="form-input" required placeholder="@user:matrix.org">
802
+ </div>
803
+ <button type="submit" class="btn-sm" style="padding: 12px; margin-top: 8px;">Начать чат</button>
804
+ </form>
805
+ </div>
806
  </div>
807
+
808
+ <!-- Join Room Modal -->
809
+ <div id="joinRoomModal" class="modal-overlay hidden">
810
+ <div class="modal-card">
811
+ <div class="modal-header">
812
+ <span>Присоединиться к комнате</span>
813
+ <button onclick="closeModal('joinRoomModal')" style="background:none; border:none; color:var(--text-main); cursor:pointer;">✕</button>
814
+ </div>
815
+ <form onsubmit="handleJoinRoom(event)" style="display: flex; flex-direction: column; gap: 12px;">
816
+ <div class="form-group">
817
+ <label class="form-label">ID или Алиас комнаты *</label>
818
+ <input type="text" id="joinRoomInput" class="form-input" required placeholder="#room:matrix.org или !id:matrix.org">
819
+ </div>
820
+ <button type="submit" class="btn-sm" style="padding: 12px; margin-top: 8px;">Войти</button>
821
+ </form>
822
  </div>
823
+ </div>
824
+
825
+ <!-- Room Info Modal -->
826
+ <div id="roomDetailsModal" class="modal-overlay hidden">
827
+ <div class="modal-card">
828
+ <div class="modal-header">
829
+ <span>Информация о комнате</span>
830
+ <button onclick="closeModal('roomDetailsModal')" style="background:none; border:none; color:var(--text-main); cursor:pointer;">✕</button>
831
+ </div>
832
+ <div style="display: flex; flex-direction: column; items-center; gap: 12px; text-align: center;">
833
+ <div id="infoModalAvatar" class="avatar" style="width: 64px; height: 64px; margin: 0 auto; font-size: 24px;">#</div>
834
+ <h3 id="infoModalName"></h3>
835
+ <p id="infoModalTopic" style="font-size: 13px; color: var(--text-muted);"></p>
836
+ <div class="form-group" style="text-align: left; width: 100%; margin-top: 12px;">
837
+ <label class="form-label">Room ID</label>
838
+ <input type="text" id="infoModalId" class="form-input" readonly>
839
+ </div>
840
+ <button onclick="leaveCurrentRoom()" class="btn-sm" style="background: var(--danger); color: white; width: 100%; margin-top: 12px;">Выйти из комнаты</button>
841
+ </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
842
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
843
  </div>
844
+
845
+ <!-- Image Preview Modal -->
846
+ <div id="imageViewerModal" class="modal-overlay hidden" onclick="closeModal('imageViewerModal')">
847
+ <img id="fullImageView" src="" style="max-width: 90vw; max-height: 90vh; border-radius: var(--radius-md); object-fit: contain;">
 
 
 
 
 
 
 
 
 
848
  </div>
 
849
 
850
+ <script>
851
+ const state = {
852
+ hsUrl: '',
853
+ accessToken: '',
854
+ userId: '',
855
+ nextBatch: '',
856
+ rooms: {},
857
+ invites: {},
858
+ currentRoomId: null,
859
+ activeTab: 'chats', // 'chats' | 'dms' | 'inbox' | 'settings'
860
+ syncing: false,
861
+ replyToEvent: null,
862
+ contextTarget: null
863
+ };
864
+
865
+ // Utility: Show Toast Notifications
866
+ function showToast(msg, isError = false) {
867
+ const container = document.getElementById('toastContainer');
868
+ const toast = document.createElement('div');
869
+ toast.style.cssText = `
870
+ padding: 12px 16px;
871
+ border-radius: 8px;
872
+ background: ${isError ? '#ef4444' : '#182230'};
873
+ color: #fff;
874
+ font-size: 13px;
875
+ border: 1px solid var(--border-color);
876
+ box-shadow: 0 10px 15px -3px rgba(0,0,0,0.5);
877
+ transition: opacity 0.3s;
878
+ `;
879
+ toast.innerText = msg;
880
+ container.appendChild(toast);
881
+ setTimeout(() => {
882
+ toast.style.opacity = '0';
883
+ setTimeout(() => toast.remove(), 300);
884
+ }, 3000);
885
+ }
886
+
887
+ // Convert MXC URI to HTTP
888
+ function mxcToHttp(mxcUrl) {
889
+ if (!mxcUrl || !mxcUrl.startsWith('mxc://')) return null;
890
+ const parts = mxcUrl.substring(6).split('/');
891
+ if (parts.length < 2) return null;
892
+ return `${state.hsUrl}/_matrix/media/v3/download/${parts[0]}/${parts[1]}`;
893
+ }
894
+
895
+ // Matrix API Client helper
896
+ async function apiReq(endpoint, method = 'GET', body = null, isRaw = false) {
897
+ const headers = {};
898
+ if (state.accessToken) headers['Authorization'] = `Bearer ${state.accessToken}`;
899
+ if (body && !isRaw) headers['Content-Type'] = 'application/json';
900
+
901
+ const opts = { method, headers };
902
+ if (body) opts.body = isRaw ? body : JSON.stringify(body);
903
+
904
+ try {
905
+ const res = await fetch(`${state.hsUrl}/_matrix/${endpoint}`, opts);
906
+ const data = await res.json();
907
+ if (!res.ok) throw new Error(data.error || data.errcode || 'API Error');
908
+ return data;
909
+ } catch (err) {
910
+ console.error(`API Error [${endpoint}]:`, err);
911
+ throw err;
912
+ }
913
+ }
914
+
915
+ // Login Handler
916
+ function toggleCustomServerInput() {
917
+ const select = document.getElementById('hsSelect');
918
+ const customInput = document.getElementById('hsCustomInput');
919
+ if (select.value === 'custom') {
920
+ customInput.classList.remove('hidden');
921
+ } else {
922
+ customInput.classList.add('hidden');
923
+ }
924
+ }
925
+
926
+ function toggleAuthFields() {
927
+ const type = document.getElementById('authTypeSelect').value;
928
+ if (type === 'password') {
929
+ document.getElementById('passAuthFields').classList.remove('hidden');
930
+ document.getElementById('tokenAuthFields').classList.add('hidden');
931
+ } else {
932
+ document.getElementById('passAuthFields').classList.add('hidden');
933
+ document.getElementById('tokenAuthFields').classList.remove('hidden');
934
+ }
935
+ }
936
+
937
+ async function handleLogin(e) {
938
+ e.preventDefault();
939
+ const selectVal = document.getElementById('hsSelect').value;
940
+ state.hsUrl = (selectVal === 'custom' ? document.getElementById('hsCustomInput').value : selectVal).trim().replace(/\/$/, '');
941
+
942
+ if (!state.hsUrl) return showToast('Укажите корректный URL сервера', true);
943
+
944
+ const authType = document.getElementById('authTypeSelect').value;
945
+
946
+ try {
947
+ document.getElementById('loginBtn').innerText = 'Подключение...';
948
+
949
+ if (authType === 'token') {
950
+ const token = document.getElementById('tokenInput').value.trim();
951
+ if (!token) return showToast('Введите Access Token', true);
952
+ state.accessToken = token;
953
+ const res = await apiReq('client/v3/account/whoami');
954
+ state.userId = res.user_id;
955
+ } else {
956
+ const user = document.getElementById('userInput').value.trim();
957
+ const pass = document.getElementById('passInput').value;
958
+ const res = await apiReq('client/v3/login', 'POST', {
959
+ type: 'm.login.password',
960
+ identifier: { type: 'm.id.user', user: user },
961
+ password: pass
962
+ });
963
+ state.accessToken = res.access_token;
964
+ state.userId = res.user_id;
965
+ }
966
+
967
+ localStorage.setItem('matrix_hs', state.hsUrl);
968
+ localStorage.setItem('matrix_token', state.accessToken);
969
+ localStorage.setItem('matrix_user', state.userId);
970
+
971
+ initClient();
972
+ showToast('Успешный вход!');
973
+ } catch (err) {
974
+ showToast(`Ошибка входа: ${err.message}`, true);
975
+ } finally {
976
+ document.getElementById('loginBtn').innerText = 'Войти';
977
+ }
978
+ }
979
+
980
+ function checkSavedSession() {
981
+ const hs = localStorage.getItem('matrix_hs');
982
+ const token = localStorage.getItem('matrix_token');
983
+ const user = localStorage.getItem('matrix_user');
984
+ if (hs && token && user) {
985
+ state.hsUrl = hs;
986
+ state.accessToken = token;
987
+ state.userId = user;
988
+ initClient();
989
+ }
990
+ }
991
+
992
+ function logout() {
993
+ localStorage.clear();
994
+ location.reload();
995
+ }
996
+
997
+ function initClient() {
998
+ document.getElementById('loginView').classList.add('hidden');
999
+ document.getElementById('mainView').classList.remove('hidden');
1000
+ document.getElementById('settingsUserId').value = state.userId;
1001
+ loadUserProfile();
1002
+ startSync();
1003
+ }
1004
+
1005
+ async function loadUserProfile() {
1006
+ try {
1007
+ const data = await apiReq(`client/v3/profile/${encodeURIComponent(state.userId)}`);
1008
+ if (data.displayname) document.getElementById('settingsDisplayName').value = data.displayname;
1009
+ if (data.avatar_url) {
1010
+ const httpUrl = mxcToHttp(data.avatar_url);
1011
+ if (httpUrl) document.getElementById('settingsAvatarPreview').innerHTML = `<img src="${httpUrl}" class="avatar" style="width:100%; height:100%;">`;
1012
+ }
1013
+ } catch(e){}
1014
+ }
1015
+
1016
+ async function startSync() {
1017
+ if (state.syncing) return;
1018
+ state.syncing = true;
1019
+
1020
+ while (state.accessToken) {
1021
+ try {
1022
+ const timeout = state.nextBatch ? 30000 : 0;
1023
+ const endpoint = `client/v3/sync?timeout=${timeout}${state.nextBatch ? `&since=${state.nextBatch}` : ''}`;
1024
+ const data = await apiReq(endpoint);
1025
+
1026
+ state.nextBatch = data.next_batch;
1027
+ processSyncData(data);
1028
+ } catch (err) {
1029
+ await new Promise(r => setTimeout(r, 5000));
1030
+ }
1031
+ }
1032
+ }
1033
+
1034
+ function processSyncData(data) {
1035
+ if (data.rooms?.join) {
1036
+ for (const [roomId, roomData] of Object.entries(data.rooms.join)) {
1037
+ if (!state.rooms[roomId]) {
1038
+ state.rooms[roomId] = { name: roomId, topic: '', avatar: null, events: [], unread: 0, isDirect: false };
1039
+ }
1040
+ const room = state.rooms[roomId];
1041
+
1042
+ const allEvents = [...(roomData.state?.events || []), ...(roomData.timeline?.events || [])];
1043
+ for (const ev of allEvents) {
1044
+ if (ev.type === 'm.room.name' && ev.content.name) room.name = ev.content.name;
1045
+ if (ev.type === 'm.room.canonical_alias' && ev.content.alias && room.name === roomId) room.name = ev.content.alias;
1046
+ if (ev.type === 'm.room.topic' && ev.content.topic) room.topic = ev.content.topic;
1047
+ if (ev.type === 'm.room.avatar' && ev.content.url) room.avatar = mxcToHttp(ev.content.url);
1048
+
1049
+ if (ev.type === 'm.room.message') {
1050
+ if (!room.events.some(e => e.event_id === ev.event_id)) {
1051
+ room.events.push(ev);
1052
+ if (roomId !== state.currentRoomId) room.unread++;
1053
+ }
1054
+ }
1055
+ }
1056
+ }
1057
+ }
1058
+
1059
+ if (data.rooms?.invite) {
1060
+ state.invites = {};
1061
+ for (const [roomId, inviteData] of Object.entries(data.rooms.invite)) {
1062
+ let name = roomId;
1063
+ let inviter = 'Неизвестно';
1064
+ for (const ev of (inviteData.invite_state?.events || [])) {
1065
+ if (ev.type === 'm.room.name') name = ev.content.name;
1066
+ if (ev.type === 'm.room.member' && ev.state_key === state.userId) inviter = ev.sender;
1067
+ }
1068
+ state.invites[roomId] = { roomId, name, inviter };
1069
+ }
1070
+ }
1071
+
1072
+ updateUI();
1073
+ }
1074
+
1075
+ function updateUI() {
1076
+ const inviteCount = Object.keys(state.invites).length;
1077
+ const badge = document.getElementById('inboxBadge');
1078
+ badge.innerText = inviteCount;
1079
+ if (inviteCount > 0) badge.classList.remove('hidden'); else badge.classList.add('hidden');
1080
+
1081
+ renderSidebarList();
1082
+ if (state.currentRoomId) renderTimeline();
1083
+ }
1084
+
1085
+ function renderSidebarList() {
1086
+ const list = document.getElementById('listContainer');
1087
+ list.innerHTML = '';
1088
+
1089
+ if (state.activeTab === 'chats' || state.activeTab === 'dms') {
1090
+ const isDmTab = state.activeTab === 'dms';
1091
+ const entries = Object.entries(state.rooms).filter(([_, room]) => isDmTab ? room.isDirect : !room.isDirect);
1092
+
1093
+ if (entries.length === 0) {
1094
+ list.innerHTML = `<div style="text-align:center; padding:20px; font-size:12px; color:var(--text-muted);">${isDmTab ? 'Нет личных сообщений' : 'Нет комнат'}</div>`;
1095
+ return;
1096
+ }
1097
+
1098
+ entries.forEach(([id, room]) => {
1099
+ const item = document.createElement('div');
1100
+ item.className = `room-item ${id === state.currentRoomId ? 'active' : ''}`;
1101
+ item.onclick = () => selectRoom(id);
1102
+ item.oncontextmenu = (e) => showRoomContextMenu(e, id);
1103
+
1104
+ const avatarHtml = room.avatar
1105
+ ? `<img src="${room.avatar}" class="avatar">`
1106
+ : `<div class="avatar">${(room.name[0] || '#').toUpperCase()}</div>`;
1107
+
1108
+ item.innerHTML = `
1109
+ ${avatarHtml}
1110
+ <div class="room-info">
1111
+ <div class="room-name-row">
1112
+ <span class="room-name">${escapeHtml(room.name)}</span>
1113
+ ${room.unread > 0 ? `<span class="badge" style="position:static;">${room.unread}</span>` : ''}
1114
+ </div>
1115
+ <div class="room-topic">${escapeHtml(room.topic || 'Без описания')}</div>
1116
+ </div>
1117
+ `;
1118
+ list.appendChild(item);
1119
+ });
1120
+ } else if (state.activeTab === 'inbox') {
1121
+ const invites = Object.values(state.invites);
1122
+ if (invites.length === 0) {
1123
+ list.innerHTML = `<div style="text-align:center; padding:20px; font-size:12px; color:var(--text-muted);">Входящих приглашений нет</div>`;
1124
+ return;
1125
+ }
1126
+
1127
+ invites.forEach(inv => {
1128
+ const card = document.createElement('div');
1129
+ card.className = 'modal-card';
1130
+ card.style.padding = '12px';
1131
+ card.innerHTML = `
1132
+ <div style="font-weight:bold; font-size:14px;">${escapeHtml(inv.name)}</div>
1133
+ <div style="font-size:12px; color:var(--text-muted);">От: ${escapeHtml(inv.inviter)}</div>
1134
+ <div style="display:flex; gap:8px; margin-top:8px;">
1135
+ <button onclick="acceptInvite('${inv.roomId}')" class="btn-sm" style="flex:1;">Принять</button>
1136
+ <button onclick="rejectInvite('${inv.roomId}')" class="btn-sm btn-secondary" style="flex:1;">Отклонить</button>
1137
+ </div>
1138
+ `;
1139
+ list.appendChild(card);
1140
+ });
1141
+ }
1142
+ }
1143
+
1144
+ function selectRoom(roomId) {
1145
+ state.currentRoomId = roomId;
1146
+ if (state.rooms[roomId]) state.rooms[roomId].unread = 0;
1147
+
1148
+ const room = state.rooms[roomId];
1149
+ document.getElementById('currentRoomName').innerText = room ? room.name : roomId;
1150
+ document.getElementById('currentRoomTopic').innerText = room ? (room.topic || 'Без темы') : '';
1151
+
1152
+ const avatarEl = document.getElementById('currentRoomAvatar');
1153
+ if (room && room.avatar) avatarEl.innerHTML = `<img src="${room.avatar}" class="avatar" style="width:100%;height:100%;">`;
1154
+ else avatarEl.innerText = room ? (room.name[0] || '#').toUpperCase() : '#';
1155
+
1156
+ renderSidebarList();
1157
+ renderTimeline();
1158
+ }
1159
+
1160
+ function renderTimeline() {
1161
+ const container = document.getElementById('messageTimeline');
1162
+ container.innerHTML = '';
1163
+
1164
+ const room = state.rooms[state.currentRoomId];
1165
+ if (!room || room.events.length === 0) {
1166
+ container.innerHTML = `<div style="margin:auto; color:var(--text-muted); font-size:13px;">В этой комнате нет сообщений</div>`;
1167
+ return;
1168
+ }
1169
+
1170
+ room.events.forEach(ev => {
1171
+ const isMe = ev.sender === state.userId;
1172
+ const body = ev.content?.body || '';
1173
+ const time = new Date(ev.origin_server_ts).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
1174
+
1175
+ const group = document.createElement('div');
1176
+ group.className = `message-group ${isMe ? 'me' : 'other'}`;
1177
+ group.oncontextmenu = (e) => showMessageContextMenu(e, ev);
1178
+
1179
+ let contentHtml = escapeHtml(body);
1180
+ if (ev.content?.msgtype === 'm.image' && ev.content.url) {
1181
+ const imgUrl = mxcToHttp(ev.content.url);
1182
+ contentHtml = `<img src="${imgUrl}" class="media-img" onclick="openImageViewer('${imgUrl}')"><br>` + contentHtml;
1183
+ } else if (ev.content?.msgtype === 'm.video' && ev.content.url) {
1184
+ const videoUrl = mxcToHttp(ev.content.url);
1185
+ contentHtml = `<video src="${videoUrl}" controls class="media-video"></video><br>` + contentHtml;
1186
+ }
1187
+
1188
+ group.innerHTML = `
1189
+ <div class="message-header">
1190
+ <span class="sender-name">${escapeHtml(ev.sender)}</span>
1191
+ <span class="message-time">${time}</span>
1192
+ </div>
1193
+ <div class="message-bubble">${contentHtml}</div>
1194
+ `;
1195
+ container.appendChild(group);
1196
+ });
1197
+
1198
+ container.scrollTop = container.scrollHeight;
1199
+ }
1200
+
1201
+ function showRoomContextMenu(e, roomId) {
1202
+ e.preventDefault();
1203
+ closeContextMenu();
1204
+ const menu = document.getElementById('customContextMenu');
1205
+ menu.style.left = `${e.clientX}px`;
1206
+ menu.style.top = `${e.clientY}px`;
1207
+ menu.innerHTML = `
1208
+ <div class="context-item" onclick="openRoomDetailsModal('${roomId}')">ℹ️ Информация</div>
1209
+ <div class="context-item danger" onclick="leaveRoom('${roomId}')">🚪 Выйти из комнаты</div>
1210
+ `;
1211
+ menu.classList.remove('hidden');
1212
+ }
1213
+
1214
+ function showMessageContextMenu(e, ev) {
1215
+ e.preventDefault();
1216
+ closeContextMenu();
1217
+ state.contextTarget = ev;
1218
+ const menu = document.getElementById('customContextMenu');
1219
+ menu.style.left = `${e.clientX}px`;
1220
+ menu.style.top = `${e.clientY}px`;
1221
+ menu.innerHTML = `
1222
+ <div class="context-item" onclick="setReply('${ev.event_id}', '${escapeHtml(ev.content?.body)}')">↩️ Ответить</div>
1223
+ <div class="context-item danger" onclick="deleteMessageLocally('${ev.event_id}')">🗑️ Удалить у себя</div>
1224
+ `;
1225
+ menu.classList.remove('hidden');
1226
+ }
1227
+
1228
+ function closeContextMenu() {
1229
+ document.getElementById('customContextMenu').classList.add('hidden');
1230
+ }
1231
+
1232
+ document.addEventListener('click', closeContextMenu);
1233
+
1234
+ function setReply(eventId, text) {
1235
+ state.replyToEvent = eventId;
1236
+ document.getElementById('replyText').innerText = `Ответ: ${text}`;
1237
+ document.getElementById('replyBanner').classList.remove('hidden');
1238
+ }
1239
+
1240
+ function cancelReply() {
1241
+ state.replyToEvent = null;
1242
+ document.getElementById('replyBanner').classList.add('hidden');
1243
+ }
1244
+
1245
+ function deleteMessageLocally(eventId) {
1246
+ if (!state.currentRoomId) return;
1247
+ const room = state.rooms[state.currentRoomId];
1248
+ if (room) {
1249
+ room.events = room.events.filter(e => e.event_id !== eventId);
1250
+ renderTimeline();
1251
+ showToast('Сообщение удалено локально');
1252
+ }
1253
+ }
1254
+
1255
+ async function sendMessage(e) {
1256
+ e.preventDefault();
1257
+ if (!state.currentRoomId) return;
1258
+ const input = document.getElementById('msgInput');
1259
+ const body = input.value.trim();
1260
+ if (!body) return;
1261
+
1262
+ input.value = '';
1263
+ const txnId = 'm' + Date.now();
1264
+
1265
+ const payload = { msgtype: 'm.text', body };
1266
+ if (state.replyToEvent) {
1267
+ payload['m.relates_to'] = { 'm.in_reply_to': { event_id: state.replyToEvent } };
1268
+ cancelReply();
1269
+ }
1270
+
1271
+ try {
1272
+ await apiReq(`client/v3/rooms/${encodeURIComponent(state.currentRoomId)}/send/m.room.message/${txnId}`, 'PUT', payload);
1273
+ } catch (err) {
1274
+ showToast(`Ошибка отправки: ${err.message}`, true);
1275
+ }
1276
+ }
1277
+
1278
+ async function uploadMediaFile(file) {
1279
+ const res = await fetch(`${state.hsUrl}/_matrix/media/v3/upload`, {
1280
+ method: 'POST',
1281
+ headers: {
1282
+ 'Authorization': `Bearer ${state.accessToken}`,
1283
+ 'Content-Type': file.type || 'application/octet-stream'
1284
+ },
1285
+ body: file
1286
+ });
1287
+ const data = await res.json();
1288
+ if (!res.ok) throw new Error(data.error || 'Upload error');
1289
+ return data.content_uri;
1290
+ }
1291
+
1292
+ async function sendFile(input) {
1293
+ if (!input.files?.[0] || !state.currentRoomId) return;
1294
+ const file = input.files[0];
1295
+ try {
1296
+ showToast('Загрузка файла...');
1297
+ const mxcUrl = await uploadMediaFile(file);
1298
+ const txnId = 'm' + Date.now();
1299
+ const isImg = file.type.startsWith('image/');
1300
+ const isVid = file.type.startsWith('video/');
1301
+
1302
+ await apiReq(`client/v3/rooms/${encodeURIComponent(state.currentRoomId)}/send/m.room.message/${txnId}`, 'PUT', {
1303
+ msgtype: isImg ? 'm.image' : isVid ? 'm.video' : 'm.file',
1304
+ body: file.name,
1305
+ url: mxcUrl
1306
+ });
1307
+ showToast('Файл отправлен');
1308
+ } catch (err) {
1309
+ showToast(`Ошибка отправки файла: ${err.message}`, true);
1310
+ }
1311
+ }
1312
+
1313
+ async function handleStartDm(e) {
1314
+ e.preventDefault();
1315
+ const targetUser = document.getElementById('dmUserIdInput').value.trim();
1316
+ if (!targetUser) return;
1317
+
1318
+ try {
1319
+ const res = await apiReq('client/v3/createRoom', 'POST', {
1320
+ is_direct: true,
1321
+ invite: [targetUser],
1322
+ preset: 'trusted_private_chat'
1323
+ });
1324
+ closeModal('createDmModal');
1325
+ if (res.room_id) {
1326
+ if (!state.rooms[res.room_id]) state.rooms[res.room_id] = { name: targetUser, topic: '', avatar: null, events: [], unread: 0, isDirect: true };
1327
+ else state.rooms[res.room_id].isDirect = true;
1328
+ selectRoom(res.room_id);
1329
+ }
1330
+ showToast('Чат создан');
1331
+ } catch (err) {
1332
+ showToast(`Ошибка: ${err.message}`, true);
1333
+ }
1334
+ }
1335
+
1336
+ async function handleCreateRoom(e) {
1337
+ e.preventDefault();
1338
+ const name = document.getElementById('newRoomName').value.trim();
1339
+ const topic = document.getElementById('newRoomTopic').value.trim();
1340
+ const alias = document.getElementById('newRoomAlias').value.trim();
1341
+ const isPublic = document.getElementById('newRoomPublic').checked;
1342
+ const avatarFile = document.getElementById('newRoomAvatarFile').files[0];
1343
+
1344
+ try {
1345
+ let avatarMxc = null;
1346
+ if (avatarFile) avatarMxc = await uploadMediaFile(avatarFile);
1347
+
1348
+ const initialState = [];
1349
+ if (avatarMxc) initialState.push({ type: 'm.room.avatar', content: { url: avatarMxc } });
1350
+
1351
+ const body = {
1352
+ name, topic,
1353
+ preset: isPublic ? 'public_chat' : 'private_chat',
1354
+ visibility: isPublic ? 'public' : 'private',
1355
+ initial_state: initialState
1356
+ };
1357
+ if (alias) body.room_alias_name = alias;
1358
+
1359
+ const res = await apiReq('client/v3/createRoom', 'POST', body);
1360
+ closeModal('createRoomModal');
1361
+ if (res.room_id) selectRoom(res.room_id);
1362
+ showToast('Комната создана');
1363
+ } catch (err) {
1364
+ showToast(`Ошибка: ${err.message}`, true);
1365
+ }
1366
+ }
1367
+
1368
+ async function handleJoinRoom(e) {
1369
+ e.preventDefault();
1370
+ const input = document.getElementById('joinRoomInput').value.trim();
1371
+ try {
1372
+ const res = await apiReq(`client/v3/join/${encodeURIComponent(input)}`, 'POST', {});
1373
+ closeModal('joinRoomModal');
1374
+ if (res.room_id) selectRoom(res.room_id);
1375
+ showToast('Вы присоединились!');
1376
+ } catch (err) {
1377
+ showToast(`Ошибка входа: ${err.message}`, true);
1378
+ }
1379
+ }
1380
+
1381
+ async function leaveRoom(roomId) {
1382
+ try {
1383
+ await apiReq(`client/v3/rooms/${encodeURIComponent(roomId)}/leave`, 'POST', {});
1384
+ delete state.rooms[roomId];
1385
+ if (state.currentRoomId === roomId) state.currentRoomId = null;
1386
+ updateUI();
1387
+ showToast('Вы вышли из комнаты');
1388
+ } catch (err) {
1389
+ showToast(`Ошибка: ${err.message}`, true);
1390
+ }
1391
+ }
1392
+
1393
+ function openRoomDetailsModal(roomId) {
1394
+ const room = state.rooms[roomId];
1395
+ if (!room) return;
1396
+ document.getElementById('infoModalName').innerText = room.name;
1397
+ document.getElementById('infoModalTopic').innerText = room.topic || 'Без темы';
1398
+ document.getElementById('infoModalId').value = roomId;
1399
+ openModal('roomDetailsModal');
1400
+ }
1401
+
1402
+ function openCurrentRoomDetails() {
1403
+ if (state.currentRoomId) openRoomDetailsModal(state.currentRoomId);
1404
+ }
1405
+
1406
+ function leaveCurrentRoom() {
1407
+ if (state.currentRoomId) {
1408
+ leaveRoom(state.currentRoomId);
1409
+ closeModal('roomDetailsModal');
1410
+ }
1411
+ }
1412
+
1413
+ async function acceptInvite(roomId) {
1414
+ try {
1415
+ await apiReq(`client/v3/join/${encodeURIComponent(roomId)}`, 'POST', {});
1416
+ delete state.invites[roomId];
1417
+ updateUI();
1418
+ selectRoom(roomId);
1419
+ } catch (err) { showToast(`Ошибка: ${err.message}`, true); }
1420
+ }
1421
+
1422
+ async function rejectInvite(roomId) {
1423
+ try {
1424
+ await apiReq(`client/v3/rooms/${encodeURIComponent(roomId)}/leave`, 'POST', {});
1425
+ delete state.invites[roomId];
1426
+ updateUI();
1427
+ } catch (err) { showToast(`Ошибка: ${err.message}`, true); }
1428
+ }
1429
+
1430
+ async function uploadProfileAvatar(input) {
1431
+ if (!input.files?.[0]) return;
1432
+ try {
1433
+ showToast('Загрузка аватара...');
1434
+ const mxcUrl = await uploadMediaFile(input.files[0]);
1435
+ await apiReq(`client/v3/profile/${encodeURIComponent(state.userId)}/avatar_url`, 'PUT', { avatar_url: mxcUrl });
1436
+ loadUserProfile();
1437
+ showToast('Аватар обновлен!');
1438
+ } catch (err) { showToast(`Ошибка: ${err.message}`, true); }
1439
+ }
1440
+
1441
+ async function saveDisplayName() {
1442
+ const name = document.getElementById('settingsDisplayName').value.trim();
1443
+ if (!name) return;
1444
+ try {
1445
+ await apiReq(`client/v3/profile/${encodeURIComponent(state.userId)}/displayname`, 'PUT', { displayname: name });
1446
+ showToast('Имя изменено!');
1447
+ } catch (err) { showToast(`Ошибка: ${err.message}`, true); }
1448
+ }
1449
+
1450
+ function setAppTheme(theme) {
1451
+ document.body.className = theme === 'matrix' ? 'theme-matrix' : theme === 'light' ? 'theme-light' : '';
1452
+ }
1453
+
1454
+ function switchTab(tab) {
1455
+ state.activeTab = tab;
1456
+ ['chats', 'dms', 'inbox', 'settings'].forEach(t => {
1457
+ const btn = document.getElementById(`tabBtn-${t}`);
1458
+ if (btn) btn.classList.toggle('active', t === tab);
1459
+ });
1460
+
1461
+ document.getElementById('chatView').classList.toggle('hidden', tab === 'settings');
1462
+ document.getElementById('settingsView').classList.toggle('hidden', tab !== 'settings');
1463
+
1464
+ const titleMap = { chats: 'Чаты', dms: 'Личные сообщения', inbox: 'Приглашения', settings: 'Настройки' };
1465
+ document.getElementById('sidebarTitle').innerText = titleMap[tab] || 'Чаты';
1466
+
1467
+ renderSidebarList();
1468
+ }
1469
+
1470
+ function filterRooms() {
1471
+ const query = document.getElementById('searchInput').value.toLowerCase();
1472
+ const items = document.querySelectorAll('#listContainer .room-item');
1473
+ items.forEach(el => el.style.display = el.innerText.toLowerCase().includes(query) ? 'flex' : 'none');
1474
+ }
1475
+
1476
+ function openImageViewer(url) {
1477
+ document.getElementById('fullImageView').src = url;
1478
+ openModal('imageViewerModal');
1479
+ }
1480
+
1481
+ function openModal(id) { document.getElementById(id).classList.remove('hidden'); }
1482
+ function closeModal(id) { document.getElementById(id).classList.add('hidden'); }
1483
+
1484
+ function escapeHtml(str) {
1485
+ if (!str) return '';
1486
+ return str.replace(/[&<>"']/g, m => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#039;' }[m]));
1487
+ }
1488
 
1489
+ // Auto Load saved session on launch
1490
+ window.onload = checkSavedSession;
1491
+ </script>
 
1492
  </body>
1493
  </html>