💄 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 now = Utc::now ();
let server_list = state.unregistered_servers.to_vec ().await; let mut server_list = state.unregistered_servers.to_vec ().await;
let mut seen_tripcodes = HashSet::new ();
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 () let unregistered_servers = server_list.into_iter ()
.rev () .map (|x| {
.filter_map (|x| {
let last_seen = match pretty_print_last_seen (now, x.seen) { let last_seen = match pretty_print_last_seen (now, x.seen) {
Negative => "Error (negative time)".into (), Negative => "Error (negative time)".into (),
Connected => "Recently".into (), Connected => "Recently".into (),
Description (s) => s, Description (s) => s,
}; };
let t = (x.name, x.tripcode); let tripcode = base64::encode (x.tripcode.as_bytes ());
if seen_tripcodes.contains (&t) { UnregisteredServer {
return None; name: x.name,
}
seen_tripcodes.insert (t.clone ());
let (name, tripcode) = t;
let tripcode = base64::encode (tripcode.as_bytes ());
Some (UnregisteredServer {
name,
tripcode, tripcode,
last_seen, last_seen,
}) }
}).collect (); }).collect ();
UnregisteredServerListPage { UnregisteredServerListPage {

View File

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