@@ -387,13 +387,14 @@ impl App {
387387 Ok ( ( ) )
388388 }
389389
390- /// Forward a message from one chat to another.
390+ /// Forward a message from one chat to another (optionally to a specific topic) .
391391 /// Returns the new message ID in the destination chat.
392392 pub async fn forward_message (
393393 & self ,
394394 from_chat_id : i64 ,
395395 msg_id : i64 ,
396396 to_chat_id : i64 ,
397+ to_topic_id : Option < i32 > ,
397398 ) -> Result < i64 > {
398399 let from_peer = self . resolve_peer_ref ( from_chat_id) . await ?;
399400 let to_peer = self . resolve_peer_ref ( to_chat_id) . await ?;
@@ -415,7 +416,7 @@ impl App {
415416 id : vec ! [ msg_id as i32 ] ,
416417 random_id : vec ! [ random_id] ,
417418 to_peer : to_input_peer,
418- top_msg_id : None ,
419+ top_msg_id : to_topic_id ,
419420 schedule_date : None ,
420421 send_as : None ,
421422 quick_reply_shortcut : None ,
@@ -434,14 +435,29 @@ impl App {
434435 Ok ( new_msg_id)
435436 }
436437
437- /// Mark a chat as read.
438- pub async fn mark_read ( & mut self , chat_id : i64 ) -> Result < ( ) > {
438+ /// Mark a chat (or topic in a forum) as read.
439+ pub async fn mark_read ( & mut self , chat_id : i64 , topic_id : Option < i32 > ) -> Result < ( ) > {
439440 let peer_ref = self . resolve_peer_ref ( chat_id) . await ?;
440- self . tg
441- . client
442- . mark_as_read ( peer_ref)
443- . await
444- . context ( format ! ( "Failed to mark chat {} as read" , chat_id) ) ?;
441+
442+ if let Some ( tid) = topic_id {
443+ // For forum topics, use ReadDiscussion to mark the topic as read
444+ let input_peer: tl:: enums:: InputPeer = peer_ref. into ( ) ;
445+ let request = tl:: functions:: messages:: ReadDiscussion {
446+ peer : input_peer,
447+ msg_id : tid,
448+ read_max_id : i32:: MAX ,
449+ } ;
450+ self . tg . client . invoke ( & request) . await . context ( format ! (
451+ "Failed to mark topic {} in chat {} as read" ,
452+ tid, chat_id
453+ ) ) ?;
454+ } else {
455+ self . tg
456+ . client
457+ . mark_as_read ( peer_ref)
458+ . await
459+ . context ( format ! ( "Failed to mark chat {} as read" , chat_id) ) ?;
460+ }
445461 Ok ( ( ) )
446462 }
447463
@@ -1026,33 +1042,63 @@ impl App {
10261042 Ok ( ( ) )
10271043 }
10281044
1029- /// Send typing indicator to a chat.
1030- pub async fn set_typing ( & self , chat_id : i64 ) -> Result < ( ) > {
1045+ /// Send typing indicator to a chat (or topic in a forum) .
1046+ pub async fn set_typing ( & self , chat_id : i64 , topic_id : Option < i32 > ) -> Result < ( ) > {
10311047 let peer_ref = self . resolve_peer_ref ( chat_id) . await ?;
1032- self . tg
1033- . client
1034- . action ( peer_ref)
1035- . oneshot ( SendMessageAction :: SendMessageTypingAction )
1036- . await
1037- . context ( format ! (
1038- "Failed to set typing indicator in chat {}" ,
1039- chat_id
1048+
1049+ if let Some ( tid) = topic_id {
1050+ // For forum topics, use raw TL to set typing with top_msg_id
1051+ let input_peer: tl:: enums:: InputPeer = peer_ref. into ( ) ;
1052+ let request = tl:: functions:: messages:: SetTyping {
1053+ peer : input_peer,
1054+ top_msg_id : Some ( tid) ,
1055+ action : SendMessageAction :: SendMessageTypingAction ,
1056+ } ;
1057+ self . tg . client . invoke ( & request) . await . context ( format ! (
1058+ "Failed to set typing indicator in topic {} of chat {}" ,
1059+ tid, chat_id
10401060 ) ) ?;
1061+ } else {
1062+ self . tg
1063+ . client
1064+ . action ( peer_ref)
1065+ . oneshot ( SendMessageAction :: SendMessageTypingAction )
1066+ . await
1067+ . context ( format ! (
1068+ "Failed to set typing indicator in chat {}" ,
1069+ chat_id
1070+ ) ) ?;
1071+ }
10411072 Ok ( ( ) )
10421073 }
10431074
1044- /// Cancel typing indicator in a chat.
1045- pub async fn cancel_typing ( & self , chat_id : i64 ) -> Result < ( ) > {
1075+ /// Cancel typing indicator in a chat (or topic in a forum) .
1076+ pub async fn cancel_typing ( & self , chat_id : i64 , topic_id : Option < i32 > ) -> Result < ( ) > {
10461077 let peer_ref = self . resolve_peer_ref ( chat_id) . await ?;
1047- self . tg
1048- . client
1049- . action ( peer_ref)
1050- . cancel ( )
1051- . await
1052- . context ( format ! (
1053- "Failed to cancel typing indicator in chat {}" ,
1054- chat_id
1078+
1079+ if let Some ( tid) = topic_id {
1080+ // For forum topics, use raw TL to cancel typing with top_msg_id
1081+ let input_peer: tl:: enums:: InputPeer = peer_ref. into ( ) ;
1082+ let request = tl:: functions:: messages:: SetTyping {
1083+ peer : input_peer,
1084+ top_msg_id : Some ( tid) ,
1085+ action : SendMessageAction :: SendMessageCancelAction ,
1086+ } ;
1087+ self . tg . client . invoke ( & request) . await . context ( format ! (
1088+ "Failed to cancel typing indicator in topic {} of chat {}" ,
1089+ tid, chat_id
10551090 ) ) ?;
1091+ } else {
1092+ self . tg
1093+ . client
1094+ . action ( peer_ref)
1095+ . cancel ( )
1096+ . await
1097+ . context ( format ! (
1098+ "Failed to cancel typing indicator in chat {}" ,
1099+ chat_id
1100+ ) ) ?;
1101+ }
10561102 Ok ( ( ) )
10571103 }
10581104}
0 commit comments