feat: implement unread notification count and enhance user listing with pagination
Some checks failed
lint / lint (push) Has been cancelled
test / unit (push) Has been cancelled
test / integration (push) Has been cancelled
lint / lint (pull_request) Failing after 9m33s
test / unit (pull_request) Successful in 16m24s
test / integration (pull_request) Failing after 16m52s
Some checks failed
lint / lint (push) Has been cancelled
test / unit (push) Has been cancelled
test / integration (push) Has been cancelled
lint / lint (pull_request) Failing after 9m33s
test / unit (pull_request) Successful in 16m24s
test / integration (pull_request) Failing after 16m52s
This commit is contained in:
@@ -25,6 +25,17 @@ pub struct Thought {
|
||||
pub updated_at: Option<DateTime<Utc>>,
|
||||
}
|
||||
|
||||
impl Visibility {
|
||||
pub fn as_str(&self) -> &'static str {
|
||||
match self {
|
||||
Visibility::Public => "public",
|
||||
Visibility::Followers => "followers",
|
||||
Visibility::Unlisted => "unlisted",
|
||||
Visibility::Direct => "direct",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Thought {
|
||||
pub fn new_local(
|
||||
id: ThoughtId,
|
||||
|
||||
@@ -184,6 +184,7 @@ pub trait NotificationRepository: Send + Sync {
|
||||
user_id: &UserId,
|
||||
page: &PageParams,
|
||||
) -> Result<Paginated<Notification>, DomainError>;
|
||||
async fn count_unread(&self, user_id: &UserId) -> Result<u64, DomainError>;
|
||||
async fn mark_read(&self, id: &NotificationId, user_id: &UserId) -> Result<(), DomainError>;
|
||||
async fn mark_all_read(&self, user_id: &UserId) -> Result<(), DomainError>;
|
||||
}
|
||||
|
||||
@@ -498,6 +498,15 @@ impl NotificationRepository for TestStore {
|
||||
per_page: 20,
|
||||
})
|
||||
}
|
||||
async fn count_unread(&self, uid: &UserId) -> Result<u64, DomainError> {
|
||||
Ok(self
|
||||
.notifications
|
||||
.lock()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.filter(|n| &n.user_id == uid && !n.read)
|
||||
.count() as u64)
|
||||
}
|
||||
async fn mark_read(&self, id: &NotificationId, _uid: &UserId) -> Result<(), DomainError> {
|
||||
if let Some(n) = self
|
||||
.notifications
|
||||
|
||||
Reference in New Issue
Block a user