Skip to content

Commit

Permalink
chore: optimize logic
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueGlassBlock committed Apr 12, 2023
1 parent 7b97182 commit b8801c3
Showing 1 changed file with 23 additions and 28 deletions.
51 changes: 23 additions & 28 deletions ricq-core/src/command/multi_msg/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{collections::HashMap, io::Write};

use bytes::{Buf, Bytes};

use crate::{msg::MessageChain, pb, RQError, RQResult};
use crate::{pb, RQError, RQResult};
use flate2::write::GzDecoder;
use prost::Message;

Expand Down Expand Up @@ -51,7 +51,7 @@ impl super::super::super::Engine {
pb::msg::PbMultiMsgTransmit::decode(Bytes::from(decoder.finish()?))?
.pb_item_list
.into_iter()
.map(|item| (item.file_name.clone().unwrap_or_default(), item))
.map(|item| (item.file_name().to_owned(), item))
.collect(),
)
}
Expand All @@ -78,38 +78,33 @@ impl super::super::super::Engine {
} else {
sender_name = head.from_nick().to_string();
}
let elements = MessageChain::from(
msg.body
.unwrap_or_default()
.rich_text
.unwrap_or_default()
.elems,
);
for elem in elements.0.iter() {
match elem {
crate::pb::msg::elem::Elem::RichMsg(rich) => {
if rich.service_id() == 35 {
let rich = crate::msg::elem::RichMsg::from(rich.clone());
let res_id = find_res_id(&rich.template1)
.ok_or_else(|| RQError::EmptyField("m_resid"))?;
let sub_nodes = self.decode_forward_message(res_id, items)?;
nodes.push(ForwardMessage::Forward(ForwardNode {
sender_id: head.from_uin(),
time: head.msg_time(),
sender_name,
nodes: sub_nodes,
}));
continue 'iter_main;
}
}
_ => {}
let elements = msg
.body
.unwrap_or_default()
.rich_text
.unwrap_or_default()
.elems;
for elem in elements.iter().filter_map(|e| e.elem.as_ref()) {
if let crate::pb::msg::elem::Elem::RichMsg(ref elem) = elem
&& elem.service_id() == 35 {
let rich = crate::msg::elem::RichMsg::from(elem.clone());
let res_id = find_res_id(&rich.template1)
.ok_or_else(|| RQError::EmptyField("m_resid"))?;
let sub_nodes = self.decode_forward_message(res_id, items)?;
nodes.push(ForwardMessage::Forward(ForwardNode {
sender_id: head.from_uin(),
time: head.msg_time(),
sender_name,
nodes: sub_nodes,
}));
continue 'iter_main;
}
}
nodes.push(ForwardMessage::Message(MessageNode {
sender_id: head.from_uin(),
time: head.msg_time(),
sender_name,
elements,
elements: elements.into(),
}))
}
Ok(nodes)
Expand Down

0 comments on commit b8801c3

Please sign in to comment.