mirror of
				https://gitlab.com/comunic/comunicapiv3
				synced 2025-11-04 09:34:04 +00:00 
			
		
		
		
	Can delete a single notification
This commit is contained in:
		@@ -660,6 +660,12 @@ impl DeleteQuery {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// Add batch conditions
 | 
			
		||||
    pub fn add_conditions(mut self, conditions: HashMap<String, mysql::Value>) -> Self {
 | 
			
		||||
        self.conditions.extend(conditions.into_iter());
 | 
			
		||||
        self
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// Add a string condition
 | 
			
		||||
    pub fn cond_str(mut self, key: &str, value: &str) -> DeleteQuery {
 | 
			
		||||
        self.conditions.insert(key.to_string(), Value::from(value));
 | 
			
		||||
 
 | 
			
		||||
@@ -10,7 +10,31 @@ use crate::data::notification::{NotifElemType, NotifEventType, NotifEventVisibil
 | 
			
		||||
use crate::data::user::UserID;
 | 
			
		||||
use crate::helpers::database;
 | 
			
		||||
 | 
			
		||||
/// check out whether a similar notification exists for given specifications
 | 
			
		||||
/// Delete notifications
 | 
			
		||||
pub fn delete(notification: &PartialNotification) -> ResultBoxError {
 | 
			
		||||
 | 
			
		||||
    // Check if we have to delete a specific notification or a group of similar notifications
 | 
			
		||||
    let conditions = match notification.id {
 | 
			
		||||
        Some(id) => {
 | 
			
		||||
            let mut map = HashMap::new();
 | 
			
		||||
            map.insert("id".to_string(), mysql::Value::from(id));
 | 
			
		||||
            map
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Delete similar notifications
 | 
			
		||||
        None => {
 | 
			
		||||
            notif_to_db(notification, false)
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    // Delete the notifications
 | 
			
		||||
    database::DeleteQuery::new(NOTIFICATIONS_TABLE)
 | 
			
		||||
        .add_conditions(conditions)
 | 
			
		||||
        .exec()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Check out whether a similar notification exists for given specifications
 | 
			
		||||
pub fn similar_exists(n: &PartialNotification) -> ResultBoxError<bool> {
 | 
			
		||||
    database::QueryInfo::new(NOTIFICATIONS_TABLE)
 | 
			
		||||
        .add_conditions(¬if_to_db(n, false))
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user