Skip to content

Commit

Permalink
Send push notifications according to users local timezone. resolves #138
Browse files Browse the repository at this point in the history
  • Loading branch information
mskg committed Mar 19, 2020
1 parent a6a47f6 commit b757989
Show file tree
Hide file tree
Showing 18 changed files with 365 additions and 191 deletions.
2 changes: 1 addition & 1 deletion apps/tabler-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,4 @@
"typescript": "3.7.4",
"typescript-tslint-plugin": "^0.5.5"
}
}
}
4 changes: 1 addition & 3 deletions apps/tabler-app/src/auth/ConfirmSignIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { parseLink } from '../helper/linking/parseLink';
import { Categories, Logger } from '../helper/Logger';
import { I18N } from '../i18n/translation';
import { IAppState } from '../model/IAppState';
import { restoreSettings, storeLanguage } from '../redux/actions/settings';
import { restoreSettings } from '../redux/actions/settings';
import { signin, singedIn } from '../redux/actions/user';
import { Background, Greeting, Logo } from './Background';
import Input from './Input';
Expand All @@ -26,7 +26,6 @@ type Props = {
singedIn: typeof singedIn;
signin: typeof signin,
restoreSettings: typeof restoreSettings,
storeLanguage: typeof storeLanguage,
};

type State = {
Expand Down Expand Up @@ -228,6 +227,5 @@ export default connect(
restoreSettings,
singedIn,
signin,
storeLanguage,
},
)(withTheme(ConfirmBase));
3 changes: 3 additions & 0 deletions apps/tabler-app/src/i18n/translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { I18NType } from './I18NType';
import { pluralize, PluralizeFunc } from './pluralize';
import DEFAULT_LANGUAGE from './translations/defaultLanguage';
import { formatNumber, FormatNumberFunc } from './formatNumber';
import * as Localization from 'expo-localization';

const logger = new Logger(Categories.App);

