From a26c5da6cbec33e26b3861dcca9524119e610af7 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Wed, 28 Apr 2021 14:20:22 +1000 Subject: [PATCH] Uniformize once and for all the conversation types no more 'direct'. those are private convos --- .../conversation/InviteContactsDialog.tsx | 6 +++--- ts/components/conversation/Quote.tsx | 3 ++- ts/components/conversation/TypingBubble.tsx | 5 +++-- ts/components/session/LeftPaneContactSection.tsx | 6 ------ ts/components/session/LeftPaneMessageSection.tsx | 9 +++------ ts/components/session/SessionClosableOverlay.tsx | 10 ++++++---- .../session/conversation/SessionConversation.tsx | 3 ++- .../session/conversation/SessionMessagesList.tsx | 5 +++-- .../menu/ConversationListItemContextMenu.tsx | 5 +++-- .../session/usingClosedConversationDetails.tsx | 7 +++++-- ts/interactions/message.ts | 9 +++------ ts/models/conversation.ts | 16 +++++++--------- ts/models/message.ts | 8 ++++---- ts/models/messageType.ts | 3 ++- ts/opengroup/opengroupV1/OpenGroup.ts | 4 ++-- ts/opengroup/opengroupV2/OpenGroupManagerV2.ts | 4 ++-- ts/receiver/closedGroups.ts | 8 ++++---- ts/receiver/configMessage.ts | 4 ++-- ts/receiver/contentMessage.ts | 4 ++-- ts/receiver/dataMessage.ts | 14 +++++++------- ts/receiver/errors.ts | 4 ++-- ts/receiver/queuedJob.ts | 8 ++++---- ts/receiver/receiver.ts | 6 +++--- .../conversations/ConversationController.ts | 8 ++++---- ts/session/group/index.ts | 8 ++++---- ts/state/ducks/conversations.ts | 5 +++-- ts/state/ducks/search.ts | 5 +++-- ts/state/selectors/conversations.ts | 3 ++- ts/test/session/unit/utils/Messages_test.ts | 8 ++++---- ts/test/state/selectors/conversations_test.ts | 11 ++++++----- ts/test/test-utils/utils/message.ts | 10 +++++----- ts/util/accountManager.ts | 4 ++-- 32 files changed, 107 insertions(+), 106 deletions(-) diff --git a/ts/components/conversation/InviteContactsDialog.tsx b/ts/components/conversation/InviteContactsDialog.tsx index d8e4ef2a2..11ca09e2d 100644 --- a/ts/components/conversation/InviteContactsDialog.tsx +++ b/ts/components/conversation/InviteContactsDialog.tsx @@ -7,7 +7,7 @@ import { DefaultTheme } from 'styled-components'; import { ConversationController } from '../../session/conversations'; import { ToastUtils, UserUtils } from '../../session/utils'; import { initiateGroupUpdate } from '../../session/group'; -import { ConversationModel, ConversationType } from '../../models/conversation'; +import { ConversationModel, ConversationTypeEnum } from '../../models/conversation'; import { getCompleteUrlForV2ConvoId } from '../../interactions/conversation'; import _ from 'lodash'; interface Props { @@ -108,7 +108,7 @@ class InviteContactsDialogInner extends React.Component { pubkeys.forEach(async pubkeyStr => { const privateConvo = await ConversationController.getInstance().getOrCreateAndWait( pubkeyStr, - ConversationType.PRIVATE + ConversationTypeEnum.PRIVATE ); if (privateConvo) { @@ -125,7 +125,7 @@ class InviteContactsDialogInner extends React.Component { pubkeys.forEach(async pubkeyStr => { const privateConvo = await ConversationController.getInstance().getOrCreateAndWait( pubkeyStr, - ConversationType.PRIVATE + ConversationTypeEnum.PRIVATE ); if (privateConvo) { diff --git a/ts/components/conversation/Quote.tsx b/ts/components/conversation/Quote.tsx index ce1edf8ed..0193380ec 100644 --- a/ts/components/conversation/Quote.tsx +++ b/ts/components/conversation/Quote.tsx @@ -10,6 +10,7 @@ import { MessageBody } from './MessageBody'; import { ColorType, LocalizerType } from '../../types/Util'; import { ContactName } from './ContactName'; import { PubKey } from '../../session/types'; +import { ConversationTypeEnum } from '../../models/conversation'; interface Props { attachment?: QuotedAttachmentType; @@ -19,7 +20,7 @@ interface Props { i18n: LocalizerType; isFromMe: boolean; isIncoming: boolean; - conversationType: 'group' | 'direct'; + conversationType: ConversationTypeEnum; convoId: string; isPublic?: boolean; withContentAbove: boolean; diff --git a/ts/components/conversation/TypingBubble.tsx b/ts/components/conversation/TypingBubble.tsx index d4fed3f45..322832f04 100644 --- a/ts/components/conversation/TypingBubble.tsx +++ b/ts/components/conversation/TypingBubble.tsx @@ -2,12 +2,13 @@ import React from 'react'; import { TypingAnimation } from './TypingAnimation'; import styled from 'styled-components'; +import { ConversationTypeEnum } from '../../models/conversation'; interface TypingBubbleProps { avatarPath?: string; phoneNumber: string; displayedName: string | null; - conversationType: string; + conversationType: ConversationTypeEnum; isTyping: boolean; } @@ -24,7 +25,7 @@ const TypingBubbleContainer = styled.div` `; export const TypingBubble = (props: TypingBubbleProps) => { - if (props.conversationType === 'group') { + if (props.conversationType === ConversationTypeEnum.GROUP) { return <>; } diff --git a/ts/components/session/LeftPaneContactSection.tsx b/ts/components/session/LeftPaneContactSection.tsx index 8e063ad71..8666520dc 100644 --- a/ts/components/session/LeftPaneContactSection.tsx +++ b/ts/components/session/LeftPaneContactSection.tsx @@ -2,16 +2,10 @@ import React from 'react'; import { ConversationListItemWithDetails } from '../ConversationListItem'; import { RowRendererParamsType } from '../LeftPane'; -import { SessionButton, SessionButtonColor, SessionButtonType } from './SessionButton'; import { AutoSizer, List } from 'react-virtualized'; import { ConversationType as ReduxConversationType } from '../../state/ducks/conversations'; -import { SessionClosableOverlay, SessionClosableOverlayType } from './SessionClosableOverlay'; -import { ToastUtils } from '../../session/utils'; import { DefaultTheme } from 'styled-components'; import { LeftPaneSectionHeader } from './LeftPaneSectionHeader'; -import { ConversationController } from '../../session/conversations'; -import { PubKey } from '../../session/types'; -import { ConversationType } from '../../models/conversation'; import autoBind from 'auto-bind'; export interface Props { diff --git a/ts/components/session/LeftPaneMessageSection.tsx b/ts/components/session/LeftPaneMessageSection.tsx index c8d85c369..9979a56b4 100644 --- a/ts/components/session/LeftPaneMessageSection.tsx +++ b/ts/components/session/LeftPaneMessageSection.tsx @@ -24,11 +24,8 @@ import { DefaultTheme } from 'styled-components'; import { LeftPaneSectionHeader } from './LeftPaneSectionHeader'; import { ConversationController } from '../../session/conversations'; import { OpenGroup } from '../../opengroup/opengroupV1/OpenGroup'; -import { ConversationType } from '../../models/conversation'; -import { - getOpenGroupV2ConversationId, - openGroupV2CompleteURLRegex, -} from '../../opengroup/utils/OpenGroupUtils'; +import { ConversationTypeEnum } from '../../models/conversation'; +import { openGroupV2CompleteURLRegex } from '../../opengroup/utils/OpenGroupUtils'; import { joinOpenGroupV2WithUIEvents } from '../../opengroup/opengroupV2/JoinOpenGroupV2'; export interface Props { @@ -374,7 +371,7 @@ export class LeftPaneMessageSection extends React.Component { if (!error) { await ConversationController.getInstance().getOrCreateAndWait( pubkey, - ConversationType.PRIVATE + ConversationTypeEnum.PRIVATE ); openConversationExternal(pubkey); } else { diff --git a/ts/components/session/SessionClosableOverlay.tsx b/ts/components/session/SessionClosableOverlay.tsx index 2dddfd715..b3031453f 100644 --- a/ts/components/session/SessionClosableOverlay.tsx +++ b/ts/components/session/SessionClosableOverlay.tsx @@ -11,6 +11,7 @@ import { SessionSpinner } from './SessionSpinner'; import { PillDivider } from './PillDivider'; import { DefaultTheme } from 'styled-components'; import { UserUtils } from '../../session/utils'; +import { ConversationTypeEnum } from '../../models/conversation'; export enum SessionClosableOverlayType { Message = 'message', @@ -67,7 +68,9 @@ export class SessionClosableOverlay extends React.Component { let filteredContactsList = contactsList; const isClosedGroupView = overlayMode === SessionClosableOverlayType.ClosedGroup; if (isClosedGroupView) { - filteredContactsList = filteredContactsList.filter(c => c.type === 'direct' && !c.isMe); + filteredContactsList = filteredContactsList.filter( + c => c.type === ConversationTypeEnum.PRIVATE && !c.isMe + ); } return filteredContactsList.map((d: any) => { @@ -108,6 +111,8 @@ export class SessionClosableOverlay extends React.Component { onButtonClick, } = this.props; + const { groupName, selectedMembers } = this.state; + const isMessageView = overlayMode === SessionClosableOverlayType.Message; const isOpenGroupView = overlayMode === SessionClosableOverlayType.OpenGroup; const isClosedGroupView = overlayMode === SessionClosableOverlayType.ClosedGroup; @@ -141,9 +146,6 @@ export class SessionClosableOverlay extends React.Component { default: } - const { groupName, selectedMembers } = this.state; - const ourSessionID = UserUtils.getOurPubKeyStrFromCache(); - const contacts = this.getContacts(); const noContactsForClosedGroup = diff --git a/ts/components/session/conversation/SessionConversation.tsx b/ts/components/session/conversation/SessionConversation.tsx index bf0f7a21b..5bc87a1ec 100644 --- a/ts/components/session/conversation/SessionConversation.tsx +++ b/ts/components/session/conversation/SessionConversation.tsx @@ -30,6 +30,7 @@ import { getMessageById, getPubkeysInPublicConversation } from '../../../data/da import autoBind from 'auto-bind'; import { getDecryptedMediaUrl } from '../../../session/crypto/DecryptedAttachmentsManager'; import { deleteOpenGroupMessages } from '../../../interactions/conversation'; +import { ConversationTypeEnum } from '../../../models/conversation'; interface State { // Message sending progress @@ -223,7 +224,7 @@ export class SessionConversation extends React.Component { const isPublic = selectedConversation.isPublic || false; - const isPrivate = selectedConversation.type === 'direct'; + const isPrivate = selectedConversation.type === ConversationTypeEnum.PRIVATE; return (
{this.renderHeader()}
diff --git a/ts/components/session/conversation/SessionMessagesList.tsx b/ts/components/session/conversation/SessionMessagesList.tsx index f936a0b39..15b761ac1 100644 --- a/ts/components/session/conversation/SessionMessagesList.tsx +++ b/ts/components/session/conversation/SessionMessagesList.tsx @@ -19,6 +19,7 @@ import { MessageModel } from '../../../models/message'; import { MessageRegularProps } from '../../../models/messageType'; import { getMessagesBySentAt } from '../../../data/data'; import autoBind from 'auto-bind'; +import { ConversationTypeEnum } from '../../../models/conversation'; interface State { showScrollButton: boolean; @@ -122,7 +123,7 @@ export class SessionMessagesList extends React.Component { const { showScrollButton } = this.state; let displayedName = null; - if (conversation.type === 'direct') { + if (conversation.type === ConversationTypeEnum.PRIVATE) { displayedName = ConversationController.getInstance().getContactProfileNameOrShortenedPubKey( conversationKey ); @@ -247,7 +248,7 @@ export class SessionMessagesList extends React.Component { return; } - if (messageProps.conversationType === 'group') { + if (messageProps.conversationType === ConversationTypeEnum.GROUP) { messageProps.weAreAdmin = conversation.groupAdmins?.includes(ourPrimary); } // a message is deletable if diff --git a/ts/components/session/menu/ConversationListItemContextMenu.tsx b/ts/components/session/menu/ConversationListItemContextMenu.tsx index da775084e..0acf21c1c 100644 --- a/ts/components/session/menu/ConversationListItemContextMenu.tsx +++ b/ts/components/session/menu/ConversationListItemContextMenu.tsx @@ -1,5 +1,6 @@ import React from 'react'; import { animation, Menu } from 'react-contexify'; +import { ConversationTypeEnum } from '../../../models/conversation'; import { getBlockMenuItem, @@ -14,7 +15,7 @@ import { export type PropsContextConversationItem = { triggerId: string; - type: 'group' | 'direct'; + type: ConversationTypeEnum; isMe: boolean; isPublic?: boolean; isBlocked?: boolean; @@ -58,7 +59,7 @@ export const ConversationListItemContextMenu = (props: PropsContextConversationI {getBlockMenuItem( isMe, - type === 'direct', + type === ConversationTypeEnum.PRIVATE, isBlocked, onBlockContact, onUnblockContact, diff --git a/ts/components/session/usingClosedConversationDetails.tsx b/ts/components/session/usingClosedConversationDetails.tsx index d25d10f4f..33c2f813f 100644 --- a/ts/components/session/usingClosedConversationDetails.tsx +++ b/ts/components/session/usingClosedConversationDetails.tsx @@ -3,7 +3,7 @@ import { PubKey } from '../../session/types'; import React from 'react'; import * as _ from 'lodash'; import { ConversationController } from '../../session/conversations'; -import { ConversationType } from '../../models/conversation'; +import { ConversationTypeEnum } from '../../models/conversation'; export type ConversationAvatar = { avatarPath?: string; @@ -55,7 +55,10 @@ export function usingClosedConversationDetails(WrappedComponent: any) { members = members.slice(0, 2); const memberConvos = await Promise.all( members.map(async m => - ConversationController.getInstance().getOrCreateAndWait(m.key, ConversationType.PRIVATE) + ConversationController.getInstance().getOrCreateAndWait( + m.key, + ConversationTypeEnum.PRIVATE + ) ) ); const memberAvatars = memberConvos.map(m => { diff --git a/ts/interactions/message.ts b/ts/interactions/message.ts index 8bc18d432..f3bc37476 100644 --- a/ts/interactions/message.ts +++ b/ts/interactions/message.ts @@ -1,12 +1,9 @@ import _ from 'lodash'; import { getV2OpenGroupRoom } from '../data/opengroups'; -import { ConversationModel, ConversationType } from '../models/conversation'; +import { ConversationModel, ConversationTypeEnum } from '../models/conversation'; import { OpenGroup } from '../opengroup/opengroupV1/OpenGroup'; import { ApiV2 } from '../opengroup/opengroupV2'; -import { - joinOpenGroupV2WithUIEvents, - parseOpenGroupV2, -} from '../opengroup/opengroupV2/JoinOpenGroupV2'; +import { joinOpenGroupV2WithUIEvents } from '../opengroup/opengroupV2/JoinOpenGroupV2'; import { isOpenGroupV2, openGroupV2CompleteURLRegex } from '../opengroup/utils/OpenGroupUtils'; import { ConversationController } from '../session/conversations'; import { PubKey } from '../session/types'; @@ -224,7 +221,7 @@ async function acceptOpenGroupInvitationV1(serverAddress: string) { const conversation = await ConversationController.getInstance().getOrCreateAndWait( conversationId, - ConversationType.GROUP + ConversationTypeEnum.GROUP ); await conversation.setPublicSource(sslServerUrl, 1); diff --git a/ts/models/conversation.ts b/ts/models/conversation.ts index 7eb4eb49d..360a53385 100644 --- a/ts/models/conversation.ts +++ b/ts/models/conversation.ts @@ -4,7 +4,7 @@ import { getMessageQueue } from '../session'; import { ConversationController } from '../session/conversations'; import { ClosedGroupVisibleMessage } from '../session/messages/outgoing/visibleMessage/ClosedGroupVisibleMessage'; import { PubKey } from '../session/types'; -import { ToastUtils, UserUtils } from '../session/utils'; +import { UserUtils } from '../session/utils'; import { BlockedNumberController } from '../util'; import { MessageController } from '../session/messages'; import { leaveClosedGroup } from '../session/group'; @@ -39,13 +39,11 @@ import { ReadReceiptMessage } from '../session/messages/outgoing/controlMessage/ import { OpenGroup } from '../opengroup/opengroupV1/OpenGroup'; import { OpenGroupUtils } from '../opengroup/utils'; import { ConversationInteraction } from '../interactions'; -import { getV2OpenGroupRoom } from '../data/opengroups'; import { OpenGroupVisibleMessage } from '../session/messages/outgoing/visibleMessage/OpenGroupVisibleMessage'; import { OpenGroupRequestCommonType } from '../opengroup/opengroupV2/ApiUtil'; import { getOpenGroupV2FromConversationId } from '../opengroup/utils/OpenGroupUtils'; -import { ApiV2 } from '../opengroup/opengroupV2'; -export enum ConversationType { +export enum ConversationTypeEnum { GROUP = 'group', PRIVATE = 'private', } @@ -203,7 +201,7 @@ export class ConversationModel extends Backbone.Model { return OpenGroupUtils.isOpenGroupV1(this.id); } public isClosedGroup() { - return this.get('type') === ConversationType.GROUP && !this.isPublic(); + return this.get('type') === ConversationTypeEnum.GROUP && !this.isPublic(); } public isBlocked() { @@ -392,7 +390,7 @@ export class ConversationModel extends Backbone.Model { id: this.id as string, activeAt: this.get('active_at'), avatarPath: this.getAvatarPath() || undefined, - type: this.isPrivate() ? 'direct' : 'group', + type: this.isPrivate() ? ConversationTypeEnum.PRIVATE : ConversationTypeEnum.GROUP, isMe: this.isMe(), isPublic: this.isPublic(), isTyping: !!this.typingTimer, @@ -1190,7 +1188,7 @@ export class ConversationModel extends Backbone.Model { public async getProfile(id: string) { const c = await ConversationController.getInstance().getOrCreateAndWait( id, - ConversationType.PRIVATE + ConversationTypeEnum.PRIVATE ); // We only need to update the profile as they are all stored inside the conversation @@ -1445,7 +1443,7 @@ export class ConversationModel extends Backbone.Model { } public isPrivate() { - return this.get('type') === ConversationType.PRIVATE; + return this.get('type') === ConversationTypeEnum.PRIVATE; } public getAvatarPath() { @@ -1487,7 +1485,7 @@ export class ConversationModel extends Backbone.Model { const convo = await ConversationController.getInstance().getOrCreateAndWait( message.get('source'), - ConversationType.PRIVATE + ConversationTypeEnum.PRIVATE ); const iconUrl = await convo.getNotificationIcon(); diff --git a/ts/models/message.ts b/ts/models/message.ts index fb194fbeb..84324a536 100644 --- a/ts/models/message.ts +++ b/ts/models/message.ts @@ -18,7 +18,7 @@ import { import autoBind from 'auto-bind'; import { saveMessage } from '../../ts/data/data'; -import { ConversationModel, ConversationType } from './conversation'; +import { ConversationModel, ConversationTypeEnum } from './conversation'; import { getSuggestedFilenameSending } from '../types/Attachment'; import { actions as conversationActions } from '../state/ducks/conversations'; import { VisibleMessage } from '../session/messages/outgoing/visibleMessage/VisibleMessage'; @@ -480,7 +480,7 @@ export class MessageModel extends Backbone.Model { authorName: contact.name, authorProfileName: contact.profileName, authorPhoneNumber: contact.phoneNumber, - conversationType: isGroup ? 'group' : 'direct', + conversationType: isGroup ? ConversationTypeEnum.GROUP : ConversationTypeEnum.PRIVATE, convoId, attachments: attachments .filter((attachment: any) => !attachment.error) @@ -695,7 +695,7 @@ export class MessageModel extends Backbone.Model { ...this.propsForMessage, disableMenu: true, // To ensure that group avatar doesn't show up - conversationType: 'direct', + conversationType: ConversationTypeEnum.PRIVATE, }, errors, contacts: sortedContacts, @@ -911,7 +911,7 @@ export class MessageModel extends Backbone.Model { return null; } - return ConversationController.getInstance().getOrCreate(source, ConversationType.PRIVATE); + return ConversationController.getInstance().getOrCreate(source, ConversationTypeEnum.PRIVATE); } public isOutgoing() { diff --git a/ts/models/messageType.ts b/ts/models/messageType.ts index 2c1a6d469..0f09aa499 100644 --- a/ts/models/messageType.ts +++ b/ts/models/messageType.ts @@ -4,6 +4,7 @@ import { v4 as uuidv4 } from 'uuid'; import { QuotedAttachmentType } from '../components/conversation/Quote'; import { AttachmentType } from '../types/Attachment'; import { Contact } from '../types/Contact'; +import { ConversationTypeEnum } from './conversation'; export type MessageModelType = 'incoming' | 'outgoing'; export type MessageDeliveryStatus = 'sending' | 'sent' | 'delivered' | 'read' | 'error'; @@ -187,7 +188,7 @@ export interface MessageRegularProps { authorProfileName?: string; /** Note: this should be formatted for display */ authorPhoneNumber: string; - conversationType: 'group' | 'direct'; + conversationType: ConversationTypeEnum; attachments?: Array; quote?: { text: string; diff --git a/ts/opengroup/opengroupV1/OpenGroup.ts b/ts/opengroup/opengroupV1/OpenGroup.ts index fbda3c659..b3b7327c0 100644 --- a/ts/opengroup/opengroupV1/OpenGroup.ts +++ b/ts/opengroup/opengroupV1/OpenGroup.ts @@ -1,4 +1,4 @@ -import { ConversationModel, ConversationType } from '../../models/conversation'; +import { ConversationModel, ConversationTypeEnum } from '../../models/conversation'; import { ConversationController } from '../../session/conversations'; import { PromiseUtils } from '../../session/utils'; import { allowOnlyOneAtATime } from '../../session/utils/Promise'; @@ -332,7 +332,7 @@ export class OpenGroup { // Create conversation const conversation = await ConversationController.getInstance().getOrCreateAndWait( conversationId, - ConversationType.GROUP // keep a group for this one as this is an old open group + ConversationTypeEnum.GROUP // keep a group for this one as this is an old open group ); // Convert conversation to a public one diff --git a/ts/opengroup/opengroupV2/OpenGroupManagerV2.ts b/ts/opengroup/opengroupV2/OpenGroupManagerV2.ts index 05565216e..67f9f2ee3 100644 --- a/ts/opengroup/opengroupV2/OpenGroupManagerV2.ts +++ b/ts/opengroup/opengroupV2/OpenGroupManagerV2.ts @@ -5,7 +5,7 @@ import { removeV2OpenGroupRoom, saveV2OpenGroupRoom, } from '../../data/opengroups'; -import { ConversationModel, ConversationType } from '../../models/conversation'; +import { ConversationModel, ConversationTypeEnum } from '../../models/conversation'; import { ConversationController } from '../../session/conversations'; import { allowOnlyOneAtATime } from '../../session/utils/Promise'; import { getOpenGroupV2ConversationId } from '../utils/OpenGroupUtils'; @@ -178,7 +178,7 @@ export class OpenGroupManagerV2 { } const conversation = await ConversationController.getInstance().getOrCreateAndWait( conversationId, - ConversationType.GROUP + ConversationTypeEnum.GROUP ); room.imageID = roomInfos.imageId || undefined; room.roomName = roomInfos.name || undefined; diff --git a/ts/receiver/closedGroups.ts b/ts/receiver/closedGroups.ts index a4fdd1555..c5793c784 100644 --- a/ts/receiver/closedGroups.ts +++ b/ts/receiver/closedGroups.ts @@ -26,7 +26,7 @@ import { import { ECKeyPair, HexKeyPair } from './keypairs'; import { UserUtils } from '../session/utils'; -import { ConversationModel, ConversationType } from '../models/conversation'; +import { ConversationModel, ConversationTypeEnum } from '../models/conversation'; import _ from 'lodash'; import { forceSyncConfigurationNowIfNeeded } from '../session/utils/syncUtils'; import { MessageController } from '../session/messages'; @@ -196,7 +196,7 @@ export async function handleNewClosedGroup( maybeConvo || (await ConversationController.getInstance().getOrCreateAndWait( groupId, - ConversationType.GROUP + ConversationTypeEnum.GROUP )); // ***** Creating a new group ***** log.info('Received a new ClosedGroup of id:', groupId); @@ -744,7 +744,7 @@ async function sendLatestKeyPairToUsers( window.log.info(`Sending latest closed group encryption key pair to: ${member}`); await ConversationController.getInstance().getOrCreateAndWait( member, - ConversationType.PRIVATE + ConversationTypeEnum.PRIVATE ); const wrappers = await ClosedGroup.buildEncryptionKeyPairWrappers([member], keyPairToUse); @@ -801,7 +801,7 @@ export async function createClosedGroup(groupName: string, members: Array { const isGroupMessage = Boolean(message.group); - const type = isGroupMessage ? ConversationType.GROUP : ConversationType.PRIVATE; + const type = isGroupMessage ? ConversationTypeEnum.GROUP : ConversationTypeEnum.PRIVATE; let conversationId = isIncoming ? source : destination || source; // for synced message if (!conversationId) { diff --git a/ts/receiver/errors.ts b/ts/receiver/errors.ts index ed98fc399..6a2ae9dee 100644 --- a/ts/receiver/errors.ts +++ b/ts/receiver/errors.ts @@ -3,7 +3,7 @@ import { toNumber } from 'lodash'; import { ConversationController } from '../session/conversations'; import { MessageController } from '../session/messages'; import { actions as conversationActions } from '../state/ducks/conversations'; -import { ConversationType } from '../models/conversation'; +import { ConversationTypeEnum } from '../models/conversation'; export async function onError(ev: any) { const { error } = ev; @@ -18,7 +18,7 @@ export async function onError(ev: any) { const id = message.get('conversationId'); const conversation = await ConversationController.getInstance().getOrCreateAndWait( id, - ConversationType.PRIVATE + ConversationTypeEnum.PRIVATE ); // force conversation unread count to be > 0 so it is highlighted conversation.set({ diff --git a/ts/receiver/queuedJob.ts b/ts/receiver/queuedJob.ts index 0d98944a1..3d1751720 100644 --- a/ts/receiver/queuedJob.ts +++ b/ts/receiver/queuedJob.ts @@ -2,12 +2,12 @@ import { queueAttachmentDownloads } from './attachments'; import { Quote } from './types'; import { PubKey } from '../session/types'; -import _, { toNumber } from 'lodash'; +import _ from 'lodash'; import { SignalService } from '../protobuf'; import { StringUtils, UserUtils } from '../session/utils'; import { ConversationController } from '../session/conversations'; -import { ConversationModel, ConversationType } from '../models/conversation'; -import { MessageCollection, MessageModel } from '../models/message'; +import { ConversationModel, ConversationTypeEnum } from '../models/conversation'; +import { MessageModel } from '../models/message'; import { MessageController } from '../session/messages'; import { getMessageById, getMessagesBySentAt } from '../../ts/data/data'; import { actions as conversationActions } from '../state/ducks/conversations'; @@ -369,7 +369,7 @@ async function handleRegularMessage( const sendingDeviceConversation = await ConversationController.getInstance().getOrCreateAndWait( source, - ConversationType.PRIVATE + ConversationTypeEnum.PRIVATE ); // Check if we need to update any profile names // the only profile we don't update with what is coming here is ours, diff --git a/ts/receiver/receiver.ts b/ts/receiver/receiver.ts index aa0f5194d..de1cfa378 100644 --- a/ts/receiver/receiver.ts +++ b/ts/receiver/receiver.ts @@ -27,7 +27,7 @@ import { StringUtils, UserUtils } from '../session/utils'; import { SignalService } from '../protobuf'; import { ConversationController } from '../session/conversations'; import { removeUnprocessed } from '../data/data'; -import { ConversationType } from '../models/conversation'; +import { ConversationTypeEnum } from '../models/conversation'; import { getOpenGroupV2ConversationId, openGroupPrefixRegex, @@ -281,7 +281,7 @@ export async function handlePublicMessage(messageData: any) { if (!isMe && profile) { const conversation = await ConversationController.getInstance().getOrCreateAndWait( source, - ConversationType.PRIVATE + ConversationTypeEnum.PRIVATE ); await updateProfile(conversation, profile, profileKey); } @@ -365,7 +365,7 @@ export async function handleOpenGroupV2Message( const ourNumber = UserUtils.getOurPubKeyStrFromCache(); const conversation = await ConversationController.getInstance().getOrCreateAndWait( conversationId, - ConversationType.GROUP + ConversationTypeEnum.GROUP ); if (!conversation) { diff --git a/ts/session/conversations/ConversationController.ts b/ts/session/conversations/ConversationController.ts index 51d922f0a..8cfe27909 100644 --- a/ts/session/conversations/ConversationController.ts +++ b/ts/session/conversations/ConversationController.ts @@ -8,7 +8,7 @@ import { ConversationAttributes, ConversationCollection, ConversationModel, - ConversationType, + ConversationTypeEnum, } from '../../models/conversation'; import { BlockedNumberController } from '../../util'; import { getSnodesFor } from '../snode_api/snodePool'; @@ -67,12 +67,12 @@ export class ConversationController { return this.conversations.add(attributes); } - public getOrCreate(id: string, type: ConversationType) { + public getOrCreate(id: string, type: ConversationTypeEnum) { if (typeof id !== 'string') { throw new TypeError("'id' must be a string"); } - if (type !== ConversationType.PRIVATE && type !== ConversationType.GROUP) { + if (type !== ConversationTypeEnum.PRIVATE && type !== ConversationTypeEnum.GROUP) { throw new TypeError(`'type' must be 'private' or 'group' got: '${type}'`); } @@ -153,7 +153,7 @@ export class ConversationController { public async getOrCreateAndWait( id: string | PubKey, - type: ConversationType + type: ConversationTypeEnum ): Promise { const initialPromise = this._initialPromise !== undefined ? this._initialPromise : Promise.resolve(); diff --git a/ts/session/group/index.ts b/ts/session/group/index.ts index 9f7f9fc17..50b27733c 100644 --- a/ts/session/group/index.ts +++ b/ts/session/group/index.ts @@ -18,7 +18,7 @@ import { encryptUsingSessionProtocol } from '../crypto/MessageEncrypter'; import { ECKeyPair } from '../../receiver/keypairs'; import { UserUtils } from '../utils'; import { ClosedGroupMemberLeftMessage } from '../messages/outgoing/controlMessage/group/ClosedGroupMemberLeftMessage'; -import { ConversationModel, ConversationType } from '../../models/conversation'; +import { ConversationModel, ConversationTypeEnum } from '../../models/conversation'; import { MessageModel } from '../../models/message'; import { MessageModelType } from '../../models/messageType'; import { MessageController } from '../messages'; @@ -86,7 +86,7 @@ export async function initiateGroupUpdate( ) { const convo = await ConversationController.getInstance().getOrCreateAndWait( groupId, - ConversationType.GROUP + ConversationTypeEnum.GROUP ); if (convo.isPublic()) { @@ -223,7 +223,7 @@ export async function updateOrCreateClosedGroup(details: GroupInfo) { const conversation = await ConversationController.getInstance().getOrCreateAndWait( id, - ConversationType.GROUP + ConversationTypeEnum.GROUP ); const updates: any = { @@ -409,7 +409,7 @@ async function sendAddedMembers( }); const promises = addedMembers.map(async m => { - await ConversationController.getInstance().getOrCreateAndWait(m, ConversationType.PRIVATE); + await ConversationController.getInstance().getOrCreateAndWait(m, ConversationTypeEnum.PRIVATE); const memberPubKey = PubKey.cast(m); await getMessageQueue().sendToPubKey(memberPubKey, newClosedGroupUpdate); }); diff --git a/ts/state/ducks/conversations.ts b/ts/state/ducks/conversations.ts index c7951d749..b6a2e03c6 100644 --- a/ts/state/ducks/conversations.ts +++ b/ts/state/ducks/conversations.ts @@ -3,8 +3,9 @@ import _, { omit } from 'lodash'; import { Constants } from '../../session'; import { createAsyncThunk } from '@reduxjs/toolkit'; import { ConversationController } from '../../session/conversations'; -import { MessageCollection, MessageModel } from '../../models/message'; +import { MessageModel } from '../../models/message'; import { getMessagesByConversation } from '../../data/data'; +import { ConversationTypeEnum } from '../../models/conversation'; // State @@ -66,7 +67,7 @@ export interface ConversationType { activeAt?: number; lastMessage?: LastMessageType; phoneNumber: string; - type: 'direct' | 'group'; + type: ConversationTypeEnum; isMe: boolean; isPublic?: boolean; unreadCount: number; diff --git a/ts/state/ducks/search.ts b/ts/state/ducks/search.ts index 842b7b92c..6b0e95ba3 100644 --- a/ts/state/ducks/search.ts +++ b/ts/state/ducks/search.ts @@ -15,6 +15,7 @@ import { import { PubKey } from '../../session/types'; import { MessageModel } from '../../models/message'; import { MessageModelType } from '../../models/messageType'; +import { ConversationTypeEnum } from '../../models/conversation'; // State @@ -257,9 +258,9 @@ async function queryConversationsAndContacts(providedQuery: string, options: Sea } else { conversations.push(primaryDevice); } - } else if (conversation.type === 'direct') { + } else if (conversation.type === ConversationTypeEnum.PRIVATE) { contacts.push(conversation.id); - } else if (conversation.type !== 'group') { + } else if (conversation.type !== ConversationTypeEnum.GROUP) { contacts.push(conversation.id); } else { conversations.push(conversation.id); diff --git a/ts/state/selectors/conversations.ts b/ts/state/selectors/conversations.ts index 218cc88d1..8d6f89227 100644 --- a/ts/state/selectors/conversations.ts +++ b/ts/state/selectors/conversations.ts @@ -11,6 +11,7 @@ import { import { getIntl, getOurNumber } from './user'; import { BlockedNumberController } from '../../util'; import { LocalizerType } from '../../types/Util'; +import { ConversationTypeEnum } from '../../models/conversation'; export const getConversations = (state: StateType): ConversationsStateType => state.conversations; @@ -140,7 +141,7 @@ export const _getLeftPaneLists = ( continue; } - if (conversation.activeAt !== undefined && conversation.type === 'direct') { + if (conversation.activeAt !== undefined && conversation.type === ConversationTypeEnum.PRIVATE) { directConversations.push(conversation); } diff --git a/ts/test/session/unit/utils/Messages_test.ts b/ts/test/session/unit/utils/Messages_test.ts index e511e7bb3..828c2ff06 100644 --- a/ts/test/session/unit/utils/Messages_test.ts +++ b/ts/test/session/unit/utils/Messages_test.ts @@ -9,7 +9,7 @@ import { ClosedGroupVisibleMessage } from '../../../../session/messages/outgoing import { MockConversation } from '../../../test-utils/utils'; import { ConfigurationMessage } from '../../../../session/messages/outgoing/controlMessage/ConfigurationMessage'; -import { ConversationModel, ConversationType } from '../../../../models/conversation'; +import { ConversationModel, ConversationTypeEnum } from '../../../../models/conversation'; import chaiAsPromised from 'chai-as-promised'; chai.use(chaiAsPromised as any); @@ -227,17 +227,17 @@ describe('Message Utils', () => { let convos: Array; const mockValidOpenGroup = new MockConversation({ - type: ConversationType.GROUP, + type: ConversationTypeEnum.GROUP, id: `${openGroupPrefix}1@chat-dev.lokinet.org`, }); const mockValidOpenGroup2 = new MockConversation({ - type: ConversationType.GROUP, + type: ConversationTypeEnum.GROUP, id: `${openGroupPrefix}1@chat-dev2.lokinet.org`, }); const mockValidClosedGroup = new MockConversation({ - type: ConversationType.GROUP, + type: ConversationTypeEnum.GROUP, }); const mockValidPrivate = { diff --git a/ts/test/state/selectors/conversations_test.ts b/ts/test/state/selectors/conversations_test.ts index c814d829b..99810915e 100644 --- a/ts/test/state/selectors/conversations_test.ts +++ b/ts/test/state/selectors/conversations_test.ts @@ -1,4 +1,5 @@ import { assert } from 'chai'; +import { ConversationTypeEnum } from '../../../models/conversation'; import { ConversationLookupType } from '../../../state/ducks/conversations'; import { @@ -17,7 +18,7 @@ describe('state/selectors/conversations', () => { name: 'No timestamp', phoneNumber: 'notused', - type: 'direct', + type: ConversationTypeEnum.PRIVATE, isMe: false, unreadCount: 1, mentionedUs: false, @@ -33,7 +34,7 @@ describe('state/selectors/conversations', () => { name: 'B', phoneNumber: 'notused', - type: 'direct', + type: ConversationTypeEnum.PRIVATE, isMe: false, unreadCount: 1, mentionedUs: false, @@ -49,7 +50,7 @@ describe('state/selectors/conversations', () => { name: 'C', phoneNumber: 'notused', - type: 'direct', + type: ConversationTypeEnum.PRIVATE, isMe: false, unreadCount: 1, mentionedUs: false, @@ -64,7 +65,7 @@ describe('state/selectors/conversations', () => { activeAt: 20, name: 'Á', phoneNumber: 'notused', - type: 'direct', + type: ConversationTypeEnum.PRIVATE, isMe: false, unreadCount: 1, mentionedUs: false, @@ -79,7 +80,7 @@ describe('state/selectors/conversations', () => { activeAt: 30, name: 'First!', phoneNumber: 'notused', - type: 'direct', + type: ConversationTypeEnum.PRIVATE, isMe: false, unreadCount: 1, mentionedUs: false, diff --git a/ts/test/test-utils/utils/message.ts b/ts/test/test-utils/utils/message.ts index 5f03216c7..c20a897db 100644 --- a/ts/test/test-utils/utils/message.ts +++ b/ts/test/test-utils/utils/message.ts @@ -1,7 +1,7 @@ import { v4 as uuid } from 'uuid'; import { generateFakePubKey, generateFakePubKeys } from './pubkey'; import { ClosedGroupVisibleMessage } from '../../../session/messages/outgoing/visibleMessage/ClosedGroupVisibleMessage'; -import { ConversationAttributes, ConversationType } from '../../../models/conversation'; +import { ConversationAttributes, ConversationTypeEnum } from '../../../models/conversation'; import { OpenGroupMessage } from '../../../session/messages/outgoing'; import { VisibleMessage } from '../../../session/messages/outgoing/visibleMessage/VisibleMessage'; import { OpenGroup } from '../../../opengroup/opengroupV1/OpenGroup'; @@ -48,13 +48,13 @@ export function generateClosedGroupMessage(groupId?: string): ClosedGroupVisible interface MockConversationParams { id?: string; members?: Array; - type: ConversationType; + type: ConversationTypeEnum; isMediumGroup?: boolean; } export class MockConversation { public id: string; - public type: ConversationType; + public type: ConversationTypeEnum; public attributes: ConversationAttributes; constructor(params: MockConversationParams) { @@ -70,7 +70,7 @@ export class MockConversation { id: this.id, name: '', profileName: undefined, - type: params.type === ConversationType.GROUP ? 'group' : params.type, + type: params.type === ConversationTypeEnum.GROUP ? 'group' : params.type, members, left: false, expireTimer: 0, @@ -85,7 +85,7 @@ export class MockConversation { } public isPrivate() { - return this.type === ConversationType.PRIVATE; + return this.type === ConversationTypeEnum.PRIVATE; } public isBlocked() { diff --git a/ts/util/accountManager.ts b/ts/util/accountManager.ts index 6d7aaab99..cd6963bda 100644 --- a/ts/util/accountManager.ts +++ b/ts/util/accountManager.ts @@ -14,7 +14,7 @@ import { import { forceSyncConfigurationNowIfNeeded } from '../session/utils/syncUtils'; import { actions as userActions } from '../state/ducks/user'; import { mn_decode, mn_encode } from '../session/crypto/mnemonic'; -import { ConversationType } from '../models/conversation'; +import { ConversationTypeEnum } from '../models/conversation'; /** * Might throw @@ -216,7 +216,7 @@ async function registrationDone(ourPubkey: string, displayName: string) { // Ensure that we always have a conversation for ourself const conversation = await ConversationController.getInstance().getOrCreateAndWait( ourPubkey, - ConversationType.PRIVATE + ConversationTypeEnum.PRIVATE ); await conversation.setLokiProfile({ displayName }); const user = {