Start work on notification panel

This commit is contained in:
Max Brunsfeld 2023-10-06 12:56:18 -07:00
parent 50cf25ae97
commit d1756b621f
24 changed files with 1021 additions and 241 deletions

View file

@ -172,7 +172,8 @@ message Envelope {
UnlinkChannel unlink_channel = 141;
MoveChannel move_channel = 142;
AddNotifications add_notification = 145; // Current max
AddNotifications add_notifications = 145;
GetChannelMessagesById get_channel_messages_by_id = 146; // Current max
}
}
@ -1101,6 +1102,10 @@ message GetChannelMessagesResponse {
bool done = 2;
}
message GetChannelMessagesById {
repeated uint64 message_ids = 1;
}
message LinkChannel {
uint64 channel_id = 1;
uint64 to = 2;
@ -1562,37 +1567,14 @@ message UpdateDiffBase {
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;
// }
uint64 id = 1;
uint32 kind = 2;
uint64 timestamp = 3;
bool is_read = 4;
optional uint64 entity_id_1 = 5;
optional uint64 entity_id_2 = 6;
optional uint64 entity_id_3 = 7;
}

View file

@ -7,14 +7,19 @@ use strum::{Display, EnumIter, EnumString, IntoEnumIterator};
#[derive(Copy, Clone, Debug, EnumIter, EnumString, Display)]
pub enum NotificationKind {
ContactRequest = 0,
ChannelInvitation = 1,
ChannelMessageMention = 2,
ContactRequestAccepted = 1,
ChannelInvitation = 2,
ChannelMessageMention = 3,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Notification {
ContactRequest {
requester_id: u64,
},
ContactRequestAccepted {
contact_id: u64,
},
ChannelInvitation {
inviter_id: u64,
channel_id: u64,
@ -26,13 +31,6 @@ pub enum Notification {
},
}
#[derive(Copy, Clone)]
pub enum NotificationEntityKind {
User,
Channel,
ChannelMessage,
}
impl Notification {
/// Load this notification from its generic representation, which is
/// used to represent it in the database, and in the wire protocol.
@ -42,15 +40,20 @@ impl Notification {
/// not change, because they're stored in that order in the database.
pub fn from_parts(kind: NotificationKind, entity_ids: [Option<u64>; 3]) -> Option<Self> {
use NotificationKind::*;
Some(match kind {
ContactRequest => Self::ContactRequest {
requester_id: entity_ids[0]?,
},
ContactRequestAccepted => 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]?,
@ -65,33 +68,23 @@ impl Notification {
/// The order in which a given notification type's fields are listed must
/// match the order they're listed in the `from_parts` method, and it must
/// not change, because they're stored in that order in the database.
///
/// Along with each field, provide the kind of entity that the field refers
/// to. This is used to load the associated entities for a batch of
/// notifications from the database.
pub fn to_parts(&self) -> (NotificationKind, [Option<(u64, NotificationEntityKind)>; 3]) {
pub fn to_parts(&self) -> (NotificationKind, [Option<u64>; 3]) {
use NotificationKind::*;
match self {
Self::ContactRequest { requester_id } => (
ContactRequest,
[
Some((*requester_id, NotificationEntityKind::User)),
None,
None,
],
),
Self::ContactRequest { requester_id } => {
(ContactRequest, [Some(*requester_id), None, None])
}
Self::ContactRequestAccepted { contact_id } => {
(ContactRequest, [Some(*contact_id), None, None])
}
Self::ChannelInvitation {
inviter_id,
channel_id,
} => (
ChannelInvitation,
[
Some((*inviter_id, NotificationEntityKind::User)),
Some((*channel_id, NotificationEntityKind::User)),
None,
],
[Some(*inviter_id), Some(*channel_id), None],
),
Self::ChannelMessageMention {
@ -100,11 +93,7 @@ impl Notification {
message_id,
} => (
ChannelMessageMention,
[
Some((*sender_id, NotificationEntityKind::User)),
Some((*channel_id, NotificationEntityKind::ChannelMessage)),
Some((*message_id, NotificationEntityKind::Channel)),
],
[Some(*sender_id), Some(*channel_id), Some(*message_id)],
),
}
}

View file

@ -133,6 +133,7 @@ impl fmt::Display for PeerId {
messages!(
(Ack, Foreground),
(AddNotifications, Foreground),
(AddProjectCollaborator, Foreground),
(ApplyCodeAction, Background),
(ApplyCodeActionResponse, Background),
@ -166,6 +167,7 @@ messages!(
(GetHoverResponse, Background),
(GetChannelMessages, Background),
(GetChannelMessagesResponse, Background),
(GetChannelMessagesById, Background),
(SendChannelMessage, Background),
(SendChannelMessageResponse, Background),
(GetCompletions, Background),
@ -329,6 +331,7 @@ request_messages!(
(SetChannelMemberAdmin, Ack),
(SendChannelMessage, SendChannelMessageResponse),
(GetChannelMessages, GetChannelMessagesResponse),
(GetChannelMessagesById, GetChannelMessagesResponse),
(GetChannelMembers, GetChannelMembersResponse),
(JoinChannel, JoinRoomResponse),
(RemoveChannelMessage, Ack),