Skip to content

Commit

Permalink
refactor: code legibility improvements for failure to send handling […
Browse files Browse the repository at this point in the history
…FS-1571] (#14826)

* refactor: code legibility improvements for failure to send handling [FS-1571]

* address code review

* remove unnecessary typing
  • Loading branch information
V-Gira committed Mar 13, 2023
1 parent 767021a commit 280fa38
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
11 changes: 5 additions & 6 deletions src/script/components/MessagesList/Message/MessageWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {WebAppEvents} from '@wireapp/webapp-events';
import {OutgoingQuote} from 'src/script/conversation/MessageRepository';
import {ContentMessage} from 'src/script/entity/message/ContentMessage';
import {Text} from 'src/script/entity/message/Text';
import {MentionEntity} from 'src/script/message/MentionEntity';
import {QuoteEntity} from 'src/script/message/QuoteEntity';
import {t} from 'Util/LocalizerUtil';

Expand All @@ -53,6 +52,10 @@ import {ContextMenuEntry} from '../../../ui/ContextMenu';

import {MessageParams} from './index';

const isOutgoingQuote = (quoteEntity: QuoteEntity): quoteEntity is OutgoingQuote => {
return quoteEntity.hash !== undefined;
};

export const MessageWrapper: React.FC<MessageParams & {hasMarker: boolean; isMessageFocused: boolean}> = ({
message,
conversation,
Expand Down Expand Up @@ -101,12 +104,8 @@ export const MessageWrapper: React.FC<MessageParams & {hasMarker: boolean; isMes
if (firstAsset instanceof Text) {
const messageId = message.id;
const messageText = firstAsset.text;
const mentions: MentionEntity[] = firstAsset.mentions() && firstAsset.mentions();
const mentions = firstAsset.mentions();
const incomingQuote = message.quote();

const isOutgoingQuote = (quoteEntity: QuoteEntity): quoteEntity is OutgoingQuote => {
return quoteEntity.hash !== undefined;
};
const quote: OutgoingQuote | undefined =
incomingQuote && isOutgoingQuote(incomingQuote) ? (incomingQuote as OutgoingQuote) : undefined;

Expand Down
2 changes: 1 addition & 1 deletion src/script/conversation/EventMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export class EventMapper {
const {id, data: eventData, edited_time: editedTime, conversation, qualified_conversation} = event;

if (eventData.quote) {
const {hash: hash, message_id: messageId, user_id: userId, error} = eventData.quote;
const {hash, message_id: messageId, user_id: userId, error} = eventData.quote;
originalEntity.quote(new QuoteEntity({error, hash, messageId, userId}));
}

Expand Down
5 changes: 2 additions & 3 deletions src/script/conversation/MessageRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1143,9 +1143,8 @@ export class MessageRepository {
private async updateMessageAsFailed(conversationEntity: Conversation, eventId: string) {
try {
const messageEntity = await this.getMessageInConversationById(conversationEntity, eventId);
const updatedStatus = StatusType.FAILED;
messageEntity.status(updatedStatus);
return await this.eventService.updateEvent(messageEntity.primary_key, {status: updatedStatus});
messageEntity.status(StatusType.FAILED);
return await this.eventService.updateEvent(messageEntity.primary_key, {status: StatusType.FAILED});
} catch (error) {
if ((error as any).type !== ConversationError.TYPE.MESSAGE_NOT_FOUND) {
throw error;
Expand Down

0 comments on commit 280fa38

Please sign in to comment.