@@ -3,7 +3,6 @@ package protocol
33import (
44 "crypto/ecdsa"
55 "encoding/json"
6- "fmt"
76 "strings"
87
98 gethcommon "github.com/ethereum/go-ethereum/common"
@@ -111,6 +110,17 @@ func applyMessagePreview(title, message string, messagePreview int) (displayTitl
111110 }
112111}
113112
113+ // applyAuthorPrivacy clears identity-revealing fields from a notification when the privacy
114+ // level is anonymous. In anonymous mode the OS notification must not expose who sent
115+ // the message: no sender name, no sender/community/chat icon.
116+ func applyAuthorPrivacy (notif * localnotifications.Notification , messagePreview int ) {
117+ if messagePreview == messagePreviewAnonymous {
118+ notif .Author = localnotifications.NotificationAuthor {}
119+ notif .CommunityIcon = ""
120+ notif .ChatIcon = ""
121+ }
122+ }
123+
114124// NotificationSettingsProvider allows querying notification preferences for local notifications.
115125// Implemented by *accounts.Database which embeds *NotificationsSettings.
116126type NotificationSettingsProvider interface {
@@ -142,7 +152,6 @@ func showMessageNotification(settings NotificationSettingsProvider, publicKey ec
142152 // For public/community chats, skip inactive (soft-deleted). For 1:1 and group,
143153 // still notify — e.g. contact requests or new messages can arrive when Active=false.
144154 if chat != nil && ! chat .Active && ! chat .OneToOne () && ! chat .PrivateGroupChat () {
145- fmt .Printf ("[local_notifications] showMessageNotification: false (chat !Active, not 1:1/group) msgId=%s\n " , message .ID )
146155 return false
147156 }
148157
@@ -168,7 +177,6 @@ func showMessageNotification(settings NotificationSettingsProvider, publicKey ec
168177 // 1. Check per-chat/community exemptions first
169178 exMuteAll , err := settings .GetExMuteAllMessages (chatID )
170179 if err == nil && exMuteAll {
171- fmt .Printf ("[local_notifications] showMessageNotification: false (exemption muteAll) msgId=%s\n " , message .ID )
172180 return false
173181 }
174182
@@ -179,21 +187,17 @@ func showMessageNotification(settings NotificationSettingsProvider, publicKey ec
179187 if chat .OneToOne () {
180188 val , err := settings .GetOneToOneChats ()
181189 if err == nil && ! isNotificationAllowed (val ) {
182- fmt .Printf ("[local_notifications] showMessageNotification: false (1:1 TurnOff) msgId=%s\n " , message .ID )
183190 return false
184191 }
185- fmt .Printf ("[local_notifications] showMessageNotification: true (1:1) msgId=%s\n " , message .ID )
186192 return true
187193 }
188194
189195 // 3. Private group chats
190196 if chat .PrivateGroupChat () {
191197 val , err := settings .GetGroupChats ()
192198 if err == nil && ! isNotificationAllowed (val ) {
193- fmt .Printf ("[local_notifications] showMessageNotification: false (group TurnOff) msgId=%s\n " , message .ID )
194199 return false
195200 }
196- fmt .Printf ("[local_notifications] showMessageNotification: true (private group) msgId=%s\n " , message .ID )
197201 return true
198202 }
199203
@@ -210,9 +214,7 @@ func showMessageNotification(settings NotificationSettingsProvider, publicKey ec
210214 exG , _ := settings .GetExGlobalMentions (chatID )
211215 effPersonal , effGlobal = exP , exG
212216 }
213- allowed := isNotificationAllowed (effPersonal ) || isNotificationAllowed (effGlobal )
214- fmt .Printf ("[local_notifications] showMessageNotification: %v (mention) msgId=%s\n " , allowed , message .ID )
215- return allowed
217+ return isNotificationAllowed (effPersonal ) || isNotificationAllowed (effGlobal )
216218 }
217219
218220 if isReplyToOwn {
@@ -222,9 +224,7 @@ func showMessageNotification(settings NotificationSettingsProvider, publicKey ec
222224 exOther , _ := settings .GetExOtherMessages (chatID )
223225 eff = exOther
224226 }
225- allowed := isNotificationAllowed (eff )
226- fmt .Printf ("[local_notifications] showMessageNotification: %v (reply to own) msgId=%s\n " , allowed , message .ID )
227- return allowed
227+ return isNotificationAllowed (eff )
228228 }
229229
230230 // 5. Other messages in public/community chats
@@ -234,9 +234,7 @@ func showMessageNotification(settings NotificationSettingsProvider, publicKey ec
234234 exOther , _ := settings .GetExOtherMessages (chatID )
235235 eff = exOther
236236 }
237- allowed := isNotificationAllowed (eff )
238- fmt .Printf ("[local_notifications] showMessageNotification: %v (other) msgId=%s\n " , allowed , message .ID )
239- return allowed
237+ return isNotificationAllowed (eff )
240238}
241239
242240func (n NotificationBody ) MarshalJSON () ([]byte , error ) {
@@ -385,14 +383,15 @@ func (n NotificationBody) toMessageNotification(id string, resolvePrimaryName fu
385383 notif .ChatIcon = chatIconDataURI (n .Chat )
386384 }
387385
386+ applyAuthorPrivacy (notif , messagePreview )
388387 return notif , nil
389388}
390389
391390func (n NotificationBody ) toContactRequestNotification (id string , profilePicturesVisibility int , messagePreview int ) (* localnotifications.Notification , error ) {
392391 title := n .Contact .PrimaryName () + " wants to connect"
393392 message := n .Contact .PrimaryName () + " sent you a contact request"
394393 displayTitle , displayMessage := applyMessagePreview (title , message , messagePreview )
395- return & localnotifications.Notification {
394+ notif := & localnotifications.Notification {
396395 ID : gethcommon .HexToHash (id ),
397396 Body : n ,
398397 Title : title ,
@@ -411,14 +410,16 @@ func (n NotificationBody) toContactRequestNotification(id string, profilePicture
411410 Timestamp : n .Message .WhisperTimestamp ,
412411 IsConversation : true ,
413412 Image : "" ,
414- }, nil
413+ }
414+ applyAuthorPrivacy (notif , messagePreview )
415+ return notif , nil
415416}
416417
417418func (n NotificationBody ) toPrivateGroupInviteNotification (id string , profilePicturesVisibility int , messagePreview int ) * localnotifications.Notification {
418419 title := n .Contact .PrimaryName () + " invited you to " + n .Chat .Name
419420 message := n .Contact .PrimaryName () + " wants you to join group " + n .Chat .Name
420421 displayTitle , displayMessage := applyMessagePreview (title , message , messagePreview )
421- return & localnotifications.Notification {
422+ notif := & localnotifications.Notification {
422423 ID : gethcommon .HexToHash (id ),
423424 Body : n ,
424425 Title : title ,
@@ -436,13 +437,15 @@ func (n NotificationBody) toPrivateGroupInviteNotification(id string, profilePic
436437 ChatIcon : chatIconDataURI (n .Chat ),
437438 Image : "" ,
438439 }
440+ applyAuthorPrivacy (notif , messagePreview )
441+ return notif
439442}
440443
441444func (n NotificationBody ) toCommunityRequestToJoinNotification (id string , profilePicturesVisibility int , messagePreview int ) * localnotifications.Notification {
442445 title := n .Contact .PrimaryName () + " wants to join " + n .Community .Name ()
443- message := n .Contact .PrimaryName () + " wants to join message " + n .Community .Name ()
446+ message := n .Contact .PrimaryName () + " wants to join " + n .Community .Name ()
444447 displayTitle , displayMessage := applyMessagePreview (title , message , messagePreview )
445- return & localnotifications.Notification {
448+ notif := & localnotifications.Notification {
446449 ID : gethcommon .HexToHash (id ),
447450 Body : n ,
448451 Title : title ,
@@ -460,4 +463,6 @@ func (n NotificationBody) toCommunityRequestToJoinNotification(id string, profil
460463 CommunityIcon : communityIconDataURI (n .Community ),
461464 Image : "" ,
462465 }
466+ applyAuthorPrivacy (notif , messagePreview )
467+ return notif
463468}
0 commit comments