From 5e314e4dcccafa70066174a9caba3be7680cac80 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Tue, 25 Jan 2022 10:55:04 +1100 Subject: [PATCH] remove 'recipients' message field and 'destination' we do not need recipients as it makes no sense for us having medium groups on the same pubkey we do not need destination as it can always be guessed from the direction and the type of conversation of that message --- stylesheets/_modules.scss | 2 +- stylesheets/_theme_dark.scss | 20 ----------------- ts/data/data.ts | 1 + ts/models/conversation.ts | 32 ++++++--------------------- ts/models/message.ts | 7 ++---- ts/models/messageType.ts | 12 +--------- ts/receiver/queuedJob.ts | 19 ++-------------- ts/session/apis/snode_api/SNodeAPI.ts | 4 ++++ ts/session/sending/MessageSender.ts | 1 + 9 files changed, 19 insertions(+), 79 deletions(-) diff --git a/stylesheets/_modules.scss b/stylesheets/_modules.scss index d5e7aeaae..fe4f307b9 100644 --- a/stylesheets/_modules.scss +++ b/stylesheets/_modules.scss @@ -1421,7 +1421,7 @@ cursor: pointer; &:hover { - background-color: $color-gray-05; + background-color: var(--color-clickable-hovered); } } diff --git a/stylesheets/_theme_dark.scss b/stylesheets/_theme_dark.scss index 1456b5e36..fb05763aa 100644 --- a/stylesheets/_theme_dark.scss +++ b/stylesheets/_theme_dark.scss @@ -48,26 +48,6 @@ } } - .recipients-input { - .recipients-container { - background-color: white; - border-bottom: 1px solid #f2f2f2; - } - - .recipient { - background-color: $blue; - color: white; - - &.error { - background-color: #f00; - } - } - - .results { - box-shadow: 0px 0px 1px rgba(#aaa, 0.8); - } - } - .loading { position: relative; &::before { diff --git a/ts/data/data.ts b/ts/data/data.ts index 1e1f0a6b2..b640ef71e 100644 --- a/ts/data/data.ts +++ b/ts/data/data.ts @@ -1,6 +1,7 @@ import { ipcRenderer } from 'electron'; // tslint:disable: no-require-imports no-var-requires one-variable-per-declaration no-void-expression +// tslint:disable: function-name import _ from 'lodash'; import { MessageResultProps } from '../components/search/MessageSearchResults'; diff --git a/ts/models/conversation.ts b/ts/models/conversation.ts index 45681bc45..e3f821e0d 100644 --- a/ts/models/conversation.ts +++ b/ts/models/conversation.ts @@ -514,13 +514,6 @@ export class ConversationModel extends Backbone.Model { return current; } - public getRecipients() { - if (this.isPrivate()) { - return [this.id]; - } - const me = UserUtils.getOurPubKeyStrFromCache(); - return _.without(this.get('members'), me); - } public async getQuoteAttachment(attachments: any, preview: any) { if (attachments && attachments.length) { @@ -710,12 +703,9 @@ export class ConversationModel extends Backbone.Model { this.clearTypingTimers(); const destination = this.id; - const isPrivate = this.isPrivate(); const expireTimer = this.get('expireTimer'); - const recipients = this.getRecipients(); - const now = Date.now(); - const networkTimestamp = now - getLatestTimestampOffset(); + const networkTimestamp = getNowWithNetworkOffset(); window?.log?.info( 'Sending message to conversation', @@ -734,16 +724,13 @@ export class ConversationModel extends Backbone.Model { preview, attachments, sent_at: networkTimestamp, - received_at: now, + received_at: networkTimestamp, expireTimer, - recipients, isDeleted: false, source: UserUtils.getOurPubKeyStrFromCache(), }; - if (!this.isPublic()) { - messageObject.destination = destination; - } else { + if (this.isPublic()) { // set the serverTimestamp only if this conversation is a public one. messageObject.serverTimestamp = Date.now(); } @@ -752,7 +739,6 @@ export class ConversationModel extends Backbone.Model { ...messageObject, groupInvitation, conversationId: this.id, - destination: isPrivate ? destination : undefined, }; const messageModel = await this.addSingleMessage(attributes); @@ -771,7 +757,7 @@ export class ConversationModel extends Backbone.Model { this.set({ lastMessage: messageModel.getNotificationText(), lastMessageStatus: 'sending', - active_at: now, + active_at: networkTimestamp, }); await this.commit(); @@ -806,7 +792,7 @@ export class ConversationModel extends Backbone.Model { } public async updateExpireTimer( - providedExpireTimer: any, + providedExpireTimer: number | null, providedSource?: string, receivedAt?: number, // is set if it comes from outside options: { @@ -874,13 +860,9 @@ export class ConversationModel extends Backbone.Model { const expireUpdate = { identifier: message.id, timestamp, - expireTimer, + expireTimer: expireTimer ? expireTimer : (null as number | null), }; - if (!expireUpdate.expireTimer) { - delete expireUpdate.expireTimer; - } - if (this.isMe()) { const expirationTimerMessage = new ExpirationTimerUpdateMessage(expireUpdate); return message.sendSyncMessageOnly(expirationTimerMessage); @@ -1519,7 +1501,7 @@ export class ConversationModel extends Backbone.Model { const { expireTimer } = json; - return typeof expireTimer === 'number' && expireTimer > 0; + return isFinite(expireTimer) && expireTimer > 0; } private shouldDoTyping() { diff --git a/ts/models/message.ts b/ts/models/message.ts index 26e96a89c..b24b598ff 100644 --- a/ts/models/message.ts +++ b/ts/models/message.ts @@ -647,12 +647,9 @@ export class MessageModel extends Backbone.Model { // We include numbers we didn't successfully send to so we can display errors. // Older messages don't have the recipients included on the message, so we fall // back to the conversation's current recipients - const phoneNumbers = this.isIncoming() + const phoneNumbers: Array = this.isIncoming() ? [this.get('source')] - : _.union( - this.get('sent_to') || [], - this.get('recipients') || this.getConversation()?.getRecipients() || [] - ); + : this.get('sent_to') || []; // This will make the error message for outgoing key errors a bit nicer const allErrors = (this.get('errors') || []).map((error: any) => { diff --git a/ts/models/messageType.ts b/ts/models/messageType.ts index 63a78750d..86b99e03a 100644 --- a/ts/models/messageType.ts +++ b/ts/models/messageType.ts @@ -15,14 +15,12 @@ export interface MessageAttributes { expireTimer: number; received_at?: number; sent_at?: number; - destination?: string; preview?: any; body?: string; expirationStartTimestamp: number; read_by: Array; decrypted_at: number; expires_at?: number; - recipients: Array; type: MessageModelType; group_update?: MessageGroupUpdate; groupInvitation?: any; @@ -48,8 +46,7 @@ export interface MessageAttributes { */ timestamp?: number; status?: MessageDeliveryStatus; - // dataMessage: any; - sent_to: any; + sent_to: Array; sent: boolean; /** @@ -113,11 +110,6 @@ export interface DataExtractionNotificationMsg { referencedAttachmentTimestamp: number; // the attachment timestamp he screenshot } -export enum MessageDirection { - outgoing = 'outgoing', - incoming = 'incoming', -} - export type PropsForDataExtractionNotification = DataExtractionNotificationMsg & { name: string; messageId: string; @@ -139,14 +131,12 @@ export interface MessageAttributesOptionals { expireTimer?: number; received_at?: number; sent_at?: number; - destination?: string; preview?: any; body?: string; expirationStartTimestamp?: number; read_by?: Array; decrypted_at?: number; expires_at?: number; - recipients?: Array; type: MessageModelType; group_update?: MessageGroupUpdate; groupInvitation?: any; diff --git a/ts/receiver/queuedJob.ts b/ts/receiver/queuedJob.ts index c95d8e658..950b4a749 100644 --- a/ts/receiver/queuedJob.ts +++ b/ts/receiver/queuedJob.ts @@ -167,23 +167,8 @@ function updateReadStatus(message: MessageModel, conversation: ConversationModel } async function handleSyncedReceipts(message: MessageModel, conversation: ConversationModel) { - const readReceipts = window.Whisper.ReadReceipts.forMessage(conversation, message); - if (readReceipts.length) { - const readBy = readReceipts.map((receipt: any) => receipt.get('reader')); - message.set({ - read_by: _.union(message.get('read_by'), readBy), - }); - } - - // A sync'd message to ourself is automatically considered read - const recipients = conversation.getRecipients(); - if (conversation.isMe()) { - message.set({ - read_by: recipients, - }); - } - - message.set({ recipients }); + console.warn('handleSyncedReceipts', message); + debugger; // If the newly received message is from us, we assume that we've seen the messages up until that point const sentTimestamp = message.get('sent_at'); diff --git a/ts/session/apis/snode_api/SNodeAPI.ts b/ts/session/apis/snode_api/SNodeAPI.ts index 18835bf61..17d54a4f7 100644 --- a/ts/session/apis/snode_api/SNodeAPI.ts +++ b/ts/session/apis/snode_api/SNodeAPI.ts @@ -39,6 +39,10 @@ function handleTimestampOffset(_request: string, snodeTimestamp: number) { } } +/** + * This function has no use to be called except during tests. + * @returns the current offset we have with the rest of the network. + */ export function getLatestTimestampOffset() { if (latestTimestampOffset === Number.MAX_SAFE_INTEGER) { window.log.warn('latestTimestampOffset is not set yet'); diff --git a/ts/session/sending/MessageSender.ts b/ts/session/sending/MessageSender.ts index 00d45e987..0f45623e4 100644 --- a/ts/session/sending/MessageSender.ts +++ b/ts/session/sending/MessageSender.ts @@ -119,6 +119,7 @@ export async function send( ); } +// tslint:disable-next-line: function-name export async function TEST_sendMessageToSnode( pubKey: string, data: Uint8Array,