Expand All @@ -29,6 +30,7 @@ export function replaceCurrentLanguage(otherLang: any) {
// moment is loaded with all available locales
moment.locale((currentLanguage as I18NType).id);

currentLanguage.timezone = Localization.timezone;
currentLanguage.format = format;
currentLanguage.pluralize = pluralize;
currentLanguage.formatDate = formatDate;
Expand Down Expand Up @@ -66,6 +68,7 @@ loadLanguage(getAppLanguage());

// tslint:disable-next-line: export-name
export const I18N: I18NType & {
timezone: string,
format: FormatFunc,
formatDate: FormatDateFunc,
pluralize: PluralizeFunc,
Expand Down
1 change: 1 addition & 0 deletions apps/tabler-app/src/model/graphql/AddressFragment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export interface AddressFragment {
street2: string | null;
postal_code: string | null;
city: string | null;
country: string | null;
}
2 changes: 2 additions & 0 deletions apps/tabler-app/src/model/graphql/Club.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface Club_Club_meetingplace1 {
street2: string | null;
postal_code: string | null;
city: string | null;
country: string | null;
location: Club_Club_meetingplace1_location | null;
}

Expand All @@ -60,6 +61,7 @@ export interface Club_Club_meetingplace2 {
street2: string | null;
postal_code: string | null;
city: string | null;
country: string | null;
location: Club_Club_meetingplace2_location | null;
}

Expand Down
21 changes: 21 additions & 0 deletions apps/tabler-app/src/model/graphql/PushTimezone.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* tslint:disable */
/* eslint-disable */
// @generated
// This file was automatically generated and should not be edited.

import { SettingInput } from "./globalTypes";

// ====================================================
// GraphQL mutation operation: PushTimezone
// ====================================================

export interface PushTimezone {
/**
* Updates a setting
*/
putSetting: boolean | null;
}

export interface PushTimezoneVariables {
input: SettingInput;
}
1 change: 1 addition & 0 deletions apps/tabler-app/src/model/graphql/globalTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export enum SettingName {
nearbymembers = "nearbymembers",
nearbymembersMap = "nearbymembersMap",
notifications = "notifications",
timezone = "timezone",
}

export enum UserRole {
Expand Down
4 changes: 0 additions & 4 deletions apps/tabler-app/src/redux/actions/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,3 @@ export const notificationState = createAction<'@@settings/notificationsAvailable
export const restoreSettings = createAction<'@@settings/restoreSettings'>(
'@@settings/restoreSettings',
);

export const storeLanguage = createAction<'@@settings/storeLanguage'>(
'@@settings/storeLanguage',
);
6 changes: 3 additions & 3 deletions apps/tabler-app/src/sagas/settings/pushLanguage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { I18N } from '../../i18n/translation';
import { SettingName } from '../../model/graphql/globalTypes';
import { Pushlanguage, PushlanguageVariables } from '../../model/graphql/Pushlanguage';

export const LANGUAGE_KEY = 'Language';
const LANGUAGE_KEY = 'setting:language';

export function* pushLanguage(/* _a: typeof settingsActions.storeLanguage.shape */) {
export function* pushLanguage() {
const client: ApolloClient<NormalizedCacheObject> = cachedAolloClient();

const existingLanguage = yield AsyncStorage.getItem(LANGUAGE_KEY);
Expand All @@ -18,7 +18,7 @@ export function* pushLanguage(/* _a: typeof settingsActions.storeLanguage.shape
yield client.mutate<Pushlanguage, PushlanguageVariables>({
mutation: gql`
mutation Pushlanguage($input: SettingInput!) {
putSetting (setting: $input)
putSetting (setting: $input)
}`,
variables: {
input: {
Expand Down
34 changes: 34 additions & 0 deletions apps/tabler-app/src/sagas/settings/pushTimezone.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { NormalizedCacheObject } from 'apollo-cache-inmemory';
import { ApolloClient } from 'apollo-client';
import gql from 'graphql-tag';
import { AsyncStorage } from 'react-native';
import { cachedAolloClient } from '../../apollo/bootstrapApollo';
import { I18N } from '../../i18n/translation';
import { SettingName } from '../../model/graphql/globalTypes';
import { PushTimezone, PushTimezoneVariables } from '../../model/graphql/PushTimezone';

const TIMEZONE_KEY = 'setting:timezone';

export function* pushTimezone() {
const client: ApolloClient<NormalizedCacheObject> = cachedAolloClient();

const kownTimezone = yield AsyncStorage.getItem(TIMEZONE_KEY);
const value = I18N.timezone;

if (kownTimezone !== value) {
yield client.mutate<PushTimezone, PushTimezoneVariables>({
mutation: gql`
mutation PushTimezone($input: SettingInput!) {
putSetting (setting: $input)
}`,
variables: {
input: {
value,
name: SettingName.timezone,
},
},
});

yield AsyncStorage.setItem(TIMEZONE_KEY, value);
}
}
2 changes: 0 additions & 2 deletions apps/tabler-app/src/sagas/settingsSaga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import * as filterActions from '../redux/actions/filter';
import * as settingsActions from '../redux/actions/settings';
import { checkAndDisableNotifications } from './settings/checkAndDisableNotifications';
import { checkLinking } from './settings/checkLinking';
import { pushLanguage } from './settings/pushLanguage';
import { restoreSettingsFromCloud } from './settings/restoreSettingsFromCloud';
import { saveFavoritesToCloud } from './settings/saveFavoritesToCloud';
import { saveNotificationSettingsToCloud } from './settings/saveNotificationSettingsToCloud';
Expand All @@ -16,7 +15,6 @@ export function* settingsSaga(): SagaIterator {

// restore settings
takeLatest(settingsActions.restoreSettings.type, restoreSettingsFromCloud),
takeLatest(settingsActions.storeLanguage.type, pushLanguage),

// mark record as modified on favorite toggle
debounce(
Expand Down
3 changes: 3 additions & 0 deletions apps/tabler-app/src/sagas/startup/syncAllSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { IAppState } from '../../model/IAppState';
import { AuthState } from '../../model/state/AuthState';
import { singedIn } from '../../redux/actions/user';
import { pushLanguage } from '../settings/pushLanguage';
import { pushTimezone } from '../settings/pushTimezone';
import { restoreSettingsFromCloud } from '../settings/restoreSettingsFromCloud';
import { logger } from './logger';

Expand All @@ -19,5 +20,7 @@ export function* syncAllSettings() {
yield updateParameters();

yield fork(pushLanguage);
yield fork(pushTimezone);

yield fork(restoreSettingsFromCloud);
}
Loading

0 comments on commit b757989

Please sign in to comment.