Start work on storing notifications in the database
This commit is contained in:
parent
45f3a98359
commit
cf6ce0dbad
16 changed files with 399 additions and 2 deletions
|
@ -29,6 +29,7 @@ rsa = "0.4"
|
|||
serde.workspace = true
|
||||
serde_derive.workspace = true
|
||||
smol-timeout = "0.6"
|
||||
strum.workspace = true
|
||||
tracing = { version = "0.1.34", features = ["log"] }
|
||||
zstd = "0.11"
|
||||
|
||||
|
|
|
@ -170,7 +170,9 @@ message Envelope {
|
|||
|
||||
LinkChannel link_channel = 140;
|
||||
UnlinkChannel unlink_channel = 141;
|
||||
MoveChannel move_channel = 142; // current max: 144
|
||||
MoveChannel move_channel = 142;
|
||||
|
||||
AddNotifications add_notification = 145; // Current max
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1557,3 +1559,40 @@ message UpdateDiffBase {
|
|||
uint64 buffer_id = 2;
|
||||
optional string diff_base = 3;
|
||||
}
|
||||
|
||||
message AddNotifications {
|
||||
repeated Notification notifications = 1;
|
||||
repeated User users = 2;
|
||||
repeated Channel channels = 3;
|
||||
repeated ChannelMessage messages = 4;
|
||||
}
|
||||
|
||||
message Notification {
|
||||
uint32 kind = 1;
|
||||
uint64 timestamp = 2;
|
||||
bool is_read = 3;
|
||||
optional uint64 entity_id_1 = 4;
|
||||
optional uint64 entity_id_2 = 5;
|
||||
optional uint64 entity_id_3 = 6;
|
||||
|
||||
// oneof variant {
|
||||
// ContactRequest contact_request = 3;
|
||||
// ChannelInvitation channel_invitation = 4;
|
||||
// ChatMessageMention chat_message_mention = 5;
|
||||
// };
|
||||
|
||||
// message ContactRequest {
|
||||
// uint64 requester_id = 1;
|
||||
// }
|
||||
|
||||
// message ChannelInvitation {
|
||||
// uint64 inviter_id = 1;
|
||||
// uint64 channel_id = 2;
|
||||
// }
|
||||
|
||||
// message ChatMessageMention {
|
||||
// uint64 sender_id = 1;
|
||||
// uint64 channel_id = 2;
|
||||
// uint64 message_id = 3;
|
||||
// }
|
||||
}
|
||||
|
|
105
crates/rpc/src/notification.rs
Normal file
105
crates/rpc/src/notification.rs
Normal file
|
@ -0,0 +1,105 @@
|
|||
use strum::{Display, EnumIter, EnumString, IntoEnumIterator};
|
||||
|
||||
// An integer indicating a type of notification. The variants' numerical
|
||||
// values are stored in the database, so they should never be removed
|
||||
// or changed.
|
||||
#[repr(i32)]
|
||||
#[derive(Copy, Clone, Debug, EnumIter, EnumString, Display)]
|
||||
pub enum NotificationKind {
|
||||
ContactRequest = 0,
|
||||
ChannelInvitation = 1,
|
||||
ChannelMessageMention = 2,
|
||||
}
|
||||
|
||||
pub enum Notification {
|
||||
ContactRequest {
|
||||
requester_id: u64,
|
||||
},
|
||||
ChannelInvitation {
|
||||
inviter_id: u64,
|
||||
channel_id: u64,
|
||||
},
|
||||
ChannelMessageMention {
|
||||
sender_id: u64,
|
||||
channel_id: u64,
|
||||
message_id: u64,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub enum NotificationEntityKind {
|
||||
User,
|
||||
Channel,
|
||||
ChannelMessage,
|
||||
}
|
||||
|
||||
impl Notification {
|
||||
pub fn from_fields(kind: NotificationKind, entity_ids: [Option<u64>; 3]) -> Option<Self> {
|
||||
use NotificationKind::*;
|
||||
|
||||
Some(match kind {
|
||||
ContactRequest => Self::ContactRequest {
|
||||
requester_id: entity_ids[0]?,
|
||||
},
|
||||
ChannelInvitation => Self::ChannelInvitation {
|
||||
inviter_id: entity_ids[0]?,
|
||||
channel_id: entity_ids[1]?,
|
||||
},
|
||||
ChannelMessageMention => Self::ChannelMessageMention {
|
||||
sender_id: entity_ids[0]?,
|
||||
channel_id: entity_ids[1]?,
|
||||
message_id: entity_ids[2]?,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
pub fn to_fields(&self) -> (NotificationKind, [Option<(u64, NotificationEntityKind)>; 3]) {
|
||||
use NotificationKind::*;
|
||||
|
||||
match self {
|
||||
Self::ContactRequest { requester_id } => (
|
||||
ContactRequest,
|
||||
[
|
||||
Some((*requester_id, NotificationEntityKind::User)),
|
||||
None,
|
||||
None,
|
||||
],
|
||||
),
|
||||
|
||||
Self::ChannelInvitation {
|
||||
inviter_id,
|
||||
channel_id,
|
||||
} => (
|
||||
ChannelInvitation,
|
||||
[
|
||||
Some((*inviter_id, NotificationEntityKind::User)),
|
||||
Some((*channel_id, NotificationEntityKind::User)),
|
||||
None,
|
||||
],
|
||||
),
|
||||
|
||||
Self::ChannelMessageMention {
|
||||
sender_id,
|
||||
channel_id,
|
||||
message_id,
|
||||
} => (
|
||||
ChannelMessageMention,
|
||||
[
|
||||
Some((*sender_id, NotificationEntityKind::User)),
|
||||
Some((*channel_id, NotificationEntityKind::ChannelMessage)),
|
||||
Some((*message_id, NotificationEntityKind::Channel)),
|
||||
],
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl NotificationKind {
|
||||
pub fn all() -> impl Iterator<Item = Self> {
|
||||
Self::iter()
|
||||
}
|
||||
|
||||
pub fn from_i32(i: i32) -> Option<Self> {
|
||||
Self::iter().find(|kind| *kind as i32 == i)
|
||||
}
|
||||
}
|
|
@ -1,9 +1,12 @@
|
|||
pub mod auth;
|
||||
mod conn;
|
||||
mod notification;
|
||||
mod peer;
|
||||
pub mod proto;
|
||||
|
||||
pub use conn::Connection;
|
||||
pub use peer::*;
|
||||
pub use notification::*;
|
||||
mod macros;
|
||||
|
||||
pub const PROTOCOL_VERSION: u32 = 64;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue