Browse Source

Store whether a ping originated from a team ping

This does not yet render (or use) this information, but it will be handy to have
in the future.
Mark Rousskov 5 years ago
parent
commit
a38a7861db
3 changed files with 8 additions and 2 deletions
  1. 1 0
      src/db.rs
  2. 6 2
      src/db/notifications.rs
  3. 1 0
      src/handlers/notification.rs

+ 1 - 0
src/db.rs

@@ -68,4 +68,5 @@ CREATE TABLE users (
 );
 ",
     "ALTER TABLE notifications ADD COLUMN short_description TEXT;",
+    "ALTER TABLE notifications ADD COLUMN team_name TEXT;",
 ];

+ 6 - 2
src/db/notifications.rs

@@ -9,6 +9,10 @@ pub struct Notification {
     pub origin_html: String,
     pub short_description: Option<String>,
     pub time: DateTime<FixedOffset>,
+
+    /// If this is Some, then the notification originated in a team-wide ping
+    /// (e.g., @rust-lang/libs). The String is the team name (e.g., libs).
+    pub team_name: Option<String>,
 }
 
 pub async fn record_ping(db: &DbClient, notification: &Notification) -> anyhow::Result<()> {
@@ -19,8 +23,8 @@ pub async fn record_ping(db: &DbClient, notification: &Notification) -> anyhow::
     .await
     .context("inserting user id / username")?;
 
-    db.execute("INSERT INTO notifications (user_id, origin_url, origin_html, time, short_description) VALUES ($1, $2, $3, $4, $5)",
-        &[&notification.user_id, &notification.origin_url, &notification.origin_html, &notification.time, &notification.short_description],
+    db.execute("INSERT INTO notifications (user_id, origin_url, origin_html, time, short_description, team_name) VALUES ($1, $2, $3, $4, $5, $6)",
+        &[&notification.user_id, &notification.origin_url, &notification.origin_html, &notification.time, &notification.short_description, &notification.team_name],
         ).await.context("inserting notification")?;
 
     Ok(())

+ 1 - 0
src/handlers/notification.rs

@@ -177,6 +177,7 @@ pub async fn handle(ctx: &Context, event: &Event) -> anyhow::Result<()> {
                     origin_html: body.to_owned(),
                     time: event.time(),
                     short_description: Some(short_description.clone()),
+                    team_name: team_name.clone(),
                 },
             )
             .await