@@ -189,21 +189,35 @@ export default class ChatList {
189189 : res . content ;
190190
191191 frappe . show_alert ( {
192- message :__ ( "You have a new message from " + res . contact_name + ": " + message ) ,
193- indicator :'green'
194- } , 5 ) ;
192+ message : `<a href="#" data-action="open-chat" style="text-decoration: none; color: inherit;">
193+ <strong>${ res . contact_name } </strong><br>
194+ <span style="opacity: 0.9;">${ message } </span>
195+ </a>` ,
196+ indicator : 'green'
197+ } , 5 , {
198+ 'open-chat' : function ( ) {
199+ // Open chat widget if closed
200+ if ( ! $ ( '.chat-element' ) . is ( ':visible' ) ) {
201+ $ ( '.chat-navbar-icon' ) . click ( ) ;
202+ }
203+ // Open the specific chat room after a small delay for widget to open
204+ setTimeout ( ( ) => {
205+ chat_room_item [ 1 ] . $chat_room . click ( ) ;
206+ } , 100 ) ;
207+ }
208+ } ) ;
195209
196210 chat_room_item [ 1 ] . set_last_message ( message , res . creation ) ;
197211
198- if ( $ ( '.chat-list' ) . length ) {
212+ if ( $ ( '.chat-list' ) . is ( ':visible' ) ) {
199213 chat_room_item [ 1 ] . set_as_unread ( ) ;
200214 chat_room_item [ 1 ] . move_to_top ( ) ;
201215 me . move_room_to_top ( chat_room_item ) ;
202- } else if ( $ ( '.chat-space' ) . length ) {
216+ } else if ( $ ( '.chat-space' ) . is ( ':visible' ) ) {
203217 mark_message_read ( res . room ) ;
204218 } else {
205- // Chat widget is closed - still update the navbar counter
206- if ( chat_room_item [ 1 ] . profile . is_read ) {
219+ // Chat widget is closed - update counter only if room was previously read
220+ if ( chat_room_item [ 1 ] . profile . is_read === 1 ) {
207221 set_notification_count ( 'increment' ) ;
208222 chat_room_item [ 1 ] . profile . is_read = 0 ;
209223 }
0 commit comments