Skip to content

Commit

Permalink
Remove outer match
Browse files Browse the repository at this point in the history
  • Loading branch information
Desiders committed Apr 28, 2024
1 parent d37f7d1 commit 36caecc
Showing 1 changed file with 41 additions and 108 deletions.
149 changes: 41 additions & 108 deletions telers/src/types/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,9 @@ impl Kind {
| Kind::EditedChannelPost(message) => message.text(),
Kind::InlineQuery(InlineQuery { query, .. })
| Kind::ChosenInlineResult(ChosenInlineResult { query, .. }) => Some(query),
Kind::CallbackQuery(CallbackQuery { data, .. }) => match data {
Some(data) => Some(data),
None => None,
},
Kind::CallbackQuery(CallbackQuery {
data: Some(data), ..
}) => Some(data),
_ => None,
}
}
Expand All @@ -104,17 +103,11 @@ impl Kind {
| Kind::BusinessMessage(message)
| Kind::EditedBusinessMessage(message)
| Kind::ChannelPost(message)
| Kind::EditedChannelPost(message) => message.caption(),
Kind::CallbackQuery(CallbackQuery { message, .. }) => {
let Some(message) = message else {
return None;
};

match message {
MaybeInaccessibleMessage::Message(message) => message.caption(),
MaybeInaccessibleMessage::InaccessibleMessage(_) => None,
}
}
| Kind::EditedChannelPost(message)
| Kind::CallbackQuery(CallbackQuery {
message: Some(MaybeInaccessibleMessage::Message(message)),
..
}) => message.caption(),
_ => None,
}
}
Expand Down Expand Up @@ -142,19 +135,14 @@ impl Kind {
| Kind::MyChatMember(ChatMemberUpdated { from, .. })
| Kind::ChatMember(ChatMemberUpdated { from, .. })
| Kind::ChatJoinRequest(ChatJoinRequest { from, .. }) => Some(from),
Kind::BusinessConnection(BusinessConnection { user, .. }) => Some(user),
Kind::BusinessConnection(BusinessConnection { user, .. })
| Kind::ChatBoost(ChatBoostUpdated {
boost: ChatBoostSource::Premium(ChatBoostSourcePremium { user }),
..
}) => Some(user),
Kind::PollAnswer(PollAnswer { user, .. })
| Kind::MessageReaction(MessageReactionUpdated { user, .. }) => user.as_ref(),
Kind::ChatBoost(ChatBoostUpdated { boost, .. }) => match boost {
ChatBoostSource::Premium(ChatBoostSourcePremium { user }) => Some(user),
ChatBoostSource::GiftCode(_) | ChatBoostSource::Giveaway(_) => None,
},
Kind::Poll(_)
| Kind::MessageReactionCount(_)
| Kind::RemovedChatBoost(_)
| Kind::DeletedBusinessMessages(_)
| Kind::ChannelPost(_)
| Kind::EditedChannelPost(_) => None,
_ => None,
}
}

Expand All @@ -175,19 +163,15 @@ impl Kind {
| Kind::EditedBusinessMessage(message)
| Kind::ChannelPost(message)
| Kind::EditedChannelPost(message) => Some(message.chat()),
Kind::CallbackQuery(CallbackQuery { message, .. }) => {
let Some(message) = message else {
return None;
};

match message {
MaybeInaccessibleMessage::Message(message) => Some(message.chat()),
MaybeInaccessibleMessage::InaccessibleMessage(InaccessibleMessage {
chat,
..
}) => Some(chat),
}
}
Kind::CallbackQuery(CallbackQuery {
message: Some(message),
..
}) => match message {
MaybeInaccessibleMessage::Message(message) => Some(message.chat()),
MaybeInaccessibleMessage::InaccessibleMessage(InaccessibleMessage {
chat, ..
}) => Some(chat),
},
Kind::MyChatMember(ChatMemberUpdated { chat, .. })
| Kind::ChatMember(ChatMemberUpdated { chat, .. })
| Kind::ChatJoinRequest(ChatJoinRequest { chat, .. })
Expand All @@ -197,12 +181,7 @@ impl Kind {
| Kind::DeletedBusinessMessages(BusinessMessagesDeleted { chat, .. }) => Some(chat),
Kind::PollAnswer(PollAnswer { voter_chat, .. }) => voter_chat.as_ref(),
Kind::MessageReaction(MessageReactionUpdated { actor_chat, .. }) => actor_chat.as_ref(),
Kind::InlineQuery(_)
| Kind::ChosenInlineResult(_)
| Kind::ShippingQuery(_)
| Kind::PreCheckoutQuery(_)
| Kind::Poll(_)
| Kind::BusinessConnection(_) => None,
_ => None,
}
}

