Skip to content

Commit 59dff59

Browse files
committed
[Telegram][QQ] Recursively append reposts to message
1 parent e686051 commit 59dff59

File tree

2 files changed

+39
-20
lines changed

2 files changed

+39
-20
lines changed

src/platform/qq/notify/mod.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::{
1212
platform::{PlatformMetadata, PlatformTrait},
1313
source::{
1414
LiveStatus, LiveStatusKind, Notification, NotificationKind, Post, PostAttachment, PostsRef,
15-
StatusSource,
15+
RepostFrom, StatusSource,
1616
},
1717
};
1818

@@ -301,10 +301,20 @@ impl Notifier {
301301
builder.ref_text("\n\n");
302302
}
303303

304-
builder.ref_text("🔁 ");
305-
builder.ref_text(format!("{}: ", repost_from.post.user.nickname));
306-
append_media(&mut builder, repost_from.post.attachments(false));
307-
builder.ref_text(repost_from.post.content.fallback());
304+
fn append_reposts_rec(
305+
builder: &mut lagrange::MessageBuilder,
306+
repost_from: &RepostFrom,
307+
) {
308+
builder.ref_text("🔁 ");
309+
builder.ref_text(format!("{}: ", repost_from.post.user.nickname));
310+
append_media(builder, repost_from.post.attachments(false));
311+
builder.ref_text(repost_from.post.content.fallback());
312+
if let Some(repost_from) = &repost_from.post.repost_from {
313+
builder.ref_text("\n\n");
314+
append_reposts_rec(builder, repost_from);
315+
}
316+
}
317+
append_reposts_rec(&mut builder, repost_from);
308318
}
309319
None => {
310320
builder.ref_text(format_if!(

src/platform/telegram/notify/mod.rs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ use crate::{
2424
platform::{PlatformMetadata, PlatformTrait},
2525
source::{
2626
DocumentRef, FileRef, LiveStatus, LiveStatusKind, Notification, NotificationKind,
27-
PlaybackFormat, PlaybackRef, Post, PostAttachment, PostUrl, PostsRef, StatusSource,
27+
PlaybackFormat, PlaybackRef, Post, PostAttachment, PostUrl, PostsRef, RepostFrom,
28+
StatusSource,
2829
},
2930
};
3031

@@ -436,21 +437,29 @@ impl Notifier {
436437
text.push_plain("\n");
437438
}
438439

439-
text.push_quote(|text| {
440-
text.push_plain("🔁 ");
441-
442-
// In order for Telegram to display more relevant information about the
443-
// post, we don't use `profile_url` here
444-
//
445-
// &repost_from.user.profile_url,
446-
if let PostUrl::Clickable(url) = &repost_from.post.urls_recursive().major() {
447-
text.push_link(&repost_from.post.user.nickname, &url.url);
448-
} else {
449-
text.push_plain(&repost_from.post.user.nickname);
440+
fn push_reposts_rec<'a>(text: &mut Text<'a>, repost_from: &'a RepostFrom) {
441+
text.push_quote(|text| {
442+
text.push_plain("🔁 ");
443+
444+
// In order for Telegram to display more relevant information about the
445+
// post, we don't use `profile_url` here
446+
//
447+
// &repost_from.post.user.profile_url,
448+
if let PostUrl::Clickable(url) = &repost_from.post.urls_recursive().major()
449+
{
450+
text.push_link(&repost_from.post.user.nickname, &url.url);
451+
} else {
452+
text.push_plain(&repost_from.post.user.nickname);
453+
}
454+
text.push_plain(": ");
455+
text.push_content(&repost_from.post.content);
456+
});
457+
if let Some(repost_from) = &repost_from.post.repost_from {
458+
text.push_plain("\n");
459+
push_reposts_rec(text, repost_from);
450460
}
451-
text.push_plain(": ");
452-
text.push_content(&repost_from.post.content);
453-
});
461+
}
462+
push_reposts_rec(&mut text, repost_from);
454463
}
455464
None => {
456465
if self.params.base.option.author_name {

0 commit comments

Comments
 (0)