Skip to content

Commit

Permalink
Minor Text Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
braxtondiggs committed Apr 23, 2022
1 parent cdf2461 commit 531aa35
Show file tree
Hide file tree
Showing 5 changed files with 24,399 additions and 3,168 deletions.
2 changes: 1 addition & 1 deletion android/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
applicationId "com.cymbit.paras"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1001
versionName "1.0.1"
versionCode 1002
versionName "1.0.2"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
aaptOptions {
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
Expand Down
14 changes: 4 additions & 10 deletions functions/src/fcm.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import * as admin from 'firebase-admin';
import db from './db';
import * as dayjs from 'dayjs';
import * as weekday from 'dayjs/plugin/weekday';
import { isEmpty } from 'lodash';
dayjs.extend(weekday);

const payload: admin.messaging.MessagingPayload = {
notification: {
Expand All @@ -25,10 +23,10 @@ async function getImmediateNotifications(tweet: any) {
const tokens: string[] = [];
query.forEach(snapshot => promise.push(snapshot));
for (const snapshot of promise) {
const { exceptionOnly, nextDay, today, token, weekend } = snapshot.data();
const { exceptionOnly, nextDay, today, token } = snapshot.data();
if (payload.notification) payload.notification.body = tweet.text;
if (token && !isEmpty(token) && (today === 'immediately' && isToday) || (nextDay === 'immediately' && !isToday)) {
if (checkWeekend(weekend, dayjs(tweet.date)) && checkException(exceptionOnly, tweet.active)) {
if (checkException(exceptionOnly, tweet.active)) {
tokens.push(token);
}
}
Expand All @@ -53,12 +51,12 @@ async function getCustomNotifications() {
const tokens: string[] = [];
query.forEach(snapshot => promise.push(snapshot));
for (const snapshot of promise) {
const { exceptionOnly, nextDay, nextDayCustom, today, todayCustom, token, weekend } = snapshot.data();
const { exceptionOnly, nextDay, nextDayCustom, today, todayCustom, token } = snapshot.data();
let date = isToday ? dayjs().format('MM/DD/YYYY') : dayjs().add(1, 'day').format('MM/DD/YYYY');
date = isToday ? `${date} ${todayCustom}` : `${date} ${nextDayCustom}`;
isActive = dayjs(date).isAfter(dayjs()) && dayjs(date).isBefore(dayjs().add(15, 'minute'));
if ((today === 'custom' && isToday && isActive) || (nextDay === 'custom' && !isToday && isActive)) {
if (token && !isEmpty(token) && checkWeekend(weekend, dayjs(date)) && checkException(exceptionOnly, isActive)) {
if (token && !isEmpty(token) && checkException(exceptionOnly, isActive)) {
tokens.push(token);
}
}
Expand All @@ -85,10 +83,6 @@ async function sendToDevices(tokens: string[], promise: FirebaseFirestore.QueryD
return Promise.all(deadTokens);
}

function checkWeekend(weekend: boolean, date: dayjs.Dayjs): boolean {
return weekend && (date.weekday() === 6 || date.weekday() === 0) || !weekend && date.weekday() !== 6 && date.weekday() !== 0;
}

function checkException(exception: boolean, active: boolean): boolean {
return exception && active ? false : true;
}
Loading

0 comments on commit 531aa35

Please sign in to comment.