-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat & refactor: impl cache logic, some events & minor refactor
- feat: impl cache mod - feat: impl parse event `GroupRequestJoin` - feat: impl internal event `FetchFilteredGroupRequestsEvent`, `FetchGroupRequestsEvent`, `FetchUserInfoEvent` - feat: impl op `cache_ops`, `resolve_stranger_uid2uin`, `fetch_group_requests` - refactor: message logic - refactor: client config parse
- Loading branch information
Showing
26 changed files
with
902 additions
and
154 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
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,20 +1,64 @@ | ||
use crate::entity::bot_friend::BotFriend; | ||
use crate::entity::bot_group_member::BotGroupMember; | ||
use dashmap::DashMap; | ||
use tokio::sync::RwLock; | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
pub enum CacheMode { | ||
Full, | ||
Half, | ||
None, | ||
} | ||
|
||
pub struct Cache { | ||
pub uin2uid: DashMap<u32, String>, | ||
pub cached_friends: RwLock<Vec<BotFriend>>, | ||
pub cached_group_members: DashMap<u32, Vec<BotGroupMember>>, | ||
pub(crate) cache_mode: CacheMode, | ||
pub(crate) uin2uid: Option<DashMap<u32, String>>, | ||
pub(crate) uid2uin: Option<DashMap<String, u32>>, | ||
pub(crate) cached_friends: Option<DashMap<u32, BotFriend>>, | ||
pub(crate) cached_group_members: Option<DashMap<u32, Vec<BotGroupMember>>>, | ||
} | ||
|
||
impl Cache { | ||
pub fn new() -> Self { | ||
pub fn new(cache_mode: CacheMode) -> Self { | ||
match cache_mode { | ||
CacheMode::Full => Self::full(), | ||
CacheMode::Half => Self::half(), | ||
CacheMode::None => Self::none(), | ||
} | ||
} | ||
|
||
fn full() -> Self { | ||
Self { | ||
uin2uid: DashMap::new(), | ||
cached_friends: RwLock::new(Vec::new()), | ||
cached_group_members: DashMap::new(), | ||
cache_mode: CacheMode::Full, | ||
uin2uid: Some(DashMap::new()), | ||
uid2uin: Some(DashMap::new()), | ||
cached_friends: Some(DashMap::new()), | ||
cached_group_members: Some(DashMap::new()), | ||
} | ||
} | ||
|
||
fn half() -> Self { | ||
Self { | ||
cache_mode: CacheMode::Half, | ||
uin2uid: None, | ||
uid2uin: None, | ||
cached_friends: Some(DashMap::new()), | ||
cached_group_members: Some(DashMap::new()), | ||
} | ||
} | ||
|
||
fn none() -> Self { | ||
Self { | ||
cache_mode: CacheMode::None, | ||
uin2uid: None, | ||
uid2uin: None, | ||
cached_friends: None, | ||
cached_group_members: None, | ||
} | ||
} | ||
|
||
pub(crate) fn insert_uin_uid(&self, uin: u32, uid: String) { | ||
// SAFETY: we can ensure that the DashMap is not None | ||
self.uin2uid.as_ref().unwrap().insert(uin, uid.clone()); | ||
self.uid2uin.as_ref().unwrap().insert(uid, uin); | ||
} | ||
} |
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 @@ | ||
pub mod fetch_group_requests; |
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,15 @@ | ||
#[derive(Debug, Default)] | ||
pub struct FetchGroupRequests { | ||
pub group_uin: u32, | ||
pub invitor_member_uid: Option<String>, | ||
pub invitor_member_card: Option<String>, | ||
pub target_member_uid: String, | ||
pub target_member_card: String, | ||
pub operator_uid: Option<String>, | ||
pub operator_name: Option<String>, | ||
pub sequence: u64, | ||
pub state: u32, | ||
pub event_type: u32, | ||
pub comment: Option<String>, | ||
pub is_filtered: bool, | ||
} |
Oops, something went wrong.