Show lastlogoff as relative last-seen time, label friend_since as 'friends since YYYY', and show the Steam account creation year in the comparison header.
This commit is contained in:
1 parent
80aae1a1df
commit
85ff1e3893
7 files changed
+55
-7
No files matched your search
@@ -153,6 +153,9 @@
|
|||||||
- Страница «Друзья» удобнее: поиск и фильтр по статусу, онлайн-друзья первыми,
|
- Страница «Друзья» удобнее: поиск и фильтр по статусу, онлайн-друзья первыми,
|
||||||
сворачиваемый ручной SteamID, поиск по играм в сравнении, часы обоих игроков,
|
сворачиваемый ручной SteamID, поиск по играм в сравнении, часы обоих игроков,
|
||||||
отметка «установлена» и переход в профиль Steam.
|
отметка «установлена» и переход в профиль Steam.
|
||||||
|
- Подписи у друзей уточнены: «был(а) в сети …» (`lastlogoff`) и отдельно
|
||||||
|
«в друзьях с YYYY» (`friend_since`), плюс «в Steam с YYYY» (`timecreated`).
|
||||||
|
Раньше год рядом с «офлайн» ошибочно читался как «офлайн с 2020».
|
||||||
- DLC/саундтреки/тулзы связаны с базовой игрой (`games.parent_appid`, схема v9):
|
- DLC/саундтреки/тулзы связаны с базовой игрой (`games.parent_appid`, схема v9):
|
||||||
в карточке появились блок «Дополнения» и ссылка «Часть игры»;
|
в карточке появились блок «Дополнения» и ссылка «Часть игры»;
|
||||||
`import_steam.py --refresh-parents` заполняет связи без полного импорта.
|
`import_steam.py --refresh-parents` заполняет связи без полного импорта.
|
||||||
|
|||||||
+6
-1
@@ -404,9 +404,14 @@ SteamID; кэш на сервере — 1 час. Если профиль зак
|
|||||||
|
|
||||||
```json
|
```json
|
||||||
{"total": 1, "friends": [{"steamid": "7656119...", "name": "Ann",
|
{"total": 1, "friends": [{"steamid": "7656119...", "name": "Ann",
|
||||||
"avatar": "https://...", "profile_url": "https://...", "state": 1}]}
|
"avatar": "https://...", "profile_url": "https://...", "state": 1,
|
||||||
|
"lastlogoff": 1700000000, "created": 1200000000,
|
||||||
|
"friend_since": 1578692405}]}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
`friend_since` — когда вы стали друзьями (не последний вход). `lastlogoff` —
|
||||||
|
время последнего выхода из сети, `created` — дата создания аккаунта Steam.
|
||||||
|
|
||||||
`/api/steam/friends/{steamid}` (17 цифр) загружает `GetOwnedGames` друга и
|
`/api/steam/friends/{steamid}` (17 цифр) загружает `GetOwnedGames` друга и
|
||||||
сравнивает с локальной библиотекой:
|
сравнивает с локальной библиотекой:
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -402,7 +402,9 @@ API может меняться. Без пакета проект работае
|
|||||||
### Друзья
|
### Друзья
|
||||||
|
|
||||||
Вкладка **Друзья** (нужен ключ Steam Web API) показывает список друзей с аватарами
|
Вкладка **Друзья** (нужен ключ Steam Web API) показывает список друзей с аватарами
|
||||||
и статусом; онлайн-друзья идут первыми. Есть поиск по имени, фильтр
|
и статусом; онлайн-друзья идут первыми. Под именем — когда друг был в сети
|
||||||
|
последний раз (`lastlogoff`) и отдельной строкой «в друзьях с YYYY»
|
||||||
|
(`friend_since`, дата знакомства, а не последний вход). Есть поиск по имени, фильтр
|
||||||
онлайн/офлайн и кнопка «обновить». Если список закрыт настройками приватности,
|
онлайн/офлайн и кнопка «обновить». Если список закрыт настройками приватности,
|
||||||
SteamID64 друга можно ввести вручную в сворачиваемом блоке. Клик по другу
|
SteamID64 друга можно ввести вручную в сворачиваемом блоке. Клик по другу
|
||||||
открывает сравнение библиотек: общие игры (статус, ваши и его часы, отметка
|
открывает сравнение библиотек: общие игры (статус, ваши и его часы, отметка
|
||||||
|
|||||||
+10
-2
@@ -527,11 +527,14 @@ class ApiTests(unittest.TestCase):
|
|||||||
return_value=[{"steamid": "1", "friend_since": 10}]), \
|
return_value=[{"steamid": "1", "friend_since": 10}]), \
|
||||||
mock.patch.object(server.steam_api, "player_summaries", return_value=[{
|
mock.patch.object(server.steam_api, "player_summaries", return_value=[{
|
||||||
"steamid": "1", "personaname": "Ann", "avatarmedium": "a",
|
"steamid": "1", "personaname": "Ann", "avatarmedium": "a",
|
||||||
"profileurl": "u", "personastate": 1}]):
|
"profileurl": "u", "personastate": 1,
|
||||||
|
"lastlogoff": 1700000000, "timecreated": 1200000000}]):
|
||||||
data = self.get("/api/steam/friends")
|
data = self.get("/api/steam/friends")
|
||||||
self.assertEqual(data["total"], 1)
|
self.assertEqual(data["total"], 1)
|
||||||
self.assertEqual(data["friends"][0]["name"], "Ann")
|
self.assertEqual(data["friends"][0]["name"], "Ann")
|
||||||
self.assertEqual(data["friends"][0]["state"], 1)
|
self.assertEqual(data["friends"][0]["state"], 1)
|
||||||
|
self.assertEqual(data["friends"][0]["lastlogoff"], 1700000000)
|
||||||
|
self.assertEqual(data["friends"][0]["created"], 1200000000)
|
||||||
|
|
||||||
def test_steam_friend_compare(self):
|
def test_steam_friend_compare(self):
|
||||||
with mock.patch.object(server.steam_api, "has_key", return_value=True), \
|
with mock.patch.object(server.steam_api, "has_key", return_value=True), \
|
||||||
@@ -539,8 +542,13 @@ class ApiTests(unittest.TestCase):
|
|||||||
{"appid": 1, "name": "Alpha", "playtime_forever": 120},
|
{"appid": 1, "name": "Alpha", "playtime_forever": 120},
|
||||||
{"appid": 999, "name": "Other", "playtime_forever": 60}]), \
|
{"appid": 999, "name": "Other", "playtime_forever": 60}]), \
|
||||||
mock.patch.object(server.steam_api, "player_summaries", return_value=[{
|
mock.patch.object(server.steam_api, "player_summaries", return_value=[{
|
||||||
"steamid": "76561198000000001", "personaname": "Ann"}]):
|
"steamid": "76561198000000001", "personaname": "Ann",
|
||||||
|
"personastate": 0, "lastlogoff": 1700000000,
|
||||||
|
"timecreated": 1200000000}]):
|
||||||
data = self.get("/api/steam/friends/76561198000000001")
|
data = self.get("/api/steam/friends/76561198000000001")
|
||||||
|
self.assertEqual(data["state"], 0)
|
||||||
|
self.assertEqual(data["lastlogoff"], 1700000000)
|
||||||
|
self.assertEqual(data["created"], 1200000000)
|
||||||
self.assertEqual(data["common_count"], 1)
|
self.assertEqual(data["common_count"], 1)
|
||||||
self.assertEqual(data["common"][0]["appid"], 1)
|
self.assertEqual(data["common"][0]["appid"], 1)
|
||||||
self.assertEqual(data["common"][0]["status"], "playing")
|
self.assertEqual(data["common"][0]["status"], "playing")
|
||||||
|
|||||||
@@ -1415,6 +1415,8 @@ class Handler(BaseHTTPRequestHandler):
|
|||||||
"profile_url": player.get("profileurl")
|
"profile_url": player.get("profileurl")
|
||||||
or f"https://steamcommunity.com/profiles/{sid}",
|
or f"https://steamcommunity.com/profiles/{sid}",
|
||||||
"state": player.get("personastate"),
|
"state": player.get("personastate"),
|
||||||
|
"lastlogoff": player.get("lastlogoff"),
|
||||||
|
"created": player.get("timecreated"),
|
||||||
"friend_since": item.get("friend_since"),
|
"friend_since": item.get("friend_since"),
|
||||||
})
|
})
|
||||||
items.sort(key=lambda row: row["name"].lower())
|
items.sort(key=lambda row: row["name"].lower())
|
||||||
@@ -1473,6 +1475,8 @@ class Handler(BaseHTTPRequestHandler):
|
|||||||
"profile_url": player.get("profileurl")
|
"profile_url": player.get("profileurl")
|
||||||
or f"https://steamcommunity.com/profiles/{friend_id}",
|
or f"https://steamcommunity.com/profiles/{friend_id}",
|
||||||
"state": player.get("personastate"),
|
"state": player.get("personastate"),
|
||||||
|
"lastlogoff": player.get("lastlogoff"),
|
||||||
|
"created": player.get("timecreated"),
|
||||||
"total_games": len(games),
|
"total_games": len(games),
|
||||||
"common_count": len(common),
|
"common_count": len(common),
|
||||||
"friend_only_count": len(friend_only),
|
"friend_only_count": len(friend_only),
|
||||||
|
|||||||
+28
-3
@@ -1402,12 +1402,35 @@ function friendOnline(friend) {
|
|||||||
function friendSince(friend) {
|
function friendSince(friend) {
|
||||||
if (!friend.friend_since) return "";
|
if (!friend.friend_since) return "";
|
||||||
const date = new Date(friend.friend_since * 1000);
|
const date = new Date(friend.friend_since * 1000);
|
||||||
return Number.isNaN(date.getTime()) ? "" : `с ${date.getFullYear()}`;
|
return Number.isNaN(date.getTime()) ? "" : `в друзьях с ${date.getFullYear()}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function relativeTime(timestamp) {
|
||||||
|
if (!timestamp) return "";
|
||||||
|
const seconds = Math.max(0, Math.floor(Date.now() / 1000 - timestamp));
|
||||||
|
if (seconds < 60) return "только что";
|
||||||
|
const minutes = Math.floor(seconds / 60);
|
||||||
|
if (minutes < 60) return `${minutes} мин назад`;
|
||||||
|
const hours = Math.floor(minutes / 60);
|
||||||
|
if (hours < 24) return `${hours} ч назад`;
|
||||||
|
const days = Math.floor(hours / 24);
|
||||||
|
if (days < 30) return `${days} дн назад`;
|
||||||
|
return new Date(timestamp * 1000).toLocaleDateString("ru-RU");
|
||||||
|
}
|
||||||
|
|
||||||
|
function friendLastSeen(friend) {
|
||||||
|
if (friendOnline(friend)) return FRIEND_STATE[Number(friend.state)] || "в сети";
|
||||||
|
if (friend.lastlogoff) return `был(а) в сети ${relativeTime(friend.lastlogoff)}`;
|
||||||
|
return "офлайн";
|
||||||
|
}
|
||||||
|
|
||||||
|
function friendAccountAge(friend) {
|
||||||
|
if (!friend.created) return "";
|
||||||
|
return `в Steam с ${new Date(friend.created * 1000).getFullYear()}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function friendCardHtml(friend) {
|
function friendCardHtml(friend) {
|
||||||
const online = friendOnline(friend);
|
const online = friendOnline(friend);
|
||||||
const label = FRIEND_STATE[Number(friend.state)] || "";
|
|
||||||
const since = friendSince(friend);
|
const since = friendSince(friend);
|
||||||
return `<button class="friend-card" type="button" data-steamid="${esc(friend.steamid)}">
|
return `<button class="friend-card" type="button" data-steamid="${esc(friend.steamid)}">
|
||||||
<span class="friend-avatar-wrap">
|
<span class="friend-avatar-wrap">
|
||||||
@@ -1418,7 +1441,8 @@ function friendCardHtml(friend) {
|
|||||||
</span>
|
</span>
|
||||||
<span class="friend-info">
|
<span class="friend-info">
|
||||||
<b>${esc(friend.name)}</b>
|
<b>${esc(friend.name)}</b>
|
||||||
<span class="friend-meta">${esc(label)}${since ? ` · ${esc(since)}` : ""}</span>
|
<span class="friend-meta">${esc(friendLastSeen(friend))}</span>
|
||||||
|
${since ? `<span class="friend-since">${esc(since)}</span>` : ""}
|
||||||
</span>
|
</span>
|
||||||
</button>`;
|
</button>`;
|
||||||
}
|
}
|
||||||
@@ -1497,6 +1521,7 @@ function renderFriendCompare(data) {
|
|||||||
<div class="friend-title">
|
<div class="friend-title">
|
||||||
<h2>${esc(data.name)}</h2>
|
<h2>${esc(data.name)}</h2>
|
||||||
<div class="muted">общих: ${data.common_count} · всего у друга: ${data.total_games} · вне библиотеки: ${data.friend_only_count}</div>
|
<div class="muted">общих: ${data.common_count} · всего у друга: ${data.total_games} · вне библиотеки: ${data.friend_only_count}</div>
|
||||||
|
<div class="muted">${esc(friendLastSeen(data))}${friendAccountAge(data) ? ` · ${esc(friendAccountAge(data))}` : ""}</div>
|
||||||
<a class="friend-profile" href="${esc(data.profile_url)}" target="_blank" rel="noopener">профиль Steam ↗</a>
|
<a class="friend-profile" href="${esc(data.profile_url)}" target="_blank" rel="noopener">профиль Steam ↗</a>
|
||||||
</div>
|
</div>
|
||||||
<button id="friendClose" class="link" type="button">закрыть</button>
|
<button id="friendClose" class="link" type="button">закрыть</button>
|
||||||
|
|||||||
@@ -992,6 +992,7 @@ html[data-theme="light"] .game-table tbody tr:hover { background: rgba(23, 32, 5
|
|||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
.friend-meta { font-size: 12px; color: var(--muted); }
|
.friend-meta { font-size: 12px; color: var(--muted); }
|
||||||
|
.friend-since { font-size: 11px; color: var(--muted); opacity: .75; }
|
||||||
.friend-compare {
|
.friend-compare {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
|||||||
Reference in new issue
Block a user