Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: impl some pack_element #22

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion mania/src/core/protos/service/oidb/NTV2RichMediaReq.proto
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,20 @@ message MsgInfoBody {
VideoInfo Video = 3;
AudioInfo Audio = 4;
bool FileExist = 5;
bytes HashSum = 6;
HashSum HashSum = 6;
}

message HashSum {
C2cSource BytesPbReserveC2c = 201;
optional TroopSource TroopSource = 202;
}

message C2cSource {
string FriendUid = 2;
}

message TroopSource {
uint32 GroupUin = 1;
}

message VideoInfo {
Expand Down
16 changes: 15 additions & 1 deletion mania/src/message/entity/forward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,21 @@ impl Display for ForwardEntity {

impl MessageEntity for ForwardEntity {
fn pack_element(&self) -> Vec<Elem> {
todo!()
let pb_reserve = dda!(Preserve {
message_id: self.message_id.0,
sender_uid: self.uid.clone(),
})
.encode_to_vec();
vec![dda!(Elem {
src_msg: Some(dda!(SrcMsg {
orig_seqs: vec![self.message_id.0 as u32],
sender_uin: self.target_uin as u64,
time: Some(self.time.timestamp() as i32),
elems: self.elems.clone(),
pb_reserve: Some(pb_reserve),
to_uin: Some(0)
}))
})]
}

fn unpack_element(elem: &Elem) -> Option<Self> {
Expand Down
35 changes: 34 additions & 1 deletion mania/src/message/entity/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,40 @@ impl Display for ImageEntity {

impl MessageEntity for ImageEntity {
fn pack_element(&self) -> Vec<Elem> {
todo!()
let is_group = self.msg_info.as_ref().is_some_and(|info| {
!info.msg_info_body.is_empty()
&& info.msg_info_body[0]
.hash_sum
.as_ref()
.is_some_and(|hash_sum| {
hash_sum
.troop_source
.as_ref()
.is_some_and(|troop| troop.group_uin != 0)
})
});
let common = self.msg_info.as_ref().map_or_else(
|| {
MsgInfo {
..Default::default()
}
.encode_to_vec()
},
|msg_info| msg_info.encode_to_vec(),
);
vec![
dda!(Elem {
custom_face: Some(self.custom_face.clone()),
not_online_image: Some(self.not_online_image.clone()),
}),
dda!(Elem {
common_elem: Some(CommonElem {
service_type: 48,
pb_elem: common,
business_type: if is_group { 20 } else { 10 }
})
}),
]
}

fn unpack_element(elem: &Elem) -> Option<Self> {
Expand Down
9 changes: 6 additions & 3 deletions mania/src/message/entity/json.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::prelude::*;
use std::iter::once;

#[derive(Default)]
pub struct JsonEntity {
Expand All @@ -20,8 +21,6 @@ impl Display for JsonEntity {

impl MessageEntity for JsonEntity {
fn pack_element(&self) -> Vec<Elem> {
let mut template1 = zlib::compress(self.json.as_bytes());
template1.push(0x01);
vec![
dda!(Elem {
text: Some(dda!(Text {
Expand All @@ -31,7 +30,11 @@ impl MessageEntity for JsonEntity {
dda!(Elem {
rich_msg: Some(dda!(RichMsg {
service_id: Some(1),
template1: Some(template1),
template1: Some(
once(0x01)
.chain(zlib::compress(self.json.as_bytes()))
.collect()
),
}),),
}),
]
Expand Down
9 changes: 8 additions & 1 deletion mania/src/message/entity/light_app.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::prelude::*;
use serde_json::Value;
use std::fmt::Debug;
use std::iter::once;

#[derive(Default)]
pub struct LightAppEntity {
Expand All @@ -22,7 +23,13 @@ impl Display for LightAppEntity {

impl MessageEntity for LightAppEntity {
fn pack_element(&self) -> Vec<Elem> {
todo!()
vec![dda!(Elem {
light_app_elem: Some(dda!(LightAppElem {
data: once(0x01)
.chain(zlib::compress(self.payload.as_bytes()))
.collect(),
})),
})]
}

fn unpack_element(elem: &Elem) -> Option<Self> {
Expand Down
14 changes: 13 additions & 1 deletion mania/src/message/entity/mention.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,19 @@ impl Display for MentionEntity {

impl MessageEntity for MentionEntity {
fn pack_element(&self) -> Vec<Elem> {
todo!()
let pb_reserve = MentionExtra {
r#type: Some(if self.uin == 0 { 1 } else { 2 }),
uin: Some(self.uin),
field5: Some(0),
uid: Some(self.uid.clone()),
}
.encode_to_vec();
vec![dda!(Elem {
text: Some(dda!(Text {
str: self.name.clone(),
pb_reserve: Some(pb_reserve),
}))
})]
}

fn unpack_element(elem: &Elem) -> Option<Self> {
Expand Down
17 changes: 16 additions & 1 deletion mania/src/message/entity/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,22 @@ impl Display for RecordEntity {

impl MessageEntity for RecordEntity {
fn pack_element(&self) -> Vec<Elem> {
todo!()
let common = self.msg_info.as_ref().map_or_else(
|| {
MsgInfo {
..Default::default()
}
.encode_to_vec()
},
|msg_info| msg_info.encode_to_vec(),
);
vec![dda!(Elem {
common_elem: Some(CommonElem {
service_type: 48,
pb_elem: common,
business_type: 22,
}),
})]
}

fn unpack_element(elem: &Elem) -> Option<Self> {
Expand Down
17 changes: 16 additions & 1 deletion mania/src/message/entity/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,22 @@ impl Display for VideoEntity {

impl MessageEntity for VideoEntity {
fn pack_element(&self) -> Vec<Elem> {
todo!()
let common = self.msg_info.as_ref().map_or_else(
|| {
MsgInfo {
..Default::default()
}
.encode_to_vec()
},
|msg_info| msg_info.encode_to_vec(),
);
vec![dda!(Elem {
common_elem: Some(CommonElem {
service_type: 48,
pb_elem: common,
business_type: 21,
}),
})]
}

fn unpack_element(elem: &Elem) -> Option<Self> {
Expand Down
12 changes: 11 additions & 1 deletion mania/src/message/entity/xml.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::prelude::*;
use std::iter::once;

#[derive(Default)]
pub struct XmlEntity {
Expand All @@ -20,7 +21,16 @@ impl Display for XmlEntity {

impl MessageEntity for XmlEntity {
fn pack_element(&self) -> Vec<Elem> {
todo!()
vec![dda!(Elem {
rich_msg: Some(dda!(RichMsg {
service_id: Some(self.service_id),
template1: Some(
once(0x01)
.chain(zlib::compress(self.xml.as_bytes()))
.collect(),
),
})),
})]
}

fn unpack_element(elem: &Elem) -> Option<Self> {
Expand Down
Loading