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

feat: group messages sent within a short timeframe (WPB-6237) #16631

Merged
merged 2 commits into from
Jan 25, 2024
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {useRelativeTimestamp} from 'src/script/hooks/useRelativeTimestamp';
import {StatusType} from 'src/script/message/StatusType';
import {useKoSubscribableChildren} from 'Util/ComponentUtil';
import {getMessageAriaLabel} from 'Util/conversationMessages';
import {fromUnixTime, TIME_IN_MILLIS} from 'Util/TimeUtil';

import {ContentAsset} from './asset';
import {MessageActionsMenu} from './MessageActions/MessageActions';
Expand Down Expand Up @@ -126,13 +125,13 @@ export const ContentMessageComponent: React.FC<ContentMessageProps> = ({
return true;
}

const currentMessageDate = fromUnixTime(message.timestamp() / TIME_IN_MILLIS.SECOND);
const previousMessageDate = fromUnixTime(previousMessage.timestamp() / TIME_IN_MILLIS.SECOND);
// Interval in milliseconds, within which messages are grouped together
const GROUPED_MESSAGE_INTERVAL = 30000;
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Let's use TimeInMillis from our time util :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's use the TIME_IN_MILLIS enum there (to make things easy to read)

Suggested change
const GROUPED_MESSAGE_INTERVAL = 30000;
const GROUPED_MESSAGE_INTERVAL = 30 * TIME_IN_MILLIS.SECOND;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh no, magic number warning :(
Better to keep it here for clarity though in my opinion (instead of currentMessageDate - previousMessageDate >= GROUPED_MESSAGE_INTERVAL * TIME_IN_MILLIS.SECOND)

Copy link
Contributor

Choose a reason for hiding this comment

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

nah it's okay, this magic number warning doesn't really make sense here (we need to fine tuned this one, I find it a little stupid sometimes)


const currentMinute = currentMessageDate.getMinutes();
const previousMinute = previousMessageDate.getMinutes();
const currentMessageDate = message.timestamp();
const previousMessageDate = previousMessage.timestamp();

if (currentMinute !== previousMinute) {
if (currentMessageDate - previousMessageDate >= GROUPED_MESSAGE_INTERVAL) {
return true;
}

Expand Down
Loading