@@ -110,6 +110,27 @@ func applyMessagePreview(title, message string, messagePreview int) (displayTitl
110110 }
111111}
112112
113+ // getMessagePreviewText returns a simplified, notification-safe preview of the message text.
114+ // Uses GetSimplifiedText when possible, falls back to raw Text. Returns empty string if message is nil or extraction fails.
115+ func getMessagePreviewText (m * common.Message , canonicalNames map [string ]string ) string {
116+ if m == nil {
117+ return ""
118+ }
119+ text , err := m .GetSimplifiedText ("" , canonicalNames )
120+ if err != nil {
121+ return strings .TrimSpace (m .Text )
122+ }
123+ return strings .TrimSpace (text )
124+ }
125+
126+ // timestampOrZero returns the message's WhisperTimestamp, or 0 if the message is nil.
127+ func timestampOrZero (m * common.Message ) uint64 {
128+ if m == nil {
129+ return 0
130+ }
131+ return m .WhisperTimestamp
132+ }
133+
113134// applyAuthorPrivacy clears identity-revealing fields from a notification when the privacy
114135// level is anonymous. In anonymous mode the OS notification must not expose who sent
115136// the message: no sender name, no sender/community/chat icon.
@@ -282,10 +303,7 @@ func NewCommunityRequestToJoinNotification(id string, community *communities.Com
282303// NewOutgoingMessageNotification creates a local notification for a message sent by the current user.
283304func NewOutgoingMessageNotification (id string , message * common.Message , chat * Chat , community * communities.Community , authorName string , authorIcon string , authorID string ) * localnotifications.Notification {
284305 title := chat .Name
285- simplifiedText , err := message .GetSimplifiedText ("" , nil )
286- if err != nil {
287- simplifiedText = message .Text
288- }
306+ simplifiedText := getMessagePreviewText (message , nil )
289307 notif := & localnotifications.Notification {
290308 ID : gethcommon .HexToHash (id ),
291309 BodyType : localnotifications .TypeMessage ,
@@ -389,7 +407,10 @@ func (n NotificationBody) toMessageNotification(id string, resolvePrimaryName fu
389407
390408func (n NotificationBody ) toContactRequestNotification (id string , profilePicturesVisibility int , messagePreview int ) (* localnotifications.Notification , error ) {
391409 title := n .Contact .PrimaryName () + " wants to connect"
392- message := n .Contact .PrimaryName () + " sent you a contact request"
410+ message := getMessagePreviewText (n .Message , nil )
411+ if message == "" {
412+ message = n .Contact .PrimaryName () + " sent you a contact request"
413+ }
393414 displayTitle , displayMessage := applyMessagePreview (title , message , messagePreview )
394415 notif := & localnotifications.Notification {
395416 ID : gethcommon .HexToHash (id ),
@@ -407,7 +428,7 @@ func (n NotificationBody) toContactRequestNotification(id string, profilePicture
407428 ID : n .Contact .ID ,
408429 },
409430 ConversationID : n .Chat .ID ,
410- Timestamp : n .Message . WhisperTimestamp ,
431+ Timestamp : timestampOrZero ( n .Message ) ,
411432 IsConversation : true ,
412433 Image : "" ,
413434 }
@@ -417,7 +438,10 @@ func (n NotificationBody) toContactRequestNotification(id string, profilePicture
417438
418439func (n NotificationBody ) toPrivateGroupInviteNotification (id string , profilePicturesVisibility int , messagePreview int ) * localnotifications.Notification {
419440 title := n .Contact .PrimaryName () + " invited you to " + n .Chat .Name
420- message := n .Contact .PrimaryName () + " wants you to join group " + n .Chat .Name
441+ message := getMessagePreviewText (n .Message , nil )
442+ if message == "" {
443+ message = n .Contact .PrimaryName () + " wants you to join group " + n .Chat .Name
444+ }
421445 displayTitle , displayMessage := applyMessagePreview (title , message , messagePreview )
422446 notif := & localnotifications.Notification {
423447 ID : gethcommon .HexToHash (id ),
@@ -443,7 +467,7 @@ func (n NotificationBody) toPrivateGroupInviteNotification(id string, profilePic
443467
444468func (n NotificationBody ) toCommunityRequestToJoinNotification (id string , profilePicturesVisibility int , messagePreview int ) * localnotifications.Notification {
445469 title := n .Contact .PrimaryName () + " wants to join " + n .Community .Name ()
446- message := n . Contact . PrimaryName () + " wants to join " + n . Community . Name ( )
470+ message := getMessagePreviewText ( n . Message , nil )
447471 displayTitle , displayMessage := applyMessagePreview (title , message , messagePreview )
448472 notif := & localnotifications.Notification {
449473 ID : gethcommon .HexToHash (id ),
0 commit comments