Files
zep/spacetimedb/src/tables.rs
T

287 lines
6.3 KiB
Rust

use spacetimedb::{Identity, Timestamp};
#[derive(spacetimedb::SpacetimeType, Clone, Copy, Debug)]
pub enum ChannelKind {
Text,
Voice,
}
#[spacetimedb::table(accessor = user, public)]
pub struct User {
#[primary_key]
pub identity: Identity,
pub name: Option<String>,
#[index(btree)]
pub online: bool,
pub issuer: Option<String>,
pub subject: Option<String>,
pub anonymous: bool,
pub avatar_id: Option<u64>,
pub banner_id: Option<u64>,
pub biography: Option<String>,
pub status: Option<String>,
pub public_key: Option<String>,
}
#[derive(spacetimedb::SpacetimeType, Clone, Debug)]
pub struct ChannelMetadata {
pub id: u64,
pub name: String,
pub kind: ChannelKind,
}
#[spacetimedb::table(accessor = server)]
pub struct Server {
#[primary_key]
#[auto_inc]
pub id: u64,
#[index(btree)]
pub name: String,
pub owner: Option<Identity>,
pub avatar_id: Option<u64>,
pub channels: Vec<ChannelMetadata>,
pub public: bool,
}
#[spacetimedb::table(accessor = server_member)]
pub struct ServerMember {
#[primary_key]
#[auto_inc]
pub id: u64,
#[index(btree)]
pub identity: Identity,
#[index(btree)]
pub server_id: u64,
pub name: Option<String>,
pub avatar_id: Option<u64>,
pub online: bool,
}
#[spacetimedb::table(accessor = channel)]
pub struct Channel {
#[primary_key]
#[auto_inc]
pub id: u64,
#[index(btree)]
pub server_id: u64, // 0 if no server (DM)
pub name: String,
pub kind: ChannelKind,
}
#[spacetimedb::table(accessor = direct_message)]
#[derive(Clone)]
pub struct DirectMessage {
#[primary_key]
#[auto_inc]
pub id: u64,
#[index(btree)]
pub channel_id: u64,
#[index(btree)]
pub sender: Identity,
#[index(btree)]
pub recipient: Identity,
#[index(btree)]
pub is_open_sender: bool,
#[index(btree)]
pub is_open_recipient: bool,
}
#[spacetimedb::table(accessor = voice_state, public)]
pub struct VoiceState {
#[primary_key]
pub identity: Identity,
#[index(btree)]
pub channel_id: u64,
pub is_sharing_screen: bool,
pub is_muted: bool,
pub is_deafened: bool,
}
#[spacetimedb::table(accessor = voice_activity, public)]
pub struct VoiceActivity {
#[primary_key]
pub identity: Identity,
#[index(btree)]
pub channel_id: u64,
pub is_talking: bool,
}
#[spacetimedb::table(accessor = watching, public)]
pub struct Watching {
#[primary_key]
#[auto_inc]
pub id: u64,
#[index(btree)]
pub watcher: Identity,
#[index(btree)]
pub watchee: Identity,
#[index(btree)]
pub channel_id: u64,
}
#[derive(spacetimedb::SpacetimeType, Clone, Copy, Debug, PartialEq)]
pub enum SignalKind {
Offer,
Answer,
IceCandidate,
}
#[derive(spacetimedb::SpacetimeType, Clone, Copy, Debug, PartialEq)]
pub enum MediaType {
Voice,
Screen,
}
#[spacetimedb::table(accessor = webrtc_signal)]
pub struct WebRTCSignal {
#[primary_key]
#[auto_inc]
pub id: u64,
#[index(btree)]
pub sender: Identity,
#[index(btree)]
pub receiver: Identity,
pub signal_kind: SignalKind,
pub media_type: MediaType,
pub data: String,
#[index(btree)]
pub channel_id: u64,
}
#[spacetimedb::table(accessor = channel_message_sequence)]
pub struct ChannelMessageSequence {
#[primary_key]
pub message_id: u64,
#[index(btree)]
pub channel_id: u64,
pub seq_id: u64,
}
#[spacetimedb::table(accessor = channel_high_water_mark)]
pub struct ChannelHighWaterMark {
#[primary_key]
pub channel_id: u64,
pub last_seq_id: u64,
}
#[spacetimedb::table(accessor = channel_subscription)]
pub struct ChannelSubscription {
#[primary_key]
pub identity: Identity,
#[index(btree)]
pub channel_id: u64,
pub earliest_seq_id: u64,
pub last_read_seq_id: u64,
}
#[spacetimedb::table(accessor = thread, public)]
pub struct Thread {
#[primary_key]
#[auto_inc]
pub id: u64,
#[index(btree)]
pub channel_id: u64,
#[unique]
pub parent_message_id: u64,
pub name: String,
}
#[derive(spacetimedb::SpacetimeType, Clone, Debug)]
pub struct Reaction {
pub identity: Identity,
pub emoji: Option<String>,
pub custom_emoji_id: Option<u64>,
}
#[spacetimedb::table(accessor = message)]
pub struct Message {
#[primary_key]
#[auto_inc]
pub id: u64,
pub sender: Identity,
#[index(btree)]
pub sent: Timestamp,
pub text: String,
#[index(btree)]
pub channel_id: u64,
#[index(btree)]
pub thread_id: Option<u64>,
pub reactions: Vec<Reaction>,
pub image_ids: Vec<u64>,
pub thread_name: Option<String>,
pub thread_reply_count: u32,
pub edited: bool,
pub is_encrypted: bool,
}
#[spacetimedb::table(accessor = custom_emoji, public)]
pub struct CustomEmoji {
#[primary_key]
#[auto_inc]
#[index(btree)]
pub id: u64,
#[index(btree)]
pub name: String,
pub category: String,
pub data: Vec<u8>,
}
#[spacetimedb::table(accessor = image)]
pub struct Image {
#[primary_key]
#[auto_inc]
#[index(btree)]
pub id: u64,
pub data: Vec<u8>,
pub mime_type: String,
pub name: Option<String>,
}
#[spacetimedb::table(accessor = typing_activity, public)]
pub struct TypingActivity {
#[primary_key]
pub identity: Identity,
#[index(btree)]
pub channel_id: u64,
pub is_typing: bool,
}
#[spacetimedb::table(accessor = recent_message)]
pub struct RecentMessage {
#[primary_key]
pub id: u64, // This is the message_id
#[index(btree)]
pub server_id: u64, // 0 if DM
#[index(btree)]
pub channel_id: u64,
pub sender: Identity,
pub text: String,
pub thread_id: Option<u64>,
pub sent: Timestamp,
pub seq_id: u64,
pub reactions: Vec<Reaction>,
pub image_ids: Vec<u64>,
pub thread_name: Option<String>,
pub thread_reply_count: u32,
pub edited: bool,
pub is_encrypted: bool,
}
#[spacetimedb::table(accessor = system_configuration, public)]
pub struct SystemConfiguration {
#[primary_key]
pub key: String,
pub value: String,
}
#[spacetimedb::table(accessor = upload_status, public)]
pub struct UploadStatus {
#[primary_key]
pub client_id: String,
#[index(btree)]
pub identity: Identity,
pub image_id: Option<u64>,
pub status: String, // "pending", "success", "error"
pub error: Option<String>,
}