Spaces:
Running
Running
Update index.html
Browse files- index.html +700 -1290
index.html
CHANGED
|
@@ -3,1473 +3,883 @@
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
-
<title>
|
|
|
|
| 7 |
<style>
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
}
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
margin: 0;
|
| 23 |
-
padding: 0;
|
| 24 |
-
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
|
| 25 |
-
}
|
| 26 |
-
|
| 27 |
-
body {
|
| 28 |
-
background-color: var(--tg-bg);
|
| 29 |
-
color: var(--tg-text);
|
| 30 |
-
height: 100vh;
|
| 31 |
-
overflow: hidden;
|
| 32 |
-
display: flex;
|
| 33 |
-
flex-direction: column;
|
| 34 |
-
}
|
| 35 |
-
|
| 36 |
-
.top-navbar {
|
| 37 |
-
background-color: var(--tg-blue);
|
| 38 |
-
color: white;
|
| 39 |
-
height: 48px;
|
| 40 |
-
display: flex;
|
| 41 |
-
align-items: center;
|
| 42 |
-
justify-content: space-between;
|
| 43 |
-
padding: 0 20px;
|
| 44 |
-
box-shadow: 0 1px 2px rgba(0,0,0,0.1);
|
| 45 |
-
flex-shrink: 0;
|
| 46 |
-
}
|
| 47 |
-
|
| 48 |
-
.top-navbar.hidden {
|
| 49 |
-
display: none;
|
| 50 |
-
}
|
| 51 |
-
|
| 52 |
-
.brand {
|
| 53 |
-
font-size: 18px;
|
| 54 |
-
font-weight: bold;
|
| 55 |
-
cursor: pointer;
|
| 56 |
-
}
|
| 57 |
-
|
| 58 |
-
.nav-links {
|
| 59 |
-
display: flex;
|
| 60 |
-
gap: 20px;
|
| 61 |
-
}
|
| 62 |
-
|
| 63 |
-
.nav-link {
|
| 64 |
-
color: white;
|
| 65 |
-
text-decoration: none;
|
| 66 |
-
font-size: 14px;
|
| 67 |
-
padding: 5px 10px;
|
| 68 |
-
border-radius: 3px;
|
| 69 |
-
cursor: pointer;
|
| 70 |
-
transition: background 0.2s;
|
| 71 |
-
}
|
| 72 |
-
|
| 73 |
-
.nav-link:hover {
|
| 74 |
-
background-color: rgba(255, 255, 255, 0.1);
|
| 75 |
-
}
|
| 76 |
-
|
| 77 |
-
.view-container {
|
| 78 |
-
display: none;
|
| 79 |
-
flex-grow: 1;
|
| 80 |
-
overflow-y: auto;
|
| 81 |
-
width: 100%;
|
| 82 |
-
}
|
| 83 |
-
|
| 84 |
-
.view-container.active {
|
| 85 |
-
display: flex;
|
| 86 |
-
}
|
| 87 |
-
|
| 88 |
-
/* Servers View */
|
| 89 |
-
#view-servers {
|
| 90 |
-
flex-direction: column;
|
| 91 |
-
align-items: center;
|
| 92 |
-
padding: 40px 20px;
|
| 93 |
-
}
|
| 94 |
-
|
| 95 |
-
.servers-wrapper {
|
| 96 |
-
background: #22272e; /* Darker theme matching your screenshot */
|
| 97 |
-
color: white;
|
| 98 |
-
border-radius: 8px;
|
| 99 |
-
width: 100%;
|
| 100 |
-
max-width: 900px;
|
| 101 |
-
box-shadow: 0 4px 12px rgba(0,0,0,0.15);
|
| 102 |
-
overflow: hidden;
|
| 103 |
-
}
|
| 104 |
-
|
| 105 |
-
.servers-header {
|
| 106 |
-
padding: 20px;
|
| 107 |
-
background: #1c2128;
|
| 108 |
-
border-bottom: 1px solid #373e47;
|
| 109 |
-
}
|
| 110 |
-
|
| 111 |
-
.servers-table {
|
| 112 |
-
width: 100%;
|
| 113 |
-
border-collapse: collapse;
|
| 114 |
-
}
|
| 115 |
-
|
| 116 |
-
.servers-table th {
|
| 117 |
-
text-align: left;
|
| 118 |
-
padding: 15px 20px;
|
| 119 |
-
color: #adbac7;
|
| 120 |
-
font-size: 14px;
|
| 121 |
-
border-bottom: 1px solid #373e47;
|
| 122 |
-
}
|
| 123 |
-
|
| 124 |
-
.servers-table td {
|
| 125 |
-
padding: 15px 20px;
|
| 126 |
-
border-bottom: 1px solid #373e47;
|
| 127 |
-
font-size: 14px;
|
| 128 |
-
}
|
| 129 |
-
|
| 130 |
-
.servers-table tr:last-child td {
|
| 131 |
-
border-bottom: none;
|
| 132 |
-
}
|
| 133 |
-
|
| 134 |
-
.server-name { color: #539bf5; font-weight: bold; }
|
| 135 |
-
.server-url { color: #539bf5; text-decoration: none; }
|
| 136 |
-
.server-desc { color: #adbac7; }
|
| 137 |
-
|
| 138 |
-
.btn-login-server {
|
| 139 |
-
background-color: var(--tg-blue);
|
| 140 |
-
color: white;
|
| 141 |
-
border: none;
|
| 142 |
-
padding: 6px 12px;
|
| 143 |
-
border-radius: 4px;
|
| 144 |
-
cursor: pointer;
|
| 145 |
-
font-size: 13px;
|
| 146 |
-
}
|
| 147 |
-
|
| 148 |
-
#view-login {
|
| 149 |
-
justify-content: center;
|
| 150 |
-
align-items: center;
|
| 151 |
-
}
|
| 152 |
-
|
| 153 |
-
.login-box {
|
| 154 |
-
background: white;
|
| 155 |
-
padding: 30px;
|
| 156 |
-
border-radius: 4px;
|
| 157 |
-
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
|
| 158 |
-
width: 320px;
|
| 159 |
-
text-align: center;
|
| 160 |
-
}
|
| 161 |
-
|
| 162 |
-
.login-box h2 {
|
| 163 |
-
margin-bottom: 20px;
|
| 164 |
-
color: var(--tg-text);
|
| 165 |
-
font-weight: normal;
|
| 166 |
-
}
|
| 167 |
-
|
| 168 |
-
.input-group {
|
| 169 |
-
margin-bottom: 15px;
|
| 170 |
-
text-align: left;
|
| 171 |
-
}
|
| 172 |
-
|
| 173 |
-
.input-group label {
|
| 174 |
-
display: block;
|
| 175 |
-
margin-bottom: 5px;
|
| 176 |
-
font-size: 13px;
|
| 177 |
-
color: var(--tg-text-muted);
|
| 178 |
-
}
|
| 179 |
-
|
| 180 |
-
.input-group input {
|
| 181 |
-
width: 100%;
|
| 182 |
-
padding: 10px;
|
| 183 |
-
border: 1px solid var(--tg-border);
|
| 184 |
-
border-radius: 3px;
|
| 185 |
-
outline: none;
|
| 186 |
-
font-size: 14px;
|
| 187 |
-
}
|
| 188 |
-
|
| 189 |
-
.input-group input:focus {
|
| 190 |
-
border-color: var(--tg-blue);
|
| 191 |
-
}
|
| 192 |
-
|
| 193 |
-
.btn-primary {
|
| 194 |
-
background-color: var(--tg-blue);
|
| 195 |
-
color: white;
|
| 196 |
-
border: none;
|
| 197 |
-
width: 100%;
|
| 198 |
-
padding: 10px;
|
| 199 |
-
border-radius: 3px;
|
| 200 |
-
cursor: pointer;
|
| 201 |
-
font-size: 15px;
|
| 202 |
-
margin-top: 10px;
|
| 203 |
-
}
|
| 204 |
-
|
| 205 |
-
.btn-primary:hover {
|
| 206 |
-
background-color: #497291;
|
| 207 |
-
}
|
| 208 |
-
|
| 209 |
-
#view-client {
|
| 210 |
-
display: none;
|
| 211 |
-
height: 100vh;
|
| 212 |
-
width: 100%;
|
| 213 |
-
flex-direction: row;
|
| 214 |
-
}
|
| 215 |
-
|
| 216 |
-
#view-client.active {
|
| 217 |
-
display: flex;
|
| 218 |
-
}
|
| 219 |
-
|
| 220 |
-
/* Left Sidebar (Rooms) */
|
| 221 |
-
.sidebar {
|
| 222 |
-
width: 300px;
|
| 223 |
-
background: white;
|
| 224 |
-
border-right: 1px solid var(--tg-border);
|
| 225 |
-
display: flex;
|
| 226 |
-
flex-direction: column;
|
| 227 |
-
flex-shrink: 0;
|
| 228 |
-
}
|
| 229 |
-
|
| 230 |
-
.sidebar-header {
|
| 231 |
-
height: 48px;
|
| 232 |
-
display: flex;
|
| 233 |
-
align-items: center;
|
| 234 |
-
padding: 0 15px;
|
| 235 |
-
border-bottom: 1px solid var(--tg-border);
|
| 236 |
-
gap: 10px;
|
| 237 |
-
}
|
| 238 |
-
|
| 239 |
-
.search-bar {
|
| 240 |
-
flex-grow: 1;
|
| 241 |
-
padding: 6px 10px;
|
| 242 |
-
border: 1px solid var(--tg-border);
|
| 243 |
-
border-radius: 15px;
|
| 244 |
-
background: #f1f1f1;
|
| 245 |
-
outline: none;
|
| 246 |
-
font-size: 13px;
|
| 247 |
-
}
|
| 248 |
-
|
| 249 |
-
.btn-icon {
|
| 250 |
-
background: none;
|
| 251 |
-
border: none;
|
| 252 |
-
font-size: 20px;
|
| 253 |
-
color: var(--tg-text-muted);
|
| 254 |
-
cursor: pointer;
|
| 255 |
-
}
|
| 256 |
-
|
| 257 |
-
.rooms-list {
|
| 258 |
-
flex-grow: 1;
|
| 259 |
-
overflow-y: auto;
|
| 260 |
-
}
|
| 261 |
-
|
| 262 |
-
.room-item {
|
| 263 |
-
display: flex;
|
| 264 |
-
padding: 10px 15px;
|
| 265 |
-
cursor: pointer;
|
| 266 |
-
transition: background 0.1s;
|
| 267 |
-
}
|
| 268 |
-
|
| 269 |
-
.room-item:hover { background: var(--tg-hover); }
|
| 270 |
-
.room-item.active { background: var(--tg-blue); color: white; }
|
| 271 |
-
|
| 272 |
-
.room-item.active .room-last-msg { color: rgba(255,255,255,0.8); }
|
| 273 |
-
|
| 274 |
-
.room-avatar {
|
| 275 |
-
width: 46px;
|
| 276 |
-
height: 46px;
|
| 277 |
-
border-radius: 50%;
|
| 278 |
-
background-color: #d2dbe3;
|
| 279 |
-
margin-right: 12px;
|
| 280 |
-
flex-shrink: 0;
|
| 281 |
-
display: flex;
|
| 282 |
-
align-items: center;
|
| 283 |
-
justify-content: center;
|
| 284 |
-
font-weight: bold;
|
| 285 |
-
color: white;
|
| 286 |
-
overflow: hidden;
|
| 287 |
-
}
|
| 288 |
-
|
| 289 |
-
.room-avatar img {
|
| 290 |
-
width: 100%;
|
| 291 |
-
height: 100%;
|
| 292 |
-
object-fit: cover;
|
| 293 |
-
}
|
| 294 |
-
|
| 295 |
-
.room-info {
|
| 296 |
-
flex-grow: 1;
|
| 297 |
-
overflow: hidden;
|
| 298 |
-
display: flex;
|
| 299 |
-
flex-direction: column;
|
| 300 |
-
justify-content: center;
|
| 301 |
-
}
|
| 302 |
-
|
| 303 |
-
.room-name {
|
| 304 |
-
font-weight: bold;
|
| 305 |
-
font-size: 14px;
|
| 306 |
-
white-space: nowrap;
|
| 307 |
-
overflow: hidden;
|
| 308 |
-
text-overflow: ellipsis;
|
| 309 |
-
margin-bottom: 3px;
|
| 310 |
-
}
|
| 311 |
-
|
| 312 |
-
.room-last-msg {
|
| 313 |
-
font-size: 13px;
|
| 314 |
-
color: var(--tg-text-muted);
|
| 315 |
-
white-space: nowrap;
|
| 316 |
-
overflow: hidden;
|
| 317 |
-
text-overflow: ellipsis;
|
| 318 |
-
}
|
| 319 |
-
|
| 320 |
-
.chat-area {
|
| 321 |
-
flex-grow: 1;
|
| 322 |
-
display: flex;
|
| 323 |
-
flex-direction: column;
|
| 324 |
-
background: url('https://web.telegram.org/a/bg-pattern-light.svg') center/cover;
|
| 325 |
-
background-color: var(--tg-bg);
|
| 326 |
-
position: relative;
|
| 327 |
-
min-width: 0;
|
| 328 |
-
}
|
| 329 |
-
|
| 330 |
-
.chat-placeholder {
|
| 331 |
-
position: absolute;
|
| 332 |
-
top: 50%;
|
| 333 |
-
left: 50%;
|
| 334 |
-
transform: translate(-50%, -50%);
|
| 335 |
-
background: rgba(0,0,0,0.2);
|
| 336 |
-
color: white;
|
| 337 |
-
padding: 5px 12px;
|
| 338 |
-
border-radius: 12px;
|
| 339 |
-
font-size: 14px;
|
| 340 |
-
}
|
| 341 |
-
|
| 342 |
-
.chat-header {
|
| 343 |
-
height: 48px;
|
| 344 |
-
background: white;
|
| 345 |
-
border-bottom: 1px solid var(--tg-border);
|
| 346 |
-
display: flex;
|
| 347 |
-
align-items: center;
|
| 348 |
-
padding: 0 20px;
|
| 349 |
-
cursor: pointer;
|
| 350 |
-
flex-shrink: 0;
|
| 351 |
-
}
|
| 352 |
-
|
| 353 |
-
.chat-header:hover { background: var(--tg-hover); }
|
| 354 |
-
|
| 355 |
-
.chat-header-info {
|
| 356 |
-
display: flex;
|
| 357 |
-
flex-direction: column;
|
| 358 |
-
flex-grow: 1;
|
| 359 |
-
min-width: 0;
|
| 360 |
-
}
|
| 361 |
-
|
| 362 |
-
.chat-title {
|
| 363 |
-
font-weight: bold;
|
| 364 |
-
font-size: 14px;
|
| 365 |
-
white-space: nowrap;
|
| 366 |
-
overflow: hidden;
|
| 367 |
-
text-overflow: ellipsis;
|
| 368 |
-
}
|
| 369 |
-
|
| 370 |
-
.chat-subtitle {
|
| 371 |
-
font-size: 12px;
|
| 372 |
-
color: var(--tg-text-muted);
|
| 373 |
-
white-space: nowrap;
|
| 374 |
-
overflow: hidden;
|
| 375 |
-
text-overflow: ellipsis;
|
| 376 |
-
}
|
| 377 |
-
|
| 378 |
-
.messages-container {
|
| 379 |
-
flex-grow: 1;
|
| 380 |
-
overflow-y: auto;
|
| 381 |
-
padding: 20px;
|
| 382 |
-
display: flex;
|
| 383 |
-
flex-direction: column;
|
| 384 |
-
}
|
| 385 |
-
|
| 386 |
-
.message {
|
| 387 |
-
max-width: 70%;
|
| 388 |
-
margin-bottom: 10px;
|
| 389 |
-
display: flex;
|
| 390 |
-
flex-direction: column;
|
| 391 |
-
}
|
| 392 |
-
|
| 393 |
-
.message.in { align-self: flex-start; }
|
| 394 |
-
.message.out { align-self: flex-end; }
|
| 395 |
-
|
| 396 |
-
.msg-bubble {
|
| 397 |
-
padding: 8px 12px;
|
| 398 |
-
border-radius: 6px;
|
| 399 |
-
position: relative;
|
| 400 |
-
font-size: 14px;
|
| 401 |
-
line-height: 1.4;
|
| 402 |
-
word-wrap: break-word;
|
| 403 |
-
box-shadow: 0 1px 1px rgba(0,0,0,0.1);
|
| 404 |
-
}
|
| 405 |
-
|
| 406 |
-
.message.in .msg-bubble {
|
| 407 |
-
background: var(--tg-msg-in);
|
| 408 |
-
border-bottom-left-radius: 0;
|
| 409 |
-
}
|
| 410 |
-
|
| 411 |
-
.message.out .msg-bubble {
|
| 412 |
-
background: var(--tg-msg-out);
|
| 413 |
-
border-bottom-right-radius: 0;
|
| 414 |
-
}
|
| 415 |
-
|
| 416 |
-
.msg-sender {
|
| 417 |
-
font-size: 12px;
|
| 418 |
-
font-weight: bold;
|
| 419 |
-
color: var(--tg-blue);
|
| 420 |
-
margin-bottom: 4px;
|
| 421 |
-
}
|
| 422 |
-
|
| 423 |
-
.message.out .msg-sender { display: none; }
|
| 424 |
-
|
| 425 |
-
.msg-time {
|
| 426 |
-
font-size: 11px;
|
| 427 |
-
color: var(--tg-text-muted);
|
| 428 |
-
float: right;
|
| 429 |
-
margin-top: 4px;
|
| 430 |
-
margin-left: 10px;
|
| 431 |
-
}
|
| 432 |
-
|
| 433 |
-
.message.out .msg-time { color: #5ea83e; }
|
| 434 |
-
|
| 435 |
-
.chat-input-area {
|
| 436 |
-
background: white;
|
| 437 |
-
padding: 10px 20px;
|
| 438 |
-
display: flex;
|
| 439 |
-
align-items: center;
|
| 440 |
-
gap: 10px;
|
| 441 |
-
flex-shrink: 0;
|
| 442 |
-
}
|
| 443 |
-
|
| 444 |
-
.chat-input {
|
| 445 |
-
flex-grow: 1;
|
| 446 |
-
border: none;
|
| 447 |
-
outline: none;
|
| 448 |
-
font-size: 14px;
|
| 449 |
-
padding: 10px 0;
|
| 450 |
-
}
|
| 451 |
-
|
| 452 |
-
.btn-send {
|
| 453 |
-
color: var(--tg-blue);
|
| 454 |
-
background: none;
|
| 455 |
-
border: none;
|
| 456 |
-
font-weight: bold;
|
| 457 |
-
cursor: pointer;
|
| 458 |
-
text-transform: uppercase;
|
| 459 |
-
font-size: 14px;
|
| 460 |
-
}
|
| 461 |
-
|
| 462 |
-
.right-sidebar {
|
| 463 |
-
width: 300px;
|
| 464 |
-
background: white;
|
| 465 |
-
border-left: 1px solid var(--tg-border);
|
| 466 |
-
display: none; /* hidden by default, toggled on click */
|
| 467 |
-
flex-direction: column;
|
| 468 |
-
flex-shrink: 0;
|
| 469 |
-
}
|
| 470 |
-
|
| 471 |
-
.right-sidebar.active {
|
| 472 |
-
display: flex;
|
| 473 |
-
}
|
| 474 |
-
|
| 475 |
-
.rs-header {
|
| 476 |
-
height: 48px;
|
| 477 |
-
display: flex;
|
| 478 |
-
align-items: center;
|
| 479 |
-
padding: 0 15px;
|
| 480 |
-
border-bottom: 1px solid var(--tg-border);
|
| 481 |
-
font-weight: bold;
|
| 482 |
-
font-size: 14px;
|
| 483 |
-
}
|
| 484 |
-
|
| 485 |
-
.rs-content {
|
| 486 |
-
padding: 20px;
|
| 487 |
-
overflow-y: auto;
|
| 488 |
-
flex-grow: 1;
|
| 489 |
-
}
|
| 490 |
-
|
| 491 |
-
.rs-avatar {
|
| 492 |
-
width: 120px;
|
| 493 |
-
height: 120px;
|
| 494 |
-
border-radius: 50%;
|
| 495 |
-
background-color: #d2dbe3;
|
| 496 |
-
margin: 0 auto 15px auto;
|
| 497 |
-
display: flex;
|
| 498 |
-
align-items: center;
|
| 499 |
-
justify-content: center;
|
| 500 |
-
font-size: 40px;
|
| 501 |
-
color: white;
|
| 502 |
-
overflow: hidden;
|
| 503 |
-
}
|
| 504 |
-
|
| 505 |
-
.rs-avatar img {
|
| 506 |
-
width: 100%;
|
| 507 |
-
height: 100%;
|
| 508 |
-
object-fit: cover;
|
| 509 |
-
}
|
| 510 |
-
|
| 511 |
-
.rs-title {
|
| 512 |
-
text-align: center;
|
| 513 |
-
font-size: 18px;
|
| 514 |
-
font-weight: bold;
|
| 515 |
-
margin-bottom: 5px;
|
| 516 |
-
word-break: break-all; /* OVERFLOW FIX */
|
| 517 |
-
}
|
| 518 |
-
|
| 519 |
-
.rs-subtitle {
|
| 520 |
-
text-align: center;
|
| 521 |
-
font-size: 13px;
|
| 522 |
-
color: var(--tg-text-muted);
|
| 523 |
-
margin-bottom: 20px;
|
| 524 |
-
}
|
| 525 |
-
|
| 526 |
-
.rs-section-title {
|
| 527 |
-
font-size: 13px;
|
| 528 |
-
color: var(--tg-blue);
|
| 529 |
-
font-weight: bold;
|
| 530 |
-
margin-bottom: 10px;
|
| 531 |
-
margin-top: 20px;
|
| 532 |
-
}
|
| 533 |
-
|
| 534 |
-
.rs-text {
|
| 535 |
-
font-size: 14px;
|
| 536 |
-
line-height: 1.4;
|
| 537 |
-
word-break: break-word;
|
| 538 |
-
}
|
| 539 |
-
|
| 540 |
-
.btn-edit-room {
|
| 541 |
-
display: block;
|
| 542 |
-
width: 100%;
|
| 543 |
-
text-align: center;
|
| 544 |
-
background: #f1f1f1;
|
| 545 |
-
border: 1px solid var(--tg-border);
|
| 546 |
-
padding: 8px;
|
| 547 |
-
border-radius: 4px;
|
| 548 |
-
margin-top: 15px;
|
| 549 |
-
cursor: pointer;
|
| 550 |
-
font-size: 13px;
|
| 551 |
-
}
|
| 552 |
-
|
| 553 |
-
.btn-edit-room:hover { background: var(--tg-hover); }
|
| 554 |
-
|
| 555 |
-
.modal-overlay {
|
| 556 |
-
position: fixed;
|
| 557 |
-
top: 0; left: 0; right: 0; bottom: 0;
|
| 558 |
-
background: rgba(0,0,0,0.5);
|
| 559 |
-
display: none;
|
| 560 |
-
align-items: center;
|
| 561 |
-
justify-content: center;
|
| 562 |
-
z-index: 1000;
|
| 563 |
-
}
|
| 564 |
-
|
| 565 |
-
.modal-overlay.active { display: flex; }
|
| 566 |
-
|
| 567 |
-
.modal-box {
|
| 568 |
-
background: white;
|
| 569 |
-
border-radius: 6px;
|
| 570 |
-
width: 400px;
|
| 571 |
-
max-width: 90%;
|
| 572 |
-
box-shadow: 0 4px 12px rgba(0,0,0,0.15);
|
| 573 |
-
overflow: hidden;
|
| 574 |
-
}
|
| 575 |
-
|
| 576 |
-
.modal-header {
|
| 577 |
-
padding: 15px 20px;
|
| 578 |
-
border-bottom: 1px solid var(--tg-border);
|
| 579 |
-
font-weight: bold;
|
| 580 |
-
font-size: 16px;
|
| 581 |
-
}
|
| 582 |
-
|
| 583 |
-
.modal-body { padding: 20px; }
|
| 584 |
-
|
| 585 |
-
.form-group { margin-bottom: 15px; }
|
| 586 |
-
.form-group label {
|
| 587 |
-
display: block;
|
| 588 |
-
margin-bottom: 5px;
|
| 589 |
-
font-size: 13px;
|
| 590 |
-
color: var(--tg-text-muted);
|
| 591 |
-
}
|
| 592 |
-
.form-input {
|
| 593 |
-
width: 100%;
|
| 594 |
-
padding: 8px 10px;
|
| 595 |
-
border: 1px solid var(--tg-border);
|
| 596 |
-
border-radius: 3px;
|
| 597 |
-
outline: none;
|
| 598 |
-
}
|
| 599 |
-
.form-input:focus { border-color: var(--tg-blue); }
|
| 600 |
-
.form-hint { font-size: 11px; color: var(--tg-text-muted); margin-top: 4px; }
|
| 601 |
-
|
| 602 |
-
.modal-footer {
|
| 603 |
-
padding: 15px 20px;
|
| 604 |
-
border-top: 1px solid var(--tg-border);
|
| 605 |
-
display: flex;
|
| 606 |
-
justify-content: flex-end;
|
| 607 |
-
gap: 10px;
|
| 608 |
-
}
|
| 609 |
-
|
| 610 |
-
.btn-cancel {
|
| 611 |
-
background: none;
|
| 612 |
-
border: none;
|
| 613 |
-
color: var(--tg-text-muted);
|
| 614 |
-
cursor: pointer;
|
| 615 |
-
padding: 8px 15px;
|
| 616 |
-
}
|
| 617 |
-
|
| 618 |
-
.toast-container {
|
| 619 |
-
position: fixed;
|
| 620 |
-
bottom: 20px;
|
| 621 |
-
left: 50%;
|
| 622 |
-
transform: translateX(-50%);
|
| 623 |
-
z-index: 2000;
|
| 624 |
-
display: flex;
|
| 625 |
-
flex-direction: column;
|
| 626 |
-
gap: 10px;
|
| 627 |
-
}
|
| 628 |
-
|
| 629 |
-
.toast {
|
| 630 |
-
background: rgba(0,0,0,0.8);
|
| 631 |
-
color: white;
|
| 632 |
-
padding: 10px 20px;
|
| 633 |
-
border-radius: 20px;
|
| 634 |
-
font-size: 13px;
|
| 635 |
-
animation: fadeInOut 3s forwards;
|
| 636 |
-
}
|
| 637 |
-
|
| 638 |
-
@keyframes fadeInOut {
|
| 639 |
-
0% { opacity: 0; transform: translateY(10px); }
|
| 640 |
-
10% { opacity: 1; transform: translateY(0); }
|
| 641 |
-
90% { opacity: 1; transform: translateY(0); }
|
| 642 |
-
100% { opacity: 0; transform: translateY(-10px); }
|
| 643 |
-
}
|
| 644 |
</style>
|
| 645 |
</head>
|
| 646 |
-
<body>
|
| 647 |
|
| 648 |
-
<div
|
| 649 |
-
<div class="brand" onclick="showView('servers')">Client:Less</div>
|
| 650 |
-
<div class="nav-links">
|
| 651 |
-
<a class="nav-link" onclick="showView('servers')">Популярные серверы</a>
|
| 652 |
-
<a class="nav-link" onclick="showView('login')">Войти</a>
|
| 653 |
-
</div>
|
| 654 |
-
</div>
|
| 655 |
|
| 656 |
-
<div id="
|
| 657 |
-
<div class="
|
| 658 |
-
<
|
| 659 |
-
|
| 660 |
-
</div>
|
| 661 |
-
<table class="servers-table">
|
| 662 |
-
<thead>
|
| 663 |
-
<tr>
|
| 664 |
-
<th>Название</th>
|
| 665 |
-
<th>URL</th>
|
| 666 |
-
<th>Примечания</th>
|
| 667 |
-
<th>Действие</th>
|
| 668 |
-
</tr>
|
| 669 |
-
</thead>
|
| 670 |
-
<tbody id="servers-tbody">
|
| 671 |
-
<!-- Populated via JS -->
|
| 672 |
-
</tbody>
|
| 673 |
-
</table>
|
| 674 |
</div>
|
| 675 |
-
|
| 676 |
-
|
| 677 |
-
|
| 678 |
-
<div
|
| 679 |
-
|
| 680 |
-
<
|
| 681 |
-
|
| 682 |
-
<input type="text" id="login-hs" placeholder="https://matrix.org" value="https://matrix.org">
|
| 683 |
-
</div>
|
| 684 |
-
<div class="input-group">
|
| 685 |
-
<label>Имя пользователя (@user:server)</label>
|
| 686 |
-
<input type="text" id="login-user" placeholder="@username:matrix.org">
|
| 687 |
-
</div>
|
| 688 |
-
<div class="input-group">
|
| 689 |
-
<label>Пароль</label>
|
| 690 |
-
<input type="password" id="login-pass" placeholder="Пароль">
|
| 691 |
-
</div>
|
| 692 |
-
<button class="btn-primary" onclick="login()">Войти</button>
|
| 693 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 694 |
</div>
|
| 695 |
|
| 696 |
-
<div id="
|
| 697 |
<!-- Sidebar -->
|
| 698 |
-
<div class="
|
| 699 |
-
<
|
| 700 |
-
|
| 701 |
-
<
|
| 702 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 703 |
</div>
|
| 704 |
-
<
|
| 705 |
-
|
|
|
|
| 706 |
</div>
|
| 707 |
</div>
|
| 708 |
|
| 709 |
-
<
|
| 710 |
-
|
| 711 |
-
<div
|
| 712 |
-
|
| 713 |
-
|
| 714 |
-
|
| 715 |
-
|
| 716 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 717 |
</div>
|
| 718 |
</div>
|
| 719 |
|
| 720 |
-
<
|
| 721 |
-
|
|
|
|
|
|
|
| 722 |
</div>
|
| 723 |
|
| 724 |
-
<
|
| 725 |
-
|
| 726 |
-
<
|
| 727 |
</div>
|
| 728 |
-
</div>
|
| 729 |
|
| 730 |
-
|
| 731 |
-
|
| 732 |
-
|
| 733 |
-
|
| 734 |
-
|
| 735 |
-
|
| 736 |
-
|
| 737 |
-
|
| 738 |
-
|
| 739 |
-
<
|
| 740 |
-
|
| 741 |
-
|
| 742 |
-
|
| 743 |
-
|
| 744 |
-
<button class="btn-edit-room" id="btn-edit-room" style="display: none;" onclick="openEditRoomModal()">✏️ Редактировать комнату</button>
|
| 745 |
</div>
|
| 746 |
</div>
|
| 747 |
</div>
|
| 748 |
|
| 749 |
-
|
| 750 |
-
|
| 751 |
-
|
| 752 |
-
<div class="modal-
|
| 753 |
-
<
|
| 754 |
-
<
|
| 755 |
-
|
| 756 |
-
|
| 757 |
-
|
| 758 |
-
</div>
|
| 759 |
-
<div class="form-group">
|
| 760 |
-
<label>Отображаемое имя (Display Name)</label>
|
| 761 |
-
<input type="text" id="profile-name-input" class="form-input" placeholder="Введите имя">
|
| 762 |
-
</div>
|
| 763 |
-
<div class="form-group">
|
| 764 |
-
<label>Аватар профиля (Загрузка файла)</label>
|
| 765 |
-
<input type="file" id="profile-avatar-file" class="form-input" accept="image/png, image/jpeg, image/gif, image/webp">
|
| 766 |
-
<div class="form-hint">Выберите изображение на ПК (оставьте пустым, чтобы не менять)</div>
|
| 767 |
-
</div>
|
| 768 |
</div>
|
| 769 |
-
<div class="
|
| 770 |
-
<button
|
| 771 |
-
<button
|
| 772 |
</div>
|
| 773 |
</div>
|
| 774 |
-
</div>
|
| 775 |
|
| 776 |
-
|
| 777 |
-
|
| 778 |
-
|
| 779 |
-
<
|
| 780 |
-
<div class="
|
| 781 |
-
<
|
| 782 |
-
|
| 783 |
-
<input type="text" id="newroom-name-input" class="form-input" placeholder="Моя новая комната">
|
| 784 |
-
</div>
|
| 785 |
-
<div class="form-group">
|
| 786 |
-
<label>Тема (Topic)</label>
|
| 787 |
-
<input type="text" id="newroom-topic-input" class="form-input" placeholder="О чем здесь общаются?">
|
| 788 |
-
</div>
|
| 789 |
-
<div class="form-group">
|
| 790 |
-
<label>Тип комнаты</label>
|
| 791 |
-
<select id="newroom-preset-select" class="form-input">
|
| 792 |
-
<option value="private_chat">Приватная комната (по приглашениям)</option>
|
| 793 |
-
<option value="public_chat">Публичная комната</option>
|
| 794 |
-
</select>
|
| 795 |
-
</div>
|
| 796 |
-
<div class="form-group">
|
| 797 |
-
<label>Аватар комнаты (Загрузка файла)</label>
|
| 798 |
-
<input type="file" id="newroom-avatar-file" class="form-input" accept="image/png, image/jpeg, image/gif, image/webp">
|
| 799 |
-
</div>
|
| 800 |
</div>
|
| 801 |
-
<div class="
|
| 802 |
-
<
|
| 803 |
-
<
|
| 804 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 805 |
</div>
|
| 806 |
-
|
| 807 |
-
|
| 808 |
-
|
| 809 |
-
|
| 810 |
-
|
| 811 |
-
<div class="
|
| 812 |
-
|
| 813 |
-
<
|
| 814 |
-
|
| 815 |
-
<input type="text" id="editroom-name-input" class="form-input">
|
| 816 |
-
</div>
|
| 817 |
-
<div class="form-group">
|
| 818 |
-
<label>Тема комнаты (Topic)</label>
|
| 819 |
-
<input type="text" id="editroom-topic-input" class="form-input">
|
| 820 |
-
</div>
|
| 821 |
-
<div class="form-group">
|
| 822 |
-
<label>Аватар комнаты (Загрузка файла)</label>
|
| 823 |
-
<input type="file" id="editroom-avatar-file" class="form-input" accept="image/png, image/jpeg, image/gif, image/webp">
|
| 824 |
-
<div class="form-hint">Оставьте пустым, чтобы не менять текущую аватарку</div>
|
| 825 |
-
</div>
|
| 826 |
</div>
|
| 827 |
-
<
|
| 828 |
-
|
| 829 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 830 |
</div>
|
|
|
|
| 831 |
</div>
|
| 832 |
</div>
|
| 833 |
|
| 834 |
-
<div class="toast-container" id="toast-container"></div>
|
| 835 |
-
|
| 836 |
<script>
|
| 837 |
-
|
| 838 |
-
|
| 839 |
-
|
| 840 |
-
|
| 841 |
-
|
| 842 |
-
|
| 843 |
-
|
| 844 |
-
|
| 845 |
-
rooms: {},
|
| 846 |
activeRoomId: null,
|
| 847 |
-
|
|
|
|
| 848 |
};
|
| 849 |
|
| 850 |
-
|
| 851 |
-
|
| 852 |
-
|
| 853 |
-
|
| 854 |
-
|
| 855 |
-
|
| 856 |
-
|
| 857 |
-
|
| 858 |
-
|
| 859 |
-
|
| 860 |
-
|
| 861 |
-
|
| 862 |
-
];
|
| 863 |
-
|
| 864 |
-
function initServers() {
|
| 865 |
-
const tbody = document.getElementById('servers-tbody');
|
| 866 |
-
POPULAR_SERVERS.forEach(srv => {
|
| 867 |
-
const tr = document.createElement('tr');
|
| 868 |
-
tr.innerHTML = `
|
| 869 |
-
<td class="server-name">${srv.name}</td>
|
| 870 |
-
<td><a href="${srv.url}" target="_blank" class="server-url">${srv.url}</a></td>
|
| 871 |
-
<td class="server-desc">${srv.notes}</td>
|
| 872 |
-
<td><button class="btn-login-server" onclick="prefillLogin('${srv.url}')">Войти</button></td>
|
| 873 |
-
`;
|
| 874 |
-
tbody.appendChild(tr);
|
| 875 |
-
});
|
| 876 |
-
}
|
| 877 |
-
|
| 878 |
-
function prefillLogin(url) {
|
| 879 |
-
document.getElementById('login-hs').value = url;
|
| 880 |
-
showView('login');
|
| 881 |
-
}
|
| 882 |
-
|
| 883 |
-
function showView(viewId) {
|
| 884 |
-
document.querySelectorAll('.view-container').forEach(el => el.classList.remove('active'));
|
| 885 |
-
document.getElementById(`view-${viewId}`).classList.add('active');
|
| 886 |
-
|
| 887 |
-
const navbar = document.getElementById('main-navbar');
|
| 888 |
-
if (viewId === 'client') {
|
| 889 |
-
navbar.classList.add('hidden'); // Hide top panel in client
|
| 890 |
-
} else {
|
| 891 |
-
navbar.classList.remove('hidden');
|
| 892 |
-
}
|
| 893 |
-
}
|
| 894 |
|
| 895 |
-
|
| 896 |
-
|
| 897 |
const toast = document.createElement('div');
|
| 898 |
-
toast.className = '
|
| 899 |
toast.innerText = msg;
|
| 900 |
-
|
| 901 |
setTimeout(() => {
|
| 902 |
-
|
|
|
|
| 903 |
}, 3000);
|
| 904 |
}
|
| 905 |
|
| 906 |
-
|
| 907 |
-
|
| 908 |
-
|
| 909 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 910 |
|
| 911 |
-
|
| 912 |
-
|
| 913 |
-
|
| 914 |
-
|
| 915 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 916 |
}
|
| 917 |
|
| 918 |
-
function
|
| 919 |
-
|
| 920 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 921 |
}
|
| 922 |
|
| 923 |
-
function
|
| 924 |
-
|
| 925 |
-
|
| 926 |
-
|
| 927 |
-
|
| 928 |
-
|
| 929 |
-
|
| 930 |
-
return `<img src="${url}" onerror="this.style.display='none'; this.nextElementSibling.style.display='flex';" style="width:100%; height:100%; object-fit:cover;">
|
| 931 |
-
<span style="display:none; width:100%; height:100%; align-items:center; justify-content:center;">${getAvatarInitials(name)}</span>`;
|
| 932 |
-
}
|
| 933 |
-
return `<span style="width:100%; height:100%; display:flex; align-items:center; justify-content:center;">${getAvatarInitials(name)}</span>`;
|
| 934 |
}
|
| 935 |
|
| 936 |
-
|
| 937 |
-
const
|
| 938 |
const user = document.getElementById('login-user').value.trim();
|
| 939 |
const pass = document.getElementById('login-pass').value;
|
| 940 |
|
| 941 |
-
if (!
|
| 942 |
-
showToast("
|
| 943 |
return;
|
| 944 |
}
|
| 945 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 946 |
try {
|
| 947 |
-
const
|
| 948 |
-
|
| 949 |
-
|
| 950 |
-
|
| 951 |
-
type: "m.login.password",
|
| 952 |
-
identifier: { type: "m.id.user", user: user },
|
| 953 |
-
password: pass
|
| 954 |
-
})
|
| 955 |
});
|
| 956 |
|
| 957 |
-
|
|
|
|
| 958 |
|
| 959 |
-
|
| 960 |
-
|
| 961 |
-
|
| 962 |
-
|
| 963 |
-
|
| 964 |
-
|
| 965 |
-
showToast("Вход выполнен успешно!");
|
| 966 |
-
showView('client');
|
| 967 |
-
startSync();
|
| 968 |
-
} else {
|
| 969 |
-
showToast(`Ошибка входа: ${data.error}`);
|
| 970 |
-
}
|
| 971 |
} catch (e) {
|
| 972 |
-
showToast("
|
| 973 |
-
|
|
|
|
| 974 |
}
|
| 975 |
-
}
|
| 976 |
|
| 977 |
-
|
| 978 |
-
|
| 979 |
-
|
| 980 |
-
syncLoop();
|
| 981 |
}
|
| 982 |
|
| 983 |
-
async function
|
| 984 |
-
|
| 985 |
-
|
| 986 |
-
|
| 987 |
-
|
| 988 |
-
|
| 989 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 990 |
|
| 991 |
-
|
| 992 |
-
|
| 993 |
-
|
| 994 |
|
| 995 |
-
|
| 996 |
-
|
| 997 |
-
|
| 998 |
-
|
| 999 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1000 |
} catch (e) {
|
| 1001 |
-
|
| 1002 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1003 |
}
|
| 1004 |
}
|
| 1005 |
}
|
| 1006 |
|
| 1007 |
function processSyncData(data) {
|
| 1008 |
-
let
|
| 1009 |
-
let activeRoomNeedsScroll = false;
|
| 1010 |
|
| 1011 |
// Process Joined Rooms
|
| 1012 |
if (data.rooms && data.rooms.join) {
|
| 1013 |
for (const [roomId, roomData] of Object.entries(data.rooms.join)) {
|
| 1014 |
-
if (!
|
| 1015 |
-
|
| 1016 |
-
|
| 1017 |
-
name: roomId, // default
|
| 1018 |
-
topic: '',
|
| 1019 |
-
avatar: null,
|
| 1020 |
-
messages: [],
|
| 1021 |
-
memberCount: 0,
|
| 1022 |
-
creator: null
|
| 1023 |
-
};
|
| 1024 |
-
uiNeedsUpdate = true;
|
| 1025 |
}
|
| 1026 |
-
|
| 1027 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1028 |
|
| 1029 |
-
// State events (
|
| 1030 |
if (roomData.state && roomData.state.events) {
|
| 1031 |
-
roomData.state.events.forEach(
|
| 1032 |
-
if (ev.type === 'm.room.name') room.name = ev.content.name;
|
| 1033 |
-
if (ev.type === 'm.room.avatar') room.avatar = mxcToHttp(ev.content.url);
|
| 1034 |
-
if (ev.type === 'm.room.topic') room.topic = ev.content.topic;
|
| 1035 |
-
if (ev.type === 'm.room.create') room.creator = ev.content.creator;
|
| 1036 |
-
});
|
| 1037 |
-
uiNeedsUpdate = true;
|
| 1038 |
}
|
| 1039 |
|
| 1040 |
-
// Timeline events (
|
| 1041 |
if (roomData.timeline && roomData.timeline.events) {
|
| 1042 |
roomData.timeline.events.forEach(ev => {
|
| 1043 |
-
|
| 1044 |
-
if (ev.type === 'm.room.name') { room.name = ev.content.name; uiNeedsUpdate = true; }
|
| 1045 |
-
if (ev.type === 'm.room.avatar') { room.avatar = mxcToHttp(ev.content.url); uiNeedsUpdate = true; }
|
| 1046 |
-
if (ev.type === 'm.room.topic') { room.topic = ev.content.topic; uiNeedsUpdate = true; }
|
| 1047 |
|
| 1048 |
-
//
|
| 1049 |
-
if (
|
| 1050 |
-
|
| 1051 |
-
|
| 1052 |
-
|
| 1053 |
-
room.messages.push({
|
| 1054 |
-
id: ev.event_id,
|
| 1055 |
-
sender: ev.sender,
|
| 1056 |
-
body: ev.content.body,
|
| 1057 |
-
ts: ev.origin_server_ts
|
| 1058 |
-
});
|
| 1059 |
-
} else {
|
| 1060 |
-
// Confirm optimistic message
|
| 1061 |
-
room.messages[existingIdx].id = ev.event_id;
|
| 1062 |
-
room.messages[existingIdx].pending = false;
|
| 1063 |
-
}
|
| 1064 |
-
|
| 1065 |
-
uiNeedsUpdate = true;
|
| 1066 |
-
if (roomId === matrixSession.activeRoomId) {
|
| 1067 |
-
activeRoomNeedsScroll = true;
|
| 1068 |
}
|
| 1069 |
}
|
| 1070 |
});
|
| 1071 |
}
|
| 1072 |
-
|
| 1073 |
-
// Member count extraction
|
| 1074 |
-
if (roomData.summary && roomData.summary.m_joined_member_count !== undefined) {
|
| 1075 |
-
room.memberCount = roomData.summary.m_joined_member_count;
|
| 1076 |
-
uiNeedsUpdate = true;
|
| 1077 |
-
}
|
| 1078 |
}
|
| 1079 |
}
|
|
|
|
|
|
|
| 1080 |
|
| 1081 |
-
if (
|
| 1082 |
-
|
| 1083 |
-
|
| 1084 |
-
|
| 1085 |
-
|
| 1086 |
-
|
| 1087 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1088 |
}
|
| 1089 |
|
| 1090 |
-
function
|
| 1091 |
-
|
| 1092 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1093 |
|
| 1094 |
-
|
| 1095 |
const div = document.createElement('div');
|
| 1096 |
-
|
| 1097 |
-
|
|
|
|
|
|
|
|
|
|
| 1098 |
|
| 1099 |
-
let lastMsgText = 'Нет сообщений';
|
| 1100 |
-
if (room.messages.length > 0) {
|
| 1101 |
-
const lastMsg = room.messages[room.messages.length - 1];
|
| 1102 |
-
lastMsgText = lastMsg.body;
|
| 1103 |
-
}
|
| 1104 |
-
|
| 1105 |
div.innerHTML = `
|
| 1106 |
-
<
|
| 1107 |
-
|
| 1108 |
-
|
| 1109 |
-
|
| 1110 |
-
<div class="room-name">${room.name}</div>
|
| 1111 |
-
<div class="room-last-msg">${lastMsgText}</div>
|
| 1112 |
</div>
|
| 1113 |
`;
|
| 1114 |
-
|
| 1115 |
-
container.appendChild(div);
|
| 1116 |
});
|
| 1117 |
}
|
| 1118 |
|
| 1119 |
-
function
|
| 1120 |
-
|
| 1121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1122 |
|
| 1123 |
-
|
| 1124 |
-
|
| 1125 |
-
|
| 1126 |
-
|
|
|
|
|
|
|
| 1127 |
|
| 1128 |
-
|
| 1129 |
-
|
| 1130 |
-
|
|
|
|
| 1131 |
}
|
| 1132 |
|
| 1133 |
-
function
|
| 1134 |
-
//
|
| 1135 |
-
|
| 1136 |
-
|
| 1137 |
-
|
| 1138 |
-
|
| 1139 |
-
|
| 1140 |
-
|
| 1141 |
-
|
| 1142 |
-
document.getElementById('rs-topic').innerText = room.topic || 'Нет описания';
|
| 1143 |
-
|
| 1144 |
-
// Edit button visibility
|
| 1145 |
-
const btnEdit = document.getElementById('btn-edit-room');
|
| 1146 |
-
if (room.creator === matrixSession.userId) {
|
| 1147 |
-
btnEdit.style.display = 'block';
|
| 1148 |
-
} else {
|
| 1149 |
-
btnEdit.style.display = 'none';
|
| 1150 |
}
|
| 1151 |
-
}
|
| 1152 |
|
| 1153 |
-
|
| 1154 |
-
if (!matrixSession.activeRoomId) return;
|
| 1155 |
-
const room = matrixSession.rooms[matrixSession.activeRoomId];
|
| 1156 |
-
const container = document.getElementById('messages-container');
|
| 1157 |
-
|
| 1158 |
-
const isAtBottom = container.scrollHeight - container.scrollTop === container.clientHeight;
|
| 1159 |
|
| 1160 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1161 |
|
| 1162 |
-
|
| 1163 |
-
|
| 1164 |
-
|
| 1165 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1166 |
|
| 1167 |
-
|
| 1168 |
-
|
| 1169 |
-
|
| 1170 |
-
|
| 1171 |
-
|
| 1172 |
-
</div>
|
| 1173 |
-
`;
|
| 1174 |
-
container.appendChild(div);
|
| 1175 |
-
});
|
| 1176 |
|
| 1177 |
-
|
| 1178 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1179 |
}
|
| 1180 |
-
}
|
| 1181 |
|
| 1182 |
-
|
| 1183 |
-
|
| 1184 |
-
|
| 1185 |
-
|
| 1186 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1187 |
}
|
| 1188 |
|
| 1189 |
-
function
|
| 1190 |
-
|
| 1191 |
-
document.getElementById('
|
| 1192 |
-
document.getElementById('
|
| 1193 |
-
document.getElementById('
|
|
|
|
| 1194 |
}
|
| 1195 |
|
| 1196 |
-
function
|
| 1197 |
-
|
| 1198 |
-
|
| 1199 |
-
|
| 1200 |
|
| 1201 |
-
|
| 1202 |
-
|
| 1203 |
-
|
| 1204 |
-
|
|
|
|
| 1205 |
}
|
| 1206 |
|
| 1207 |
-
function
|
| 1208 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1209 |
}
|
| 1210 |
|
| 1211 |
-
async function
|
| 1212 |
-
if (!
|
|
|
|
| 1213 |
try {
|
| 1214 |
-
|
| 1215 |
-
|
| 1216 |
-
headers: {
|
| 1217 |
-
'Authorization': `Bearer ${matrixSession.accessToken}`,
|
| 1218 |
-
'Content-Type': file.type || 'application/octet-stream'
|
| 1219 |
-
},
|
| 1220 |
-
body: file
|
| 1221 |
});
|
| 1222 |
-
|
| 1223 |
-
|
| 1224 |
-
const data = await res.json();
|
| 1225 |
-
return data.content_uri || null;
|
| 1226 |
-
}
|
| 1227 |
-
return null;
|
| 1228 |
} catch (e) {
|
| 1229 |
-
|
| 1230 |
-
return null;
|
| 1231 |
}
|
| 1232 |
}
|
| 1233 |
|
| 1234 |
-
|
| 1235 |
-
|
| 1236 |
-
|
| 1237 |
-
|
| 1238 |
-
|
| 1239 |
-
|
| 1240 |
-
try {
|
| 1241 |
-
let newAvatarMxc = null;
|
| 1242 |
-
if (fileInput.files.length > 0) {
|
| 1243 |
-
showToast('Загрузка аватарки...');
|
| 1244 |
-
newAvatarMxc = await uploadMedia(fileInput.files[0]);
|
| 1245 |
-
}
|
| 1246 |
|
| 1247 |
-
|
| 1248 |
-
|
| 1249 |
-
|
| 1250 |
-
headers: {
|
| 1251 |
-
'Authorization': `Bearer ${matrixSession.accessToken}`,
|
| 1252 |
-
'Content-Type': 'application/json'
|
| 1253 |
-
},
|
| 1254 |
-
body: JSON.stringify({ displayname: newName })
|
| 1255 |
-
});
|
| 1256 |
-
matrixSession.displayName = newName;
|
| 1257 |
-
}
|
| 1258 |
-
|
| 1259 |
-
if (newAvatarMxc) {
|
| 1260 |
-
await fetch(`${matrixSession.homeserver}/_matrix/client/v3/profile/${encodeURIComponent(matrixSession.userId)}/avatar_url`, {
|
| 1261 |
-
method: 'PUT',
|
| 1262 |
-
headers: {
|
| 1263 |
-
'Authorization': `Bearer ${matrixSession.accessToken}`,
|
| 1264 |
-
'Content-Type': 'application/json'
|
| 1265 |
-
},
|
| 1266 |
-
body: JSON.stringify({ avatar_url: newAvatarMxc })
|
| 1267 |
-
});
|
| 1268 |
-
matrixSession.avatarUrl = mxcToHttp(newAvatarMxc);
|
| 1269 |
-
}
|
| 1270 |
|
| 1271 |
-
|
| 1272 |
-
|
| 1273 |
-
} catch (err) {
|
| 1274 |
-
console.error('Profile update error:', err);
|
| 1275 |
-
showToast('Ошибка при обновлении профиля');
|
| 1276 |
-
}
|
| 1277 |
}
|
| 1278 |
|
| 1279 |
-
async function
|
| 1280 |
-
|
| 1281 |
-
const
|
| 1282 |
-
const
|
| 1283 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1284 |
|
| 1285 |
-
|
| 1286 |
-
|
| 1287 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1288 |
}
|
| 1289 |
|
| 1290 |
-
|
| 1291 |
-
|
| 1292 |
-
|
| 1293 |
-
|
| 1294 |
-
|
| 1295 |
-
|
| 1296 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1297 |
}
|
|
|
|
|
|
|
| 1298 |
|
| 1299 |
-
|
| 1300 |
-
|
| 1301 |
-
|
| 1302 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1303 |
};
|
|
|
|
|
|
|
| 1304 |
|
| 1305 |
-
|
| 1306 |
-
|
| 1307 |
-
|
| 1308 |
-
|
| 1309 |
-
|
| 1310 |
-
|
| 1311 |
-
}
|
| 1312 |
-
];
|
| 1313 |
-
}
|
| 1314 |
-
|
| 1315 |
-
const res = await fetch(`${matrixSession.homeserver}/_matrix/client/v3/createRoom`, {
|
| 1316 |
method: 'POST',
|
| 1317 |
-
headers: {
|
| 1318 |
-
|
| 1319 |
-
'Content-Type': 'application/json'
|
| 1320 |
-
},
|
| 1321 |
-
body: JSON.stringify(payload)
|
| 1322 |
});
|
| 1323 |
-
|
| 1324 |
const data = await res.json();
|
| 1325 |
-
if (res.ok
|
| 1326 |
-
|
| 1327 |
-
|
| 1328 |
-
|
| 1329 |
-
matrixSession.rooms[data.room_id] = {
|
| 1330 |
-
id: data.room_id,
|
| 1331 |
-
name: name,
|
| 1332 |
-
topic: topic,
|
| 1333 |
-
avatar: avatarMxc ? mxcToHttp(avatarMxc) : '',
|
| 1334 |
-
creator: matrixSession.userId,
|
| 1335 |
-
messages: [],
|
| 1336 |
-
memberCount: 1
|
| 1337 |
-
};
|
| 1338 |
-
renderRoomsList();
|
| 1339 |
-
selectRoom(data.room_id);
|
| 1340 |
-
} else {
|
| 1341 |
-
showToast(`Ошибка: ${data.error || 'Не удалось создать комнату'}`);
|
| 1342 |
-
}
|
| 1343 |
-
} catch (err) {
|
| 1344 |
-
console.error('Create room error:', err);
|
| 1345 |
-
showToast('Ошибка сети при создании комнаты');
|
| 1346 |
}
|
| 1347 |
}
|
| 1348 |
|
| 1349 |
-
async function
|
| 1350 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1351 |
|
| 1352 |
-
const
|
| 1353 |
-
|
| 1354 |
-
|
| 1355 |
-
|
|
|
|
| 1356 |
|
| 1357 |
-
|
| 1358 |
|
| 1359 |
try {
|
| 1360 |
-
|
| 1361 |
if (fileInput.files.length > 0) {
|
| 1362 |
-
|
| 1363 |
-
|
| 1364 |
-
|
| 1365 |
-
|
| 1366 |
-
|
| 1367 |
-
await fetch(`${matrixSession.homeserver}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/state/m.room.name`, {
|
| 1368 |
-
method: 'PUT',
|
| 1369 |
-
headers: {
|
| 1370 |
-
'Authorization': `Bearer ${matrixSession.accessToken}`,
|
| 1371 |
-
'Content-Type': 'application/json'
|
| 1372 |
-
},
|
| 1373 |
-
body: JSON.stringify({ name: newName })
|
| 1374 |
});
|
| 1375 |
-
room.name = newName;
|
| 1376 |
}
|
| 1377 |
|
| 1378 |
-
|
| 1379 |
-
|
| 1380 |
-
|
| 1381 |
-
|
| 1382 |
-
|
| 1383 |
-
|
| 1384 |
-
|
| 1385 |
-
|
| 1386 |
-
|
| 1387 |
-
|
| 1388 |
-
|
|
|
|
| 1389 |
|
| 1390 |
-
|
| 1391 |
-
|
| 1392 |
-
|
| 1393 |
-
|
| 1394 |
-
'Authorization': `Bearer ${matrixSession.accessToken}`,
|
| 1395 |
-
'Content-Type': 'application/json'
|
| 1396 |
-
},
|
| 1397 |
-
body: JSON.stringify({ url: newAvatarMxc })
|
| 1398 |
-
});
|
| 1399 |
-
room.avatar = mxcToHttp(newAvatarMxc);
|
| 1400 |
-
}
|
| 1401 |
|
| 1402 |
-
|
| 1403 |
-
|
| 1404 |
-
|
| 1405 |
-
|
| 1406 |
-
|
| 1407 |
-
|
| 1408 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1409 |
}
|
| 1410 |
}
|
| 1411 |
|
| 1412 |
-
async function
|
| 1413 |
-
const
|
| 1414 |
-
|
| 1415 |
-
const roomId = matrixSession.activeRoomId;
|
| 1416 |
|
| 1417 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1418 |
|
| 1419 |
-
|
| 1420 |
-
|
| 1421 |
-
const
|
| 1422 |
-
|
| 1423 |
-
// Оптимистичное обновление UI
|
| 1424 |
-
const room = matrixSession.rooms[roomId];
|
| 1425 |
-
const tempMsg = {
|
| 1426 |
-
id: txnId,
|
| 1427 |
-
txnId: txnId,
|
| 1428 |
-
sender: matrixSession.userId,
|
| 1429 |
-
body: text,
|
| 1430 |
-
ts: Date.now(),
|
| 1431 |
-
pending: true
|
| 1432 |
-
};
|
| 1433 |
-
room.messages.push(tempMsg);
|
| 1434 |
-
renderMessages(true);
|
| 1435 |
-
renderRoomsList();
|
| 1436 |
|
| 1437 |
try {
|
| 1438 |
-
|
| 1439 |
-
|
| 1440 |
-
headers: {
|
| 1441 |
-
'Authorization': `Bearer ${matrixSession.accessToken}`,
|
| 1442 |
-
'Content-Type': 'application/json'
|
| 1443 |
-
},
|
| 1444 |
-
body: JSON.stringify({
|
| 1445 |
-
msgtype: "m.text",
|
| 1446 |
-
body: text
|
| 1447 |
-
})
|
| 1448 |
});
|
| 1449 |
-
|
| 1450 |
-
|
| 1451 |
-
|
| 1452 |
-
tempMsg.body += ' ❌ (Ошибка отправки)';
|
| 1453 |
-
tempMsg.pending = false;
|
| 1454 |
-
renderMessages(true);
|
| 1455 |
-
}
|
| 1456 |
} catch (e) {
|
| 1457 |
-
|
| 1458 |
-
showToast('Ошибка сети при отправке');
|
| 1459 |
-
tempMsg.body += ' ❌ (Ошибка сети)';
|
| 1460 |
-
tempMsg.pending = false;
|
| 1461 |
-
renderMessages(true);
|
| 1462 |
}
|
| 1463 |
}
|
| 1464 |
|
| 1465 |
-
function
|
| 1466 |
-
if (
|
| 1467 |
-
|
| 1468 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1469 |
}
|
| 1470 |
|
| 1471 |
window.onload = () => {
|
| 1472 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1473 |
};
|
| 1474 |
|
| 1475 |
</script>
|
|
|
|
| 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 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
<style>
|
| 9 |
+
body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: #1e1e1e; color: #d4d4d4; }
|
| 10 |
+
.retro-border { border: 1px solid #4a4a4a; box-shadow: inset 1px 1px 0 #5a5a5a, inset -1px -1px 0 #000; }
|
| 11 |
+
.retro-panel { background-color: #2d2d2d; border: 1px solid #111; box-shadow: 1px 1px 3px rgba(0,0,0,0.5); }
|
| 12 |
+
.retro-input { background-color: #1e1e1e; border: 1px solid #000; color: #fff; box-shadow: inset 1px 1px 2px rgba(0,0,0,0.8); }
|
| 13 |
+
.retro-btn { background: linear-gradient(to bottom, #4a4a4a, #2d2d2d); border: 1px solid #111; color: #fff; box-shadow: inset 1px 1px 0 #6a6a6a; cursor: pointer; text-shadow: 1px 1px 0 #000; transition: all 0.1s; }
|
| 14 |
+
.retro-btn:hover { background: linear-gradient(to bottom, #5a5a5a, #3d3d3d); }
|
| 15 |
+
.retro-btn:active { background: #2d2d2d; box-shadow: inset 1px 1px 2px #000; }
|
| 16 |
+
.scroll-custom::-webkit-scrollbar { width: 8px; }
|
| 17 |
+
.scroll-custom::-webkit-scrollbar-track { background: #1e1e1e; border-left: 1px solid #111; }
|
| 18 |
+
.scroll-custom::-webkit-scrollbar-thumb { background: #4a4a4a; border: 1px solid #111; }
|
| 19 |
+
.room-item:hover { background-color: #3d3d3d; cursor: pointer; }
|
| 20 |
+
.room-item.active { background-color: #005a9e; border-color: #0078d7; }
|
| 21 |
+
.msg-actions { opacity: 0; transition: opacity 0.2s; }
|
| 22 |
+
.group:hover .msg-actions { opacity: 1; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
</style>
|
| 24 |
</head>
|
| 25 |
+
<body class="h-screen w-screen overflow-hidden flex items-center justify-center text-sm">
|
| 26 |
|
| 27 |
+
<div id="toast-container" class="fixed top-4 right-4 z-50 flex flex-col gap-2"></div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
+
<div id="login-screen" class="retro-panel w-96 p-6 flex flex-col gap-4">
|
| 30 |
+
<div class="text-center mb-4">
|
| 31 |
+
<h1 class="text-2xl font-bold text-white mb-1">Matrix Client</h1>
|
| 32 |
+
<p class="text-xs text-gray-400">Zero-dependency pure API client</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
</div>
|
| 34 |
+
<div class="flex flex-col gap-1">
|
| 35 |
+
<label class="text-xs text-gray-300">Homeserver URL</label>
|
| 36 |
+
<input type="text" id="login-server" value="https://matrix.unredacted.org" class="retro-input p-2 rounded-sm outline-none focus:border-blue-500">
|
| 37 |
+
</div>
|
| 38 |
+
<div class="flex flex-col gap-1">
|
| 39 |
+
<label class="text-xs text-gray-300">Username / MXID</label>
|
| 40 |
+
<input type="text" id="login-user" placeholder="user (without @server)" class="retro-input p-2 rounded-sm outline-none focus:border-blue-500">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
</div>
|
| 42 |
+
<div class="flex flex-col gap-1">
|
| 43 |
+
<label class="text-xs text-gray-300">Password</label>
|
| 44 |
+
<input type="password" id="login-pass" class="retro-input p-2 rounded-sm outline-none focus:border-blue-500">
|
| 45 |
+
</div>
|
| 46 |
+
<button id="btn-login" class="retro-btn py-2 mt-2 font-bold rounded-sm">Connect</button>
|
| 47 |
</div>
|
| 48 |
|
| 49 |
+
<div id="app-screen" class="hidden w-full h-full flex bg-[#1e1e1e]">
|
| 50 |
<!-- Sidebar -->
|
| 51 |
+
<div class="w-72 border-r border-[#111] bg-[#252526] flex flex-col flex-shrink-0">
|
| 52 |
+
<!-- Current User Info -->
|
| 53 |
+
<div class="p-3 border-b border-[#111] flex items-center justify-between bg-[#2d2d2d] shadow-sm">
|
| 54 |
+
<div class="flex items-center gap-2 overflow-hidden cursor-pointer" onclick="openMyProfile()">
|
| 55 |
+
<img id="my-avatar" src="https://placehold.co/32x32/1e1e1e/fff?text=?" class="w-8 h-8 rounded-full border border-gray-600 object-cover">
|
| 56 |
+
<div class="flex flex-col overflow-hidden">
|
| 57 |
+
<span id="my-name" class="font-bold text-white truncate text-xs">...</span>
|
| 58 |
+
<span id="my-id" class="text-[10px] text-gray-400 truncate">...</span>
|
| 59 |
+
</div>
|
| 60 |
+
</div>
|
| 61 |
+
<button onclick="logout()" title="Logout" class="retro-btn p-1 px-2 text-xs rounded-sm ml-2">Выход</button>
|
| 62 |
+
</div>
|
| 63 |
+
<!-- Actions -->
|
| 64 |
+
<div class="p-2 grid grid-cols-2 gap-1 border-b border-[#111]">
|
| 65 |
+
<button onclick="openModal('create-room-modal')" class="retro-btn py-1 text-xs rounded-sm">Создать</button>
|
| 66 |
+
<button onclick="openModal('join-room-modal')" class="retro-btn py-1 text-xs rounded-sm">Войти / DM</button>
|
| 67 |
</div>
|
| 68 |
+
<!-- Room List -->
|
| 69 |
+
<div class="flex-1 overflow-y-auto scroll-custom p-1" id="room-list">
|
| 70 |
+
<!-- Rooms rendered here -->
|
| 71 |
</div>
|
| 72 |
</div>
|
| 73 |
|
| 74 |
+
<div class="flex-1 flex flex-col min-w-0 bg-[#1e1e1e] relative">
|
| 75 |
+
<!-- Room Header -->
|
| 76 |
+
<div id="room-header" class="hidden h-14 border-b border-[#111] bg-[#2d2d2d] items-center px-4 justify-between flex-shrink-0">
|
| 77 |
+
<div class="flex items-center gap-3 overflow-hidden">
|
| 78 |
+
<img id="active-room-avatar" src="https://placehold.co/40x40/1e1e1e/fff?text=?" class="w-10 h-10 rounded-full border border-gray-600 object-cover">
|
| 79 |
+
<div class="flex flex-col">
|
| 80 |
+
<div class="flex items-center gap-2">
|
| 81 |
+
<span id="active-room-name" class="font-bold text-white text-base truncate max-w-md">Select a room</span>
|
| 82 |
+
<span id="active-room-enc" class="hidden text-xs bg-red-900 text-red-200 px-1 rounded">E2EE</span>
|
| 83 |
+
</div>
|
| 84 |
+
<span id="active-room-topic" class="text-xs text-gray-400 truncate max-w-lg"></span>
|
| 85 |
+
</div>
|
| 86 |
+
</div>
|
| 87 |
+
<div class="flex gap-2">
|
| 88 |
+
<button onclick="openModal('invite-modal')" class="retro-btn px-3 py-1 text-xs rounded-sm">Пригласить</button>
|
| 89 |
+
<button onclick="leaveCurrentRoom()" class="retro-btn px-3 py-1 text-xs rounded-sm text-red-400 border-red-900">Выйти</button>
|
| 90 |
</div>
|
| 91 |
</div>
|
| 92 |
|
| 93 |
+
<!-- Empty State -->
|
| 94 |
+
<div id="empty-state" class="flex-1 flex flex-col items-center justify-center text-gray-500">
|
| 95 |
+
<div class="text-4xl mb-4">💬</div>
|
| 96 |
+
<p>Выберите чат слева или создайте новый</p>
|
| 97 |
</div>
|
| 98 |
|
| 99 |
+
<!-- Messages Timeline -->
|
| 100 |
+
<div id="chat-timeline" class="hidden flex-1 overflow-y-auto scroll-custom p-4 space-y-3 bg-[#1e1e1e]">
|
| 101 |
+
<!-- Messages rendered here -->
|
| 102 |
</div>
|
|
|
|
| 103 |
|
| 104 |
+
<!-- Message Input Area -->
|
| 105 |
+
<div id="chat-input-area" class="hidden border-t border-[#111] bg-[#2d2d2d] flex-shrink-0 p-3 flex flex-col gap-2">
|
| 106 |
+
<!-- Reply Context -->
|
| 107 |
+
<div id="reply-context" class="hidden bg-[#1e1e1e] border-l-2 border-blue-500 p-2 text-xs flex justify-between items-center rounded-sm text-gray-300">
|
| 108 |
+
<div class="truncate">
|
| 109 |
+
<span class="font-bold text-blue-400 mr-2" id="reply-sender">User</span>
|
| 110 |
+
<span id="reply-text" class="text-gray-400 truncate">...</span>
|
| 111 |
+
</div>
|
| 112 |
+
<button onclick="cancelReply()" class="ml-2 text-gray-500 hover:text-white font-bold">×</button>
|
| 113 |
+
</div>
|
| 114 |
+
<div class="flex gap-2 items-end">
|
| 115 |
+
<textarea id="msg-input" rows="2" placeholder="Написать сообщение..." class="flex-1 retro-input p-2 rounded-sm outline-none focus:border-blue-500 resize-none scroll-custom text-sm" onkeydown="handleInputKey(event)"></textarea>
|
| 116 |
+
<button onclick="sendCurrentMessage()" class="retro-btn px-4 py-2 h-full rounded-sm font-bold h-[54px]">Отправить</button>
|
| 117 |
+
</div>
|
|
|
|
| 118 |
</div>
|
| 119 |
</div>
|
| 120 |
</div>
|
| 121 |
|
| 122 |
+
<div id="modal-backdrop" class="hidden fixed inset-0 bg-black bg-opacity-70 z-40 flex items-center justify-center backdrop-blur-sm">
|
| 123 |
+
|
| 124 |
+
<!-- User Profile Modal -->
|
| 125 |
+
<div id="profile-modal" class="hidden retro-panel w-80 p-5 rounded-sm flex flex-col items-center gap-4 relative modal-content">
|
| 126 |
+
<button onclick="closeModals()" class="absolute top-2 right-3 text-gray-400 hover:text-white font-bold text-lg">×</button>
|
| 127 |
+
<img id="mod-prof-avatar" src="" class="w-24 h-24 rounded-full border-2 border-gray-500 object-cover mt-2">
|
| 128 |
+
<div class="text-center w-full">
|
| 129 |
+
<h2 id="mod-prof-name" class="text-lg font-bold text-white truncate w-full">Name</h2>
|
| 130 |
+
<p id="mod-prof-id" class="text-xs text-gray-400 truncate w-full">@user:server.com</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
</div>
|
| 132 |
+
<div class="flex flex-col gap-2 w-full mt-2">
|
| 133 |
+
<button id="btn-prof-copy" class="retro-btn py-2 text-sm rounded-sm">Скопировать ссылку</button>
|
| 134 |
+
<button id="btn-prof-dm" class="retro-btn py-2 text-sm rounded-sm text-blue-300">Написать (DM)</button>
|
| 135 |
</div>
|
| 136 |
</div>
|
|
|
|
| 137 |
|
| 138 |
+
<!-- Create Room Modal -->
|
| 139 |
+
<div id="create-room-modal" class="hidden retro-panel w-96 p-5 rounded-sm flex flex-col gap-4 relative modal-content">
|
| 140 |
+
<button onclick="closeModals()" class="absolute top-2 right-3 text-gray-400 hover:text-white font-bold text-lg">×</button>
|
| 141 |
+
<h2 class="text-lg font-bold text-white mb-2">Создать комнату</h2>
|
| 142 |
+
<div class="flex flex-col gap-1">
|
| 143 |
+
<label class="text-xs text-gray-300">Аватар (файл)</label>
|
| 144 |
+
<input type="file" id="create-room-avatar" accept="image/*" class="text-xs retro-input p-1">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
</div>
|
| 146 |
+
<div class="flex flex-col gap-1">
|
| 147 |
+
<label class="text-xs text-gray-300">Название *</label>
|
| 148 |
+
<input type="text" id="create-room-name" class="retro-input p-2 rounded-sm text-sm">
|
| 149 |
</div>
|
| 150 |
+
<div class="flex flex-col gap-1">
|
| 151 |
+
<label class="text-xs text-gray-300">Тема (Topic)</label>
|
| 152 |
+
<input type="text" id="create-room-topic" class="retro-input p-2 rounded-sm text-sm">
|
| 153 |
+
</div>
|
| 154 |
+
<div class="flex gap-4 mt-2">
|
| 155 |
+
<label class="flex items-center gap-1 text-sm text-gray-300 cursor-pointer">
|
| 156 |
+
<input type="radio" name="room-vis" value="public" class="accent-blue-500"> Публичная
|
| 157 |
+
</label>
|
| 158 |
+
<label class="flex items-center gap-1 text-sm text-gray-300 cursor-pointer">
|
| 159 |
+
<input type="radio" name="room-vis" value="private" checked class="accent-blue-500"> Приватная
|
| 160 |
+
</label>
|
| 161 |
+
</div>
|
| 162 |
+
<button onclick="submitCreateRoom()" class="retro-btn py-2 mt-2 text-sm font-bold rounded-sm">Создать</button>
|
| 163 |
</div>
|
| 164 |
+
|
| 165 |
+
<!-- Join/DM Modal -->
|
| 166 |
+
<div id="join-room-modal" class="hidden retro-panel w-96 p-5 rounded-sm flex flex-col gap-4 relative modal-content">
|
| 167 |
+
<button onclick="closeModals()" class="absolute top-2 right-3 text-gray-400 hover:text-white font-bold text-lg">×</button>
|
| 168 |
+
<h2 class="text-lg font-bold text-white mb-2">Войти / Написать</h2>
|
| 169 |
+
<div class="flex flex-col gap-1">
|
| 170 |
+
<label class="text-xs text-gray-300">ID пользователя или Алиас комнаты</label>
|
| 171 |
+
<input type="text" id="join-target-id" placeholder="@user:server.com OR #room:server.com" class="retro-input p-2 rounded-sm text-sm">
|
| 172 |
+
<p class="text-[10px] text-gray-500 mt-1">Если ввести @user, создастся личный чат (DM). Если #room или !room, будет выполнен вход в комнату.</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
</div>
|
| 174 |
+
<button onclick="submitJoinOrDM()" class="retro-btn py-2 mt-2 text-sm font-bold rounded-sm">Подключиться</button>
|
| 175 |
+
</div>
|
| 176 |
+
|
| 177 |
+
<!-- Invite Modal -->
|
| 178 |
+
<div id="invite-modal" class="hidden retro-panel w-80 p-5 rounded-sm flex flex-col gap-4 relative modal-content">
|
| 179 |
+
<button onclick="closeModals()" class="absolute top-2 right-3 text-gray-400 hover:text-white font-bold text-lg">×</button>
|
| 180 |
+
<h2 class="text-lg font-bold text-white mb-2">Пригласить</h2>
|
| 181 |
+
<div class="flex flex-col gap-1">
|
| 182 |
+
<label class="text-xs text-gray-300">ID пользователя</label>
|
| 183 |
+
<input type="text" id="invite-target-id" placeholder="@user:server.com" class="retro-input p-2 rounded-sm text-sm">
|
| 184 |
</div>
|
| 185 |
+
<button onclick="submitInvite()" class="retro-btn py-2 mt-2 text-sm font-bold rounded-sm">Отправить приглашение</button>
|
| 186 |
</div>
|
| 187 |
</div>
|
| 188 |
|
|
|
|
|
|
|
| 189 |
<script>
|
| 190 |
+
// State
|
| 191 |
+
const state = {
|
| 192 |
+
baseUrl: localStorage.getItem('mx_base_url') || 'https://matrix.unredacted.org',
|
| 193 |
+
token: localStorage.getItem('mx_access_token') || '',
|
| 194 |
+
userId: localStorage.getItem('mx_user_id') || '',
|
| 195 |
+
syncToken: localStorage.getItem('mx_sync_token') || '',
|
| 196 |
+
isSyncing: false,
|
| 197 |
+
rooms: {}, // Data layer
|
|
|
|
| 198 |
activeRoomId: null,
|
| 199 |
+
replyingTo: null, // { eventId, sender, body }
|
| 200 |
+
myProfile: {}
|
| 201 |
};
|
| 202 |
|
| 203 |
+
// DOM Elements
|
| 204 |
+
const el = {
|
| 205 |
+
login: document.getElementById('login-screen'),
|
| 206 |
+
app: document.getElementById('app-screen'),
|
| 207 |
+
modals: document.getElementById('modal-backdrop'),
|
| 208 |
+
roomList: document.getElementById('room-list'),
|
| 209 |
+
chatTimeline: document.getElementById('chat-timeline'),
|
| 210 |
+
chatInput: document.getElementById('chat-input-area'),
|
| 211 |
+
roomHeader: document.getElementById('room-header'),
|
| 212 |
+
emptyState: document.getElementById('empty-state'),
|
| 213 |
+
toastContainer: document.getElementById('toast-container')
|
| 214 |
+
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
|
| 216 |
+
// Utility: Toast notifications
|
| 217 |
+
function showToast(msg, isError = false) {
|
| 218 |
const toast = document.createElement('div');
|
| 219 |
+
toast.className = `px-4 py-2 rounded shadow-md text-sm text-white ${isError ? 'bg-red-700' : 'bg-green-700'} border border-${isError ? 'red' : 'green'}-900 opacity-90 transition-opacity`;
|
| 220 |
toast.innerText = msg;
|
| 221 |
+
el.toastContainer.appendChild(toast);
|
| 222 |
setTimeout(() => {
|
| 223 |
+
toast.classList.add('opacity-0');
|
| 224 |
+
setTimeout(() => toast.remove(), 300);
|
| 225 |
}, 3000);
|
| 226 |
}
|
| 227 |
|
| 228 |
+
// Utility: Core API fetch wrapper
|
| 229 |
+
async function apiCall(endpoint, method = 'GET', body = null, isMediaUpload = false) {
|
| 230 |
+
const headers = {};
|
| 231 |
+
if (state.token) headers['Authorization'] = `Bearer ${state.token}`;
|
| 232 |
+
|
| 233 |
+
if (body && !isMediaUpload) {
|
| 234 |
+
headers['Content-Type'] = 'application/json';
|
| 235 |
+
body = JSON.stringify(body);
|
| 236 |
+
}
|
| 237 |
|
| 238 |
+
try {
|
| 239 |
+
const res = await fetch(`${state.baseUrl}/_matrix/${isMediaUpload ? 'media' : 'client'}/v3${endpoint}`, {
|
| 240 |
+
method,
|
| 241 |
+
headers,
|
| 242 |
+
body
|
| 243 |
+
});
|
| 244 |
+
|
| 245 |
+
if (res.status === 401) {
|
| 246 |
+
logout();
|
| 247 |
+
throw new Error("Unauthorized");
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
const data = await res.json();
|
| 251 |
+
if (!res.ok) throw new Error(data.error || `HTTP ${res.status}`);
|
| 252 |
+
return data;
|
| 253 |
+
} catch (err) {
|
| 254 |
+
console.error("API Error:", err);
|
| 255 |
+
throw err;
|
| 256 |
+
}
|
| 257 |
}
|
| 258 |
|
| 259 |
+
function getMediaUrl(mxcUrl, width=null, height=null) {
|
| 260 |
+
if (!mxcUrl) return null;
|
| 261 |
+
if (!mxcUrl.startsWith('mxc://')) return mxcUrl; // Might be a standard HTTP url if malformed, but fallback
|
| 262 |
+
|
| 263 |
+
const parts = mxcUrl.replace('mxc://', '').split('/');
|
| 264 |
+
const serverName = parts[0];
|
| 265 |
+
const mediaId = parts[1];
|
| 266 |
+
|
| 267 |
+
if (width && height) {
|
| 268 |
+
return `${state.baseUrl}/_matrix/media/v3/thumbnail/${serverName}/${mediaId}?width=${width}&height=${height}&method=crop`;
|
| 269 |
+
} else {
|
| 270 |
+
return `${state.baseUrl}/_matrix/media/v3/download/${serverName}/${mediaId}`;
|
| 271 |
+
}
|
| 272 |
}
|
| 273 |
|
| 274 |
+
function escapeHtml(unsafe) {
|
| 275 |
+
return (unsafe || '').toString()
|
| 276 |
+
.replace(/&/g, "&")
|
| 277 |
+
.replace(/</g, "<")
|
| 278 |
+
.replace(/>/g, ">")
|
| 279 |
+
.replace(/"/g, """)
|
| 280 |
+
.replace(/'/g, "'");
|
|
|
|
|
|
|
|
|
|
|
|
|
| 281 |
}
|
| 282 |
|
| 283 |
+
document.getElementById('btn-login').onclick = async () => {
|
| 284 |
+
const server = document.getElementById('login-server').value.trim();
|
| 285 |
const user = document.getElementById('login-user').value.trim();
|
| 286 |
const pass = document.getElementById('login-pass').value;
|
| 287 |
|
| 288 |
+
if (!server || !user || !pass) {
|
| 289 |
+
showToast("Заполните все поля", true);
|
| 290 |
return;
|
| 291 |
}
|
| 292 |
|
| 293 |
+
// Normalize base URL
|
| 294 |
+
state.baseUrl = server.replace(/\/$/, "");
|
| 295 |
+
if (!state.baseUrl.startsWith('http')) state.baseUrl = 'https://' + state.baseUrl;
|
| 296 |
+
|
| 297 |
+
const btn = document.getElementById('btn-login');
|
| 298 |
+
btn.innerText = "Подключение...";
|
| 299 |
+
btn.disabled = true;
|
| 300 |
+
|
| 301 |
try {
|
| 302 |
+
const data = await apiCall('/login', 'POST', {
|
| 303 |
+
type: 'm.login.password',
|
| 304 |
+
identifier: { type: 'm.id.user', user: user },
|
| 305 |
+
password: pass
|
|
|
|
|
|
|
|
|
|
|
|
|
| 306 |
});
|
| 307 |
|
| 308 |
+
state.token = data.access_token;
|
| 309 |
+
state.userId = data.user_id;
|
| 310 |
|
| 311 |
+
localStorage.setItem('mx_base_url', state.baseUrl);
|
| 312 |
+
localStorage.setItem('mx_access_token', state.token);
|
| 313 |
+
localStorage.setItem('mx_user_id', state.userId);
|
| 314 |
+
|
| 315 |
+
showToast("Вход выполнен успешно");
|
| 316 |
+
initApp();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 317 |
} catch (e) {
|
| 318 |
+
showToast("Ошибка входа: " + e.message, true);
|
| 319 |
+
btn.innerText = "Connect";
|
| 320 |
+
btn.disabled = false;
|
| 321 |
}
|
| 322 |
+
};
|
| 323 |
|
| 324 |
+
function logout() {
|
| 325 |
+
localStorage.clear();
|
| 326 |
+
location.reload();
|
|
|
|
| 327 |
}
|
| 328 |
|
| 329 |
+
async function initApp() {
|
| 330 |
+
el.login.classList.add('hidden');
|
| 331 |
+
el.app.classList.remove('hidden');
|
| 332 |
+
|
| 333 |
+
// Load own profile basic info
|
| 334 |
+
try {
|
| 335 |
+
const profile = await apiCall(`/profile/${encodeURIComponent(state.userId)}`);
|
| 336 |
+
state.myProfile = profile;
|
| 337 |
+
document.getElementById('my-name').innerText = profile.displayname || state.userId;
|
| 338 |
+
document.getElementById('my-id').innerText = state.userId;
|
| 339 |
+
if (profile.avatar_url) {
|
| 340 |
+
document.getElementById('my-avatar').src = getMediaUrl(profile.avatar_url, 64, 64);
|
| 341 |
+
}
|
| 342 |
+
} catch (e) {
|
| 343 |
+
document.getElementById('my-name').innerText = state.userId;
|
| 344 |
+
}
|
| 345 |
|
| 346 |
+
// Start Sync Loop
|
| 347 |
+
startSync();
|
| 348 |
+
}
|
| 349 |
|
| 350 |
+
async function startSync() {
|
| 351 |
+
if (state.isSyncing) return;
|
| 352 |
+
state.isSyncing = true;
|
| 353 |
+
|
| 354 |
+
while (state.isSyncing) {
|
| 355 |
+
try {
|
| 356 |
+
let url = `/sync?timeout=30000`;
|
| 357 |
+
if (state.syncToken) url += `&since=${state.syncToken}`;
|
| 358 |
+
|
| 359 |
+
const data = await apiCall(url);
|
| 360 |
+
state.syncToken = data.next_batch;
|
| 361 |
+
localStorage.setItem('mx_sync_token', state.syncToken);
|
| 362 |
+
|
| 363 |
+
processSyncData(data);
|
| 364 |
} catch (e) {
|
| 365 |
+
if (e.message !== "Unauthorized") {
|
| 366 |
+
console.error("Sync error, retrying in 5s...", e);
|
| 367 |
+
await new Promise(r => setTimeout(r, 5000));
|
| 368 |
+
} else {
|
| 369 |
+
break;
|
| 370 |
+
}
|
| 371 |
}
|
| 372 |
}
|
| 373 |
}
|
| 374 |
|
| 375 |
function processSyncData(data) {
|
| 376 |
+
let roomsUpdated = false;
|
|
|
|
| 377 |
|
| 378 |
// Process Joined Rooms
|
| 379 |
if (data.rooms && data.rooms.join) {
|
| 380 |
for (const [roomId, roomData] of Object.entries(data.rooms.join)) {
|
| 381 |
+
if (!state.rooms[roomId]) {
|
| 382 |
+
state.rooms[roomId] = { id: roomId, name: '', topic: '', avatar: null, members: {}, timeline: [], isEncrypted: false };
|
| 383 |
+
roomsUpdated = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 384 |
}
|
| 385 |
+
const room = state.rooms[roomId];
|
| 386 |
+
|
| 387 |
+
// Helper to process state
|
| 388 |
+
const processState = (ev) => {
|
| 389 |
+
if (ev.type === 'm.room.name') { room.name = ev.content.name; roomsUpdated = true; }
|
| 390 |
+
else if (ev.type === 'm.room.topic') room.topic = ev.content.topic;
|
| 391 |
+
else if (ev.type === 'm.room.avatar') { room.avatar = ev.content.url; roomsUpdated = true; }
|
| 392 |
+
else if (ev.type === 'm.room.encryption') room.isEncrypted = true;
|
| 393 |
+
else if (ev.type === 'm.room.member') {
|
| 394 |
+
room.members[ev.state_key] = {
|
| 395 |
+
displayname: ev.content.displayname,
|
| 396 |
+
avatar_url: ev.content.avatar_url,
|
| 397 |
+
membership: ev.content.membership
|
| 398 |
+
};
|
| 399 |
+
roomsUpdated = true;
|
| 400 |
+
}
|
| 401 |
+
};
|
| 402 |
|
| 403 |
+
// State events (current state)
|
| 404 |
if (roomData.state && roomData.state.events) {
|
| 405 |
+
roomData.state.events.forEach(processState);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 406 |
}
|
| 407 |
|
| 408 |
+
// Timeline events (messages and inline state changes)
|
| 409 |
if (roomData.timeline && roomData.timeline.events) {
|
| 410 |
roomData.timeline.events.forEach(ev => {
|
| 411 |
+
if (ev.state_key !== undefined) processState(ev);
|
|
|
|
|
|
|
|
|
|
| 412 |
|
| 413 |
+
// Check if event already exists to avoid dupes during sync overlap
|
| 414 |
+
if (!room.timeline.find(e => e.event_id === ev.event_id)) {
|
| 415 |
+
room.timeline.push(ev);
|
| 416 |
+
if (state.activeRoomId === roomId) {
|
| 417 |
+
appendMessageToUI(ev);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 418 |
}
|
| 419 |
}
|
| 420 |
});
|
| 421 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 422 |
}
|
| 423 |
}
|
| 424 |
+
|
| 425 |
+
// Process Invites (Basic auto-accept or UI notice could go here, for simplicity we skip rendering invites separately but user can join manually via ID)
|
| 426 |
|
| 427 |
+
if (roomsUpdated) renderRoomList();
|
| 428 |
+
}
|
| 429 |
+
|
| 430 |
+
function getComputedRoomName(room) {
|
| 431 |
+
if (room.name) return room.name;
|
| 432 |
+
// Fallback to member names
|
| 433 |
+
const otherMembers = Object.keys(room.members)
|
| 434 |
+
.filter(id => id !== state.userId && room.members[id].membership === 'join')
|
| 435 |
+
.map(id => room.members[id].displayname || id);
|
| 436 |
+
|
| 437 |
+
if (otherMembers.length > 0) return otherMembers.join(', ');
|
| 438 |
+
return "Empty Room";
|
| 439 |
}
|
| 440 |
|
| 441 |
+
function renderRoomList() {
|
| 442 |
+
el.roomList.innerHTML = '';
|
| 443 |
+
|
| 444 |
+
const roomsArray = Object.values(state.rooms).sort((a, b) => {
|
| 445 |
+
// Sort by latest activity - simple fallback: just alphabetical for now
|
| 446 |
+
const nameA = getComputedRoomName(a).toLowerCase();
|
| 447 |
+
const nameB = getComputedRoomName(b).toLowerCase();
|
| 448 |
+
return nameA.localeCompare(nameB);
|
| 449 |
+
});
|
| 450 |
|
| 451 |
+
roomsArray.forEach(room => {
|
| 452 |
const div = document.createElement('div');
|
| 453 |
+
const displayName = escapeHtml(getComputedRoomName(room));
|
| 454 |
+
const avatarSrc = getMediaUrl(room.avatar, 40, 40) || `https://placehold.co/40x40/2d2d2d/fff?text=${encodeURIComponent(displayName.charAt(0))}`;
|
| 455 |
+
|
| 456 |
+
div.className = `room-item p-2 border-b border-[#111] flex items-center gap-3 transition-colors ${state.activeRoomId === room.id ? 'active' : ''}`;
|
| 457 |
+
div.onclick = () => switchRoom(room.id);
|
| 458 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 459 |
div.innerHTML = `
|
| 460 |
+
<img src="${avatarSrc}" class="w-8 h-8 rounded-full border border-gray-600 object-cover flex-shrink-0">
|
| 461 |
+
<div class="flex flex-col overflow-hidden w-full">
|
| 462 |
+
<span class="text-white text-xs font-bold truncate">${displayName}</span>
|
| 463 |
+
<span class="text-gray-400 text-[10px] truncate">${room.isEncrypted ? '🔒 Зашифровано' : (room.topic || 'No topic')}</span>
|
|
|
|
|
|
|
| 464 |
</div>
|
| 465 |
`;
|
| 466 |
+
el.roomList.appendChild(div);
|
|
|
|
| 467 |
});
|
| 468 |
}
|
| 469 |
|
| 470 |
+
function switchRoom(roomId) {
|
| 471 |
+
if (!state.rooms[roomId]) return;
|
| 472 |
+
state.activeRoomId = roomId;
|
| 473 |
+
renderRoomList(); // Update active class
|
| 474 |
+
|
| 475 |
+
const room = state.rooms[roomId];
|
| 476 |
+
el.emptyState.classList.add('hidden');
|
| 477 |
+
el.roomHeader.classList.remove('hidden');
|
| 478 |
+
el.chatTimeline.classList.remove('hidden');
|
| 479 |
+
el.chatInput.classList.remove('hidden');
|
| 480 |
+
|
| 481 |
+
// Header
|
| 482 |
+
const displayName = getComputedRoomName(room);
|
| 483 |
+
document.getElementById('active-room-name').innerText = displayName;
|
| 484 |
+
document.getElementById('active-room-topic').innerText = room.topic || roomId;
|
| 485 |
+
document.getElementById('active-room-avatar').src = getMediaUrl(room.avatar, 64, 64) || `https://placehold.co/64x64/2d2d2d/fff?text=${encodeURIComponent(displayName.charAt(0))}`;
|
| 486 |
+
|
| 487 |
+
const encBadge = document.getElementById('active-room-enc');
|
| 488 |
+
if (room.isEncrypted) encBadge.classList.remove('hidden');
|
| 489 |
+
else encBadge.classList.add('hidden');
|
| 490 |
|
| 491 |
+
// Timeline
|
| 492 |
+
el.chatTimeline.innerHTML = '';
|
| 493 |
+
room.timeline.forEach(ev => appendMessageToUI(ev, true));
|
| 494 |
+
scrollToBottom();
|
| 495 |
+
cancelReply(); // Clear any pending reply context
|
| 496 |
+
}
|
| 497 |
|
| 498 |
+
function scrollToBottom() {
|
| 499 |
+
setTimeout(() => {
|
| 500 |
+
el.chatTimeline.scrollTop = el.chatTimeline.scrollHeight;
|
| 501 |
+
}, 50);
|
| 502 |
}
|
| 503 |
|
| 504 |
+
function appendMessageToUI(ev, batch = false) {
|
| 505 |
+
// Handle Redactions (Deletions)
|
| 506 |
+
if (ev.type === 'm.room.redaction') {
|
| 507 |
+
const target = document.getElementById(`msg-${ev.redacts}`);
|
| 508 |
+
if (target) {
|
| 509 |
+
const bodyEl = target.querySelector('.msg-body');
|
| 510 |
+
if (bodyEl) bodyEl.innerHTML = '<span class="italic text-gray-500">🚫 Сообщение удалено</span>';
|
| 511 |
+
}
|
| 512 |
+
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 513 |
}
|
|
|
|
| 514 |
|
| 515 |
+
if (ev.type !== 'm.room.message' && ev.type !== 'm.room.encrypted') return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 516 |
|
| 517 |
+
const room = state.rooms[state.activeRoomId];
|
| 518 |
+
const senderInfo = room.members[ev.sender] || {};
|
| 519 |
+
const senderName = senderInfo.displayname || ev.sender;
|
| 520 |
+
const senderAvatar = getMediaUrl(senderInfo.avatar_url, 32, 32) || `https://placehold.co/32x32/1e1e1e/fff?text=${encodeURIComponent(senderName.charAt(0))}`;
|
| 521 |
+
const time = new Date(ev.origin_server_ts).toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'});
|
| 522 |
|
| 523 |
+
let contentBody = '';
|
| 524 |
+
let isMedia = false;
|
| 525 |
+
let mediaHtml = '';
|
| 526 |
+
|
| 527 |
+
// Check if redacted (sometimes sent within unsigned data)
|
| 528 |
+
if (ev.unsigned && ev.unsigned.redacted_because) {
|
| 529 |
+
contentBody = '<span class="italic text-gray-500">🚫 Сообщение удалено</span>';
|
| 530 |
+
} else if (ev.type === 'm.room.encrypted') {
|
| 531 |
+
contentBody = '<span class="italic text-yellow-600">🔒 Сообщение зашифровано (не поддерживается клиентом)</span>';
|
| 532 |
+
} else {
|
| 533 |
+
if (!ev.content) return;
|
| 534 |
|
| 535 |
+
// Format reply block if exists
|
| 536 |
+
let replyHtml = '';
|
| 537 |
+
if (ev.content['m.relates_to'] && ev.content['m.relates_to']['m.in_reply_to']) {
|
| 538 |
+
replyHtml = `<div class="text-xs bg-[#252526] border-l-2 border-gray-500 p-1 mb-1 text-gray-400 rounded-sm">В ответ на сообщение</div>`;
|
| 539 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 540 |
|
| 541 |
+
if (ev.content.msgtype === 'm.text') {
|
| 542 |
+
contentBody = replyHtml + escapeHtml(ev.content.body).replace(/\n/g, '<br>');
|
| 543 |
+
} else if (ev.content.msgtype === 'm.image' && ev.content.url) {
|
| 544 |
+
isMedia = true;
|
| 545 |
+
mediaHtml = `<img src="${getMediaUrl(ev.content.url)}" class="max-w-xs max-h-64 rounded border border-gray-700 mt-1 cursor-pointer" onclick="window.open(this.src)">`;
|
| 546 |
+
contentBody = replyHtml + `<span class="text-gray-400 text-xs">${escapeHtml(ev.content.body)}</span>`;
|
| 547 |
+
} else {
|
| 548 |
+
contentBody = replyHtml + `<span class="italic text-gray-400">Формат [${ev.content.msgtype}] не поддерживается</span>`;
|
| 549 |
+
}
|
| 550 |
}
|
|
|
|
| 551 |
|
| 552 |
+
const div = document.createElement('div');
|
| 553 |
+
div.id = `msg-${ev.event_id}`;
|
| 554 |
+
div.className = 'group flex gap-3 hover:bg-[#252526] p-1 rounded transition-colors relative';
|
| 555 |
+
|
| 556 |
+
const isMe = ev.sender === state.userId;
|
| 557 |
+
|
| 558 |
+
div.innerHTML = `
|
| 559 |
+
<img src="${senderAvatar}" class="w-8 h-8 rounded border border-gray-600 object-cover cursor-pointer hover:opacity-80" onclick="openUserProfile('${ev.sender}')" title="Открыть профиль">
|
| 560 |
+
<div class="flex flex-col min-w-0 w-full">
|
| 561 |
+
<div class="flex items-baseline gap-2">
|
| 562 |
+
<span class="font-bold text-sm text-[#569cd6] cursor-pointer hover:underline" onclick="openUserProfile('${ev.sender}')">${escapeHtml(senderName)}</span>
|
| 563 |
+
<span class="text-[10px] text-gray-500">${time}</span>
|
| 564 |
+
</div>
|
| 565 |
+
<div class="msg-body text-gray-300 text-sm break-words">${contentBody}</div>
|
| 566 |
+
${mediaHtml}
|
| 567 |
+
</div>
|
| 568 |
+
<div class="msg-actions absolute top-2 right-2 flex gap-1 bg-[#1e1e1e] p-1 rounded border border-[#111] shadow">
|
| 569 |
+
<button onclick="setupReply('${ev.event_id}', '${escapeHtml(senderName)}', '${escapeHtml(ev.content?.body || 'Медиа')}')" class="text-xs text-gray-400 hover:text-white px-1">Ответить</button>
|
| 570 |
+
${isMe ? `<button onclick="deleteMessage('${ev.event_id}')" class="text-xs text-red-500 hover:text-red-400 px-1 border-l border-gray-700 ml-1">Удалить</button>` : ''}
|
| 571 |
+
</div>
|
| 572 |
+
`;
|
| 573 |
+
|
| 574 |
+
el.chatTimeline.appendChild(div);
|
| 575 |
+
|
| 576 |
+
if (!batch) {
|
| 577 |
+
const isAtBottom = el.chatTimeline.scrollHeight - el.chatTimeline.scrollTop <= el.chatTimeline.clientHeight + 100;
|
| 578 |
+
if (isAtBottom || isMe) scrollToBottom();
|
| 579 |
+
}
|
| 580 |
}
|
| 581 |
|
| 582 |
+
function setupReply(eventId, sender, body) {
|
| 583 |
+
state.replyingTo = { eventId, sender, body };
|
| 584 |
+
document.getElementById('reply-context').classList.remove('hidden');
|
| 585 |
+
document.getElementById('reply-sender').innerText = sender;
|
| 586 |
+
document.getElementById('reply-text').innerText = body.length > 50 ? body.substring(0, 50) + '...' : body;
|
| 587 |
+
document.getElementById('msg-input').focus();
|
| 588 |
}
|
| 589 |
|
| 590 |
+
function cancelReply() {
|
| 591 |
+
state.replyingTo = null;
|
| 592 |
+
document.getElementById('reply-context').classList.add('hidden');
|
| 593 |
+
}
|
| 594 |
|
| 595 |
+
function handleInputKey(e) {
|
| 596 |
+
if (e.key === 'Enter' && !e.shiftKey) {
|
| 597 |
+
e.preventDefault();
|
| 598 |
+
sendCurrentMessage();
|
| 599 |
+
}
|
| 600 |
}
|
| 601 |
|
| 602 |
+
async function sendCurrentMessage() {
|
| 603 |
+
if (!state.activeRoomId) return;
|
| 604 |
+
const input = document.getElementById('msg-input');
|
| 605 |
+
const text = input.value.trim();
|
| 606 |
+
if (!text) return;
|
| 607 |
+
|
| 608 |
+
input.value = ''; // Fast clear for UX
|
| 609 |
+
|
| 610 |
+
const txnId = `m${Date.now()}`;
|
| 611 |
+
const content = {
|
| 612 |
+
msgtype: 'm.text',
|
| 613 |
+
body: text
|
| 614 |
+
};
|
| 615 |
+
|
| 616 |
+
if (state.replyingTo) {
|
| 617 |
+
content['m.relates_to'] = {
|
| 618 |
+
'm.in_reply_to': { event_id: state.replyingTo.eventId }
|
| 619 |
+
};
|
| 620 |
+
// Adding rich reply fallback for matrix spec
|
| 621 |
+
content.format = "org.matrix.custom.html";
|
| 622 |
+
content.formatted_body = `<mx-reply><blockquote>In reply to <a href="https://matrix.to/#/${state.activeRoomId}/${state.replyingTo.eventId}">@${state.replyingTo.sender}</a><br>${escapeHtml(state.replyingTo.body)}</blockquote></mx-reply>${escapeHtml(text).replace(/\n/g, '<br>')}`;
|
| 623 |
+
content.body = `> <${state.replyingTo.sender}> ${state.replyingTo.body}\n\n${text}`;
|
| 624 |
+
cancelReply();
|
| 625 |
+
}
|
| 626 |
+
|
| 627 |
+
try {
|
| 628 |
+
await apiCall(`/rooms/${encodeURIComponent(state.activeRoomId)}/send/m.room.message/${txnId}`, 'PUT', content);
|
| 629 |
+
// The message will appear via sync loop shortly
|
| 630 |
+
} catch (e) {
|
| 631 |
+
showToast("Ошибка отправки: " + e.message, true);
|
| 632 |
+
input.value = text; // Restore text
|
| 633 |
+
}
|
| 634 |
}
|
| 635 |
|
| 636 |
+
async function deleteMessage(eventId) {
|
| 637 |
+
if (!state.activeRoomId) return;
|
| 638 |
+
const txnId = `t${Date.now()}`;
|
| 639 |
try {
|
| 640 |
+
await apiCall(`/rooms/${encodeURIComponent(state.activeRoomId)}/redact/${eventId}/${txnId}`, 'PUT', {
|
| 641 |
+
reason: "User requested deletion"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 642 |
});
|
| 643 |
+
showToast("Сообщение удалено");
|
| 644 |
+
// Sync handles UI update
|
|
|
|
|
|
|
|
|
|
|
|
|
| 645 |
} catch (e) {
|
| 646 |
+
showToast("Не удалось удалить: " + e.message, true);
|
|
|
|
| 647 |
}
|
| 648 |
}
|
| 649 |
|
| 650 |
+
function openModal(id) {
|
| 651 |
+
el.modals.classList.remove('hidden');
|
| 652 |
+
document.querySelectorAll('.modal-content').forEach(m => m.classList.add('hidden'));
|
| 653 |
+
document.getElementById(id).classList.remove('hidden');
|
| 654 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 655 |
|
| 656 |
+
function closeModals() {
|
| 657 |
+
el.modals.classList.add('hidden');
|
| 658 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 659 |
|
| 660 |
+
function openMyProfile() {
|
| 661 |
+
openUserProfile(state.userId);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 662 |
}
|
| 663 |
|
| 664 |
+
async function openUserProfile(userId) {
|
| 665 |
+
openModal('profile-modal');
|
| 666 |
+
const modName = document.getElementById('mod-prof-name');
|
| 667 |
+
const modId = document.getElementById('mod-prof-id');
|
| 668 |
+
const modAvatar = document.getElementById('mod-prof-avatar');
|
| 669 |
+
|
| 670 |
+
modName.innerText = "Загрузка...";
|
| 671 |
+
modId.innerText = userId;
|
| 672 |
+
modAvatar.src = `https://placehold.co/128x128/1e1e1e/fff?text=?`;
|
| 673 |
|
| 674 |
+
try {
|
| 675 |
+
const profile = await apiCall(`/profile/${encodeURIComponent(userId)}`);
|
| 676 |
+
modName.innerText = profile.displayname || userId;
|
| 677 |
+
if (profile.avatar_url) {
|
| 678 |
+
modAvatar.src = getMediaUrl(profile.avatar_url, 256, 256);
|
| 679 |
+
}
|
| 680 |
+
} catch (e) {
|
| 681 |
+
modName.innerText = userId;
|
| 682 |
+
// Profile might be private or not exist, ignore
|
| 683 |
}
|
| 684 |
|
| 685 |
+
document.getElementById('btn-prof-copy').onclick = () => {
|
| 686 |
+
const link = `https://matrix.to/#/${userId}`;
|
| 687 |
+
// Fallback approach for iframe clipboards
|
| 688 |
+
const textArea = document.createElement("textarea");
|
| 689 |
+
textArea.value = link;
|
| 690 |
+
document.body.appendChild(textArea);
|
| 691 |
+
textArea.select();
|
| 692 |
+
try {
|
| 693 |
+
document.execCommand('copy');
|
| 694 |
+
showToast("Ссылка скопирована!");
|
| 695 |
+
} catch (err) {
|
| 696 |
+
showToast("Не удалось скопировать", true);
|
| 697 |
}
|
| 698 |
+
document.body.removeChild(textArea);
|
| 699 |
+
};
|
| 700 |
|
| 701 |
+
const dmBtn = document.getElementById('btn-prof-dm');
|
| 702 |
+
if (userId === state.userId) {
|
| 703 |
+
dmBtn.classList.add('hidden');
|
| 704 |
+
} else {
|
| 705 |
+
dmBtn.classList.remove('hidden');
|
| 706 |
+
dmBtn.onclick = () => {
|
| 707 |
+
closeModals();
|
| 708 |
+
createDirectMessage(userId);
|
| 709 |
};
|
| 710 |
+
}
|
| 711 |
+
}
|
| 712 |
|
| 713 |
+
async function uploadMedia(file) {
|
| 714 |
+
const formData = new FormData();
|
| 715 |
+
formData.append('file', file);
|
| 716 |
+
|
| 717 |
+
try {
|
| 718 |
+
const res = await fetch(`${state.baseUrl}/_matrix/media/v3/upload`, {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 719 |
method: 'POST',
|
| 720 |
+
headers: { 'Authorization': `Bearer ${state.token}`, 'Content-Type': file.type },
|
| 721 |
+
body: file
|
|
|
|
|
|
|
|
|
|
| 722 |
});
|
|
|
|
| 723 |
const data = await res.json();
|
| 724 |
+
if (!res.ok) throw new Error(data.error);
|
| 725 |
+
return data.content_uri; // returns mxc:// string
|
| 726 |
+
} catch (e) {
|
| 727 |
+
throw e;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 728 |
}
|
| 729 |
}
|
| 730 |
|
| 731 |
+
async function submitCreateRoom() {
|
| 732 |
+
const name = document.getElementById('create-room-name').value.trim();
|
| 733 |
+
const topic = document.getElementById('create-room-topic').value.trim();
|
| 734 |
+
const visibility = document.querySelector('input[name="room-vis"]:checked').value;
|
| 735 |
+
const fileInput = document.getElementById('create-room-avatar');
|
| 736 |
+
|
| 737 |
+
if (!name) { showToast("Укажите название", true); return; }
|
| 738 |
|
| 739 |
+
const payload = {
|
| 740 |
+
name: name,
|
| 741 |
+
preset: visibility === 'public' ? 'public_chat' : 'private_chat',
|
| 742 |
+
initial_state: []
|
| 743 |
+
};
|
| 744 |
|
| 745 |
+
if (topic) payload.topic = topic;
|
| 746 |
|
| 747 |
try {
|
| 748 |
+
// Upload avatar if selected
|
| 749 |
if (fileInput.files.length > 0) {
|
| 750 |
+
const mxc = await uploadMedia(fileInput.files[0]);
|
| 751 |
+
payload.initial_state.push({
|
| 752 |
+
type: 'm.room.avatar',
|
| 753 |
+
state_key: '',
|
| 754 |
+
content: { url: mxc }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 755 |
});
|
|
|
|
| 756 |
}
|
| 757 |
|
| 758 |
+
const data = await apiCall('/createRoom', 'POST', payload);
|
| 759 |
+
showToast("Комната создана");
|
| 760 |
+
closeModals();
|
| 761 |
+
// Reset inputs
|
| 762 |
+
document.getElementById('create-room-name').value = '';
|
| 763 |
+
document.getElementById('create-room-topic').value = '';
|
| 764 |
+
fileInput.value = '';
|
| 765 |
+
|
| 766 |
+
// Automatically switch to it when sync catches up
|
| 767 |
+
setTimeout(() => {
|
| 768 |
+
if (state.rooms[data.room_id]) switchRoom(data.room_id);
|
| 769 |
+
}, 1500);
|
| 770 |
|
| 771 |
+
} catch (e) {
|
| 772 |
+
showToast("Ошибка создания: " + e.message, true);
|
| 773 |
+
}
|
| 774 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 775 |
|
| 776 |
+
async function createDirectMessage(targetUserId) {
|
| 777 |
+
try {
|
| 778 |
+
showToast("Создание чата...");
|
| 779 |
+
const data = await apiCall('/createRoom', 'POST', {
|
| 780 |
+
preset: 'trusted_private_chat',
|
| 781 |
+
is_direct: true,
|
| 782 |
+
invite: [targetUserId]
|
| 783 |
+
});
|
| 784 |
+
showToast("Чат создан");
|
| 785 |
+
setTimeout(() => {
|
| 786 |
+
if (state.rooms[data.room_id]) switchRoom(data.room_id);
|
| 787 |
+
}, 1500);
|
| 788 |
+
} catch (e) {
|
| 789 |
+
showToast("Ошибка: " + e.message, true);
|
| 790 |
}
|
| 791 |
}
|
| 792 |
|
| 793 |
+
async function submitJoinOrDM() {
|
| 794 |
+
const target = document.getElementById('join-target-id').value.trim();
|
| 795 |
+
if (!target) return;
|
|
|
|
| 796 |
|
| 797 |
+
try {
|
| 798 |
+
if (target.startsWith('@')) {
|
| 799 |
+
// Create DM
|
| 800 |
+
await createDirectMessage(target);
|
| 801 |
+
closeModals();
|
| 802 |
+
} else if (target.startsWith('#') || target.startsWith('!')) {
|
| 803 |
+
// Join Room
|
| 804 |
+
showToast("Подключение к комнате...");
|
| 805 |
+
const data = await apiCall(`/join/${encodeURIComponent(target)}`, 'POST', {});
|
| 806 |
+
showToast("Вы вошли в комнату");
|
| 807 |
+
closeModals();
|
| 808 |
+
setTimeout(() => switchRoom(data.room_id), 1500);
|
| 809 |
+
} else {
|
| 810 |
+
showToast("Неверный формат. Используйте @user... или #room...", true);
|
| 811 |
+
}
|
| 812 |
+
} catch (e) {
|
| 813 |
+
showToast("Ошибка: " + e.message, true);
|
| 814 |
+
}
|
| 815 |
+
document.getElementById('join-target-id').value = '';
|
| 816 |
+
}
|
| 817 |
|
| 818 |
+
async function submitInvite() {
|
| 819 |
+
if (!state.activeRoomId) return;
|
| 820 |
+
const target = document.getElementById('invite-target-id').value.trim();
|
| 821 |
+
if (!target) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 822 |
|
| 823 |
try {
|
| 824 |
+
await apiCall(`/rooms/${encodeURIComponent(state.activeRoomId)}/invite`, 'POST', {
|
| 825 |
+
user_id: target
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 826 |
});
|
| 827 |
+
showToast(`Приглашение отправлено ${target}`);
|
| 828 |
+
closeModals();
|
| 829 |
+
document.getElementById('invite-target-id').value = '';
|
|
|
|
|
|
|
|
|
|
|
|
|
| 830 |
} catch (e) {
|
| 831 |
+
showToast("Ошибка: " + e.message, true);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 832 |
}
|
| 833 |
}
|
| 834 |
|
| 835 |
+
async function leaveCurrentRoom() {
|
| 836 |
+
if (!state.activeRoomId) return;
|
| 837 |
+
// Using basic UI replace instead of window.confirm
|
| 838 |
+
const header = document.getElementById('active-room-name');
|
| 839 |
+
const originalName = header.innerText;
|
| 840 |
+
header.innerText = "Подтвердите выход (кликните снова)";
|
| 841 |
+
header.classList.add('text-red-500');
|
| 842 |
+
|
| 843 |
+
const btn = el.roomHeader.querySelector('button.text-red-400');
|
| 844 |
+
const originalOnclick = btn.onclick;
|
| 845 |
+
|
| 846 |
+
btn.onclick = async () => {
|
| 847 |
+
try {
|
| 848 |
+
await apiCall(`/rooms/${encodeURIComponent(state.activeRoomId)}/leave`, 'POST', {});
|
| 849 |
+
showToast("Вы вышли из комнаты");
|
| 850 |
+
|
| 851 |
+
// Clear state immediately for UX
|
| 852 |
+
delete state.rooms[state.activeRoomId];
|
| 853 |
+
state.activeRoomId = null;
|
| 854 |
+
renderRoomList();
|
| 855 |
+
|
| 856 |
+
el.roomHeader.classList.add('hidden');
|
| 857 |
+
el.chatTimeline.classList.add('hidden');
|
| 858 |
+
el.chatInput.classList.add('hidden');
|
| 859 |
+
el.emptyState.classList.remove('hidden');
|
| 860 |
+
|
| 861 |
+
} catch (e) {
|
| 862 |
+
showToast("Ошибка: " + e.message, true);
|
| 863 |
+
} finally {
|
| 864 |
+
btn.onclick = originalOnclick;
|
| 865 |
+
header.classList.remove('text-red-500');
|
| 866 |
+
}
|
| 867 |
+
};
|
| 868 |
+
|
| 869 |
+
// Timeout to cancel confirm
|
| 870 |
+
setTimeout(() => {
|
| 871 |
+
header.innerText = originalName;
|
| 872 |
+
header.classList.remove('text-red-500');
|
| 873 |
+
btn.onclick = originalOnclick;
|
| 874 |
+
}, 3000);
|
| 875 |
}
|
| 876 |
|
| 877 |
window.onload = () => {
|
| 878 |
+
if (state.token && state.userId) {
|
| 879 |
+
initApp();
|
| 880 |
+
} else {
|
| 881 |
+
el.login.classList.remove('hidden');
|
| 882 |
+
}
|
| 883 |
};
|
| 884 |
|
| 885 |
</script>
|