Profiles: Expose notifications for profile
- Expose notification counts for profile - Expose Accept & Reject Follow Request constructors - Don't error on missing activitypub for RejectFollowRequest
This commit is contained in:
parent
f350d718ac
commit
0a64034ea9
|
@ -87,25 +87,25 @@ impl Action for RejectFollowRequest {
|
||||||
.remove(self.follow_request_id)?;
|
.remove(self.follow_request_id)?;
|
||||||
|
|
||||||
if let Some(undo_follow_request) = opt {
|
if let Some(undo_follow_request) = opt {
|
||||||
let follow_apub_id = ctx
|
|
||||||
.apub
|
|
||||||
.apub_for_follow_request(self.follow_request_id)?
|
|
||||||
.req()?;
|
|
||||||
ctx.apub.delete_object(&follow_apub_id)?;
|
|
||||||
|
|
||||||
ctx.store
|
ctx.store
|
||||||
.view
|
.view
|
||||||
.follow_request_notifs
|
.follow_request_notifs
|
||||||
.remove(undo_follow_request.0.id);
|
.remove(undo_follow_request.0.id);
|
||||||
|
|
||||||
if ctx.is_local(undo_follow_request.0.left)?
|
if let Some(follow_apub_id) =
|
||||||
&& !ctx.is_local(undo_follow_request.0.right)?
|
ctx.apub.apub_for_follow_request(self.follow_request_id)?
|
||||||
{
|
{
|
||||||
return Ok(Some(Box::new(crate::apub::results::RejectFollow {
|
ctx.apub.delete_object(&follow_apub_id)?;
|
||||||
follow_apub_id,
|
|
||||||
profile_id: undo_follow_request.0.left,
|
if ctx.is_local(undo_follow_request.0.left)?
|
||||||
requester_id: undo_follow_request.0.right,
|
&& !ctx.is_local(undo_follow_request.0.right)?
|
||||||
})));
|
{
|
||||||
|
return Ok(Some(Box::new(crate::apub::results::RejectFollow {
|
||||||
|
follow_apub_id,
|
||||||
|
profile_id: undo_follow_request.0.left,
|
||||||
|
requester_id: undo_follow_request.0.right,
|
||||||
|
})));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -394,10 +394,26 @@ pub struct AcceptFollowRequest {
|
||||||
published: DateTime<Utc>,
|
published: DateTime<Utc>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl AcceptFollowRequest {
|
||||||
|
pub fn from_id(follow_request_id: Uuid) -> Self {
|
||||||
|
AcceptFollowRequest {
|
||||||
|
accept_apub_id: None,
|
||||||
|
follow_request_id,
|
||||||
|
published: Utc::now(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct RejectFollowRequest {
|
pub struct RejectFollowRequest {
|
||||||
follow_request_id: Uuid,
|
follow_request_id: Uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl RejectFollowRequest {
|
||||||
|
pub fn from_id(follow_request_id: Uuid) -> Self {
|
||||||
|
RejectFollowRequest { follow_request_id }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct UndoFollowRequest {
|
pub struct UndoFollowRequest {
|
||||||
follow_request_id: Uuid,
|
follow_request_id: Uuid,
|
||||||
}
|
}
|
||||||
|
|
|
@ -750,7 +750,7 @@ fn count(
|
||||||
let count = match tree.get(key.as_bytes())? {
|
let count = match tree.get(key.as_bytes())? {
|
||||||
Some(ivec) => {
|
Some(ivec) => {
|
||||||
let s = String::from_utf8_lossy(&ivec);
|
let s = String::from_utf8_lossy(&ivec);
|
||||||
let count: u64 = s.parse().expect("Count is valid");
|
let count: u64 = s.parse().unwrap_or(0);
|
||||||
count
|
count
|
||||||
}
|
}
|
||||||
None => 0,
|
None => 0,
|
||||||
|
|
|
@ -134,7 +134,17 @@ impl NotificationStore {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove(&self, notification_id: Uuid) {
|
pub fn count(&self, profile_id: Uuid) -> Result<u64, StoreError> {
|
||||||
|
let keys = self.keys();
|
||||||
|
if let Some(count) = self.counts.get(keys.counts_key(profile_id))? {
|
||||||
|
let count: u64 = String::from_utf8_lossy(&count).parse().unwrap_or(0);
|
||||||
|
Ok(count)
|
||||||
|
} else {
|
||||||
|
Ok(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn remove(&self, notification_id: Uuid) {
|
||||||
for profile_id in self.profiles(notification_id) {
|
for profile_id in self.profiles(notification_id) {
|
||||||
let keys = self.keys();
|
let keys = self.keys();
|
||||||
|
|
||||||
|
@ -283,6 +293,16 @@ impl NotificationStore {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn for_profile(&self, profile_id: Uuid) -> impl DoubleEndedIterator<Item = Uuid> {
|
||||||
|
let keys = self.keys();
|
||||||
|
|
||||||
|
self.notifications
|
||||||
|
.scan_prefix(keys.notification_prefix(profile_id))
|
||||||
|
.values()
|
||||||
|
.filter_map(|res| res.ok())
|
||||||
|
.filter_map(uuid_from_ivec)
|
||||||
|
}
|
||||||
|
|
||||||
fn notification_keys(&self, profile_id: Uuid) -> impl DoubleEndedIterator<Item = sled::IVec> {
|
fn notification_keys(&self, profile_id: Uuid) -> impl DoubleEndedIterator<Item = sled::IVec> {
|
||||||
let keys = self.keys();
|
let keys = self.keys();
|
||||||
|
|
||||||
|
@ -308,6 +328,12 @@ impl NotificationStore {
|
||||||
.scan_prefix(keys.profile_prefix(notification_id))
|
.scan_prefix(keys.profile_prefix(notification_id))
|
||||||
.values()
|
.values()
|
||||||
.filter_map(|res| res.ok())
|
.filter_map(|res| res.ok())
|
||||||
.filter_map(|ivec| Uuid::from_slice(&ivec).ok())
|
.filter_map(uuid_from_ivec)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn uuid_from_ivec(ivec: sled::IVec) -> Option<Uuid> {
|
||||||
|
Uuid::from_slice(&ivec)
|
||||||
|
.map_err(|e| log::warn!("Failed to parse ivec {}", e))
|
||||||
|
.ok()
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue