mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Friends functionality (#90)
### Description Implements and closes #86 ### Game Robocraft ### Please confirm - [x] I am the legal owner or represent the owner of all work submitted - [x] I consent to my submission being added to this FOSS project - [ ] This PR used LLMs to generate some or all of the code changes Reviewed-on: https://git.ngram.ca/OpenJam/rc-servers/pulls/90 Co-authored-by: NG (Graham) <ngniusness@gmail.com> Co-committed-by: NG (Graham) <ngniusness@gmail.com>
This commit is contained in:
1 parent
872f224af6
commit
9502522ac4
30 files changed
+1108
-35
No files matched your search
@@ -0,0 +1,59 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
|
||||
#[sea_orm(table_name = "friends")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: i32,
|
||||
pub creation_time: i64, // seconds since unix epoch
|
||||
pub friend_source: i32,
|
||||
pub friend_target: i32,
|
||||
pub state: FriendStatus,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(
|
||||
belongs_to = "super::user::Entity",
|
||||
from = "Column::FriendSource",
|
||||
to = "super::user::Column::Id"
|
||||
)]
|
||||
Source,
|
||||
#[sea_orm(
|
||||
belongs_to = "super::user::Entity",
|
||||
from = "Column::FriendTarget",
|
||||
to = "super::user::Column::Id"
|
||||
)]
|
||||
Target,
|
||||
}
|
||||
|
||||
/*impl Related<super::user::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Source.def()
|
||||
}
|
||||
}*/
|
||||
|
||||
impl Related<super::user::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Target.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)]
|
||||
#[sea_orm(rs_type = "String", db_type = "String(StringLen::None)", rename_all = "PascalCase")]
|
||||
pub enum FriendStatus {
|
||||
InviteSent,
|
||||
InvitePending,
|
||||
Accepted,
|
||||
Declined,
|
||||
Cancelled,
|
||||
Removed,
|
||||
}
|
||||
|
||||
pub const FINAL_STATUSES: [FriendStatus; 3] = [
|
||||
FriendStatus::Declined,
|
||||
FriendStatus::Cancelled,
|
||||
FriendStatus::Removed,
|
||||
];
|
||||
@@ -12,6 +12,7 @@ pub mod game_event;
|
||||
pub mod multiplayer_game_score;
|
||||
#[cfg(feature = "factory")]
|
||||
pub mod factory;
|
||||
pub mod friend;
|
||||
|
||||
pub fn parse_int_csv(s: &str) -> Vec<u32> {
|
||||
s.split(',').filter_map(|i_as_s| {
|
||||
|
||||
@@ -27,6 +27,8 @@ pub enum Relation {
|
||||
Player,
|
||||
#[sea_orm(has_many = "super::factory::vehicle::Entity")]
|
||||
FactoryUploads,
|
||||
#[sea_orm(has_many = "super::friend::Entity")]
|
||||
Friends, // this will probably join the wrong column (i.e. in the wrong direction)
|
||||
}
|
||||
|
||||
impl Related<super::permissions::Entity> for Entity {
|
||||
@@ -65,4 +67,10 @@ impl Related<super::factory::vehicle::Entity> for Entity {
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::friend::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Friends.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
Reference in new issue
Block a user