Commit 9be48344 authored by Yuwei Huang's avatar Yuwei Huang Committed by Commit Bot

[remoting][mobile] Add allow_dont_show_again to notification

Now only messages with allow_dont_show_again set to true will show the
"Don't show again" check box.

Bug: 1001291
Change-Id: I920a8bf6188a063a078d230b38c4543ae108bb25
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1846237Reviewed-by: default avatarJamie Walch <jamiewalch@chromium.org>
Commit-Queue: Yuwei Huang <yuweih@chromium.org>
Cr-Commit-Position: refs/heads/master@{#703493}
parent 143ecbc0
......@@ -76,7 +76,7 @@ bool FindKeyAndGet(const base::Value& dict,
const std::string& type_name) {
const base::Value* value = dict.FindKey(key);
if (!value) {
LOG(ERROR) << "|" << key << "| not found in dictionary.";
LOG(WARNING) << "|" << key << "| not found in dictionary.";
return false;
}
if (!(value->*is_t_checker)()) {
......@@ -314,6 +314,8 @@ base::Optional<NotificationMessage> NotificationClient::ParseAndMatchRule(
}
message->message_id = message_id;
message->link_url = link_url;
message->allow_dont_show_again = false;
FindKeyAndGet(rule, "allow_dont_show_again", &message->allow_dont_show_again);
*out_message_text_filename = message_text_filename;
*out_link_text_filename = link_text_filename;
return message;
......
......@@ -67,6 +67,7 @@ base::Value CreateDefaultRule() {
rule.SetStringKey("link_text", "link_text.json");
rule.SetStringKey("link_url", "https://example.com/some_link");
rule.SetIntKey("percent", 100);
rule.SetBoolKey("allow_dont_show_again", true);
return rule;
}
......@@ -84,6 +85,7 @@ NotificationMessage CreateDefaultNotification() {
message.message_text = "zh-CN:message";
message.link_text = "zh-CN:link";
message.link_url = "https://example.com/some_link";
message.allow_dont_show_again = true;
return message;
}
......@@ -312,4 +314,23 @@ TEST_F(NotificationClientTest, DebugBuildsDontIgnoreDevMessages) {
client_->GetNotification(kTestEmail, callback.Get());
}
TEST_F(NotificationClientTest, AllowDontShowAgainNotSet_DefaultToFalse) {
base::Value rules(base::Value::Type::LIST);
base::Value rule = CreateDefaultRule();
rule.RemoveKey("allow_dont_show_again");
rules.Append(std::move(rule));
EXPECT_CALL(*fetcher_, FetchJsonFile("notification/rules.json"))
.WillOnce(ReturnByMove(std::move(rules)));
EXPECT_CALL(*fetcher_, FetchJsonFile("notification/message_text.json"))
.WillOnce(ReturnByMove(CreateDefaultTranslations("message")));
EXPECT_CALL(*fetcher_, FetchJsonFile("notification/link_text.json"))
.WillOnce(ReturnByMove(CreateDefaultTranslations("link")));
NotificationMessage notification = CreateDefaultNotification();
notification.allow_dont_show_again = false;
base::MockCallback<NotificationClient::NotificationCallback> callback;
EXPECT_CALL(callback, Run(MessageMatches(notification)));
client_->GetNotification(kTestEmail, callback.Get());
}
} // namespace remoting
\ No newline at end of file
......@@ -28,6 +28,7 @@ struct NotificationMessage final {
std::string message_text;
std::string link_text;
std::string link_url;
bool allow_dont_show_again;
};
} // namespace remoting
......
......@@ -210,7 +210,7 @@ static const CGFloat kDontShowAgainViewHeightAdjustment = 10.f;
- (void)viewDidDisappear:(BOOL)animated {
DCHECK(_completion);
_completion(_dontShowAgainSwitch.on);
_completion(_dontShowAgainSwitch && _dontShowAgainSwitch.on);
// Release the block as long as the dialog is disappeared, since it could
// potentially have retain loop.
_completion = nil;
......
......@@ -125,7 +125,8 @@ void NotificationPresenter::OnNotificationFetched(
objectForFlag:RemotingFlagLastSeenNotificationMessageId]);
NotificationUiState ui_state = NSNumberToUiState([RemotingPreferences.instance
objectForFlag:RemotingFlagNotificationUiState]);
if (ui_state == USER_CHOSE_DONT_SHOW_AGAIN &&
if (notification->allow_dont_show_again &&
ui_state == USER_CHOSE_DONT_SHOW_AGAIN &&
last_seen_message_id == notification->message_id) {
return;
}
......@@ -165,10 +166,12 @@ void NotificationPresenter::OnNotificationFetched(
break;
}
case NotificationMessage::Appearance::DIALOG: {
BOOL shouldShowDontShowAgain = notification->allow_dont_show_again &&
ui_state == SHOWN_AT_LEAST_ONCE;
NotificationDialogViewController* dialogVc =
[[NotificationDialogViewController alloc]
initWithNotificationMessage:*notification
shouldShowDontShowAgainToggle:(ui_state == SHOWN_AT_LEAST_ONCE)];
shouldShowDontShowAgainToggle:shouldShowDontShowAgain];
[dialogVc presentOnTopVCWithCompletion:^(BOOL isDontShowAgainOn) {
NotificationUiState new_ui_state = isDontShowAgainOn
? USER_CHOSE_DONT_SHOW_AGAIN
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment