💄 sort unregistered servers by name

main
_ 2021-05-02 18:30:03 +00:00
parent 62248aca53
commit dc53aeed30
2 changed files with 33 additions and 26 deletions

View File

@ -358,34 +358,30 @@ async fn handle_unregistered_servers_internal (state: &Arc <Relay>)
let now = Utc::now ();
let server_list = state.unregistered_servers.to_vec ().await;
let mut seen_tripcodes = HashSet::new ();
let mut server_list = state.unregistered_servers.to_vec ().await;
server_list.sort_by_key (|s| {
(s.name.clone (), s.tripcode.as_bytes ().clone (), now - s.seen)
});
server_list.dedup_by_key (|s| {
(s.name.clone (), s.tripcode)
});
let unregistered_servers = server_list.into_iter ()
.rev ()
.filter_map (|x| {
.map (|x| {
let last_seen = match pretty_print_last_seen (now, x.seen) {
Negative => "Error (negative time)".into (),
Connected => "Recently".into (),
Description (s) => s,
};
let t = (x.name, x.tripcode);
let tripcode = base64::encode (x.tripcode.as_bytes ());
if seen_tripcodes.contains (&t) {
return None;
}
seen_tripcodes.insert (t.clone ());
let (name, tripcode) = t;
let tripcode = base64::encode (tripcode.as_bytes ());
Some (UnregisteredServer {
name,
UnregisteredServer {
name: x.name,
tripcode,
last_seen,
})
}
}).collect ();
UnregisteredServerListPage {

View File

@ -12,24 +12,28 @@ AIABAACAAQAAgAEAAIABAACAAQAAgAEAAIABAACAAQAA" rel="icon" type="image/x-icon" />
body {
font-family: sans-serif;
}
td {
padding: 0px;
form {
display: inline;
}
td > * {
padding: 20px;
display: block;
td {
/*padding: 20px;*/
}
.entry {
}
.grey {
color: #888;
text-align: right;
}
.entry_list {
width: 100%;
border-collapse: collapse;
}
.padded {
padding: 20px;
}
.submit {
padding: 10px;
}
tbody tr:nth-child(odd) {
background-color: #ddd;
}
@ -54,9 +58,16 @@ AIABAACAAQAAgAEAAIABAACAAQAAgAEAAIABAACAAQAA" rel="icon" type="image/x-icon" />
{{#each unregistered_servers}}
<tr>
<td>{{this.name}}</td>
<td>{{this.tripcode}}</td>
<td><span class="grey">{{this.last_seen}}</span></td>
<td><span class="padded">{{this.name}}</span></td>
<td>
<span class="padded">{{this.tripcode}}</span>
<form>
<input type="hidden" name="name" value="{{this.name}}">
<input type="hidden" name="tripcode" value="{{this.tripcode}}">
<input class="submit" type="submit" value="Register">
</form>
</td>
<td><span class="padded">{{this.last_seen}}</span></td>
</tr>
{{/each}}