Spaces:
Running
Running
Update index.html
Browse files- index.html +98 -11
index.html
CHANGED
|
@@ -579,17 +579,26 @@
|
|
| 579 |
padding: 0 16px;
|
| 580 |
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
|
| 581 |
flex-shrink: 0;
|
|
|
|
| 582 |
}
|
| 583 |
|
| 584 |
.chat-header-title {
|
| 585 |
font-weight: 600;
|
| 586 |
font-size: 15px;
|
| 587 |
color: #222;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 588 |
}
|
| 589 |
|
| 590 |
.chat-header-status {
|
| 591 |
font-size: 12px;
|
| 592 |
color: var(--tg-subtext);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 593 |
}
|
| 594 |
|
| 595 |
.messages-container {
|
|
@@ -712,11 +721,18 @@
|
|
| 712 |
color: #111;
|
| 713 |
margin-bottom: 4px;
|
| 714 |
word-break: break-word;
|
|
|
|
|
|
|
|
|
|
| 715 |
}
|
| 716 |
|
| 717 |
.info-members-count {
|
| 718 |
font-size: 12px;
|
| 719 |
color: var(--tg-subtext);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 720 |
}
|
| 721 |
|
| 722 |
.info-section {
|
|
@@ -1672,10 +1688,15 @@
|
|
| 1672 |
}
|
| 1673 |
|
| 1674 |
function updateRoomHeaderAndSide(room) {
|
| 1675 |
-
|
| 1676 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1677 |
|
| 1678 |
-
const initial =
|
| 1679 |
const avatarBox = document.getElementById('info-avatar-box');
|
| 1680 |
|
| 1681 |
if (room.avatar) {
|
|
@@ -1684,9 +1705,12 @@
|
|
| 1684 |
avatarBox.innerText = initial;
|
| 1685 |
}
|
| 1686 |
|
| 1687 |
-
document.getElementById('info-name-box').innerText =
|
| 1688 |
-
document.getElementById('info-count-box').innerText =
|
| 1689 |
-
|
|
|
|
|
|
|
|
|
|
| 1690 |
|
| 1691 |
// Show edit room buttons if user is creator
|
| 1692 |
const isCreator = room.creator === matrixSession.userId || room.id.includes(matrixSession.userId.split(':')[0]);
|
|
@@ -1726,6 +1750,13 @@
|
|
| 1726 |
|
| 1727 |
room.members = members;
|
| 1728 |
renderMembersList(members);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1729 |
} else {
|
| 1730 |
memberList.innerHTML = `<li style="font-size:12px; color:var(--tg-subtext);">Не удалось загрузить участников</li>`;
|
| 1731 |
}
|
|
@@ -1839,7 +1870,7 @@
|
|
| 1839 |
});
|
| 1840 |
matrixSession.displayName = newName;
|
| 1841 |
}
|
| 1842 |
-
|
| 1843 |
if (newAvatar) {
|
| 1844 |
await fetch(`${matrixSession.homeserver}/_matrix/client/v3/profile/${encodeURIComponent(matrixSession.userId)}/avatar_url`, {
|
| 1845 |
method: 'PUT',
|
|
@@ -1849,15 +1880,15 @@
|
|
| 1849 |
},
|
| 1850 |
body: JSON.stringify({ avatar_url: newAvatar })
|
| 1851 |
});
|
| 1852 |
-
matrixSession.avatarUrl =
|
| 1853 |
}
|
| 1854 |
|
| 1855 |
updateUserProfileUI();
|
| 1856 |
-
showToast('
|
| 1857 |
closeModal('modal-profile');
|
| 1858 |
} catch (err) {
|
| 1859 |
-
console.error('
|
| 1860 |
-
showToast('
|
| 1861 |
}
|
| 1862 |
}
|
| 1863 |
|
|
@@ -1871,6 +1902,8 @@
|
|
| 1871 |
return;
|
| 1872 |
}
|
| 1873 |
|
|
|
|
|
|
|
| 1874 |
try {
|
| 1875 |
const res = await fetch(`${matrixSession.homeserver}/_matrix/client/v3/createRoom`, {
|
| 1876 |
method: 'POST',
|
|
@@ -1910,6 +1943,60 @@
|
|
| 1910 |
}
|
| 1911 |
}
|
| 1912 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1913 |
async function saveRoomSettings() {
|
| 1914 |
if (!matrixSession.activeRoomId) return;
|
| 1915 |
|
|
|
|
| 579 |
padding: 0 16px;
|
| 580 |
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
|
| 581 |
flex-shrink: 0;
|
| 582 |
+
min-width: 0;
|
| 583 |
}
|
| 584 |
|
| 585 |
.chat-header-title {
|
| 586 |
font-weight: 600;
|
| 587 |
font-size: 15px;
|
| 588 |
color: #222;
|
| 589 |
+
white-space: nowrap;
|
| 590 |
+
overflow: hidden;
|
| 591 |
+
text-overflow: ellipsis;
|
| 592 |
+
max-width: 350px;
|
| 593 |
}
|
| 594 |
|
| 595 |
.chat-header-status {
|
| 596 |
font-size: 12px;
|
| 597 |
color: var(--tg-subtext);
|
| 598 |
+
white-space: nowrap;
|
| 599 |
+
overflow: hidden;
|
| 600 |
+
text-overflow: ellipsis;
|
| 601 |
+
max-width: 350px;
|
| 602 |
}
|
| 603 |
|
| 604 |
.messages-container {
|
|
|
|
| 721 |
color: #111;
|
| 722 |
margin-bottom: 4px;
|
| 723 |
word-break: break-word;
|
| 724 |
+
text-align: center;
|
| 725 |
+
max-width: 100%;
|
| 726 |
+
padding: 0 10px;
|
| 727 |
}
|
| 728 |
|
| 729 |
.info-members-count {
|
| 730 |
font-size: 12px;
|
| 731 |
color: var(--tg-subtext);
|
| 732 |
+
word-break: break-all;
|
| 733 |
+
text-align: center;
|
| 734 |
+
max-width: 100%;
|
| 735 |
+
padding: 0 10px;
|
| 736 |
}
|
| 737 |
|
| 738 |
.info-section {
|
|
|
|
| 1688 |
}
|
| 1689 |
|
| 1690 |
function updateRoomHeaderAndSide(room) {
|
| 1691 |
+
const displayName = room.name || 'Без названия';
|
| 1692 |
+
const statusText = (room.members && room.members.length > 0)
|
| 1693 |
+
? `${room.members.length} участник(ов)`
|
| 1694 |
+
: room.id;
|
| 1695 |
+
|
| 1696 |
+
document.getElementById('active-chat-title').innerText = displayName;
|
| 1697 |
+
document.getElementById('active-chat-status').innerText = statusText;
|
| 1698 |
|
| 1699 |
+
const initial = displayName ? displayName[0].toUpperCase() : '#';
|
| 1700 |
const avatarBox = document.getElementById('info-avatar-box');
|
| 1701 |
|
| 1702 |
if (room.avatar) {
|
|
|
|
| 1705 |
avatarBox.innerText = initial;
|
| 1706 |
}
|
| 1707 |
|
| 1708 |
+
document.getElementById('info-name-box').innerText = displayName;
|
| 1709 |
+
document.getElementById('info-count-box').innerText = statusText;
|
| 1710 |
+
|
| 1711 |
+
const descBox = document.getElementById('info-description-box');
|
| 1712 |
+
descBox.innerText = room.topic || 'Описание отсутствует.';
|
| 1713 |
+
descBox.style.wordBreak = 'break-word';
|
| 1714 |
|
| 1715 |
// Show edit room buttons if user is creator
|
| 1716 |
const isCreator = room.creator === matrixSession.userId || room.id.includes(matrixSession.userId.split(':')[0]);
|
|
|
|
| 1750 |
|
| 1751 |
room.members = members;
|
| 1752 |
renderMembersList(members);
|
| 1753 |
+
|
| 1754 |
+
// Обновляем шапку и панель, если участники догрузились
|
| 1755 |
+
if (matrixSession.activeRoomId === room.id) {
|
| 1756 |
+
const countText = `${members.length} участник(ов)`;
|
| 1757 |
+
document.getElementById('active-chat-status').innerText = countText;
|
| 1758 |
+
document.getElementById('info-count-box').innerText = countText;
|
| 1759 |
+
}
|
| 1760 |
} else {
|
| 1761 |
memberList.innerHTML = `<li style="font-size:12px; color:var(--tg-subtext);">Не удалось загрузить участников</li>`;
|
| 1762 |
}
|
|
|
|
| 1870 |
});
|
| 1871 |
matrixSession.displayName = newName;
|
| 1872 |
}
|
| 1873 |
+
|
| 1874 |
if (newAvatar) {
|
| 1875 |
await fetch(`${matrixSession.homeserver}/_matrix/client/v3/profile/${encodeURIComponent(matrixSession.userId)}/avatar_url`, {
|
| 1876 |
method: 'PUT',
|
|
|
|
| 1880 |
},
|
| 1881 |
body: JSON.stringify({ avatar_url: newAvatar })
|
| 1882 |
});
|
| 1883 |
+
matrixSession.avatarUrl = newAvatar;
|
| 1884 |
}
|
| 1885 |
|
| 1886 |
updateUserProfileUI();
|
| 1887 |
+
showToast('Настройки профиля сохранены!');
|
| 1888 |
closeModal('modal-profile');
|
| 1889 |
} catch (err) {
|
| 1890 |
+
console.error('Profile update error:', err);
|
| 1891 |
+
showToast('Ошибка при обновлении профиля');
|
| 1892 |
}
|
| 1893 |
}
|
| 1894 |
|
|
|
|
| 1902 |
return;
|
| 1903 |
}
|
| 1904 |
|
| 1905 |
+
if (!matrixSession.accessToken) return;
|
| 1906 |
+
|
| 1907 |
try {
|
| 1908 |
const res = await fetch(`${matrixSession.homeserver}/_matrix/client/v3/createRoom`, {
|
| 1909 |
method: 'POST',
|
|
|
|
| 1943 |
}
|
| 1944 |
}
|
| 1945 |
|
| 1946 |
+
async function sendMessage() {
|
| 1947 |
+
const input = document.getElementById('message-input');
|
| 1948 |
+
const text = input.value.trim();
|
| 1949 |
+
|
| 1950 |
+
if (!text || !matrixSession.activeRoomId) return;
|
| 1951 |
+
|
| 1952 |
+
const roomId = matrixSession.activeRoomId;
|
| 1953 |
+
const txnId = 'm' + Date.now() + '_' + Math.random().toString(36).substring(2, 6);
|
| 1954 |
+
const sendUrl = `${matrixSession.homeserver}/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${txnId}`;
|
| 1955 |
+
|
| 1956 |
+
input.value = '';
|
| 1957 |
+
|
| 1958 |
+
// Оптимистичное обновление UI: сразу показываем сообщение в чате
|
| 1959 |
+
const room = matrixSession.rooms[roomId];
|
| 1960 |
+
const now = new Date();
|
| 1961 |
+
const timeStr = `${String(now.getHours()).padStart(2, '0')}:${String(now.getMinutes()).padStart(2, '0')}`;
|
| 1962 |
+
|
| 1963 |
+
room.messages.push({
|
| 1964 |
+
id: txnId,
|
| 1965 |
+
sender: 'Вы',
|
| 1966 |
+
rawSender: matrixSession.userId,
|
| 1967 |
+
text: text,
|
| 1968 |
+
time: timeStr,
|
| 1969 |
+
incoming: false,
|
| 1970 |
+
ts: now.getTime()
|
| 1971 |
+
});
|
| 1972 |
+
|
| 1973 |
+
if (matrixSession.activeRoomId === roomId) {
|
| 1974 |
+
renderMessages(room);
|
| 1975 |
+
}
|
| 1976 |
+
renderRoomsList();
|
| 1977 |
+
|
| 1978 |
+
try {
|
| 1979 |
+
const res = await fetch(sendUrl, {
|
| 1980 |
+
method: 'PUT',
|
| 1981 |
+
headers: {
|
| 1982 |
+
'Authorization': `Bearer ${matrixSession.accessToken}`,
|
| 1983 |
+
'Content-Type': 'application/json'
|
| 1984 |
+
},
|
| 1985 |
+
body: JSON.stringify({
|
| 1986 |
+
msgtype: 'm.text',
|
| 1987 |
+
body: text
|
| 1988 |
+
})
|
| 1989 |
+
});
|
| 1990 |
+
|
| 1991 |
+
if (!res.ok) {
|
| 1992 |
+
showToast('Ошибка при отправке сообщения.');
|
| 1993 |
+
}
|
| 1994 |
+
} catch (err) {
|
| 1995 |
+
console.error('Send error:', err);
|
| 1996 |
+
showToast('Не удалось отправить сообщение.');
|
| 1997 |
+
}
|
| 1998 |
+
}
|
| 1999 |
+
|
| 2000 |
async function saveRoomSettings() {
|
| 2001 |
if (!matrixSession.activeRoomId) return;
|
| 2002 |
|