diff --git a/browser/extensions/api/brave_rewards_api.cc b/browser/extensions/api/brave_rewards_api.cc index 2cb95e86bafe..6707376f0d1a 100644 --- a/browser/extensions/api/brave_rewards_api.cc +++ b/browser/extensions/api/brave_rewards_api.cc @@ -105,9 +105,9 @@ BraveRewardsDonateToTwitterUserFunction::Run() { if (rewards_service) { AddRef(); std::map args; - args["user_id"] = params->user_id; - args["name"] = params->name; - args["screen_name"] = params->screen_name; + args["user_id"] = params->tweet_meta_data.user_id; + args["name"] = params->tweet_meta_data.name; + args["screen_name"] = params->tweet_meta_data.screen_name; rewards_service->SaveTwitterPublisherInfo( args, base::Bind(&BraveRewardsDonateToTwitterUserFunction:: @@ -145,12 +145,17 @@ void BraveRewardsDonateToTwitterUserFunction::OnTwitterPublisherInfoSaved( auto params_dict = std::make_unique(); params_dict->SetString("publisherKey", publisher_info->id); - auto tweet_metadata_dict = std::make_unique(); - tweet_metadata_dict->SetString("name", publisher_info->name); - tweet_metadata_dict->SetString("screenName", params->screen_name); - tweet_metadata_dict->SetString("tweetId", params->tweet_id); - tweet_metadata_dict->SetString("tweetText", params->tweet_text); - params_dict->SetDictionary("tweetMetaData", std::move(tweet_metadata_dict)); + auto tweet_meta_data_dict = std::make_unique(); + tweet_meta_data_dict->SetString("name", publisher_info->name); + tweet_meta_data_dict->SetString("screenName", + params->tweet_meta_data.screen_name); + tweet_meta_data_dict->SetString("userId", params->tweet_meta_data.user_id); + tweet_meta_data_dict->SetString("tweetId", params->tweet_meta_data.tweet_id); + tweet_meta_data_dict->SetInteger("tweetTimestamp", + params->tweet_meta_data.tweet_timestamp); + tweet_meta_data_dict->SetString("tweetText", + params->tweet_meta_data.tweet_text); + params_dict->SetDictionary("tweetMetaData", std::move(tweet_meta_data_dict)); ::brave_rewards::OpenDonationDialog(contents, std::move(params_dict)); diff --git a/common/extensions/api/brave_rewards.json b/common/extensions/api/brave_rewards.json index 80ff319f94f4..b009bd1ebd1a 100644 --- a/common/extensions/api/brave_rewards.json +++ b/common/extensions/api/brave_rewards.json @@ -364,24 +364,34 @@ "type": "integer" }, { - "name": "userId", - "type": "string" - }, - { - "name": "name", - "type": "string" - }, - { - "name": "screenName", - "type": "string" - }, - { - "name": "tweetId", - "type": "string" - }, - { - "name": "tweetText", - "type": "string" + "name": "tweetMetaData", + "type": "object", + "properties": { + "userId": { + "type": "string", + "description": "User ID of tweet author" + }, + "name": { + "type": "string", + "description": "Name of tweet author" + }, + "screenName": { + "type": "string", + "description": "Twitter handle of tweet author" + }, + "tweetId": { + "type": "string", + "description": "Unique tweet ID" + }, + "tweetTimestamp": { + "type": "number", + "description": "Timestamp (in milliseconds) of tweet" + }, + "tweetText": { + "type": "string", + "description": "Textual contents of tweet" + } + } } ] }, diff --git a/components/brave_rewards/resources/extension/brave_rewards/background.ts b/components/brave_rewards/resources/extension/brave_rewards/background.ts index da097bf51537..8ed9e26c7a78 100644 --- a/components/brave_rewards/resources/extension/brave_rewards/background.ts +++ b/components/brave_rewards/resources/extension/brave_rewards/background.ts @@ -78,7 +78,7 @@ chrome.runtime.onConnect.addListener(function () { }) }) -const donateToTwitterUser = (userId: string, name: string, screenName: string, tweetId: string, tweetText: string) => { +const donateToTwitterUser = (tweetMetaData: RewardsDonate.TweetMetaData) => { chrome.tabs.query({ active: true, windowId: chrome.windows.WINDOW_ID_CURRENT @@ -90,7 +90,7 @@ const donateToTwitterUser = (userId: string, name: string, screenName: string, t if (tabId === undefined) { return } - chrome.braveRewards.donateToTwitterUser(tabId, userId, name, screenName, tweetId, tweetText) + chrome.braveRewards.donateToTwitterUser(tabId, tweetMetaData) }) } @@ -98,7 +98,7 @@ chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => { const action = typeof msg === 'string' ? msg : msg.type switch (action) { case 'donateToTwitterUser': { - donateToTwitterUser(msg.userId, msg.name, msg.screenName, msg.tweetId, msg.tweetText) + donateToTwitterUser(msg.tweetMetaData) return false } case 'rewardsEnabled': { diff --git a/components/brave_rewards/resources/extension/brave_rewards/content.ts b/components/brave_rewards/resources/extension/brave_rewards/content.ts index 3d9be2691793..83cb7a852a83 100644 --- a/components/brave_rewards/resources/extension/brave_rewards/content.ts +++ b/components/brave_rewards/resources/extension/brave_rewards/content.ts @@ -13,11 +13,17 @@ const getTweetMetaData = (tweet: Element): RewardsDonate.TweetMetaData | null => if (!tweetTextElements || tweetTextElements.length === 0) { return null } + const tweetTimestampElements = tweet.getElementsByClassName('js-short-timestamp') + if (!tweetTimestampElements || tweetTimestampElements.length === 0) { + return null + } + const tweetTimestamp = tweetTimestampElements[0].getAttribute('data-time-ms') || '' return { name: tweet.getAttribute('data-name') || '', screenName: tweet.getAttribute('data-screen-name') || '', userId: tweet.getAttribute('data-user-id') || '', tweetId: tweet.getAttribute('data-tweet-id') || '', + tweetTimestamp: parseInt(tweetTimestamp, 10) || 0, tweetText: tweetTextElements[0].textContent || '' } } @@ -34,7 +40,7 @@ const createBraveTipAction = (tweet: Element) => { braveTipButton.onclick = function (event) { const tweetMetaData = getTweetMetaData(tweet) if (tweetMetaData) { - const msg = { type: 'donateToTwitterUser', ...tweetMetaData } + const msg = { type: 'donateToTwitterUser', tweetMetaData: tweetMetaData } chrome.runtime.sendMessage(msg) } } diff --git a/components/definitions/chromel.d.ts b/components/definitions/chromel.d.ts index 453a38335fb7..0d3c251af919 100644 --- a/components/definitions/chromel.d.ts +++ b/components/definitions/chromel.d.ts @@ -15,7 +15,7 @@ declare namespace chrome.dns { declare namespace chrome.braveRewards { const createWallet: () => {} const donateToSite: (tabId: number, publisherKey: string) => {} - const donateToTwitterUser: (tabId: number, userId: string, name: string, screenName: string, tweetId: string, tweetText: string) => {} + const donateToTwitterUser: (tabId: number, tweetMetaData: RewardsDonate.TweetMetaData) => {} const getPublisherData: (windowId: number, url: string, faviconUrl: string, publisherBlob: string | undefined) => {} const getWalletProperties: () => {} const getCurrentReport: () => {} diff --git a/components/definitions/rewardsDonate.d.ts b/components/definitions/rewardsDonate.d.ts index beae954a1536..95e7e46f1d4a 100644 --- a/components/definitions/rewardsDonate.d.ts +++ b/components/definitions/rewardsDonate.d.ts @@ -37,6 +37,7 @@ declare namespace RewardsDonate { screenName: string userId: string tweetId: string + tweetTimestamp: number tweetText: string }