From 18c71b291c592141c9d5a65bbf95c6656511f6df Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Tue, 3 Nov 2020 16:16:20 -0800 Subject: [PATCH] Fix left pane draft display and GV2 typing indicators --- .../ConversationListItem.stories.tsx | 21 ++++++++++++++ ts/components/ConversationListItem.tsx | 27 +++++++++-------- ts/components/Lightbox.tsx | 4 +-- ts/models/conversations.ts | 29 +++++++++++++------ ts/textsecure/SendMessage.ts | 8 ++--- 5 files changed, 58 insertions(+), 31 deletions(-) diff --git a/ts/components/ConversationListItem.stories.tsx b/ts/components/ConversationListItem.stories.tsx index c7b811a34a86..ae95b873ddb1 100644 --- a/ts/components/ConversationListItem.stories.tsx +++ b/ts/components/ConversationListItem.stories.tsx @@ -103,6 +103,27 @@ story.add('Typing Status', () => { return ; }); +story.add('With draft', () => { + const props = createProps({ + shouldShowDraft: true, + draftPreview: "I'm in the middle of typing this...", + }); + + return ; +}); + +story.add('Deleted for everyone', () => { + const props = createProps({ + lastMessage: { + status: 'sent', + text: 'You should not see this!', + deletedForEveryone: true, + }, + }); + + return ; +}); + story.add('Message Request', () => { const props = createProps({ acceptedMessageRequest: false, diff --git a/ts/components/ConversationListItem.tsx b/ts/components/ConversationListItem.tsx index 710f2c928563..fe6e12e37000 100644 --- a/ts/components/ConversationListItem.tsx +++ b/ts/components/ConversationListItem.tsx @@ -178,23 +178,14 @@ export class ConversationListItem extends React.PureComponent { return null; } + const messageBody = lastMessage ? lastMessage.text : ''; const withUnread = isNumber(unreadCount) && unreadCount > 0; const showingDraft = shouldShowDraft && draftPreview; const deletedForEveryone = Boolean( lastMessage && lastMessage.deletedForEveryone ); - // Note: instead of re-using showingDraft here we explode it because - // typescript can't tell that draftPreview is truthy otherwise - // Avoiding touching logic to fix linting /* eslint-disable no-nested-ternary */ - const text = - shouldShowDraft && draftPreview - ? draftPreview - : lastMessage && lastMessage.text - ? lastMessage.text - : ''; - return (
{ ) : ( <> {showingDraft ? ( - - {i18n('ConversationListItem--draft-prefix')} - + <> + + {i18n('ConversationListItem--draft-prefix')} + + + ) : deletedForEveryone ? ( {i18n('message--deletedForEveryone')} ) : ( { const { contentType } = this.props; // These are the only image types supported by Electron's NativeImage - if (contentType !== 'image/png' && contentType !== 'image/jpg') { - event?.preventDefault(); + if (event && contentType !== 'image/png' && contentType !== 'image/jpg') { + event.preventDefault(); } }; diff --git a/ts/models/conversations.ts b/ts/models/conversations.ts index 66bb597f8256..93aa6b5b5c00 100644 --- a/ts/models/conversations.ts +++ b/ts/models/conversations.ts @@ -867,6 +867,23 @@ export class ConversationModel extends window.Backbone.Model< }; } + getGroupIdBuffer(): ArrayBuffer | undefined { + const groupIdString = this.get('groupId'); + + if (!groupIdString) { + return undefined; + } + + if (this.isGroupV1()) { + return fromEncodedBinaryToArrayBuffer(groupIdString); + } + if (this.isGroupV2()) { + return base64ToArrayBuffer(groupIdString); + } + + return undefined; + } + sendTypingMessage(isTyping: boolean): void { if (!window.textsecure.messaging) { return; @@ -878,7 +895,7 @@ export class ConversationModel extends window.Backbone.Model< } const recipientId = this.isPrivate() ? this.getSendTarget() : undefined; - const groupId = !this.isPrivate() ? this.get('groupId') : undefined; + const groupId = this.getGroupIdBuffer(); const groupMembers = this.getRecipients(); // We don't send typing messages if our recipients list is empty @@ -1408,13 +1425,7 @@ export class ConversationModel extends window.Backbone.Model< } ); - const groupId = this.get('groupId'); - let groupIdBuffer; - if (groupId && this.isGroupV1()) { - groupIdBuffer = fromEncodedBinaryToArrayBuffer(groupId); - } else if (groupId && this.isGroupV2()) { - groupIdBuffer = base64ToArrayBuffer(groupId); - } + const groupId = this.getGroupIdBuffer(); try { await wrap( @@ -1422,7 +1433,7 @@ export class ConversationModel extends window.Backbone.Model< { threadE164: this.get('e164'), threadUuid: this.get('uuid'), - groupId: groupIdBuffer, + groupId, type: response, }, sendOptions diff --git a/ts/textsecure/SendMessage.ts b/ts/textsecure/SendMessage.ts index 9c3a7dc4f979..c7cb4ebeefb0 100644 --- a/ts/textsecure/SendMessage.ts +++ b/ts/textsecure/SendMessage.ts @@ -21,7 +21,6 @@ import Crypto from './Crypto'; import { base64ToArrayBuffer, concatenateBytes, - fromEncodedBinaryToArrayBuffer, getZeroes, hexToArrayBuffer, } from '../Crypto'; @@ -982,7 +981,7 @@ export default class MessageSender { async sendTypingMessage( options: { recipientId?: string; - groupId?: string; + groupId?: ArrayBuffer; groupMembers: Array; isTyping: boolean; timestamp?: number; @@ -1007,15 +1006,12 @@ export default class MessageSender { const recipients = (groupId ? without(groupMembers, myNumber, myUuid) : [recipientId]) as Array; - const groupIdBuffer = groupId - ? fromEncodedBinaryToArrayBuffer(groupId) - : null; const action = isTyping ? ACTION_ENUM.STARTED : ACTION_ENUM.STOPPED; const finalTimestamp = timestamp || Date.now(); const typingMessage = new window.textsecure.protobuf.TypingMessage(); - typingMessage.groupId = groupIdBuffer; + typingMessage.groupId = groupId || null; typingMessage.action = action; typingMessage.timestamp = finalTimestamp;