aboutsummaryrefslogtreecommitdiff
path: root/src/model/channel
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2017-09-18 17:48:52 -0700
committerZeyla Hellyer <[email protected]>2017-09-18 17:48:52 -0700
commitdae2cb77b407044f44a7a2790d93efba3891854e (patch)
treebef263c4490536cf8b56e988e71dd1aa43bc2696 /src/model/channel
parentFix compiles of a variety of feature combinations (diff)
downloadserenity-dae2cb77b407044f44a7a2790d93efba3891854e.tar.xz
serenity-dae2cb77b407044f44a7a2790d93efba3891854e.zip
Apply rustfmt
Diffstat (limited to 'src/model/channel')
-rw-r--r--src/model/channel/attachment.rs5
-rw-r--r--src/model/channel/channel_category.rs5
-rw-r--r--src/model/channel/channel_id.rs11
-rw-r--r--src/model/channel/group.rs17
-rw-r--r--src/model/channel/guild_channel.rs13
-rw-r--r--src/model/channel/message.rs29
-rw-r--r--src/model/channel/mod.rs53
-rw-r--r--src/model/channel/private_channel.rs10
-rw-r--r--src/model/channel/reaction.rs3
9 files changed, 50 insertions, 96 deletions
diff --git a/src/model/channel/attachment.rs b/src/model/channel/attachment.rs
index 079f4a9..8a3cbfa 100644
--- a/src/model/channel/attachment.rs
+++ b/src/model/channel/attachment.rs
@@ -32,9 +32,8 @@ impl Attachment {
/// If this attachment is an image, then a tuple of the width and height
/// in pixels is returned.
pub fn dimensions(&self) -> Option<(u64, u64)> {
- self.width.and_then(
- |width| self.height.map(|height| (width, height)),
- )
+ self.width
+ .and_then(|width| self.height.map(|height| (width, height)))
}
/// Downloads the attachment, returning back a vector of bytes.
diff --git a/src/model/channel/channel_category.rs b/src/model/channel/channel_category.rs
index 119f1f1..c88f7fa 100644
--- a/src/model/channel/channel_category.rs
+++ b/src/model/channel/channel_category.rs
@@ -94,10 +94,7 @@ impl ChannelCategory {
}
let mut map = Map::new();
- map.insert(
- "name".to_owned(),
- Value::String(self.name.clone()),
- );
+ map.insert("name".to_owned(), Value::String(self.name.clone()));
map.insert(
"position".to_owned(),
Value::Number(Number::from(self.position)),
diff --git a/src/model/channel/channel_id.rs b/src/model/channel/channel_id.rs
index a8e16ef..e5dad79 100644
--- a/src/model/channel/channel_id.rs
+++ b/src/model/channel/channel_id.rs
@@ -124,9 +124,7 @@ impl ChannelId {
.map(|message_id| message_id.0)
.collect::<Vec<u64>>();
- let map = json!({
- "messages": ids
- });
+ let map = json!({ "messages": ids });
http::delete_messages(self.0, &map)
}
@@ -256,13 +254,12 @@ impl ChannelId {
/// [Read Message History]: permissions/constant.READ_MESSAGE_HISTORY.html
#[inline]
pub fn message<M: Into<MessageId>>(&self, message_id: M) -> Result<Message> {
- http::get_message(self.0, message_id.into().0).map(
- |mut msg| {
+ http::get_message(self.0, message_id.into().0)
+ .map(|mut msg| {
msg.transform_content();
msg
- },
- )
+ })
}
/// Gets messages from the channel.
diff --git a/src/model/channel/group.rs b/src/model/channel/group.rs
index 438437c..418ce3a 100644
--- a/src/model/channel/group.rs
+++ b/src/model/channel/group.rs
@@ -5,7 +5,7 @@ use model::*;
use builder::{CreateMessage, GetMessages};
#[cfg(feature = "model")]
use http::{self, AttachmentType};
-#[cfg(feature="model")]
+#[cfg(feature = "model")]
use internal::RwLockExt;
#[cfg(feature = "model")]
use std::borrow::Cow;
@@ -125,11 +125,8 @@ impl Group {
reaction_type: R)
-> Result<()>
where M: Into<MessageId>, R: Into<ReactionType> {
- self.channel_id.delete_reaction(
- message_id,
- user_id,
- reaction_type,
- )
+ self.channel_id
+ .delete_reaction(message_id, user_id, reaction_type)
}
/// Edits a [`Message`] in the channel given its Id.
@@ -247,12 +244,8 @@ impl Group {
after: Option<U>)
-> Result<Vec<User>>
where M: Into<MessageId>, R: Into<ReactionType>, U: Into<UserId> {
- self.channel_id.reaction_users(
- message_id,
- reaction_type,
- limit,
- after,
- )
+ self.channel_id
+ .reaction_users(message_id, reaction_type, limit, after)
}
/// Removes a recipient from the group. If the recipient is already not in
diff --git a/src/model/channel/guild_channel.rs b/src/model/channel/guild_channel.rs
index e75ba60..20e5d41 100644
--- a/src/model/channel/guild_channel.rs
+++ b/src/model/channel/guild_channel.rs
@@ -313,10 +313,7 @@ impl GuildChannel {
}
let mut map = Map::new();
- map.insert(
- "name".to_owned(),
- Value::String(self.name.clone()),
- );
+ map.insert("name".to_owned(), Value::String(self.name.clone()));
map.insert(
"position".to_owned(),
Value::Number(Number::from(self.position)),
@@ -545,12 +542,8 @@ impl GuildChannel {
after: Option<U>)
-> Result<Vec<User>>
where M: Into<MessageId>, R: Into<ReactionType>, U: Into<UserId> {
- self.id.reaction_users(
- message_id,
- reaction_type,
- limit,
- after,
- )
+ self.id
+ .reaction_users(message_id, reaction_type, limit, after)
}
/// Sends a message with just the given message content in the channel.
diff --git a/src/model/channel/message.rs b/src/model/channel/message.rs
index 1edc9a1..d36d290 100644
--- a/src/model/channel/message.rs
+++ b/src/model/channel/message.rs
@@ -292,10 +292,9 @@ impl Message {
}
// And finally replace everyone and here mentions.
- result.replace("@everyone", "@\u{200B}everyone").replace(
- "@here",
- "@\u{200B}here",
- )
+ result
+ .replace("@everyone", "@\u{200B}everyone")
+ .replace("@here", "@\u{200B}here")
}
/// Gets the list of [`User`]s who have reacted to a [`Message`] with a
@@ -321,12 +320,8 @@ impl Message {
after: Option<U>)
-> Result<Vec<User>>
where R: Into<ReactionType>, U: Into<UserId> {
- self.channel_id.reaction_users(
- self.id,
- reaction_type,
- limit,
- after,
- )
+ self.channel_id
+ .reaction_users(self.id, reaction_type, limit, after)
}
/// Returns the associated `Guild` for the message if one is in the cache.
@@ -339,9 +334,8 @@ impl Message {
/// [`guild_id`]: #method.guild_id
#[cfg(feature = "cache")]
pub fn guild(&self) -> Option<Arc<RwLock<Guild>>> {
- self.guild_id().and_then(|guild_id| {
- CACHE.read().unwrap().guild(guild_id)
- })
+ self.guild_id()
+ .and_then(|guild_id| CACHE.read().unwrap().guild(guild_id))
}
/// Retrieves the Id of the guild that the message was sent in, if sent in
@@ -361,8 +355,7 @@ impl Message {
#[cfg(feature = "cache")]
pub fn is_private(&self) -> bool {
match CACHE.read().unwrap().channel(self.channel_id) {
- Some(Channel::Group(_)) |
- Some(Channel::Private(_)) => true,
+ Some(Channel::Group(_)) | Some(Channel::Private(_)) => true,
_ => false,
}
}
@@ -379,7 +372,11 @@ impl Message {
let count = content.chars().count() as i64;
let diff = count - (constants::MESSAGE_CODE_LIMIT as i64);
- if diff > 0 { Some(diff as u64) } else { None }
+ if diff > 0 {
+ Some(diff as u64)
+ } else {
+ None
+ }
}
/// Pins this message to its channel.
diff --git a/src/model/channel/mod.rs b/src/model/channel/mod.rs
index 824aea7..33912f1 100644
--- a/src/model/channel/mod.rs
+++ b/src/model/channel/mod.rs
@@ -130,11 +130,8 @@ impl Channel {
reaction_type: R)
-> Result<()>
where M: Into<MessageId>, R: Into<ReactionType> {
- self.id().delete_reaction(
- message_id,
- user_id,
- reaction_type,
- )
+ self.id()
+ .delete_reaction(message_id, user_id, reaction_type)
}
/// Edits a [`Message`] in the channel given its Id.
@@ -237,12 +234,8 @@ impl Channel {
after: Option<U>)
-> Result<Vec<User>>
where M: Into<MessageId>, R: Into<ReactionType>, U: Into<UserId> {
- self.id().reaction_users(
- message_id,
- reaction_type,
- limit,
- after,
- )
+ self.id()
+ .reaction_users(message_id, reaction_type, limit, after)
}
/// Retrieves the Id of the inner [`Group`], [`GuildChannel`], or
@@ -348,26 +341,18 @@ impl<'de> Deserialize<'de> for Channel {
};
match kind {
- 0 | 2 => {
- serde_json::from_value::<GuildChannel>(Value::Object(v))
- .map(|x| Channel::Guild(Arc::new(RwLock::new(x))))
- .map_err(DeError::custom)
- },
- 1 => {
- serde_json::from_value::<PrivateChannel>(Value::Object(v))
- .map(|x| Channel::Private(Arc::new(RwLock::new(x))))
- .map_err(DeError::custom)
- },
- 3 => {
- serde_json::from_value::<Group>(Value::Object(v))
- .map(|x| Channel::Group(Arc::new(RwLock::new(x))))
- .map_err(DeError::custom)
- },
- 4 => {
- serde_json::from_value::<ChannelCategory>(Value::Object(v))
- .map(|x| Channel::Category(Arc::new(RwLock::new(x))))
- .map_err(DeError::custom)
- },
+ 0 | 2 => serde_json::from_value::<GuildChannel>(Value::Object(v))
+ .map(|x| Channel::Guild(Arc::new(RwLock::new(x))))
+ .map_err(DeError::custom),
+ 1 => serde_json::from_value::<PrivateChannel>(Value::Object(v))
+ .map(|x| Channel::Private(Arc::new(RwLock::new(x))))
+ .map_err(DeError::custom),
+ 3 => serde_json::from_value::<Group>(Value::Object(v))
+ .map(|x| Channel::Group(Arc::new(RwLock::new(x))))
+ .map_err(DeError::custom),
+ 4 => serde_json::from_value::<ChannelCategory>(Value::Object(v))
+ .map(|x| Channel::Category(Arc::new(RwLock::new(x))))
+ .map_err(DeError::custom),
_ => Err(DeError::custom("Unknown channel type")),
}
}
@@ -445,10 +430,8 @@ impl ChannelType {
struct PermissionOverwriteData {
allow: Permissions,
deny: Permissions,
- #[serde(deserialize_with = "deserialize_u64")]
- id: u64,
- #[serde(rename = "type")]
- kind: String,
+ #[serde(deserialize_with = "deserialize_u64")] id: u64,
+ #[serde(rename = "type")] kind: String,
}
/// A channel-specific permission overwrite for a member or role.
diff --git a/src/model/channel/private_channel.rs b/src/model/channel/private_channel.rs
index a51ba09..dab3bc5 100644
--- a/src/model/channel/private_channel.rs
+++ b/src/model/channel/private_channel.rs
@@ -7,7 +7,7 @@ use model::*;
use builder::{CreateMessage, GetMessages};
#[cfg(feature = "model")]
use http::AttachmentType;
-#[cfg(feature="model")]
+#[cfg(feature = "model")]
use internal::RwLockExt;
/// A Direct Message text channel with another user.
@@ -193,12 +193,8 @@ impl PrivateChannel {
after: Option<U>)
-> Result<Vec<User>>
where M: Into<MessageId>, R: Into<ReactionType>, U: Into<UserId> {
- self.id.reaction_users(
- message_id,
- reaction_type,
- limit,
- after,
- )
+ self.id
+ .reaction_users(message_id, reaction_type, limit, after)
}
/// Pins a [`Message`] to the channel.
diff --git a/src/model/channel/reaction.rs b/src/model/channel/reaction.rs
index 44e1db6..605ac7f 100644
--- a/src/model/channel/reaction.rs
+++ b/src/model/channel/reaction.rs
@@ -46,8 +46,7 @@ impl Reaction {
/// [Manage Messages]: permissions/constant.MANAGE_MESSAGES.html
/// [permissions]: permissions
pub fn delete(&self) -> Result<()> {
- let user_id =
- feature_cache! {
+ let user_id = feature_cache! {
{
let user = if self.user_id == CACHE.read().unwrap().user.id {
None