| |
}
|
| |
|
| |
/// Delete the given notifications.
|
| - |
pub fn clear(&mut self, ids: &[NotificationId]) -> Result<usize, Error> {
|
| - |
transaction(&self.db, |_| {
|
| - |
let mut stmt = self
|
| - |
.db
|
| - |
.prepare("DELETE FROM `repository-notifications` WHERE rowid = ?")?;
|
| - |
|
| - |
// N.b. we need to keep the count manually since the change count
|
| - |
// will always be `1` because of each reset.
|
| - |
let mut count = 0;
|
| - |
for id in ids {
|
| - |
stmt.bind((1, *id as i64))?;
|
| - |
stmt.next()?;
|
| - |
stmt.reset()?;
|
| - |
count += self.db.change_count();
|
| - |
}
|
| - |
Ok(count)
|
| - |
})
|
| + |
pub fn clear(
|
| + |
&mut self,
|
| + |
filter_by: Option<FilterBy>,
|
| + |
ids: &[NotificationId],
|
| + |
) -> Result<usize, Error> {
|
| + |
match filter_by {
|
| + |
Some(FilterBy { ref_update }) => transaction(&self.db, |_| {
|
| + |
let mut stmt = self.db.prepare(
|
| + |
"DELETE FROM `repository-notifications` WHERE rowid = ?1 AND status = ?2",
|
| + |
)?;
|
| + |
|
| + |
// N.b. we need to keep the count manually since the change count
|
| + |
// will always be `1` because of each reset.
|
| + |
let mut count = 0;
|
| + |
for id in ids {
|
| + |
stmt.bind((1, *id as i64))?;
|
| + |
stmt.bind((2, ref_update.as_str()))?;
|
| + |
stmt.next()?;
|
| + |
stmt.reset()?;
|
| + |
count += self.db.change_count();
|
| + |
}
|
| + |
Ok(count)
|
| + |
}),
|
| + |
None => transaction(&self.db, |_| {
|
| + |
let mut stmt = self
|
| + |
.db
|
| + |
.prepare("DELETE FROM `repository-notifications` WHERE rowid = ?")?;
|
| + |
|
| + |
// N.b. we need to keep the count manually since the change count
|
| + |
// will always be `1` because of each reset.
|
| + |
let mut count = 0;
|
| + |
for id in ids {
|
| + |
stmt.bind((1, *id as i64))?;
|
| + |
stmt.next()?;
|
| + |
stmt.reset()?;
|
| + |
count += self.db.change_count();
|
| + |
}
|
| + |
Ok(count)
|
| + |
}),
|
| + |
}
|
| |
}
|
| |
|
| |
/// Delete all notifications of a repo.
|
| - |
pub fn clear_by_repo(&mut self, repo: &RepoId) -> Result<usize, Error> {
|
| - |
let mut stmt = self
|
| - |
.db
|
| - |
.prepare("DELETE FROM `repository-notifications` WHERE repo = ?")?;
|
| + |
pub fn clear_by_repo(
|
| + |
&mut self,
|
| + |
filter_by: Option<FilterBy>,
|
| + |
repo: &RepoId,
|
| + |
) -> Result<usize, Error> {
|
| + |
match filter_by {
|
| + |
Some(FilterBy { ref_update }) => transaction(&self.db, |_| {
|
| + |
let mut stmt = self.db.prepare(
|
| + |
"DELETE FROM `repository-notifications` WHERE repo = ?1 where ref = ?2",
|
| + |
)?;
|
| + |
|
| + |
stmt.bind((1, repo))?;
|
| + |
stmt.bind((2, ref_update.as_str()))?;
|
| + |
stmt.next()?;
|
| |
|
| - |
stmt.bind((1, repo))?;
|
| - |
stmt.next()?;
|
| + |
Ok(self.db.change_count())
|
| + |
}),
|
| + |
None => transaction(&self.db, |_| {
|
| + |
let mut stmt = self
|
| + |
.db
|
| + |
.prepare("DELETE FROM `repository-notifications` WHERE repo = ?")?;
|
| |
|
| - |
Ok(self.db.change_count())
|
| + |
stmt.bind((1, repo))?;
|
| + |
stmt.next()?;
|
| + |
|
| + |
Ok(self.db.change_count())
|
| + |
}),
|
| + |
}
|
| |
}
|
| |
|
| |
/// Delete all notifications from all repos.
|
| |
}
|
| |
}
|
| |
|
| + |
#[derive(Debug)]
|
| + |
pub struct FilterBy {
|
| + |
pub ref_update: FilterByRefUpdate,
|
| + |
}
|
| + |
|
| + |
#[derive(Debug)]
|
| + |
pub enum FilterByRefUpdate {
|
| + |
Merged,
|
| + |
Deleted,
|
| + |
Created,
|
| + |
Opened,
|
| + |
Updated,
|
| + |
Draft,
|
| + |
}
|
| + |
|
| + |
impl FilterByRefUpdate {
|
| + |
fn as_str(&self) -> &'static str {
|
| + |
match self {
|
| + |
Self::Merged => "merged",
|
| + |
Self::Deleted => "deleted",
|
| + |
Self::Created => "created",
|
| + |
Self::Opened => "opened",
|
| + |
Self::Updated => "updated",
|
| + |
Self::Draft => "draft",
|
| + |
}
|
| + |
}
|
| + |
}
|
| + |
|
| |
#[cfg(test)]
|
| |
#[allow(clippy::unwrap_used)]
|
| |
mod test {
|