Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
wsxiaoys authored and zwpaper committed Dec 12, 2024
1 parent 7d0d5be commit c749141
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion ee/tabby-db/migrations/0039_add-notification-inbox.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CREATE TABLE notifications (
updated_at TIMESTAMP NOT NULL DEFAULT(DATETIME('now')),

-- enum of admin, all_user
kind VARCHAR(255) NOT NULL DEFAULT 'admin',
recipient VARCHAR(255) NOT NULL DEFAULT 'admin',

-- content of notification, in markdown format.
content TEXT NOT NULL
Expand Down
Binary file modified ee/tabby-db/schema.sqlite
Binary file not shown.
2 changes: 1 addition & 1 deletion ee/tabby-db/schema/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ CREATE TABLE notifications(
created_at TIMESTAMP NOT NULL DEFAULT(DATETIME('now')),
updated_at TIMESTAMP NOT NULL DEFAULT(DATETIME('now')),
-- enum of admin, all_user
kind VARCHAR(255) NOT NULL DEFAULT 'admin',
recipient VARCHAR(255) NOT NULL DEFAULT 'admin',
-- content of notification, in markdown format.
content TEXT NOT NULL
);
Expand Down
2 changes: 1 addition & 1 deletion ee/tabby-db/schema/schema.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 9 additions & 9 deletions ee/tabby-db/src/notifications.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ use crate::DbConn;
pub struct NotificationDAO {
pub id: i64,

pub kind: String,
pub recipient: String,
pub content: String,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}

impl DbConn {
pub async fn create_notification(&self, kind: &str, content: &str) -> Result<i64> {
pub async fn create_notification(&self, recipient: &str, content: &str) -> Result<i64> {
let res = query!(
"INSERT INTO notifications (kind, content) VALUES (?, ?)",
kind,
"INSERT INTO notifications (recipient, content) VALUES (?, ?)",
recipient,
content
)
.execute(&self.pool)
Expand Down Expand Up @@ -47,17 +47,17 @@ impl DbConn {
.get_user(user_id)
.await?
.context("User doesn't exist")?;
let kind_clause = if user.is_admin {
"kind = 'all_user' OR kind = 'admin'"
let recipient_clause = if user.is_admin {
"recipient = 'all_user' OR recipient = 'admin'"
} else {
"kind = 'all_user'"
"recipient = 'all_user'"
};
let date_7days_ago = Utc::now() - Duration::days(7);
let sql = format!(
r#"
SELECT notifications.id, notifications.created_at, notifications.updated_at, kind, content
SELECT notifications.id, notifications.created_at, notifications.updated_at, recipient, content
FROM notifications LEFT JOIN readed_notifications ON notifications.id = readed_notifications.notification_id
WHERE ({kind_clause}) AND notifications.created_at > '{date_7days_ago}' AND readed_notifications.user_id IS NULL -- notification is not marked as readed
WHERE ({recipient_clause}) AND notifications.created_at > '{date_7days_ago}' AND readed_notifications.user_id IS NULL -- notification is not marked as readed
"#
);
let notifications = query_as(&sql).fetch_all(&self.pool).await?;
Expand Down
12 changes: 6 additions & 6 deletions ee/tabby-schema/src/dao.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use tabby_db::{
use crate::{
integration::{Integration, IntegrationKind, IntegrationStatus},
interface::UserValue,
notification::NotificationKind,
notification::NotificationRecipient,
repository::RepositoryKind,
schema::{
auth::{self, OAuthCredential, OAuthProvider},
Expand Down Expand Up @@ -469,18 +469,18 @@ impl DbEnum for thread::Role {
}
}

impl DbEnum for NotificationKind {
impl DbEnum for NotificationRecipient {
fn as_enum_str(&self) -> &'static str {
match self {
NotificationKind::Admin => "admin",
NotificationKind::AllUser => "all_user",
NotificationRecipient::Admin => "admin",
NotificationRecipient::AllUser => "all_user",
}
}

fn from_enum_str(s: &str) -> anyhow::Result<Self> {
match s {
"admin" => Ok(NotificationKind::Admin),
"all_user" => Ok(NotificationKind::AllUser),
"admin" => Ok(NotificationRecipient::Admin),
"all_user" => Ok(NotificationRecipient::AllUser),
_ => bail!("{s} is not a valid value for NotificationKind"),
}
}
Expand Down
2 changes: 1 addition & 1 deletion ee/tabby-schema/src/schema/notification.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use juniper::GraphQLEnum;

#[derive(GraphQLEnum, Clone, Debug)]
pub enum NotificationKind {
pub enum NotificationRecipient {
Admin,
AllUser,
}

0 comments on commit c749141

Please sign in to comment.