@@ -3,11 +3,11 @@ use crate::client::store::conversations::merge_conversation_from_chat;
33use crate :: client:: store:: is_cache_expired;
44use crate :: models:: ChatLogStatus ;
55use crate :: utils:: now_millis;
6- use crate :: REMOVED_CONVERSATION_CACHE_EXPIRE_SECS ;
76use crate :: {
87 callback:: MessageCallback ,
98 request:: { ChatRequest , ChatRequestType } ,
109} ;
10+ use crate :: { PING_TIMEOUT_SECS , REMOVED_CONVERSATION_CACHE_EXPIRE_SECS } ;
1111use http:: StatusCode ;
1212use log:: { info, warn} ;
1313use tokio:: sync:: mpsc:: { unbounded_channel, UnboundedSender } ;
@@ -61,6 +61,7 @@ impl ClientStore {
6161 } else {
6262 ChatLogStatus :: SendFailed
6363 } ;
64+
6465 if let Some ( pending) = self . peek_pending_request ( & req. chat_id ) . await {
6566 match status {
6667 ChatLogStatus :: Sent => {
@@ -75,6 +76,28 @@ impl ClientStore {
7576 }
7677 _ => { }
7778 }
79+ } else {
80+ if content_type == "ping" && req. seq == 0 {
81+ match req. content . as_ref ( ) {
82+ Some ( content) => {
83+ let data = match serde_json:: from_str :: < serde_json:: Value > (
84+ & content. text ,
85+ ) {
86+ Ok ( data) => data,
87+ Err ( _) => return vec ! [ ] ,
88+ } ;
89+ let timestamp = match data[ "timestamp" ] . as_i64 ( ) {
90+ Some ( timestamp) => timestamp,
91+ None => return vec ! [ ] ,
92+ } ;
93+ let diff = now_millis ( ) - timestamp;
94+ if diff >= PING_TIMEOUT_SECS * 1000 {
95+ warn ! ( "ping timeout:{}" , diff) ;
96+ }
97+ }
98+ _ => { }
99+ }
100+ }
78101 }
79102
80103 self . update_outoing_chat_log_state ( & topic_id, & chat_id, status, Some ( ack_seq) )
0 commit comments