Skip to content

Commit e48a04e

Browse files
committed
fix(push): Route contact request pushes to Activity Center
Add a dedicated contact request push notification type and classify contact request messages with it before sending remote push notifications. Map contact request APNS payloads to `status-app://contact-requests` so tapping the notification opens the Activity Center Contact requests group instead of the chats list. Also add server-side filtering for blocked contact request authors and cover the new mapping in push notification tests. Part of status-app issue #21189
1 parent 8213ddd commit e48a04e

6 files changed

Lines changed: 90 additions & 5 deletions

File tree

protocol/protobuf/push_notifications.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ message PushNotification {
7979
MESSAGE = 1;
8080
MENTION = 2;
8181
REQUEST_TO_JOIN_COMMUNITY = 3;
82+
CONTACT_REQUEST = 4;
8283
}
8384
bytes author = 7;
8485
}

protocol/pushnotificationclient/client.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,8 +1073,13 @@ func (c *Client) handleDirectMessageSent(sentMessage *messagingevents.SentMessag
10731073
chatID = message.ChatId
10741074
}
10751075

1076+
notificationType := protobuf.PushNotification_MESSAGE
1077+
if message.ContentType == protobuf.ChatMessage_CONTACT_REQUEST {
1078+
notificationType = protobuf.PushNotification_CONTACT_REQUEST
1079+
}
1080+
10761081
// we send the notifications and return the info of the devices notified
1077-
infos, err := c.SendNotification(publicKey, installationIDs, trackedMessageIDs[0], chatID, protobuf.PushNotification_MESSAGE)
1082+
infos, err := c.SendNotification(publicKey, installationIDs, trackedMessageIDs[0], chatID, notificationType)
10781083
if err != nil {
10791084
return err
10801085
}
@@ -1084,7 +1089,7 @@ func (c *Client) handleDirectMessageSent(sentMessage *messagingevents.SentMessag
10841089
for _, messageID := range trackedMessageIDs {
10851090

10861091
c.config.Logger.Debug("marking as sent ", zap.String("messageID", types.EncodeHex(messageID)), zap.String("id", i.InstallationID))
1087-
if err := c.notifiedOn(publicKey, i.InstallationID, messageID, chatID, protobuf.PushNotification_MESSAGE); err != nil {
1092+
if err := c.notifiedOn(publicKey, i.InstallationID, messageID, chatID, notificationType); err != nil {
10881093
return err
10891094
}
10901095

protocol/pushnotificationserver/gorush.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ import (
1515
const defaultNewMessageNotificationText = "New message in Messenger"
1616
const defaultMentionNotificationText = "New mention or reply in Communities"
1717
const defaultRequestToJoinCommunityNotificationText = "Someone requested to join a community you are an admin of"
18+
const defaultContactRequestNotificationText = "Someone sent you a contact request"
1819

19-
const deepLinkChats = "status-app://chats" // plain messages -> messenger
20-
const deepLinkActivityCenter = "status-app://ac" // mentions, community requests, etc. -> activity center
20+
const deepLinkChats = "status-app://chats" // plain messages -> messenger
21+
const deepLinkActivityCenter = "status-app://ac" // mentions, community requests, etc. -> activity center
22+
const deepLinkContactRequests = "status-app://contact-requests" // contact requests -> activity center contact requests
2123

2224
type GoRushRequestData struct {
2325
EncryptedMessage string `json:"encryptedMessage"`
@@ -67,6 +69,8 @@ func PushNotificationRegistrationToGoRushRequest(requestAndRegistrations []*Requ
6769
text = defaultNewMessageNotificationText
6870
} else if request.Type == protobuf.PushNotification_REQUEST_TO_JOIN_COMMUNITY {
6971
text = defaultRequestToJoinCommunityNotificationText
72+
} else if request.Type == protobuf.PushNotification_CONTACT_REQUEST {
73+
text = defaultContactRequestNotificationText
7074
} else {
7175
text = defaultMentionNotificationText
7276
}
@@ -78,6 +82,8 @@ func PushNotificationRegistrationToGoRushRequest(requestAndRegistrations []*Requ
7882
pushType = "alert"
7983
if request.Type == protobuf.PushNotification_MESSAGE {
8084
deepLink = deepLinkChats
85+
} else if request.Type == protobuf.PushNotification_CONTACT_REQUEST {
86+
deepLink = deepLinkContactRequests
8187
} else {
8288
deepLink = deepLinkActivityCenter
8389
}

protocol/pushnotificationserver/gorush_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@ func TestPushNotificationRegistrationToGoRushRequest(t *testing.T) {
6969
TokenType: protobuf.PushNotificationRegistration_FIREBASE_TOKEN,
7070
},
7171
},
72+
{
73+
Request: &protobuf.PushNotification{
74+
ChatId: chatID,
75+
Type: protobuf.PushNotification_CONTACT_REQUEST,
76+
PublicKey: publicKey2,
77+
InstallationId: installationID3,
78+
Message: message3,
79+
},
80+
Registration: &protobuf.PushNotificationRegistration{
81+
DeviceToken: token3,
82+
TokenType: protobuf.PushNotificationRegistration_APN_TOKEN,
83+
},
84+
},
7285
}
7386

7487
expectedRequests := &GoRushRequest{
@@ -108,6 +121,21 @@ func TestPushNotificationRegistrationToGoRushRequest(t *testing.T) {
108121
PublicKey: types.EncodeHex(publicKey2),
109122
},
110123
},
124+
{
125+
Tokens: []string{token3},
126+
Platform: platform1,
127+
Message: defaultContactRequestNotificationText,
128+
ContentAvailable: true,
129+
Sound: "default",
130+
Priority: "high",
131+
PushType: "alert",
132+
Data: &GoRushRequestData{
133+
EncryptedMessage: hexMessage3,
134+
ChatID: types.EncodeHex(chatID),
135+
PublicKey: types.EncodeHex(publicKey2),
136+
DeepLink: deepLinkContactRequests,
137+
},
138+
},
111139
},
112140
}
113141
actualRequests := PushNotificationRegistrationToGoRushRequest(requestAndRegistrations)
@@ -153,6 +181,7 @@ func TestGoRushRequestDeepLinkByType(t *testing.T) {
153181
{"message", protobuf.PushNotification_MESSAGE, deepLinkChats},
154182
{"mention", protobuf.PushNotification_MENTION, deepLinkActivityCenter},
155183
{"community request", protobuf.PushNotification_REQUEST_TO_JOIN_COMMUNITY, deepLinkActivityCenter},
184+
{"contact request", protobuf.PushNotification_CONTACT_REQUEST, deepLinkContactRequests},
156185
{"unknown", protobuf.PushNotification_UNKNOWN_PUSH_NOTIFICATION_TYPE, deepLinkActivityCenter},
157186
}
158187
for _, tc := range cases {

protocol/pushnotificationserver/server.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ func (s *Server) buildPushNotificationReport(pn *protobuf.PushNotification, regi
392392
} else if registration.AccessToken != pn.AccessToken {
393393
s.config.Logger.Debug("invalid token")
394394
report.Error = protobuf.PushNotificationReport_WRONG_TOKEN
395-
} else if (s.isMessageNotification(pn) && !s.isValidMessageNotification(pn, registration)) || (s.isMentionNotification(pn) && !s.isValidMentionNotification(pn, registration)) || (s.isRequestToJoinCommunityNotification(pn) && !s.isValidRequestToJoinCommunityNotification(pn, registration)) {
395+
} else if (s.isMessageNotification(pn) && !s.isValidMessageNotification(pn, registration)) || (s.isMentionNotification(pn) && !s.isValidMentionNotification(pn, registration)) || (s.isRequestToJoinCommunityNotification(pn) && !s.isValidRequestToJoinCommunityNotification(pn, registration)) || (s.isContactRequestNotification(pn) && !s.isValidContactRequestNotification(pn, registration)) {
396396
s.config.Logger.Debug("filtered notification")
397397
// We report as successful but don't send the notification
398398
// for privacy reasons, as otherwise we would disclose that
@@ -565,3 +565,14 @@ func (s *Server) isRequestToJoinCommunityNotification(pn *protobuf.PushNotificat
565565
func (s *Server) isValidRequestToJoinCommunityNotification(pn *protobuf.PushNotification, registration *protobuf.PushNotificationRegistration) bool {
566566
return s.isRequestToJoinCommunityNotification(pn) && !s.contains(registration.BlockedChatList, pn.Author)
567567
}
568+
569+
func (s *Server) isContactRequestNotification(pn *protobuf.PushNotification) bool {
570+
return pn.Type == protobuf.PushNotification_CONTACT_REQUEST
571+
}
572+
573+
// isValidContactRequestNotification checks:
574+
// this is a contact request
575+
// the author is not blocked
576+
func (s *Server) isValidContactRequestNotification(pn *protobuf.PushNotification, registration *protobuf.PushNotificationRegistration) bool {
577+
return s.isContactRequestNotification(pn) && !s.contains(registration.BlockedChatList, pn.Author)
578+
}

protocol/pushnotificationserver/server_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,12 @@ func (s *ServerSuite) TestBuildPushNotificationReport() {
691691
ChatId: chatID,
692692
AccessToken: accessToken,
693693
}
694+
validContactRequestPN := &protobuf.PushNotification{
695+
Type: protobuf.PushNotification_CONTACT_REQUEST,
696+
ChatId: chatID,
697+
Author: author,
698+
AccessToken: accessToken,
699+
}
694700
validRegistration := &protobuf.PushNotificationRegistration{
695701
AccessToken: accessToken,
696702
BlockedChatList: blockedChatList,
@@ -733,6 +739,17 @@ func (s *ServerSuite) TestBuildPushNotificationReport() {
733739
},
734740
},
735741
},
742+
{
743+
name: "valid contact request",
744+
pn: validContactRequestPN,
745+
registration: validRegistration,
746+
expectedResponse: &reportResult{
747+
sendNotification: true,
748+
report: &protobuf.PushNotificationReport{
749+
Success: true,
750+
},
751+
},
752+
},
736753
{
737754
name: "unknow push notification",
738755
pn: &protobuf.PushNotification{
@@ -884,6 +901,22 @@ func (s *ServerSuite) TestBuildPushNotificationReport() {
884901
},
885902
},
886903
},
904+
{
905+
name: "blocked contact request author",
906+
pn: &protobuf.PushNotification{
907+
Type: protobuf.PushNotification_CONTACT_REQUEST,
908+
Author: blockedAuthor,
909+
ChatId: chatID,
910+
AccessToken: accessToken,
911+
},
912+
registration: validRegistration,
913+
expectedResponse: &reportResult{
914+
sendNotification: false,
915+
report: &protobuf.PushNotificationReport{
916+
Success: true,
917+
},
918+
},
919+
},
887920
{
888921
name: "blocked mentions",
889922
pn: &protobuf.PushNotification{

0 commit comments

Comments
 (0)