Expand All @@ -227,32 +206,12 @@ impl Kind {
| Kind::BusinessMessage(message)
| Kind::EditedBusinessMessage(message)
| Kind::ChannelPost(message)
| Kind::EditedChannelPost(message) => message.sender_chat(),
Kind::CallbackQuery(CallbackQuery { message, .. }) => {
let Some(message) = message else {
return None;
};

match message {
MaybeInaccessibleMessage::Message(message) => message.sender_chat(),
MaybeInaccessibleMessage::InaccessibleMessage(_) => None,
}
}
Kind::InlineQuery(_)
| Kind::ChosenInlineResult(_)
| Kind::ShippingQuery(_)
| Kind::PreCheckoutQuery(_)
| Kind::PollAnswer(_)
| Kind::MyChatMember(_)
| Kind::ChatMember(_)
| Kind::ChatJoinRequest(_)
| Kind::Poll(_)
| Kind::MessageReaction(_)
| Kind::MessageReactionCount(_)
| Kind::ChatBoost(_)
| Kind::RemovedChatBoost(_)
| Kind::BusinessConnection(_)
| Kind::DeletedBusinessMessages(_) => None,
| Kind::EditedChannelPost(message)
| Kind::CallbackQuery(CallbackQuery {
message: Some(MaybeInaccessibleMessage::Message(message)),
..
}) => message.sender_chat(),
_ => None,
}
}

Expand All @@ -273,32 +232,12 @@ impl Kind {
| Kind::BusinessMessage(message)
| Kind::EditedBusinessMessage(message)
| Kind::ChannelPost(message)
| Kind::EditedChannelPost(message) => message.thread_id(),
Kind::CallbackQuery(CallbackQuery { message, .. }) => {
let Some(message) = message else {
return None;
};

match message {
MaybeInaccessibleMessage::Message(message) => message.thread_id(),
MaybeInaccessibleMessage::InaccessibleMessage(_) => None,
}
}
Kind::InlineQuery(_)
| Kind::ChosenInlineResult(_)
| Kind::ShippingQuery(_)
| Kind::PreCheckoutQuery(_)
| Kind::PollAnswer(_)
| Kind::MyChatMember(_)
| Kind::ChatMember(_)
| Kind::ChatJoinRequest(_)
| Kind::Poll(_)
| Kind::MessageReaction(_)
| Kind::MessageReactionCount(_)
| Kind::ChatBoost(_)
| Kind::RemovedChatBoost(_)
| Kind::BusinessConnection(_)
| Kind::DeletedBusinessMessages(_) => None,
| Kind::EditedChannelPost(message)
| Kind::CallbackQuery(CallbackQuery {
message: Some(MaybeInaccessibleMessage::Message(message)),
..
}) => message.thread_id(),
_ => None,
}
}

Expand Down Expand Up @@ -326,17 +265,11 @@ impl Kind {
| Kind::BusinessMessage(message)
| Kind::EditedBusinessMessage(message)
| Kind::ChannelPost(message)
| Kind::EditedChannelPost(message) => Some(message),
Kind::CallbackQuery(CallbackQuery { message, .. }) => {
let Some(message) = message else {
return None;
};

match message {
MaybeInaccessibleMessage::Message(message) => Some(message),
MaybeInaccessibleMessage::InaccessibleMessage(_) => None,
}
}
| Kind::EditedChannelPost(message)
| Kind::CallbackQuery(CallbackQuery {
message: Some(MaybeInaccessibleMessage::Message(message)),
..
}) => Some(message),
_ => None,
}
}
Expand Down

0 comments on commit 36caecc

Please sign in to comment.