Show someones primary corp in who.

This commit is contained in:
Condorra 2023-03-19 15:41:48 +11:00
parent 929a64f93e
commit 8084b020c3
3 changed files with 20 additions and 3 deletions

View File

@ -65,6 +65,7 @@ impl From<Row> for SendqueueItem {
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct OnlineInfo {
pub username: String,
pub corp: Option<String>,
pub time: Option<DateTime<Utc>>
}
@ -679,11 +680,21 @@ impl DBTrans {
pub async fn get_online_info(&self) ->DResult<Vec<OnlineInfo>> {
Ok(self.pg_trans()?.query(
"SELECT jsonb_build_object(\
"WITH show_corps AS (\
SELECT DISTINCT ON (member_username) \
m.member_username AS username, \
c.details ->> 'name' AS corpname \
FROM corps c JOIN corp_membership m ON m.corp_id = c.corp_id \
ORDER BY m.member_username, (m.details->>'priority')::int DESC NULLS LAST, \
(m.details->>'joined_at') :: TIMESTAMPTZ ASC \
)\
SELECT jsonb_build_object(\
'username', u.details->>'username',\
'corp', c.corpname, \
'time', s.details->>'last_active'\
) FROM sessions s \
JOIN users u ON u.current_session = s.session \
LEFT JOIN show_corps c ON c.username = LOWER(u.username) \
ORDER BY s.details->>'last_active' DESC", &[]
).await?
.into_iter()

View File

@ -8,8 +8,9 @@ pub struct Verb;
impl UserVerb for Verb {
async fn handle(self: &Self, ctx: &mut VerbContext, _verb: &str, _remaining: &str) -> UResult<()> {
let mut msg = String::new();
msg.push_str(&format!(ansi!("<bold><bgblue><white>| {:20} | {:15} |<reset>\n"),
msg.push_str(&format!(ansi!("<bold><bgblue><white>| {:20} | {:20} | {:15} |<reset>\n"),
ansi!("Username"),
ansi!("Corp"),
ansi!("Idle")));
for online in ctx.trans.get_online_info().await? {
if let Some(online_time) = online.time {
@ -18,7 +19,8 @@ impl UserVerb for Verb {
std::time::Duration::from_secs(
(Utc::now() - online_time).num_seconds() as u64));
msg.push_str(&format!(
"| {:20} | {:15} |\n", &ignore_special_characters(&online.username),
"| {:20} | {:20} | {:15} |\n", &ignore_special_characters(&online.username),
&ignore_special_characters(&online.corp.unwrap_or("".to_string())),
&format!("{}", &diff)));
}
}

View File

@ -38,6 +38,8 @@ pub struct CorpMembership {
pub permissions: Vec<CorpPermission>,
pub allow_combat: bool,
pub job_title: String,
pub priority: i64,
pub chat_on: bool
}
impl Default for CorpMembership {
@ -48,6 +50,8 @@ impl Default for CorpMembership {
permissions: vec!(),
allow_combat: false,
job_title: "Employee".to_owned(),
priority: 100,
chat_on: true,
}
}
}