Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/rewards pings integration #69

Merged
Merged
Changes from 1 commit
Commits
File filter
Filter file types
Jump to
Jump to file
Failed to load files.

Always

Just for now

Next
persist in localstorage with prefs
  • Loading branch information
trickpattyFH20 authored and IAmThePan committed May 19, 2018
commit 3f801800aa95a225a8503b1fe7040127c85a7313
@@ -430,6 +430,7 @@ function handleRewards(name, message, tab_id, callback) {
button.update();
break;
case 'deleteReward':
rewards.markRewardRead(message.offerId);
rewards.deleteReward(message.offerId);
button.update();
break;
@@ -246,6 +246,7 @@ class PanelData {
enable_offers: this._confData.get('enable_offers'),
rewards: rewards.storedOffers,
unread_offer_ids: rewards.unreadOfferIds,
total_offers_seen: rewards.totalOffersSeen,
};
return this._rewardsView;
}
@@ -19,7 +19,7 @@ import conf from './Conf';
import tabInfo from './TabInfo';
import Policy from './Policy';
import globals from './Globals';
import { log } from '../utils/common';
import { log, prefsGet, prefsSet } from '../utils/common';
import { sendMessage, injectScript } from '../utils/utils';
import * as accounts from '../utils/accounts';

@@ -31,22 +31,22 @@ const t = chrome.i18n.getMessage;
*/
class Rewards {
constructor() {
this.storedOffers = {};
this.unreadOfferIds = [];
this.getStoredOffers();
this.currentOffer = null;
this.ports = new Map();
this.channelsSupported = (typeof chrome.runtime.onConnect === 'object');
}

deleteReward(offerId) {
this.markRewardRead(offerId);
delete this.storedOffers[offerId];
// @TODO send signal?
this.updateStoredOffers();
}

markRewardRead(offerId) {
const rewardIdx = this.unreadOfferIds.indexOf(offerId);
this.unreadOfferIds.splice(rewardIdx, 1);
this.updateStoredOffers();
}

sendSignal(message) {
@@ -62,7 +62,24 @@ class Rewards {
cliqz.modules['offers-v2'].background.actions.processRealEstateMessage(signal);
}

getStoredOffers() {
return prefsGet('storedOffers', 'unreadOfferIds', 'totalOffersSeen')
.then((response) => {
this.storedOffers = response.storedOffers || {};
this.unreadOfferIds = response.unreadOfferIds || [];
this.totalOffersSeen = response.totalOffersSeen || 0;
});
}

updateStoredOffers() {
prefsSet({ storedOffers: this.storedOffers });
prefsSet({ unreadOfferIds: this.unreadOfferIds }).then(() => { button.update(); });
}

showHotDog(tab_id, offer) {
this.updateStoredOffers();
this.totalOffersSeen++;
prefsSet({ totalOffersSeen: this.totalOffersSeen });
this.currentOffer = offer;
const tab = tabInfo.getTabInfo(tab_id);

ProTip! Use n and p to navigate between commits in a pull request.