diff options
| author | Lakelezz <[email protected]> | 2018-10-30 15:10:10 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2018-10-30 15:10:10 +0100 |
| commit | 867a744720c46c0b04a2d34c2119ad366aa440ef (patch) | |
| tree | ab9fd0708f2c4bafe3c554991bb2509c01f898ae /src/model | |
| parent | Fix cache write lock timer (#423) (diff) | |
| download | serenity-867a744720c46c0b04a2d34c2119ad366aa440ef.tar.xz serenity-867a744720c46c0b04a2d34c2119ad366aa440ef.zip | |
Add Function to neutralise Mentions (#414)
Diffstat (limited to 'src/model')
| -rw-r--r-- | src/model/channel/channel_id.rs | 14 | ||||
| -rw-r--r-- | src/model/guild/role.rs | 9 |
2 files changed, 19 insertions, 4 deletions
diff --git a/src/model/channel/channel_id.rs b/src/model/channel/channel_id.rs index a897002..3f52055 100644 --- a/src/model/channel/channel_id.rs +++ b/src/model/channel/channel_id.rs @@ -14,6 +14,8 @@ use builder::{ }; #[cfg(all(feature = "cache", feature = "model"))] use CACHE; +#[cfg(all(feature = "cache", feature = "model"))] +use Cache; #[cfg(feature = "model")] use http::{self, AttachmentType}; #[cfg(feature = "model")] @@ -293,7 +295,17 @@ impl ChannelId { /// [`Channel`]: ../channel/enum.Channel.html #[cfg(feature = "cache")] #[inline] - pub fn to_channel_cached(self) -> Option<Channel> { CACHE.read().channel(self) } + pub fn to_channel_cached(self) -> Option<Channel> { + self._to_channel_cached(&CACHE) + } + + /// To allow testing pass their own cache instead of using the globale one. + #[cfg(feature = "cache")] + #[inline] + pub(crate) fn _to_channel_cached(self, cache: &RwLock<Cache>) -> Option<Channel> { + cache.read().channel(self) + } + /// Search the cache for the channel. If it can't be found, the channel is /// requested over REST. diff --git a/src/model/guild/role.rs b/src/model/guild/role.rs index ac969c0..53239a8 100644 --- a/src/model/guild/role.rs +++ b/src/model/guild/role.rs @@ -6,7 +6,7 @@ use builder::EditRole; #[cfg(all(feature = "cache", feature = "model"))] use internal::prelude::*; #[cfg(all(feature = "cache", feature = "model"))] -use {CACHE, http}; +use {CACHE, Cache, http}; #[cfg(all(feature = "cache", feature = "model", feature = "utils"))] use std::str::FromStr; @@ -182,9 +182,12 @@ impl RoleId { /// [`Role`]: ../guild/struct.Role.html #[cfg(feature = "cache")] pub fn to_role_cached(self) -> Option<Role> { - let cache = CACHE.read(); + self._to_role_cached(&CACHE) + } - for guild in cache.guilds.values() { + #[cfg(feature = "cache")] + pub(crate) fn _to_role_cached(self, cache: &RwLock<Cache>) -> Option<Role> { + for guild in cache.read().guilds.values() { let guild = guild.read(); if !guild.roles.contains_key(&self) { |