Show correct text in case of mentions

This commit is contained in:
Andrea Maria Piana 2020-09-03 08:58:58 +02:00
parent 18877cae6f
commit 0d998e1858
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
2 changed files with 15 additions and 5 deletions

View File

@ -12,7 +12,8 @@ import (
"github.com/status-im/status-go/protocol/protobuf" "github.com/status-im/status-go/protocol/protobuf"
) )
const defaultNotificationMessage = "You have a new message" const defaultNewMessageNotificationText = "You have a new message"
const defaultMentionNotificationText = "Someone mentioned you"
type GoRushRequestData struct { type GoRushRequestData struct {
EncryptedMessage string `json:"encryptedMessage"` EncryptedMessage string `json:"encryptedMessage"`
@ -52,11 +53,17 @@ func PushNotificationRegistrationToGoRushRequest(requestAndRegistrations []*Requ
for _, requestAndRegistration := range requestAndRegistrations { for _, requestAndRegistration := range requestAndRegistrations {
request := requestAndRegistration.Request request := requestAndRegistration.Request
registration := requestAndRegistration.Registration registration := requestAndRegistration.Registration
var text string
if request.Type == protobuf.PushNotification_MESSAGE {
text = defaultNewMessageNotificationText
} else {
text = defaultMentionNotificationText
}
goRushRequests.Notifications = append(goRushRequests.Notifications, goRushRequests.Notifications = append(goRushRequests.Notifications,
&GoRushRequestNotification{ &GoRushRequestNotification{
Tokens: []string{registration.DeviceToken}, Tokens: []string{registration.DeviceToken},
Platform: tokenTypeToGoRushPlatform(registration.TokenType), Platform: tokenTypeToGoRushPlatform(registration.TokenType),
Message: defaultNotificationMessage, Message: text,
Topic: registration.ApnTopic, Topic: registration.ApnTopic,
Data: &GoRushRequestData{ Data: &GoRushRequestData{
EncryptedMessage: types.EncodeHex(request.Message), EncryptedMessage: types.EncodeHex(request.Message),

View File

@ -33,6 +33,7 @@ func TestPushNotificationRegistrationToGoRushRequest(t *testing.T) {
{ {
Request: &protobuf.PushNotification{ Request: &protobuf.PushNotification{
ChatId: chatID, ChatId: chatID,
Type: protobuf.PushNotification_MESSAGE,
PublicKey: publicKey1, PublicKey: publicKey1,
InstallationId: installationID1, InstallationId: installationID1,
Message: message1, Message: message1,
@ -45,6 +46,7 @@ func TestPushNotificationRegistrationToGoRushRequest(t *testing.T) {
{ {
Request: &protobuf.PushNotification{ Request: &protobuf.PushNotification{
ChatId: chatID, ChatId: chatID,
Type: protobuf.PushNotification_MESSAGE,
PublicKey: publicKey1, PublicKey: publicKey1,
InstallationId: installationID2, InstallationId: installationID2,
Message: message2, Message: message2,
@ -57,6 +59,7 @@ func TestPushNotificationRegistrationToGoRushRequest(t *testing.T) {
{ {
Request: &protobuf.PushNotification{ Request: &protobuf.PushNotification{
ChatId: chatID, ChatId: chatID,
Type: protobuf.PushNotification_MENTION,
PublicKey: publicKey2, PublicKey: publicKey2,
InstallationId: installationID3, InstallationId: installationID3,
Message: message3, Message: message3,
@ -73,7 +76,7 @@ func TestPushNotificationRegistrationToGoRushRequest(t *testing.T) {
{ {
Tokens: []string{token1}, Tokens: []string{token1},
Platform: platform1, Platform: platform1,
Message: defaultNotificationMessage, Message: defaultNewMessageNotificationText,
Data: &GoRushRequestData{ Data: &GoRushRequestData{
EncryptedMessage: hexMessage1, EncryptedMessage: hexMessage1,
ChatID: types.EncodeHex(chatID), ChatID: types.EncodeHex(chatID),
@ -83,7 +86,7 @@ func TestPushNotificationRegistrationToGoRushRequest(t *testing.T) {
{ {
Tokens: []string{token2}, Tokens: []string{token2},
Platform: platform2, Platform: platform2,
Message: defaultNotificationMessage, Message: defaultNewMessageNotificationText,
Data: &GoRushRequestData{ Data: &GoRushRequestData{
EncryptedMessage: hexMessage2, EncryptedMessage: hexMessage2,
ChatID: types.EncodeHex(chatID), ChatID: types.EncodeHex(chatID),
@ -93,7 +96,7 @@ func TestPushNotificationRegistrationToGoRushRequest(t *testing.T) {
{ {
Tokens: []string{token3}, Tokens: []string{token3},
Platform: platform3, Platform: platform3,
Message: defaultNotificationMessage, Message: defaultMentionNotificationText,
Data: &GoRushRequestData{ Data: &GoRushRequestData{
EncryptedMessage: hexMessage3, EncryptedMessage: hexMessage3,
ChatID: types.EncodeHex(chatID), ChatID: types.EncodeHex(chatID),