You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
session-desktop/ts/receiver/receiver.ts

386 lines
12 KiB
TypeScript

// TODO: fix libloki and textsecure not being available here yet
import { EnvelopePlus } from './types';
export { downloadAttachment } from './attachments';
4 years ago
import { v4 as uuidv4 } from 'uuid';
import { addToCache, getAllFromCache, getAllFromCacheForSource, removeFromCache } from './cache';
import { processMessage } from '../session/snode_api/swarmPolling';
import { onError } from './errors';
// innerHandleContentMessage is only needed because of code duplication in handleDecryptedEnvelope...
Session v1.6.2 (#1639) * padd Message buffer for all outgoing messages (even opengroupv2) * pad and unpad message everywhere attachment not padded for opengroup only * lint * enable fileserver v2 sending side * removed all en unused local strings * remove all unused keys for other locales * update displayname even if we dont have avatar on incoming profile * redesign group invitation message type * ask confirmation before joining opengroup invitation * remove the channelId from groupInvitation * fallback to envelope timestamp if dataMessage.timestamp is 0 * match group invitation design with ios * speed up first load of room message by prefetching token * create convo for members if they don't exist also, removing a private convo does not remove it entirely as we need the convo to be able to remove members * fix avatar download on restore when linking device Fixes #1601 * make sure the left member convo exist in rendering GroupUpdate * Reply attachments (#1591) * First attachment showing in reply composition. * WIP: Adding thumbnail to quote response composition component. * Added icon for voice recording attachment * Updated formatting. * Formatting. * removed duplicate styling. * WIP: Converting quote component to functional components. * Fix bug where thumbnails for attachment replies wasn't showing. * yarn Formatting. * Removed old quote component. * Add type to contentTypeSupported method. * Moved quote subcomponents out of Quote component. * yarn format * Add export to quote subcomponents. * Fixing linting errors. * remove commented line. * Addressing PR comments. * Allow pasting images into composition box as attachments (#1616) * Allow pasting images into composition box as attachments * Fix linter errors * Fix typo * Get snode from snode (#1614) * force deleteAccount after 10sec timeout waiting for configMessage * move some constants to file where they are used * add a way to fetch snodes from snodes * remove a snode from a pubkey's swarm if we get 421 without valid content * remove getVersion from snodes * hide groupMembers in right panel for non-group convo * Fix fonts sans serif (#1619) * force deleteAccount after 10sec timeout waiting for configMessage * move some constants to file where they are used * add a way to fetch snodes from snodes * remove a snode from a pubkey's swarm if we get 421 without valid content * remove getVersion from snodes * hide groupMembers in right panel for non-group convo * fix font sans serif by using roboto instead Fixes #1617 * WIP: User nicknames (#1618) * WIP Adding change nickname dialog. * WIP adding nickname change dialog. * WIP nickname dialog. * WIP: Able to set conversation nicknames. Next step cleaning and adding to conversation list menu. * Fix message capitilisations. * Add change nickname to conversation list menu. * Enable clear nickname menu item. * Added messages for changing nicknames. * Clearing nicknames working from header and message list. * Adding modal styling to nickname modal. * Reorder nickname menu item positions. * Add group based conditional nickname menu options to conversation header menu. * minor tidying. * Remove unused error causing el option. * Formatting. * Linting fixes. * Made PR fixes * Prioritise displaying nicknames for inviting new closed group members and updating closed group members. * Fix app image start for non-debian based distribs (#1622) Fixes #1620 * fixup nickname dialog for enter key pressed event (#1623) also add some type for it and remove unused props * Fix attachment extension vnd (#1628) * allow openoffice document extension and don't use * allow opendocument to be shared with the extension rather than mimetype Fixes #1593 * allow message without padding * add test for odt files * More Japanese translations (#1632) * Translate some untranslated strings into Japanese * Tweak some Japanese translations * Add new Japanese translations * WIP: Closed group reliability (#1630) * WIP: added non-durable messaging function. * WIP: Non-durable sending * WIP: adding dialog box. * Creating dialog if group invite message promises don't return true. * removed console log * applied PR changes, linting and formatting. * WIP: allowing resend invite to failures. * using lookup. * WIP: recursively opening dialog. * WIP: debugging reject triggering on confirmation modal. * register events fix. * Closed group invite retry dialog working. * Added english text to messages. * Prevent saving of hexkey pair if it already exists. * Fixed nickname edit input trimming end letter. * Don't show closed group invite dialog unless it has failed at least once. * Fix linting error. * Fix plurality. * Ensure admin members are included in all invite reattempts, mixed plurality. * test fixing windows build * Revert "test fixing windows build" This reverts commit 8ed2e0891d160a774de452e8373aea179502e221. Co-authored-by: Warrick <wcor690@aucklanduni.ac.nz> Co-authored-by: shellhazard <unva1idated@protonmail.com> Co-authored-by: beantaco <64012487+beantaco@users.noreply.github.com>
4 years ago
import { handleContentMessage, innerHandleContentMessage } from './contentMessage';
import _, { noop } from 'lodash';
4 years ago
export { processMessage };
import {
createMessage,
handleMessageEvent,
isMessageDuplicate,
MessageCreationData,
updateProfileOneAtATime,
} from './dataMessage';
import { getEnvelopeId } from './common';
import { StringUtils, UserUtils } from '../session/utils';
import { SignalService } from '../protobuf';
import { ConversationController } from '../session/conversations';
import { removeUnprocessed } from '../data/data';
import { ConversationTypeEnum } from '../models/conversation';
import {
getOpenGroupV2ConversationId,
openGroupPrefixRegex,
} from '../opengroup/utils/OpenGroupUtils';
import { OpenGroupMessageV2 } from '../opengroup/opengroupV2/OpenGroupMessageV2';
import { OpenGroupRequestCommonType } from '../opengroup/opengroupV2/ApiUtil';
import { handleMessageJob } from './queuedJob';
import { fromBase64ToArray } from '../session/utils/String';
Session v1.6.2 (#1639) * padd Message buffer for all outgoing messages (even opengroupv2) * pad and unpad message everywhere attachment not padded for opengroup only * lint * enable fileserver v2 sending side * removed all en unused local strings * remove all unused keys for other locales * update displayname even if we dont have avatar on incoming profile * redesign group invitation message type * ask confirmation before joining opengroup invitation * remove the channelId from groupInvitation * fallback to envelope timestamp if dataMessage.timestamp is 0 * match group invitation design with ios * speed up first load of room message by prefetching token * create convo for members if they don't exist also, removing a private convo does not remove it entirely as we need the convo to be able to remove members * fix avatar download on restore when linking device Fixes #1601 * make sure the left member convo exist in rendering GroupUpdate * Reply attachments (#1591) * First attachment showing in reply composition. * WIP: Adding thumbnail to quote response composition component. * Added icon for voice recording attachment * Updated formatting. * Formatting. * removed duplicate styling. * WIP: Converting quote component to functional components. * Fix bug where thumbnails for attachment replies wasn't showing. * yarn Formatting. * Removed old quote component. * Add type to contentTypeSupported method. * Moved quote subcomponents out of Quote component. * yarn format * Add export to quote subcomponents. * Fixing linting errors. * remove commented line. * Addressing PR comments. * Allow pasting images into composition box as attachments (#1616) * Allow pasting images into composition box as attachments * Fix linter errors * Fix typo * Get snode from snode (#1614) * force deleteAccount after 10sec timeout waiting for configMessage * move some constants to file where they are used * add a way to fetch snodes from snodes * remove a snode from a pubkey's swarm if we get 421 without valid content * remove getVersion from snodes * hide groupMembers in right panel for non-group convo * Fix fonts sans serif (#1619) * force deleteAccount after 10sec timeout waiting for configMessage * move some constants to file where they are used * add a way to fetch snodes from snodes * remove a snode from a pubkey's swarm if we get 421 without valid content * remove getVersion from snodes * hide groupMembers in right panel for non-group convo * fix font sans serif by using roboto instead Fixes #1617 * WIP: User nicknames (#1618) * WIP Adding change nickname dialog. * WIP adding nickname change dialog. * WIP nickname dialog. * WIP: Able to set conversation nicknames. Next step cleaning and adding to conversation list menu. * Fix message capitilisations. * Add change nickname to conversation list menu. * Enable clear nickname menu item. * Added messages for changing nicknames. * Clearing nicknames working from header and message list. * Adding modal styling to nickname modal. * Reorder nickname menu item positions. * Add group based conditional nickname menu options to conversation header menu. * minor tidying. * Remove unused error causing el option. * Formatting. * Linting fixes. * Made PR fixes * Prioritise displaying nicknames for inviting new closed group members and updating closed group members. * Fix app image start for non-debian based distribs (#1622) Fixes #1620 * fixup nickname dialog for enter key pressed event (#1623) also add some type for it and remove unused props * Fix attachment extension vnd (#1628) * allow openoffice document extension and don't use * allow opendocument to be shared with the extension rather than mimetype Fixes #1593 * allow message without padding * add test for odt files * More Japanese translations (#1632) * Translate some untranslated strings into Japanese * Tweak some Japanese translations * Add new Japanese translations * WIP: Closed group reliability (#1630) * WIP: added non-durable messaging function. * WIP: Non-durable sending * WIP: adding dialog box. * Creating dialog if group invite message promises don't return true. * removed console log * applied PR changes, linting and formatting. * WIP: allowing resend invite to failures. * using lookup. * WIP: recursively opening dialog. * WIP: debugging reject triggering on confirmation modal. * register events fix. * Closed group invite retry dialog working. * Added english text to messages. * Prevent saving of hexkey pair if it already exists. * Fixed nickname edit input trimming end letter. * Don't show closed group invite dialog unless it has failed at least once. * Fix linting error. * Fix plurality. * Ensure admin members are included in all invite reattempts, mixed plurality. * test fixing windows build * Revert "test fixing windows build" This reverts commit 8ed2e0891d160a774de452e8373aea179502e221. Co-authored-by: Warrick <wcor690@aucklanduni.ac.nz> Co-authored-by: shellhazard <unva1idated@protonmail.com> Co-authored-by: beantaco <64012487+beantaco@users.noreply.github.com>
4 years ago
import { removeMessagePadding } from '../session/crypto/BufferPadding';
// TODO: check if some of these exports no longer needed
interface ReqOptions {
conversationId: string;
}
const incomingMessagePromises: Array<Promise<any>> = [];
async function handleEnvelope(envelope: EnvelopePlus) {
// TODO: enable below
// if (this.stoppingProcessing) {
// return Promise.resolve();
// }
if (envelope.content && envelope.content.length > 0) {
return handleContentMessage(envelope);
}
await removeFromCache(envelope);
throw new Error('Received message with no content and no legacyMessage');
}
class EnvelopeQueue {
private count: number = 0;
// Last pending promise
private pending: Promise<any> = Promise.resolve();
public add(task: any): void {
this.count += 1;
const promise = this.pending.then(task, task);
this.pending = promise;
this.pending.then(this.cleanup.bind(this, promise), this.cleanup.bind(this, promise));
}
private cleanup(promise: Promise<any>) {
// We want to clear out the promise chain whenever possible because it could
// lead to large memory usage over time:
// https://github.com/nodejs/node/issues/6673#issuecomment-244331609
if (this.pending === promise) {
this.pending = Promise.resolve();
}
}
}
const envelopeQueue = new EnvelopeQueue();
function queueEnvelope(envelope: EnvelopePlus) {
const id = getEnvelopeId(envelope);
window.log.info('queueing envelope', id);
const task = handleEnvelope.bind(null, envelope);
const taskWithTimeout = window.textsecure.createTaskWithTimeout(task, `queueEnvelope ${id}`);
try {
envelopeQueue.add(taskWithTimeout);
} catch (error) {
window.log.error(
'queueEnvelope error handling envelope',
id,
':',
error && error.stack ? error.stack : error
);
}
}
async function handleRequestDetail(
plaintext: Uint8Array,
options: ReqOptions,
lastPromise: Promise<any>
): Promise<void> {
const envelope: any = SignalService.Envelope.decode(plaintext);
// After this point, decoding errors are not the server's
// fault, and we should handle them gracefully and tell the
// user they received an invalid message
// The message is for a medium size group
if (options.conversationId) {
const ourNumber = UserUtils.getOurPubKeyStrFromCache();
const senderIdentity = envelope.source;
if (senderIdentity === ourNumber) {
return;
}
// Sender identity will be lost if we load from cache, because
// plaintext (and protobuf.Envelope) does not have that field...
envelope.source = options.conversationId;
// tslint:disable-next-line no-parameter-reassignment
plaintext = SignalService.Envelope.encode(envelope).finish();
envelope.senderIdentity = senderIdentity;
}
envelope.id = envelope.serverGuid || uuidv4();
envelope.serverTimestamp = envelope.serverTimestamp ? envelope.serverTimestamp.toNumber() : null;
try {
// NOTE: Annoyngly we add plaintext to the cache
// after we've already processed some of it (thus the
// need to handle senderIdentity separately)...
await addToCache(envelope, plaintext);
// TODO: This is the glue between the first and the last part of the
// receiving pipeline refactor. It is to be implemented in the next PR.
// To ensure that we queue in the same order we receive messages
await lastPromise;
queueEnvelope(envelope);
} catch (error) {
window.log.error(
'handleRequest error trying to add message to cache:',
error && error.stack ? error.stack : error
);
}
}
export function handleRequest(body: any, options: ReqOptions): void {
// tslint:disable-next-line no-promise-as-boolean
const lastPromise = _.last(incomingMessagePromises) || Promise.resolve();
const plaintext = body;
const promise = handleRequestDetail(plaintext, options, lastPromise).catch(e => {
window.log.error('Error handling incoming message:', e && e.stack ? e.stack : e);
void onError(e);
});
incomingMessagePromises.push(promise);
}
// tslint:enable:cyclomatic-complexity max-func-body-length */
// ***********************************************************************
// ***********************************************************************
// ***********************************************************************
export async function queueAllCached() {
const items = await getAllFromCache();
items.forEach(async item => {
await queueCached(item);
});
}
export async function queueAllCachedFromSource(source: string) {
const items = await getAllFromCacheForSource(source);
// queue all cached for this source, but keep the order
await items.reduce(async (promise, item) => {
await promise;
await queueCached(item);
}, Promise.resolve());
}
async function queueCached(item: any) {
try {
const envelopePlaintext = StringUtils.encode(item.envelope, 'base64');
const envelopeArray = new Uint8Array(envelopePlaintext);
const envelope: any = SignalService.Envelope.decode(envelopeArray);
envelope.id = envelope.serverGuid || item.id;
envelope.source = envelope.source || item.source;
// Why do we need to do this???
envelope.sourceDevice = 1;
envelope.senderIdentity = envelope.senderIdentity || item.senderIdentity;
envelope.serverTimestamp = envelope.serverTimestamp || item.serverTimestamp;
const { decrypted } = item;
if (decrypted) {
const payloadPlaintext = StringUtils.encode(decrypted, 'base64');
queueDecryptedEnvelope(envelope, payloadPlaintext);
} else {
queueEnvelope(envelope);
}
} catch (error) {
window.log.error(
'queueCached error handling item',
item.id,
'removing it. Error:',
error && error.stack ? error.stack : error
);
try {
const { id } = item;
await removeUnprocessed(id);
} catch (deleteError) {
window.log.error(
'queueCached error deleting item',
item.id,
'Error:',
deleteError && deleteError.stack ? deleteError.stack : deleteError
);
}
}
}
function queueDecryptedEnvelope(envelope: any, plaintext: ArrayBuffer) {
const id = getEnvelopeId(envelope);
window.log.info('queueing decrypted envelope', id);
const task = handleDecryptedEnvelope.bind(null, envelope, plaintext);
const taskWithTimeout = window.textsecure.createTaskWithTimeout(
task,
`queueEncryptedEnvelope ${id}`
);
try {
envelopeQueue.add(taskWithTimeout);
} catch (error) {
window.log.error(
`queueDecryptedEnvelope error handling envelope ${id}:`,
error && error.stack ? error.stack : error
);
}
}
async function handleDecryptedEnvelope(envelope: EnvelopePlus, plaintext: ArrayBuffer) {
// if (this.stoppingProcessing) {
// return Promise.resolve();
// }
if (envelope.content) {
await innerHandleContentMessage(envelope, plaintext);
} else {
await removeFromCache(envelope);
}
}
Session v1.6.2 (#1639) * padd Message buffer for all outgoing messages (even opengroupv2) * pad and unpad message everywhere attachment not padded for opengroup only * lint * enable fileserver v2 sending side * removed all en unused local strings * remove all unused keys for other locales * update displayname even if we dont have avatar on incoming profile * redesign group invitation message type * ask confirmation before joining opengroup invitation * remove the channelId from groupInvitation * fallback to envelope timestamp if dataMessage.timestamp is 0 * match group invitation design with ios * speed up first load of room message by prefetching token * create convo for members if they don't exist also, removing a private convo does not remove it entirely as we need the convo to be able to remove members * fix avatar download on restore when linking device Fixes #1601 * make sure the left member convo exist in rendering GroupUpdate * Reply attachments (#1591) * First attachment showing in reply composition. * WIP: Adding thumbnail to quote response composition component. * Added icon for voice recording attachment * Updated formatting. * Formatting. * removed duplicate styling. * WIP: Converting quote component to functional components. * Fix bug where thumbnails for attachment replies wasn't showing. * yarn Formatting. * Removed old quote component. * Add type to contentTypeSupported method. * Moved quote subcomponents out of Quote component. * yarn format * Add export to quote subcomponents. * Fixing linting errors. * remove commented line. * Addressing PR comments. * Allow pasting images into composition box as attachments (#1616) * Allow pasting images into composition box as attachments * Fix linter errors * Fix typo * Get snode from snode (#1614) * force deleteAccount after 10sec timeout waiting for configMessage * move some constants to file where they are used * add a way to fetch snodes from snodes * remove a snode from a pubkey's swarm if we get 421 without valid content * remove getVersion from snodes * hide groupMembers in right panel for non-group convo * Fix fonts sans serif (#1619) * force deleteAccount after 10sec timeout waiting for configMessage * move some constants to file where they are used * add a way to fetch snodes from snodes * remove a snode from a pubkey's swarm if we get 421 without valid content * remove getVersion from snodes * hide groupMembers in right panel for non-group convo * fix font sans serif by using roboto instead Fixes #1617 * WIP: User nicknames (#1618) * WIP Adding change nickname dialog. * WIP adding nickname change dialog. * WIP nickname dialog. * WIP: Able to set conversation nicknames. Next step cleaning and adding to conversation list menu. * Fix message capitilisations. * Add change nickname to conversation list menu. * Enable clear nickname menu item. * Added messages for changing nicknames. * Clearing nicknames working from header and message list. * Adding modal styling to nickname modal. * Reorder nickname menu item positions. * Add group based conditional nickname menu options to conversation header menu. * minor tidying. * Remove unused error causing el option. * Formatting. * Linting fixes. * Made PR fixes * Prioritise displaying nicknames for inviting new closed group members and updating closed group members. * Fix app image start for non-debian based distribs (#1622) Fixes #1620 * fixup nickname dialog for enter key pressed event (#1623) also add some type for it and remove unused props * Fix attachment extension vnd (#1628) * allow openoffice document extension and don't use * allow opendocument to be shared with the extension rather than mimetype Fixes #1593 * allow message without padding * add test for odt files * More Japanese translations (#1632) * Translate some untranslated strings into Japanese * Tweak some Japanese translations * Add new Japanese translations * WIP: Closed group reliability (#1630) * WIP: added non-durable messaging function. * WIP: Non-durable sending * WIP: adding dialog box. * Creating dialog if group invite message promises don't return true. * removed console log * applied PR changes, linting and formatting. * WIP: allowing resend invite to failures. * using lookup. * WIP: recursively opening dialog. * WIP: debugging reject triggering on confirmation modal. * register events fix. * Closed group invite retry dialog working. * Added english text to messages. * Prevent saving of hexkey pair if it already exists. * Fixed nickname edit input trimming end letter. * Don't show closed group invite dialog unless it has failed at least once. * Fix linting error. * Fix plurality. * Ensure admin members are included in all invite reattempts, mixed plurality. * test fixing windows build * Revert "test fixing windows build" This reverts commit 8ed2e0891d160a774de452e8373aea179502e221. Co-authored-by: Warrick <wcor690@aucklanduni.ac.nz> Co-authored-by: shellhazard <unva1idated@protonmail.com> Co-authored-by: beantaco <64012487+beantaco@users.noreply.github.com>
4 years ago
/**
* Only used for opengroupv1 it seems.
* To be removed soon
*/
export async function handlePublicMessage(messageData: any) {
const { source } = messageData;
const { group, profile, profileKey } = messageData.message;
const isMe = UserUtils.isUsFromCache(source);
if (!isMe && profile) {
const conversation = await ConversationController.getInstance().getOrCreateAndWait(
source,
ConversationTypeEnum.PRIVATE
);
await updateProfileOneAtATime(conversation, profile, profileKey);
}
const isPublicVisibleMessage = group && group.id && !!group.id.match(openGroupPrefixRegex);
if (!isPublicVisibleMessage) {
throw new Error('handlePublicMessage Should only be called with public message groups');
}
const ev = {
// Public chat messages from ourselves should be outgoing
type: isMe ? 'sent' : 'message',
data: messageData,
confirm: () => {
/* do nothing */
},
};
Session v1.6.2 (#1639) * padd Message buffer for all outgoing messages (even opengroupv2) * pad and unpad message everywhere attachment not padded for opengroup only * lint * enable fileserver v2 sending side * removed all en unused local strings * remove all unused keys for other locales * update displayname even if we dont have avatar on incoming profile * redesign group invitation message type * ask confirmation before joining opengroup invitation * remove the channelId from groupInvitation * fallback to envelope timestamp if dataMessage.timestamp is 0 * match group invitation design with ios * speed up first load of room message by prefetching token * create convo for members if they don't exist also, removing a private convo does not remove it entirely as we need the convo to be able to remove members * fix avatar download on restore when linking device Fixes #1601 * make sure the left member convo exist in rendering GroupUpdate * Reply attachments (#1591) * First attachment showing in reply composition. * WIP: Adding thumbnail to quote response composition component. * Added icon for voice recording attachment * Updated formatting. * Formatting. * removed duplicate styling. * WIP: Converting quote component to functional components. * Fix bug where thumbnails for attachment replies wasn't showing. * yarn Formatting. * Removed old quote component. * Add type to contentTypeSupported method. * Moved quote subcomponents out of Quote component. * yarn format * Add export to quote subcomponents. * Fixing linting errors. * remove commented line. * Addressing PR comments. * Allow pasting images into composition box as attachments (#1616) * Allow pasting images into composition box as attachments * Fix linter errors * Fix typo * Get snode from snode (#1614) * force deleteAccount after 10sec timeout waiting for configMessage * move some constants to file where they are used * add a way to fetch snodes from snodes * remove a snode from a pubkey's swarm if we get 421 without valid content * remove getVersion from snodes * hide groupMembers in right panel for non-group convo * Fix fonts sans serif (#1619) * force deleteAccount after 10sec timeout waiting for configMessage * move some constants to file where they are used * add a way to fetch snodes from snodes * remove a snode from a pubkey's swarm if we get 421 without valid content * remove getVersion from snodes * hide groupMembers in right panel for non-group convo * fix font sans serif by using roboto instead Fixes #1617 * WIP: User nicknames (#1618) * WIP Adding change nickname dialog. * WIP adding nickname change dialog. * WIP nickname dialog. * WIP: Able to set conversation nicknames. Next step cleaning and adding to conversation list menu. * Fix message capitilisations. * Add change nickname to conversation list menu. * Enable clear nickname menu item. * Added messages for changing nicknames. * Clearing nicknames working from header and message list. * Adding modal styling to nickname modal. * Reorder nickname menu item positions. * Add group based conditional nickname menu options to conversation header menu. * minor tidying. * Remove unused error causing el option. * Formatting. * Linting fixes. * Made PR fixes * Prioritise displaying nicknames for inviting new closed group members and updating closed group members. * Fix app image start for non-debian based distribs (#1622) Fixes #1620 * fixup nickname dialog for enter key pressed event (#1623) also add some type for it and remove unused props * Fix attachment extension vnd (#1628) * allow openoffice document extension and don't use * allow opendocument to be shared with the extension rather than mimetype Fixes #1593 * allow message without padding * add test for odt files * More Japanese translations (#1632) * Translate some untranslated strings into Japanese * Tweak some Japanese translations * Add new Japanese translations * WIP: Closed group reliability (#1630) * WIP: added non-durable messaging function. * WIP: Non-durable sending * WIP: adding dialog box. * Creating dialog if group invite message promises don't return true. * removed console log * applied PR changes, linting and formatting. * WIP: allowing resend invite to failures. * using lookup. * WIP: recursively opening dialog. * WIP: debugging reject triggering on confirmation modal. * register events fix. * Closed group invite retry dialog working. * Added english text to messages. * Prevent saving of hexkey pair if it already exists. * Fixed nickname edit input trimming end letter. * Don't show closed group invite dialog unless it has failed at least once. * Fix linting error. * Fix plurality. * Ensure admin members are included in all invite reattempts, mixed plurality. * test fixing windows build * Revert "test fixing windows build" This reverts commit 8ed2e0891d160a774de452e8373aea179502e221. Co-authored-by: Warrick <wcor690@aucklanduni.ac.nz> Co-authored-by: shellhazard <unva1idated@protonmail.com> Co-authored-by: beantaco <64012487+beantaco@users.noreply.github.com>
4 years ago
await handleMessageEvent(ev); // open groups v1
}
export async function handleOpenGroupV2Message(
message: OpenGroupMessageV2,
roomInfos: OpenGroupRequestCommonType
) {
const { base64EncodedData, sentTimestamp, sender, serverId } = message;
const { serverUrl, roomId } = roomInfos;
if (!base64EncodedData || !sentTimestamp || !sender || !serverId) {
window.log.warn('Invalid data passed to handleMessageEvent.', message);
return;
}
Session v1.6.2 (#1639) * padd Message buffer for all outgoing messages (even opengroupv2) * pad and unpad message everywhere attachment not padded for opengroup only * lint * enable fileserver v2 sending side * removed all en unused local strings * remove all unused keys for other locales * update displayname even if we dont have avatar on incoming profile * redesign group invitation message type * ask confirmation before joining opengroup invitation * remove the channelId from groupInvitation * fallback to envelope timestamp if dataMessage.timestamp is 0 * match group invitation design with ios * speed up first load of room message by prefetching token * create convo for members if they don't exist also, removing a private convo does not remove it entirely as we need the convo to be able to remove members * fix avatar download on restore when linking device Fixes #1601 * make sure the left member convo exist in rendering GroupUpdate * Reply attachments (#1591) * First attachment showing in reply composition. * WIP: Adding thumbnail to quote response composition component. * Added icon for voice recording attachment * Updated formatting. * Formatting. * removed duplicate styling. * WIP: Converting quote component to functional components. * Fix bug where thumbnails for attachment replies wasn't showing. * yarn Formatting. * Removed old quote component. * Add type to contentTypeSupported method. * Moved quote subcomponents out of Quote component. * yarn format * Add export to quote subcomponents. * Fixing linting errors. * remove commented line. * Addressing PR comments. * Allow pasting images into composition box as attachments (#1616) * Allow pasting images into composition box as attachments * Fix linter errors * Fix typo * Get snode from snode (#1614) * force deleteAccount after 10sec timeout waiting for configMessage * move some constants to file where they are used * add a way to fetch snodes from snodes * remove a snode from a pubkey's swarm if we get 421 without valid content * remove getVersion from snodes * hide groupMembers in right panel for non-group convo * Fix fonts sans serif (#1619) * force deleteAccount after 10sec timeout waiting for configMessage * move some constants to file where they are used * add a way to fetch snodes from snodes * remove a snode from a pubkey's swarm if we get 421 without valid content * remove getVersion from snodes * hide groupMembers in right panel for non-group convo * fix font sans serif by using roboto instead Fixes #1617 * WIP: User nicknames (#1618) * WIP Adding change nickname dialog. * WIP adding nickname change dialog. * WIP nickname dialog. * WIP: Able to set conversation nicknames. Next step cleaning and adding to conversation list menu. * Fix message capitilisations. * Add change nickname to conversation list menu. * Enable clear nickname menu item. * Added messages for changing nicknames. * Clearing nicknames working from header and message list. * Adding modal styling to nickname modal. * Reorder nickname menu item positions. * Add group based conditional nickname menu options to conversation header menu. * minor tidying. * Remove unused error causing el option. * Formatting. * Linting fixes. * Made PR fixes * Prioritise displaying nicknames for inviting new closed group members and updating closed group members. * Fix app image start for non-debian based distribs (#1622) Fixes #1620 * fixup nickname dialog for enter key pressed event (#1623) also add some type for it and remove unused props * Fix attachment extension vnd (#1628) * allow openoffice document extension and don't use * allow opendocument to be shared with the extension rather than mimetype Fixes #1593 * allow message without padding * add test for odt files * More Japanese translations (#1632) * Translate some untranslated strings into Japanese * Tweak some Japanese translations * Add new Japanese translations * WIP: Closed group reliability (#1630) * WIP: added non-durable messaging function. * WIP: Non-durable sending * WIP: adding dialog box. * Creating dialog if group invite message promises don't return true. * removed console log * applied PR changes, linting and formatting. * WIP: allowing resend invite to failures. * using lookup. * WIP: recursively opening dialog. * WIP: debugging reject triggering on confirmation modal. * register events fix. * Closed group invite retry dialog working. * Added english text to messages. * Prevent saving of hexkey pair if it already exists. * Fixed nickname edit input trimming end letter. * Don't show closed group invite dialog unless it has failed at least once. * Fix linting error. * Fix plurality. * Ensure admin members are included in all invite reattempts, mixed plurality. * test fixing windows build * Revert "test fixing windows build" This reverts commit 8ed2e0891d160a774de452e8373aea179502e221. Co-authored-by: Warrick <wcor690@aucklanduni.ac.nz> Co-authored-by: shellhazard <unva1idated@protonmail.com> Co-authored-by: beantaco <64012487+beantaco@users.noreply.github.com>
4 years ago
// Note: opengroup messages are not padded
const dataUint = new Uint8Array(removeMessagePadding(fromBase64ToArray(base64EncodedData)));
const decoded = SignalService.Content.decode(dataUint);
const conversationId = getOpenGroupV2ConversationId(serverUrl, roomId);
if (!conversationId) {
window.log.error('We cannot handle a message without a conversationId');
return;
}
const dataMessage = decoded?.dataMessage;
if (!dataMessage) {
window.log.error('Invalid decoded opengroup message: no dataMessage');
return;
}
if (!ConversationController.getInstance().get(conversationId)) {
window.log.error('Received a message for an unknown convo. Skipping');
return;
}
const isMe = UserUtils.isUsFromCache(sender);
// for an opengroupv2 incoming message the serverTimestamp and the timestamp
const messageCreationData: MessageCreationData = {
isPublic: true,
sourceDevice: 1,
serverId,
serverTimestamp: sentTimestamp,
receivedAt: Date.now(),
destination: conversationId,
timestamp: sentTimestamp,
unidentifiedStatus: undefined,
expirationStartTimestamp: undefined,
source: sender,
message: dataMessage,
};
if (await isMessageDuplicate(messageCreationData)) {
window.log.info('Received duplicate message. Dropping it.');
return;
}
// this line just create an empty message with some basic stuff set.
// the whole decoding of data is happening in handleMessageJob()
const msg = createMessage(messageCreationData, !isMe);
// if the message is `sent` (from secondary device) we have to set the sender manually... (at least for now)
// source = source || msg.get('source');
const ourNumber = UserUtils.getOurPubKeyStrFromCache();
const conversation = await ConversationController.getInstance().getOrCreateAndWait(
conversationId,
ConversationTypeEnum.GROUP
);
if (!conversation) {
window.log.warn('Skipping handleJob for unknown convo: ', conversationId);
return;
}
conversation.queueJob(async () => {
await handleMessageJob(msg, conversation, decoded?.dataMessage, ourNumber, noop, sender);
});
}