add: reactions

This commit is contained in:
trisua 2025-03-24 22:42:33 -04:00
parent c46eb3b807
commit 382e3bc7a6
18 changed files with 357 additions and 11 deletions

View file

@ -18,6 +18,8 @@ pub struct JournalPage {
/// The owner of the journal page (and moderators) are the ***only*** people
/// capable of removing entries.
pub write_access: JournalPageWriteAccess,
pub likes: isize,
pub dislikes: isize,
}
impl JournalPage {
@ -34,6 +36,8 @@ impl JournalPage {
owner,
read_access: JournalPageReadAccess::default(),
write_access: JournalPageWriteAccess::default(),
likes: 0,
dislikes: 0,
}
}
}
@ -124,6 +128,8 @@ pub struct JournalEntry {
pub journal: usize,
/// Extra information about the journal entry.
pub context: JournalEntryContext,
pub likes: isize,
pub dislikes: isize,
}
impl JournalEntry {
@ -139,6 +145,8 @@ impl JournalEntry {
owner,
journal,
context: JournalEntryContext::default(),
likes: 0,
dislikes: 0,
}
}
}

View file

@ -2,6 +2,7 @@ pub mod auth;
pub mod journal;
pub mod journal_permissions;
pub mod permissions;
pub mod reactions;
use serde::{Deserialize, Serialize};

View file

@ -20,6 +20,7 @@ bitflags! {
const VIEW_REPORTS = 1 << 9;
const VIEW_AUDIT_LOG = 1 << 10;
const MANAGE_MEMBERSHIPS = 1 << 11;
const MANAGE_REACTIONS = 1 << 12;
const _ = !0;
}

View file

@ -0,0 +1,34 @@
use serde::{Deserialize, Serialize};
use tetratto_shared::{snow::AlmostSnowflake, unix_epoch_timestamp};
/// All of the items which support reactions.
#[derive(Serialize, Deserialize)]
pub enum AssetType {
JournalPage,
JournalEntry,
}
#[derive(Serialize, Deserialize)]
pub struct Reaction {
pub id: usize,
pub created: usize,
pub owner: usize,
pub asset: usize,
pub asset_type: AssetType,
}
impl Reaction {
/// Create a new [`Reaction`].
pub fn new(owner: usize, asset: usize, asset_type: AssetType) -> Self {
Self {
id: AlmostSnowflake::new(1234567890)
.to_string()
.parse::<usize>()
.unwrap(),
created: unix_epoch_timestamp() as usize,
owner,
asset,
asset_type,
}
}
}