-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: parse group increase & decrease event & caching_logic
- Loading branch information
Showing
12 changed files
with
284 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,58 @@ | ||
use crate::core::business::LogicRegistry; | ||
use crate::core::business::{BusinessHandle, LogicFlow}; | ||
use crate::core::event::notify::group_sys_decrease::GroupSysDecreaseEvent; | ||
use crate::core::event::notify::group_sys_increase::GroupSysIncreaseEvent; | ||
use crate::core::event::prelude::*; | ||
use mania_macros::handle_event; | ||
use std::sync::Arc; | ||
|
||
#[handle_event(GroupSysIncreaseEvent, GroupSysDecreaseEvent)] | ||
async fn caching_logic( | ||
event: &mut dyn ServerEvent, | ||
handle: Arc<BusinessHandle>, | ||
flow: LogicFlow, | ||
) -> &dyn ServerEvent { | ||
match flow { | ||
LogicFlow::InComing => caching_logic_incoming(event, handle).await, | ||
LogicFlow::OutGoing => event, | ||
} | ||
} | ||
|
||
async fn caching_logic_incoming( | ||
event: &mut dyn ServerEvent, | ||
handle: Arc<BusinessHandle>, | ||
) -> &dyn ServerEvent { | ||
match event { | ||
_ if let Some(increase) = event.as_any_mut().downcast_mut::<GroupSysIncreaseEvent>() => { | ||
tracing::info!( | ||
"caching_logic_incoming GroupSysIncreaseEvent: {:?}", | ||
increase | ||
); | ||
if let Err(e) = handle.refresh_group_members_cache(increase.group_uin).await { | ||
tracing::error!("refresh_group_members_cache failed: {:?}", e); | ||
} | ||
} | ||
_ if let Some(decrease) = event.as_any_mut().downcast_mut::<GroupSysDecreaseEvent>() => { | ||
tracing::info!( | ||
"caching_logic_incoming GroupSysDecreaseEvent: {:?}", | ||
decrease | ||
); | ||
let self_uid = handle | ||
.context | ||
.key_store | ||
.uid | ||
.load() | ||
.as_ref() | ||
.expect("Missing self_uid") | ||
.as_ref() | ||
.clone(); | ||
if decrease.member_uid != self_uid | ||
&& let Err(e) = handle.refresh_group_members_cache(decrease.group_uin).await | ||
{ | ||
tracing::error!("refresh_group_members_cache failed: {:?}", e); | ||
} | ||
} | ||
_ => {} | ||
} | ||
event | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod fetch_group_requests; | ||
pub mod group_sys_enum; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use crate::core::event::prelude::TryFromPrimitive; | ||
|
||
#[derive(Debug, Default, Eq, PartialEq, TryFromPrimitive)] | ||
#[repr(u32)] | ||
pub enum GroupMemberIncreaseEventType { | ||
#[default] | ||
Unknown = 0, | ||
Approve = 130, | ||
Invite = 131, | ||
} | ||
|
||
#[derive(Debug, Default, Eq, PartialEq, TryFromPrimitive)] | ||
#[repr(u32)] | ||
pub enum GroupMemberDecreaseEventType { | ||
#[default] | ||
Unknown = 0, | ||
KickMe = 3, | ||
Disband = 129, | ||
Leave = 130, | ||
Kick = 131, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use crate::core::entity::group_sys_enum::GroupMemberDecreaseEventType; | ||
use crate::core::event::prelude::*; | ||
|
||
#[derive(Debug, DummyEvent, Default)] | ||
pub struct GroupSysDecreaseEvent { | ||
pub group_uin: u32, | ||
pub member_uid: String, | ||
pub operator_uid: Option<String>, | ||
pub event_type: GroupMemberDecreaseEventType, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use crate::core::entity::group_sys_enum::GroupMemberIncreaseEventType; | ||
use crate::core::event::prelude::*; | ||
|
||
#[derive(Debug, DummyEvent, Default)] | ||
pub struct GroupSysIncreaseEvent { | ||
pub group_uin: u32, | ||
pub member_uid: String, | ||
pub invitor_uid: Option<String>, | ||
pub event_type: GroupMemberIncreaseEventType, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.