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

Standardize on using created instead of timestamp #12540

Merged
merged 22 commits into from
Nov 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@
</activity>

<meta-data android:name="com.urbanairship.reactnative.AIRSHIP_EXTENDER"
android:value="com.expensify.chat.CustomAirshipExtender" />
android:value="com.expensify.chat.customairshipextender.CustomAirshipExtender" />
</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,23 @@

import android.content.Context;
import android.database.CursorWindow;

import androidx.multidex.MultiDexApplication;

import com.expensify.chat.bootsplash.BootSplashPackage;
import com.facebook.react.PackageList;
import com.facebook.react.ReactApplication;
import com.reactnativecommunity.webview.RNCWebViewPackage;
import com.reactnativecommunity.webview.RNCWebViewPackage;
import com.reactnativecommunity.webview.RNCWebViewPackage;
import com.existfragger.rnimagesize.RNImageSizePackage;
import com.google.firebase.crashlytics.FirebaseCrashlytics;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.config.ReactFeatureFlags;
import com.facebook.react.modules.i18nmanager.I18nUtil;
import com.facebook.soloader.SoLoader;
import java.lang.reflect.InvocationTargetException;
import com.google.firebase.crashlytics.FirebaseCrashlytics;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import com.facebook.react.modules.i18nmanager.I18nUtil;

