Merge pull request #1458 from Bilb/remove-body-pending

Remove body pending and 2000 body limit
pull/1466/head
Audric Ackermann 4 years ago committed by GitHub
commit a1703a44e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -39,7 +39,6 @@ interface MessageAttributes {
expirationTimerUpdate: any; expirationTimerUpdate: any;
unread: boolean; unread: boolean;
group: any; group: any;
bodyPending: boolean;
timestamp: number; timestamp: number;
status: MessageDeliveryStatus; status: MessageDeliveryStatus;
} }
@ -50,7 +49,6 @@ export interface MessageRegularProps {
isAdmin?: boolean; isAdmin?: boolean;
weAreAdmin?: boolean; weAreAdmin?: boolean;
text?: string; text?: string;
bodyPending?: boolean;
id: string; id: string;
collapseMetadata?: boolean; collapseMetadata?: boolean;
direction: 'incoming' | 'outgoing'; direction: 'incoming' | 'outgoing';

@ -29,7 +29,6 @@
loadQuoteData, loadQuoteData,
loadPreviewData, loadPreviewData,
} = window.Signal.Migrations; } = window.Signal.Migrations;
const { bytesFromString } = window.Signal.Crypto;
window.AccountCache = Object.create(null); window.AccountCache = Object.create(null);
window.AccountJobs = Object.create(null); window.AccountJobs = Object.create(null);
@ -525,7 +524,6 @@
return { return {
text: this.createNonBreakingLastSeparator(this.get('body')), text: this.createNonBreakingLastSeparator(this.get('body')),
bodyPending: this.get('bodyPending'),
id: this.id, id: this.id,
direction: this.isIncoming() ? 'incoming' : 'outgoing', direction: this.isIncoming() ? 'incoming' : 'outgoing',
timestamp: this.get('sent_at'), timestamp: this.get('sent_at'),
@ -870,17 +868,10 @@
// TODO: In the future it might be best if we cache the upload results if possible. // TODO: In the future it might be best if we cache the upload results if possible.
// This way we don't upload duplicated data. // This way we don't upload duplicated data.
const attachmentsWithData = await Promise.all( const finalAttachments = await Promise.all(
(this.get('attachments') || []).map(loadAttachmentData) (this.get('attachments') || []).map(loadAttachmentData)
); );
const {
body,
attachments: finalAttachments,
} = Whisper.Message.getLongMessageAttachment({
body: this.get('body'),
attachments: attachmentsWithData,
now: this.get('sent_at'),
});
const filenameOverridenAttachments = finalAttachments.map(attachment => ({ const filenameOverridenAttachments = finalAttachments.map(attachment => ({
...attachment, ...attachment,
fileName: Signal.Types.Attachment.getSuggestedFilenameSending({ fileName: Signal.Types.Attachment.getSuggestedFilenameSending({
@ -906,7 +897,7 @@
]); ]);
return { return {
body, body: this.get('body'),
attachments, attachments,
preview, preview,
quote, quote,
@ -1531,31 +1522,6 @@
}, },
}); });
// Receive will be enabled before we enable send
Whisper.Message.LONG_MESSAGE_CONTENT_TYPE = 'text/x-signal-plain';
Whisper.Message.getLongMessageAttachment = ({ body, attachments, now }) => {
if (body.length <= 2048) {
return {
body,
attachments,
};
}
const data = bytesFromString(body);
const attachment = {
contentType: Whisper.Message.LONG_MESSAGE_CONTENT_TYPE,
fileName: `long-message-${now}.txt`,
data,
size: data.byteLength,
};
return {
body: body.slice(0, 2048),
attachments: [attachment, ...attachments],
};
};
Whisper.Message.refreshExpirationTimer = () => Whisper.Message.refreshExpirationTimer = () =>
Whisper.ExpiringMessagesListener.update(); Whisper.ExpiringMessagesListener.update();

@ -263,7 +263,6 @@ async function _addAttachmentToMessage(message, attachment, { type, index }) {
const { data } = await Signal.Migrations.loadAttachmentData(attachment); const { data } = await Signal.Migrations.loadAttachmentData(attachment);
message.set({ message.set({
body: attachment.isError ? message.get('body') : stringFromBytes(data), body: attachment.isError ? message.get('body') : stringFromBytes(data),
bodyPending: false,
}); });
} finally { } finally {
Signal.Migrations.deleteAttachmentData(attachment.path); Signal.Migrations.deleteAttachmentData(attachment.path);

@ -547,7 +547,6 @@ class MessageInner extends React.PureComponent<MessageRegularProps, State> {
public renderText() { public renderText() {
const { const {
text, text,
bodyPending,
direction, direction,
status, status,
conversationType, conversationType,
@ -578,7 +577,6 @@ class MessageInner extends React.PureComponent<MessageRegularProps, State> {
<MessageBody <MessageBody
text={contents || ''} text={contents || ''}
i18n={window.i18n} i18n={window.i18n}
bodyPending={bodyPending}
isGroup={conversationType === 'group'} isGroup={conversationType === 'group'}
convoId={convoId} convoId={convoId}
disableLinks={multiSelectMode} disableLinks={multiSelectMode}

@ -10,7 +10,6 @@ import { LocalizerType, RenderTextCallbackType } from '../../types/Util';
interface Props { interface Props {
text: string; text: string;
bodyPending?: boolean;
/** If set, all emoji will be the same size. Otherwise, just one emoji will be large. */ /** If set, all emoji will be the same size. Otherwise, just one emoji will be large. */
disableJumbomoji?: boolean; disableJumbomoji?: boolean;
/** If set, links will be left alone instead of turned into clickable `<a>` tags. */ /** If set, links will be left alone instead of turned into clickable `<a>` tags. */
@ -83,26 +82,13 @@ export class MessageBody extends React.Component<Props> {
isGroup: false, isGroup: false,
}; };
public addDownloading(jsx: JSX.Element): JSX.Element { public renderJsxSelectable(jsx: JSX.Element): JSX.Element {
const { i18n, bodyPending } = this.props; return <span className="text-selectable">{jsx}</span>;
return (
<span className="text-selectable">
{jsx}
{bodyPending ? (
<span className="module-message-body__highlight">
{' '}
{i18n('downloading')}
</span>
) : null}
</span>
);
} }
public render() { public render() {
const { const {
text, text,
bodyPending,
disableJumbomoji, disableJumbomoji,
disableLinks, disableLinks,
i18n, i18n,
@ -110,23 +96,12 @@ export class MessageBody extends React.Component<Props> {
convoId, convoId,
} = this.props; } = this.props;
const sizeClass = disableJumbomoji ? undefined : getSizeClass(text); const sizeClass = disableJumbomoji ? undefined : getSizeClass(text);
const textWithPending = bodyPending ? `${text}...` : text;
const emoji = renderEmoji({
i18n,
text: textWithPending,
sizeClass,
key: 0,
renderNonEmoji: renderNewLines,
isGroup,
convoId,
});
if (disableLinks) { if (disableLinks) {
return this.addDownloading( return this.renderJsxSelectable(
renderEmoji({ renderEmoji({
i18n, i18n,
text: textWithPending, text,
sizeClass, sizeClass,
key: 0, key: 0,
renderNonEmoji: renderNewLines, renderNonEmoji: renderNewLines,
@ -136,26 +111,9 @@ export class MessageBody extends React.Component<Props> {
); );
} }
const bodyContents = this.addDownloading( return this.renderJsxSelectable(
<Linkify
text={textWithPending}
renderNonLink={({ key, text: nonLinkText }) => {
return renderEmoji({
i18n,
text: nonLinkText,
sizeClass,
key,
renderNonEmoji: renderNewLines,
isGroup,
convoId,
});
}}
/>
);
return this.addDownloading(
<Linkify <Linkify
text={textWithPending} text={text}
renderNonLink={({ key, text: nonLinkText }) => { renderNonLink={({ key, text: nonLinkText }) => {
return renderEmoji({ return renderEmoji({
i18n, i18n,

@ -17,7 +17,6 @@ type Props = {
isAdmin?: boolean; isAdmin?: boolean;
isDeletable: boolean; isDeletable: boolean;
text?: string; text?: string;
bodyPending?: boolean;
id: string; id: string;
collapseMetadata?: boolean; collapseMetadata?: boolean;
direction: 'incoming' | 'outgoing'; direction: 'incoming' | 'outgoing';
@ -69,7 +68,6 @@ export const MessageMetadata = (props: Props) => {
expirationTimestamp, expirationTimestamp,
status, status,
text, text,
bodyPending,
timestamp, timestamp,
serverTimestamp, serverTimestamp,
isShowingImage, isShowingImage,
@ -86,7 +84,7 @@ export const MessageMetadata = (props: Props) => {
const withImageNoCaption = Boolean(!text && isShowingImage); const withImageNoCaption = Boolean(!text && isShowingImage);
const showError = status === 'error' && isOutgoing; const showError = status === 'error' && isOutgoing;
const showStatus = Boolean(!bodyPending && status?.length && isOutgoing); const showStatus = Boolean(status?.length && isOutgoing);
const messageStatusColor = withImageNoCaption const messageStatusColor = withImageNoCaption
? 'white' ? 'white'
: props.theme.colors.sentMessageText; : props.theme.colors.sentMessageText;
@ -124,8 +122,6 @@ export const MessageMetadata = (props: Props) => {
/> />
) : null} ) : null}
<MetadataSpacer /> <MetadataSpacer />
{bodyPending ? <Spinner size="mini" direction={direction} /> : null}
<MetadataSpacer />
{showStatus ? ( {showStatus ? (
<OutgoingMessageStatus <OutgoingMessageStatus
iconColor={messageStatusColor} iconColor={messageStatusColor}

@ -374,7 +374,7 @@ export class SessionCompositionBox extends React.Component<Props, State> {
spellCheck={true} spellCheck={true}
inputRef={this.textarea} inputRef={this.textarea}
disabled={!typingEnabled} disabled={!typingEnabled}
maxLength={Constants.CONVERSATION.MAX_MESSAGE_BODY_LENGTH} // maxLength={Constants.CONVERSATION.MAX_MESSAGE_BODY_LENGTH}
rows={1} rows={1}
style={sendMessageStyle} style={sendMessageStyle}
suggestionsPortalHost={this.container} suggestionsPortalHost={this.container}
@ -751,25 +751,8 @@ export class SessionCompositionBox extends React.Component<Props, State> {
// tslint:disable-next-line: cyclomatic-complexity // tslint:disable-next-line: cyclomatic-complexity
private async onSendMessage() { private async onSendMessage() {
const toUnicode = (str: string) => {
return str
.split('')
.map(value => {
const temp = value
.charCodeAt(0)
.toString(16)
.toUpperCase();
if (temp.length > 2) {
return `\\u${temp}`;
}
return value;
})
.join('');
};
// this is dirty but we have to replace all @(xxx) by @xxx manually here // this is dirty but we have to replace all @(xxx) by @xxx manually here
const cleanMentions = (text: string): string => { const cleanMentions = (text: string): string => {
const textUnicode = toUnicode(text);
const matches = text.match(this.mentionsRegex); const matches = text.match(this.mentionsRegex);
let replacedMentions = text; let replacedMentions = text;
(matches || []).forEach(match => { (matches || []).forEach(match => {
@ -808,10 +791,10 @@ export class SessionCompositionBox extends React.Component<Props, State> {
} }
// Verify message length // Verify message length
const msgLen = messagePlaintext?.length || 0; const msgLen = messagePlaintext?.length || 0;
if (msgLen > Constants.CONVERSATION.MAX_MESSAGE_BODY_LENGTH) { // if (msgLen > Constants.CONVERSATION.MAX_MESSAGE_BODY_LENGTH) {
ToastUtils.pushMessageBodyTooLong(); // ToastUtils.pushMessageBodyTooLong();
return; // return;
} // }
if (msgLen === 0 && this.props.stagedAttachments?.length === 0) { if (msgLen === 0 && this.props.stagedAttachments?.length === 0) {
ToastUtils.pushMessageBodyMissing(); ToastUtils.pushMessageBodyMissing();
return; return;

@ -75,32 +75,6 @@ export async function downloadAttachment(attachment: any) {
}; };
} }
async function processLongAttachments(
message: MessageModel,
attachments: Array<any>
): Promise<boolean> {
if (attachments.length === 0) {
return false;
}
if (attachments.length > 1) {
window.log.error(
`Received more than one long message attachment in message ${message.idForLogging()}`
);
}
const attachment = attachments[0];
message.set({ bodyPending: true });
await window.Signal.AttachmentDownloads.addJob(attachment, {
messageId: message.id,
type: 'long-message',
index: 0,
});
return true;
}
async function processNormalAttachments( async function processNormalAttachments(
message: MessageModel, message: MessageModel,
normalAttachments: Array<any> normalAttachments: Array<any>
@ -247,15 +221,7 @@ export async function queueAttachmentDownloads(
let count = 0; let count = 0;
const [longMessageAttachments, normalAttachments] = _.partition( const normalAttachments = message.get('attachments') || [];
message.get('attachments') || [],
(attachment: any) =>
attachment.contentType === Whisper.Message.LONG_MESSAGE_CONTENT_TYPE
);
if (await processLongAttachments(message, longMessageAttachments)) {
count += 1;
}
count += await processNormalAttachments(message, normalAttachments); count += await processNormalAttachments(message, normalAttachments);

@ -11,7 +11,7 @@ export const TTL_DEFAULT = {
// User Interface // User Interface
export const CONVERSATION = { export const CONVERSATION = {
MAX_MESSAGE_BODY_LENGTH: 2000, // MAX_MESSAGE_BODY_LENGTH: 2000,
DEFAULT_MEDIA_FETCH_COUNT: 50, DEFAULT_MEDIA_FETCH_COUNT: 50,
DEFAULT_DOCUMENTS_FETCH_COUNT: 150, DEFAULT_DOCUMENTS_FETCH_COUNT: 150,
DEFAULT_MESSAGE_FETCH_COUNT: 30, DEFAULT_MESSAGE_FETCH_COUNT: 30,

Loading…
Cancel
Save