1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use std::fmt;
use crate::command::common::PbToBytes;
use crate::msg::elem::{FriendImage, GroupImage};
use crate::pb::msg;
#[derive(Debug, Clone)]
pub enum FlashImage {
FriendImage(FriendImage),
GroupImage(GroupImage),
}
impl FlashImage {
pub fn url(&self) -> String {
match self {
FlashImage::FriendImage(i) => i.url(),
FlashImage::GroupImage(i) => i.url(),
}
}
}
impl From<FlashImage> for Vec<msg::elem::Elem> {
fn from(e: FlashImage) -> Self {
let flash = {
match e {
FlashImage::FriendImage(image) => msg::MsgElemInfoServtype3 {
flash_c2c_pic: Some(image.into()),
..Default::default()
},
FlashImage::GroupImage(image) => msg::MsgElemInfoServtype3 {
flash_troop_pic: Some(image.into()),
..Default::default()
},
}
}
.to_bytes();
vec![
msg::elem::Elem::CommonElem(msg::CommonElem {
service_type: Some(3),
pb_elem: Some(flash.to_vec()),
..Default::default()
}),
msg::elem::Elem::Text(msg::Text {
str: Some("[闪照]请使用新版手机QQ查看闪照。".to_owned()),
..Default::default()
}),
]
}
}
impl From<FriendImage> for FlashImage {
fn from(e: FriendImage) -> Self {
Self::FriendImage(e)
}
}
impl From<GroupImage> for FlashImage {
fn from(e: GroupImage) -> Self {
Self::GroupImage(e)
}
}
impl fmt::Display for FlashImage {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
FlashImage::FriendImage(i) => {
write!(f, "[FlashImage(friend): {}]", i.url())
}
FlashImage::GroupImage(i) => {
write!(f, "[FlashImage(group): {}]", i.url())
}
}
}
}