Skip to content

Commit

Permalink
feat(messenger-chat/conversation-previews): handle reaction events se…
Browse files Browse the repository at this point in the history
…nt from mobile device (#2345)

* feat(messenger-chat/conversation-previews): handle reaction events sent from mobile device

* refactor: adjust condition for filtering reaction admin messages
  • Loading branch information
domw30 authored Oct 8, 2024
1 parent 2614e7e commit 21d5ee4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/components/chat-view-container/chat-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { Fragment } from 'react';
import { Waypoint } from 'react-waypoint';
import classNames from 'classnames';
import moment from 'moment';
import { Message as MessageModel, MediaType, EditMessageOptions, Media } from '../../store/messages';
import { Message as MessageModel, MediaType, EditMessageOptions, Media, AdminMessageType } from '../../store/messages';
import InvertedScroll from '../inverted-scroll';
import { Lightbox } from '@zer0-os/zos-component-library';
import { User } from '../../store/authentication/types';
Expand Down Expand Up @@ -140,7 +140,7 @@ export class ChatView extends React.Component<Properties, State> {

renderMessageGroup(groupMessages) {
return groupMessages.map((message, index) => {
if (message.isAdmin) {
if (message.isAdmin && message.admin.type !== AdminMessageType.REACTION) {
return <AdminMessageContainer key={message.optimisticId || message.id} message={message} />;
} else {
const messageRenderProps = getMessageRenderProps(
Expand Down
13 changes: 13 additions & 0 deletions src/lib/chat/chat-message.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,19 @@ describe(adminMessageText, () => {

expect(adminText).toEqual('Courtney reacted with 10 MEOW');
});

it('translates message if amount is not found', () => {
const state = getState('current-user', { 'admin-user-id': { id: 'admin-user-id', firstName: 'Courtney' } });
const message = {
message: 'some message',
isAdmin: true,
admin: { type: AdminMessageType.REACTION, userId: 'admin-user-id' },
} as any;

const adminText = adminMessageText(message, state);

expect(adminText).toEqual('Courtney sent a reaction');
});
});
});

Expand Down
15 changes: 12 additions & 3 deletions src/lib/chat/chat-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,21 @@ export function adminMessageText(message: Message, state: RootState) {
}

function translateReaction(admin: { userId?: string; amount?: string }, currentUser, state: RootState) {
if (admin.userId === currentUser.id) {
const user = denormalizeUser(admin.userId, state);

if (!admin.amount && admin.userId === currentUser.id) {
return 'You sent a reaction';
}

if (!admin.amount && user?.firstName) {
return `${user.firstName} sent a reaction`;
}

if (admin.amount && admin.userId === currentUser.id) {
return `You reacted with ${admin.amount} MEOW`;
}

const user = denormalizeUser(admin.userId, state);
return user?.firstName ? `${user.firstName} reacted with ${admin.amount} MEOW` : null;
return admin.amount && user?.firstName ? `${user.firstName} reacted with ${admin.amount} MEOW` : null;
}

function translateJoinedZero(admin: { inviteeId?: string; inviterId?: string }, currentUser, state: RootState) {
Expand Down

0 comments on commit 21d5ee4

Please sign in to comment.