public class MainApplication extends MultiDexApplication implements ReactApplication {

Expand Down Expand Up @@ -111,13 +110,7 @@ private static void initializeFlipper(
aClass
.getMethod("initializeFlipper", Context.class, ReactInstanceManager.class)
.invoke(null, context, reactInstanceManager);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
} catch (Exception e) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

e.printStackTrace();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package com.expensify.chat;

import android.util.Log;

import com.facebook.react.bridge.ReactApplicationContext;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.expensify.chat;
package com.expensify.chat.customairshipextender;

import android.content.Context;
import androidx.annotation.NonNull;
Expand All @@ -18,4 +18,4 @@ public void onAirshipReady(@NonNull Context context, @NonNull UAirship airship)
NotificationListener notificationListener = airship.getPushManager().getNotificationListener();
pushManager.setNotificationListener(new CustomNotificationListener(notificationListener, notificationProvider));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.expensify.chat;
package com.expensify.chat.customairshipextender;

import androidx.annotation.NonNull;
import com.urbanairship.push.NotificationActionButtonInfo;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.expensify.chat;
package com.expensify.chat.customairshipextender;

import android.content.Context;
import android.graphics.Bitmap;
Expand Down Expand Up @@ -26,6 +26,8 @@
import com.urbanairship.util.ImageUtils;
import java.net.MalformedURLException;
import java.net.URL;
import java.sql.Timestamp;
import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -126,7 +128,7 @@ private void applyMessageStyle(@NonNull Context context, NotificationCompat.Buil
String avatar = reportAction.get("avatar").getString();
String accountID = Integer.toString(reportAction.get("actorAccountID").getInt(-1));
String message = reportAction.get("message").getList().get(0).getMap().get("text").getString();
long time = reportAction.get("timestamp").getLong(0);
long time = Timestamp.valueOf(reportAction.get("created").getString(Instant.now().toString())).getTime();
String roomName = payload.get("roomName") == null ? "" : payload.get("roomName").getString("");
String conversationTitle = "Chat with " + name;
if (!roomName.isEmpty()) {
Expand Down
26 changes: 13 additions & 13 deletions src/components/withLocalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ const withLocalizePropTypes = {
/** Formats number formatted according to locale and options */
numberFormat: PropTypes.func.isRequired,

/** Converts a timestamp into a localized string representation that's relative to current moment in time */
timestampToRelative: PropTypes.func.isRequired,
/** Converts a datetime into a localized string representation that's relative to current moment in time */
datetimeToRelative: PropTypes.func.isRequired,

/** Formats a timestamp to local date and time string */
timestampToDateTime: PropTypes.func.isRequired,
/** Formats a datetime to local date and time string */
datetimeToCalendarTime: PropTypes.func.isRequired,

/** Returns a locally converted phone number without the country code */
toLocalPhone: PropTypes.func.isRequired,
Expand Down Expand Up @@ -59,8 +59,8 @@ class LocaleContextProvider extends React.Component {
return {
translate: this.translate.bind(this),
numberFormat: this.numberFormat.bind(this),
timestampToRelative: this.timestampToRelative.bind(this),
timestampToDateTime: this.timestampToDateTime.bind(this),
datetimeToRelative: this.datetimeToRelative.bind(this),
datetimeToCalendarTime: this.datetimeToCalendarTime.bind(this),
fromLocalPhone: this.fromLocalPhone.bind(this),
toLocalPhone: this.toLocalPhone.bind(this),
fromLocaleDigit: this.fromLocaleDigit.bind(this),
Expand Down Expand Up @@ -88,22 +88,22 @@ class LocaleContextProvider extends React.Component {
}

/**
* @param {Number} timestamp
* @param {String} datetime
* @returns {String}
*/
timestampToRelative(timestamp) {
return DateUtils.timestampToRelative(this.props.preferredLocale, timestamp);
datetimeToRelative(datetime) {
return DateUtils.datetimeToRelative(this.props.preferredLocale, datetime);
}

/**
* @param {Number} timestamp
* @param {String} datetime - ISO-formatted datetime string
* @param {Boolean} [includeTimezone]
* @returns {String}
*/
timestampToDateTime(timestamp, includeTimezone) {
return DateUtils.timestampToDateTime(
datetimeToCalendarTime(datetime, includeTimezone) {
return DateUtils.datetimeToCalendarTime(
this.props.preferredLocale,
timestamp,
datetime,
includeTimezone,
);
}
Expand Down
45 changes: 28 additions & 17 deletions src/libs/DateUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,41 +33,41 @@ Onyx.connect({
});

/**
* Gets the user's stored time-zone NVP and returns a localized
* Moment object for the given timestamp
* Gets the user's stored time zone NVP and returns a localized
* Moment object for the given ISO-formatted datetime string
*
* @param {String} locale
* @param {Number} timestamp
* @param {String} datetime
* @param {String} [currentSelectedTimezone]
*
* @returns {Moment}
*
* @private
*/
function getLocalMomentFromTimestamp(locale, timestamp, currentSelectedTimezone = timezone.selected) {
function getLocalMomentFromDatetime(locale, datetime, currentSelectedTimezone = timezone.selected) {
moment.locale(locale);
if (!timestamp) {
if (!datetime) {
return moment.tz(currentSelectedTimezone);
}
return moment.unix(timestamp).tz(currentSelectedTimezone);
return moment.utc(datetime).tz(currentSelectedTimezone);
}

/**
* Formats a timestamp to local date and time string
* Formats an ISO-formatted datetime string to local date and time string
*
* e.g.
*
* Jan 20 at 5:30 PM within the past year
* Jan 20, 2019 at 5:30 PM anything over 1 year ago
*
* @param {String} locale
* @param {Number} timestamp
* @param {String} datetime
* @param {Boolean} includeTimeZone
*
* @returns {String}
*/
function timestampToDateTime(locale, timestamp, includeTimeZone = false) {
const date = getLocalMomentFromTimestamp(locale, timestamp);
function datetimeToCalendarTime(locale, datetime, includeTimeZone = false) {
const date = getLocalMomentFromDatetime(locale, datetime);
const tz = includeTimeZone ? ' [UTC]Z' : '';

const todayAt = Localize.translate(locale, 'common.todayAt');
Expand All @@ -86,7 +86,7 @@ function timestampToDateTime(locale, timestamp, includeTimeZone = false) {
}

/**
* Converts a timestamp into a localized string representation
* Converts an ISO-formatted datetime string into a localized string representation
* that's relative to current moment in time.
*
* e.g.
Expand All @@ -99,12 +99,12 @@ function timestampToDateTime(locale, timestamp, includeTimeZone = false) {
* Jan 20, 2019 anything over 1 year
*
* @param {String} locale
* @param {Number} timestamp
* @param {String} datetime
*
* @returns {String}
*/
function timestampToRelative(locale, timestamp) {
const date = getLocalMomentFromTimestamp(locale, timestamp);
function datetimeToRelative(locale, datetime) {
const date = getLocalMomentFromDatetime(locale, datetime);

return moment(date).fromNow();
}
Expand Down Expand Up @@ -161,18 +161,29 @@ function getMicroseconds() {
return Date.now() * CONST.MICROSECONDS_PER_MS;
}

/**
* Returns the current time in milliseconds in the format expected by the database
* @returns {String}
*/
function currentDBTime() {
return new Date().toISOString()
.replace('T', ' ')
.replace('Z', '');
}

/**
* @namespace DateUtils
*/
const DateUtils = {
timestampToRelative,
timestampToDateTime,
datetimeToRelative,
datetimeToCalendarTime,
startCurrentDateUpdater,
getLocalMomentFromTimestamp,
getLocalMomentFromDatetime,
getCurrentTimezone,
canUpdateTimezone,
setTimezoneUpdated,
getMicroseconds,
currentDBTime,
};

export default DateUtils;
3 changes: 2 additions & 1 deletion src/libs/ReportActionsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import _ from 'underscore';
import lodashMerge from 'lodash/merge';
import ExpensiMark from 'expensify-common/lib/ExpensiMark';
import Onyx from 'react-native-onyx';
import moment from 'moment';
import * as CollectionUtils from './CollectionUtils';
import CONST from '../CONST';
import ONYXKEYS from '../ONYXKEYS';
Expand Down Expand Up @@ -83,7 +84,7 @@ function isConsecutiveActionMadeByPreviousActor(reportActions, actionIndex) {
}

// Comments are only grouped if they happen within 5 minutes of each other
if (currentAction.action.timestamp - previousAction.action.timestamp > 300) {
if (moment(currentAction.action.created).unix() - moment(previousAction.action.created).unix() > 300) {
return false;
}

Expand Down
8 changes: 4 additions & 4 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import _ from 'underscore';
import Str from 'expensify-common/lib/str';
import lodashGet from 'lodash/get';
import Onyx from 'react-native-onyx';
import moment from 'moment';
import ExpensiMark from 'expensify-common/lib/ExpensiMark';
import ONYXKEYS from '../ONYXKEYS';
import CONST from '../CONST';
Expand All @@ -15,6 +14,7 @@ import ROUTES from '../ROUTES';
import * as NumberUtils from './NumberUtils';
import * as NumberFormatUtils from './NumberFormatUtils';
import Permissions from './Permissions';
import DateUtils from './DateUtils';

let sessionEmail;
Onyx.connect({
Expand Down Expand Up @@ -643,7 +643,7 @@ function buildOptimisticReportAction(sequenceNumber, text, file) {
sequenceNumber,
clientID: NumberUtils.generateReportActionClientID(),
avatar: lodashGet(allPersonalDetails, [currentUserEmail, 'avatar'], getDefaultAvatar(currentUserEmail)),
timestamp: moment().unix(),
created: DateUtils.currentDBTime(),
message: [
{
type: CONST.REPORT.MESSAGE.TYPE.COMMENT,
Expand Down Expand Up @@ -795,7 +795,7 @@ function buildOptimisticIOUReportAction(sequenceNumber, type, amount, currency,
reportActionID: NumberUtils.rand64(),
sequenceNumber,
shouldShow: true,
timestamp: moment().unix(),
created: DateUtils.currentDBTime(),
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
};
}
Expand Down Expand Up @@ -883,7 +883,7 @@ function buildOptimisticCreatedReportAction(ownerEmail) {
automatic: false,
sequenceNumber: 0,
avatar: lodashGet(allPersonalDetails, [currentUserEmail, 'avatar'], getDefaultAvatar(currentUserEmail)),
timestamp: moment().unix(),
created: DateUtils.currentDBTime(),
shouldShow: true,
},
};
Expand Down
4 changes: 2 additions & 2 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -1323,12 +1323,12 @@ Onyx.connect({
return;
}

if (!action.timestamp) {
if (!action.created) {
return;
}

// If we are past the deadline to notify for this comment don't do it
if (moment.utc(action.timestamp * 1000).isBefore(moment.utc().subtract(10, 'seconds'))) {
if (moment.utc(moment(action.created).unix() * 1000).isBefore(moment.utc().subtract(10, 'seconds'))) {
handledReportActions[reportID] = handledReportActions[reportID] || {};
handledReportActions[reportID][action.sequenceNumber] = true;
return;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/DetailsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class DetailsPage extends React.PureComponent {
// If we have a reportID param this means that we
// arrived here via the ParticipantsPage and should be allowed to navigate back to it
const shouldShowBackButton = Boolean(this.props.route.params.reportID);
const timezone = details.timezone ? DateUtils.getLocalMomentFromTimestamp(this.props.preferredLocale, null, details.timezone.selected) : null;
const timezone = details.timezone ? DateUtils.getLocalMomentFromDatetime(this.props.preferredLocale, null, details.timezone.selected) : null;
const GMTTime = timezone ? `${timezone.toString().split(/[+-]/)[0].slice(-3)} ${timezone.zoneAbbr()}` : '';
const currentTime = (timezone && Number.isNaN(Number(timezone.zoneAbbr()))) ? timezone.zoneAbbr() : GMTTime;
const shouldShowLocalTime = !ReportUtils.hasExpensifyEmails([details.login]);
Expand Down
4 changes: 2 additions & 2 deletions src/pages/home/report/ParticipantLocalTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class ParticipantLocalTime extends PureComponent {

getParticipantLocalTime() {
const reportRecipientTimezone = lodashGet(this.props.participant, 'timezone', CONST.DEFAULT_TIME_ZONE);
const reportTimezone = DateUtils.getLocalMomentFromTimestamp(this.props.preferredLocale, null, reportRecipientTimezone.selected);
const currentTimezone = DateUtils.getLocalMomentFromTimestamp(this.props.preferredLocale);
const reportTimezone = DateUtils.getLocalMomentFromDatetime(this.props.preferredLocale, null, reportRecipientTimezone.selected);
const currentTimezone = DateUtils.getLocalMomentFromDatetime(this.props.preferredLocale);
const reportRecipientDay = reportTimezone.format('dddd');
const currentUserDay = currentTimezone.format('dddd');

Expand Down
4 changes: 2 additions & 2 deletions src/pages/home/report/ReportActionItemDate.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import {withCurrentDate} from '../../../components/OnyxProvider';

const propTypes = {
/** UTC timestamp for when the action was created */
timestamp: PropTypes.number.isRequired,
created: PropTypes.string.isRequired,
...withLocalizePropTypes,
};

const ReportActionItemDate = props => (
<Text style={[styles.chatItemMessageHeaderTimestamp]}>
{props.timestampToDateTime(props.timestamp)}
{props.datetimeToCalendarTime(props.created)}
</Text>
);

Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/report/ReportActionItemSingle.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const ReportActionItemSingle = (props) => {
/>
))}
</Pressable>
<ReportActionItemDate timestamp={props.action.timestamp} />
<ReportActionItemDate created={props.action.created} />
</View>
) : null}
{props.children}
Expand Down
Loading