remove getInstance of conversationController to get()

pull/1719/head
Audric Ackermann 4 years ago
parent 35b55df180
commit 89a0868fc3
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -152,8 +152,7 @@ window.setPassword = (passPhrase, oldPhrase) =>
window.libsession = require('./ts/session');
window.getConversationController =
window.libsession.Conversations.ConversationController.getInstance;
window.getConversationController = window.libsession.Conversations.getConversationController;
// We never do these in our code, so we'll prevent it everywhere
window.open = () => null;
@ -347,9 +346,6 @@ window.Signal.Data = require('./ts/data/data');
window.getMessageController = () => window.libsession.Messages.MessageController.getInstance();
window.getConversationController = () =>
window.libsession.Conversations.ConversationController.getInstance();
// Pulling these in separately since they access filesystem, electron
window.Signal.Backup = require('./js/modules/backup');
window.Signal.Logs = require('./js/modules/logs');

@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React from 'react';
import classNames from 'classnames';
import { QRCode } from 'react-qr-svg';
@ -15,7 +15,7 @@ import { ConversationModel, ConversationTypeEnum } from '../models/conversation'
import { SessionWrapperModal } from './session/SessionWrapperModal';
import { AttachmentUtil } from '../util';
import { ConversationController } from '../session/conversations';
import { getConversationController } from '../session/conversations';
import { SpacerLG, SpacerMD } from './basic/Text';
import autoBind from 'auto-bind';
import { editProfileModal } from '../state/ducks/modalDialog';
@ -38,7 +38,7 @@ export class EditProfileDialog extends React.Component<{}, State> {
autoBind(this);
this.convo = ConversationController.getInstance().get(UserUtils.getOurPubKeyStrFromCache());
this.convo = getConversationController().get(UserUtils.getOurPubKeyStrFromCache());
this.state = {
profileName: this.convo.getProfileName() || '',
@ -313,7 +313,7 @@ export class EditProfileDialog extends React.Component<{}, State> {
private async commitProfileEdits(newName: string, avatar: any) {
const ourNumber = UserUtils.getOurPubKeyStrFromCache();
const conversation = await ConversationController.getInstance().getOrCreateAndWait(
const conversation = await getConversationController().getOrCreateAndWait(
ourNumber,
ConversationTypeEnum.PRIVATE
);

@ -38,7 +38,6 @@ const OnionPathModalInner = () => {
const onionPath = useSelector(getFirstOnionPath);
// including the device and destination in calculation
const glowDuration = onionPath.length + 2;
console.warn('onionPath', onionPath);
if (!onionPath || onionPath.length === 0) {
return <SessionSpinner loading={true} />;
}

@ -3,7 +3,7 @@ import { Avatar, AvatarSize } from './Avatar';
import { SessionButton, SessionButtonColor, SessionButtonType } from './session/SessionButton';
import { SessionIdEditable } from './session/SessionIdEditable';
import { ConversationController } from '../session/conversations';
import { getConversationController } from '../session/conversations';
import { ConversationTypeEnum } from '../models/conversation';
import { SessionWrapperModal } from './session/SessionWrapperModal';
import { SpacerMD } from './basic/Text';
@ -19,7 +19,7 @@ type Props = {
export const UserDetailsDialog = (props: Props) => {
const [isEnlargedImageShown, setIsEnlargedImageShown] = useState(false);
const convo = ConversationController.getInstance().get(props.conversationId);
const convo = getConversationController().get(props.conversationId);
const size = isEnlargedImageShown ? AvatarSize.HUGE : AvatarSize.XL;
const userName = props.userName || props.conversationId;
@ -29,7 +29,7 @@ export const UserDetailsDialog = (props: Props) => {
}
async function onClickStartConversation() {
const conversation = await ConversationController.getInstance().getOrCreateAndWait(
const conversation = await getConversationController().getOrCreateAndWait(
convo.id,
ConversationTypeEnum.PRIVATE
);

@ -3,7 +3,7 @@ import React from 'react';
import { SessionButton, SessionButtonColor } from '../session/SessionButton';
import { SessionWrapperModal } from '../session/SessionWrapperModal';
import { SpacerLG } from '../basic/Text';
import { ConversationController } from '../../session/conversations';
import { getConversationController } from '../../session/conversations';
import { adminLeaveClosedGroup } from '../../state/ducks/modalDialog';
type Props = {
@ -11,14 +11,14 @@ type Props = {
};
export const AdminLeaveClosedGroupDialog = (props: Props) => {
const convo = ConversationController.getInstance().get(props.conversationId);
const convo = getConversationController().get(props.conversationId);
const titleText = `${window.i18n('leaveGroup')} ${convo.getName()}`;
const warningAsAdmin = `${window.i18n('leaveGroupConfirmationAdmin')}`;
const okText = window.i18n('leaveAndRemoveForEveryone');
const cancelText = window.i18n('cancel');
const onClickOK = async () => {
await ConversationController.getInstance()
await getConversationController()
.get(props.conversationId)
.leaveClosedGroup();
closeDialog();

@ -4,7 +4,7 @@ import { SessionModal } from '../session/SessionModal';
import { SessionButton, SessionButtonColor } from '../session/SessionButton';
import { ContactType, SessionMemberListItem } from '../session/SessionMemberListItem';
import { DefaultTheme, useTheme } from 'styled-components';
import { ConversationController } from '../../session/conversations';
import { getConversationController } from '../../session/conversations';
import { ToastUtils, UserUtils } from '../../session/utils';
import { initiateGroupUpdate } from '../../session/group';
import { ConversationModel, ConversationTypeEnum } from '../../models/conversation';
@ -26,10 +26,10 @@ const InviteContactsDialogInner = (props: Props) => {
const theme = useTheme();
const dispatch = useDispatch();
const convo = ConversationController.getInstance().get(conversationId);
const convo = getConversationController().get(conversationId);
// tslint:disable-next-line: max-func-body-length
let contacts = ConversationController.getInstance()
let contacts = getConversationController()
.getConversations()
.filter(d => !!d && !d.isBlocked() && d.isPrivate() && !d.isMe() && !!d.get('active_at'));
if (!convo.isPublic()) {
@ -118,7 +118,7 @@ const InviteContactsDialogInner = (props: Props) => {
name: convo.getName(),
};
pubkeys.forEach(async pubkeyStr => {
const privateConvo = await ConversationController.getInstance().getOrCreateAndWait(
const privateConvo = await getConversationController().getOrCreateAndWait(
pubkeyStr,
ConversationTypeEnum.PRIVATE
);

@ -7,7 +7,7 @@ import { SessionSpinner } from '../session/SessionSpinner';
import { Flex } from '../basic/Flex';
import { ApiV2 } from '../../opengroup/opengroupV2';
import { SessionWrapperModal } from '../session/SessionWrapperModal';
import { ConversationController } from '../../session/conversations';
import { getConversationController } from '../../session/conversations';
import { useDispatch } from 'react-redux';
import { updateAddModeratorsModal } from '../../state/ducks/modalDialog';
import _ from 'lodash';
@ -21,7 +21,7 @@ export const AddModeratorsDialog = (props: Props) => {
const theme = useTheme();
const dispatch = useDispatch();
const convo = ConversationController.getInstance().get(conversationId);
const convo = getConversationController().get(conversationId);
const [inputBoxValue, setInputBoxValue] = useState('');
const [addingInProgress, setAddingInProgress] = useState(false);

@ -2,7 +2,7 @@ import React from 'react';
import { DefaultTheme } from 'styled-components';
import { ConversationModel } from '../../models/conversation';
import { ApiV2 } from '../../opengroup/opengroupV2';
import { ConversationController } from '../../session/conversations';
import { getConversationController } from '../../session/conversations';
import { PubKey } from '../../session/types';
import { ToastUtils } from '../../session/utils';
import { Flex } from '../basic/Flex';
@ -47,7 +47,7 @@ export class RemoveModeratorsDialog extends React.Component<Props, State> {
const { removingInProgress, firstLoading } = this.state;
const hasMods = this.state.modList.length !== 0;
const convo = ConversationController.getInstance().get(this.props.conversationId);
const convo = getConversationController().get(this.props.conversationId);
const chatName = convo.get('name');
@ -134,11 +134,11 @@ export class RemoveModeratorsDialog extends React.Component<Props, State> {
private refreshModList() {
let modPubKeys: Array<string> = [];
const convo = ConversationController.getInstance().get(this.props.conversationId);
const convo = getConversationController().get(this.props.conversationId);
modPubKeys = convo.getGroupAdmins() || [];
const convos = ConversationController.getInstance().getConversations();
const convos = getConversationController().getConversations();
const moderatorsConvos = modPubKeys
.map(
pubKey =>
@ -190,7 +190,7 @@ export class RemoveModeratorsDialog extends React.Component<Props, State> {
removingInProgress: true,
});
let res;
const convo = ConversationController.getInstance().get(this.props.conversationId);
const convo = getConversationController().get(this.props.conversationId);
const roomInfos = convo.toOpenGroupV2();
const modsToRemove = _.compact(removedMods.map(m => PubKey.from(m)));

@ -5,7 +5,7 @@ import { SessionButton, SessionButtonColor, SessionButtonType } from '../session
import { ContactType, SessionMemberListItem } from '../session/SessionMemberListItem';
import { ToastUtils, UserUtils } from '../../session/utils';
import autoBind from 'auto-bind';
import { ConversationController } from '../../session/conversations';
import { getConversationController } from '../../session/conversations';
import _ from 'lodash';
import { SpacerLG, SpacerMD, Text } from '../basic/Text';
@ -34,13 +34,13 @@ export class UpdateGroupMembersDialog extends React.Component<Props, State> {
super(props);
autoBind(this);
this.convo = ConversationController.getInstance().get(props.conversationId);
this.convo = getConversationController().get(props.conversationId);
const admins = this.convo.get('groupAdmins') || [];
const ourPK = UserUtils.getOurPubKeyStrFromCache();
const isAdmin = this.convo.get('groupAdmins')?.includes(ourPK) ? true : false;
const convos = ConversationController.getInstance()
const convos = getConversationController()
.getConversations()
.filter(d => !!d);
@ -79,7 +79,7 @@ export class UpdateGroupMembersDialog extends React.Component<Props, State> {
const zombies = _.compact(
existingZombies.map(d => {
const zombieConvo = ConversationController.getInstance().get(d);
const zombieConvo = getConversationController().get(d);
if (!zombieConvo) {
window?.log?.warn('Zombie convo not found');
return null;

@ -8,7 +8,7 @@ import { SpacerMD } from '../basic/Text';
import { updateGroupNameModal } from '../../state/ducks/modalDialog';
import autoBind from 'auto-bind';
import { ConversationModel } from '../../models/conversation';
import { ConversationController } from '../../session/conversations';
import { getConversationController } from '../../session/conversations';
import { ClosedGroup } from '../../session';
type Props = {
@ -30,7 +30,7 @@ export class UpdateGroupNameDialog extends React.Component<Props, State> {
super(props);
autoBind(this);
this.convo = ConversationController.getInstance().get(props.conversationId);
this.convo = getConversationController().get(props.conversationId);
this.state = {
groupName: this.convo.getName(),

@ -3,7 +3,7 @@ import { SessionIconButton, SessionIconSize, SessionIconType } from './icon';
import { Avatar, AvatarSize } from '../Avatar';
import { darkTheme, lightTheme } from '../../state/ducks/SessionTheme';
import { SessionToastContainer } from './SessionToastContainer';
import { ConversationController } from '../../session/conversations';
import { getConversationController } from '../../session/conversations';
import { UserUtils } from '../../session/utils';
import { syncConfigurationIfNeeded } from '../../session/utils/syncUtils';
@ -118,7 +118,7 @@ const Section = (props: { type: SectionType; avatarPath?: string }) => {
};
if (type === SectionType.Profile) {
const conversation = ConversationController.getInstance().get(ourNumber);
const conversation = getConversationController().get(ourNumber);
const profile = conversation?.getLokiProfile();
const userName = (profile && profile.displayName) || ourNumber;
@ -220,7 +220,7 @@ const removeAllV1OpenGroups = async () => {
try {
await removeConversation(v1Convo.id);
window.log.info(`deleting v1convo : ${v1Convo.id}`);
ConversationController.getInstance().unsafeDelete(v1Convo);
getConversationController().unsafeDelete(v1Convo);
if (window.inboxStore) {
window.inboxStore?.dispatch(conversationActions.conversationRemoved(v1Convo.id));
window.inboxStore?.dispatch(

@ -22,7 +22,7 @@ import { PubKey } from '../../session/types';
import { ToastUtils, UserUtils } from '../../session/utils';
import { DefaultTheme } from 'styled-components';
import { LeftPaneSectionHeader } from './LeftPaneSectionHeader';
import { ConversationController } from '../../session/conversations';
import { getConversationController } from '../../session/conversations';
import { ConversationTypeEnum } from '../../models/conversation';
import { openGroupV2CompleteURLRegex } from '../../opengroup/utils/OpenGroupUtils';
import { joinOpenGroupV2WithUIEvents } from '../../opengroup/opengroupV2/JoinOpenGroupV2';
@ -352,7 +352,7 @@ export class LeftPaneMessageSection extends React.Component<Props, State> {
const errorOnPubkey = PubKey.validateWithError(pubkeyorOns);
if (!errorOnPubkey) {
// this is a pubkey
await ConversationController.getInstance().getOrCreateAndWait(
await getConversationController().getOrCreateAndWait(
pubkeyorOns,
ConversationTypeEnum.PRIVATE
);
@ -372,7 +372,7 @@ export class LeftPaneMessageSection extends React.Component<Props, State> {
throw new Error('Got a resolved ONS but the returned entry is not a vlaid SessionID');
}
// this is a pubkey
await ConversationController.getInstance().getOrCreateAndWait(
await getConversationController().getOrCreateAndWait(
resolvedSessionID,
ConversationTypeEnum.PRIVATE
);

@ -2,7 +2,7 @@ import React from 'react';
import { Provider } from 'react-redux';
import { bindActionCreators } from 'redux';
import { ConversationModel } from '../../models/conversation';
import { ConversationController } from '../../session/conversations';
import { getConversationController } from '../../session/conversations';
import { UserUtils } from '../../session/utils';
import { createStore } from '../../state/createStore';
import { actions as conversationActions } from '../../state/ducks/conversations';
@ -70,7 +70,7 @@ export class SessionInboxView extends React.Component<any, State> {
private async setupLeftPane() {
// Here we set up a full redux store with initial state for our LeftPane Root
const convoCollection = ConversationController.getInstance().getConversations();
const convoCollection = getConversationController().getConversations();
const conversations = convoCollection.map((conversation: ConversationModel) =>
conversation.getProps()
);

@ -1,5 +1,5 @@
import React, { useState } from 'react';
import { ConversationController } from '../../session/conversations/ConversationController';
import { getConversationController } from '../../session/conversations';
import { SessionButton } from './SessionButton';
import _ from 'lodash';
@ -42,7 +42,7 @@ export const SessionNicknameDialog = (props: Props) => {
if (!conversationId) {
throw new Error('Cant save without conversation id');
}
const conversation = ConversationController.getInstance().get(conversationId);
const conversation = getConversationController().get(conversationId);
await conversation.setNickname(nickname);
onClickClose();
};

@ -27,7 +27,7 @@ import { SessionQuotedMessageComposition } from './SessionQuotedMessageCompositi
import { Mention, MentionsInput } from 'react-mentions';
import { CaptionEditor } from '../../CaptionEditor';
import { DefaultTheme } from 'styled-components';
import { ConversationController } from '../../../session/conversations';
import { getConversationController } from '../../../session/conversations';
import { ConversationType } from '../../../state/ducks/conversations';
import { SessionMemberListItem } from '../SessionMemberListItem';
import autoBind from 'auto-bind';
@ -483,7 +483,7 @@ export class SessionCompositionBox extends React.Component<Props, State> {
}
const allMembers = allPubKeys.map(pubKey => {
const conv = ConversationController.getInstance().get(pubKey);
const conv = getConversationController().get(pubKey);
let profileName = 'Anonymous';
if (conv) {
profileName = conv.getProfileName() || 'Anonymous';
@ -761,9 +761,7 @@ export class SessionCompositionBox extends React.Component<Props, State> {
// Also, check for a message length change before firing it up, to avoid
// catching ESC, tab, or whatever which is not typing
if (message.length && message.length !== this.lastBumpTypingMessageLength) {
const conversationModel = ConversationController.getInstance().get(
this.props.selectedConversationKey
);
const conversationModel = getConversationController().get(this.props.selectedConversationKey);
if (!conversationModel) {
return;
}

@ -25,7 +25,7 @@ import { ConversationType } from '../../../state/ducks/conversations';
import { MessageView } from '../../MainViewController';
import { pushUnblockToSend } from '../../../session/utils/Toast';
import { MessageDetail } from '../../conversation/MessageDetail';
import { ConversationController } from '../../../session/conversations';
import { getConversationController } from '../../../session/conversations';
import { getMessageById, getPubkeysInPublicConversation } from '../../../data/data';
import autoBind from 'auto-bind';
import { getDecryptedMediaUrl } from '../../../session/crypto/DecryptedAttachmentsManager';
@ -221,7 +221,7 @@ export class SessionConversation extends React.Component<Props, State> {
// return an empty message view
return <MessageView />;
}
const conversationModel = ConversationController.getInstance().get(selectedConversationKey);
const conversationModel = getConversationController().get(selectedConversationKey);
// TODO VINCE: OPTIMISE FOR NEW SENDING???
const sendMessageFn = (
body: any,
@ -329,7 +329,7 @@ export class SessionConversation extends React.Component<Props, State> {
if (!selectedConversation) {
return;
}
const conversationModel = ConversationController.getInstance().get(selectedConversationKey);
const conversationModel = getConversationController().get(selectedConversationKey);
const unreadCount = await conversationModel.getUnreadCount();
const messagesToFetch = Math.max(
Constants.CONVERSATION.DEFAULT_MESSAGE_FETCH_COUNT,
@ -344,7 +344,7 @@ export class SessionConversation extends React.Component<Props, State> {
public getHeaderProps() {
const { selectedConversationKey, ourNumber } = this.props;
const { selectedMessages, messageDetailShowProps } = this.state;
const conversation = ConversationController.getInstance().getOrThrow(selectedConversationKey);
const conversation = getConversationController().getOrThrow(selectedConversationKey);
const expireTimer = conversation.get('expireTimer');
const expirationSettingName = expireTimer
? window.Whisper.ExpirationTimerOptions.getName(expireTimer || 0)
@ -440,7 +440,7 @@ export class SessionConversation extends React.Component<Props, State> {
// tslint:disable-next-line: max-func-body-length
public getRightPanelProps() {
const { selectedConversationKey } = this.props;
const conversation = ConversationController.getInstance().getOrThrow(selectedConversationKey);
const conversation = getConversationController().getOrThrow(selectedConversationKey);
const ourPrimary = window.storage.get('primaryDevicePubKey');
const members = conversation.get('members') || [];
@ -529,9 +529,7 @@ export class SessionConversation extends React.Component<Props, State> {
// Get message objects
const { selectedConversationKey, selectedConversation, messages } = this.props;
const conversationModel = ConversationController.getInstance().getOrThrow(
selectedConversationKey
);
const conversationModel = getConversationController().getOrThrow(selectedConversationKey);
if (!selectedConversation) {
window?.log?.info('No valid selected conversation.');
return;
@ -685,9 +683,7 @@ export class SessionConversation extends React.Component<Props, State> {
}
if (!_.isEqual(this.state.quotedMessageTimestamp, quotedMessageTimestamp)) {
const { messages, selectedConversationKey } = this.props;
const conversationModel = ConversationController.getInstance().getOrThrow(
selectedConversationKey
);
const conversationModel = getConversationController().getOrThrow(selectedConversationKey);
let quotedMessageProps = null;
if (quotedMessageTimestamp) {
@ -1084,7 +1080,7 @@ export class SessionConversation extends React.Component<Props, State> {
window?.log?.info(`getPubkeysInPublicConversation returned '${allPubKeys?.length}' members`);
const allMembers = allPubKeys.map((pubKey: string) => {
const conv = ConversationController.getInstance().get(pubKey);
const conv = getConversationController().get(pubKey);
const profileName = conv?.getProfileName() || 'Anonymous';
return {

@ -14,7 +14,7 @@ import { ConversationType } from '../../../state/ducks/conversations';
import { SessionLastSeenIndicator } from './SessionLastSeenIndicator';
import { ToastUtils } from '../../../session/utils';
import { TypingBubble } from '../../conversation/TypingBubble';
import { ConversationController } from '../../../session/conversations';
import { getConversationController } from '../../../session/conversations';
import { MessageModel } from '../../../models/message';
import { MessageRegularProps } from '../../../models/messageType';
import { getMessagesBySentAt } from '../../../data/data';
@ -132,7 +132,7 @@ export class SessionMessagesList extends React.Component<Props, State> {
let displayedName = null;
if (conversation.type === ConversationTypeEnum.PRIVATE) {
displayedName = ConversationController.getInstance().getContactProfileNameOrShortenedPubKey(
displayedName = getConversationController().getContactProfileNameOrShortenedPubKey(
conversationKey
);
}
@ -358,7 +358,7 @@ export class SessionMessagesList extends React.Component<Props, State> {
return;
}
const conversation = ConversationController.getInstance().getOrThrow(conversationKey);
const conversation = getConversationController().getOrThrow(conversationKey);
if (conversation.isBlocked()) {
return;

@ -9,7 +9,7 @@ import {
changeNickNameModal,
updateConfirmModal,
} from '../../../state/ducks/modalDialog';
import { ConversationController } from '../../../session/conversations';
import { getConversationController } from '../../../session/conversations';
import {
blockConvoById,
clearNickNameByConvoId,
@ -163,7 +163,7 @@ export function getDeleteContactMenuItem(
: window.i18n('deleteContactConfirmation'),
onClickClose,
onClickOk: () => {
void ConversationController.getInstance().deleteContact(conversationId);
void getConversationController().deleteContact(conversationId);
onClickClose();
},
})

@ -1,7 +1,7 @@
import React from 'react';
import { PromiseUtils, StringUtils, ToastUtils, UserUtils } from '../../../session/utils';
import { ConversationController } from '../../../session/conversations';
import { getConversationController } from '../../../session/conversations';
import { createOrUpdateItem, removeAll } from '../../../data/data';
import { SignUpTab } from './SignUpTab';
import { SignInTab } from './SignInTab';
@ -63,8 +63,8 @@ export async function resetRegistration() {
await removeAll();
await window.storage.reset();
await window.storage.fetch();
ConversationController.getInstance().reset();
await ConversationController.getInstance().load();
getConversationController().reset();
await getConversationController().load();
}
const passwordsAreValid = (password: string, verifyPassword: string) => {

@ -7,7 +7,7 @@ import { BlockedNumberController, PasswordUtil } from '../../../util';
import { ToastUtils } from '../../../session/utils';
import { ConversationLookupType } from '../../../state/ducks/conversations';
import { StateType } from '../../../state/reducer';
import { ConversationController } from '../../../session/conversations';
import { getConversationController } from '../../../session/conversations';
import { getConversationLookup } from '../../../state/selectors/conversations';
import { connect } from 'react-redux';
import { getPasswordHash } from '../../../../ts/data/data';
@ -566,7 +566,7 @@ class SettingsViewInner extends React.Component<SettingsViewProps, State> {
for (const blockedNumber of blockedNumbers) {
let title: string;
const currentModel = ConversationController.getInstance().get(blockedNumber);
const currentModel = getConversationController().get(blockedNumber);
if (currentModel) {
title = currentModel.getProfileName() || currentModel.getName() || window.i18n('anonymous');
} else {

@ -2,7 +2,7 @@ import { GroupUtils, UserUtils } from '../../session/utils';
import { PubKey } from '../../session/types';
import React from 'react';
import * as _ from 'lodash';
import { ConversationController } from '../../session/conversations';
import { getConversationController } from '../../session/conversations';
import { ConversationTypeEnum } from '../../models/conversation';
export type ConversationAvatar = {
@ -55,10 +55,7 @@ export function usingClosedConversationDetails(WrappedComponent: any) {
members = members.slice(0, 2);
const memberConvos = await Promise.all(
members.map(async m =>
ConversationController.getInstance().getOrCreateAndWait(
m.key,
ConversationTypeEnum.PRIVATE
)
getConversationController().getOrCreateAndWait(m.key, ConversationTypeEnum.PRIVATE)
)
);
const memberAvatars = memberConvos.map(m => {

@ -14,7 +14,7 @@ import { MessageModel } from '../models/message';
import { ApiV2 } from '../opengroup/opengroupV2';
import _ from 'lodash';
import { ConversationController } from '../session/conversations';
import { getConversationController } from '../session/conversations';
import { BlockedNumberController } from '../util/blockedNumberController';
import {
adminLeaveClosedGroup,
@ -136,7 +136,7 @@ export async function deleteOpenGroupMessages(
}
export async function blockConvoById(conversationId: string) {
const conversation = ConversationController.getInstance().get(conversationId);
const conversation = getConversationController().get(conversationId);
if (!conversation.id || conversation.isPublic()) {
return;
@ -151,7 +151,7 @@ export async function blockConvoById(conversationId: string) {
}
export async function unblockConvoById(conversationId: string) {
const conversation = ConversationController.getInstance().get(conversationId);
const conversation = getConversationController().get(conversationId);
if (!conversation) {
// we assume it's a block contact and not group.
@ -172,37 +172,33 @@ export async function unblockConvoById(conversationId: string) {
}
export async function showUpdateGroupNameByConvoId(conversationId: string) {
const conversation = ConversationController.getInstance().get(conversationId);
const conversation = getConversationController().get(conversationId);
if (conversation.isMediumGroup()) {
// make sure all the members' convo exists so we can add or remove them
await Promise.all(
conversation
.get('members')
.map(m =>
ConversationController.getInstance().getOrCreateAndWait(m, ConversationTypeEnum.PRIVATE)
)
.map(m => getConversationController().getOrCreateAndWait(m, ConversationTypeEnum.PRIVATE))
);
}
window.inboxStore?.dispatch(updateGroupNameModal({ conversationId }));
}
export async function showUpdateGroupMembersByConvoId(conversationId: string) {
const conversation = ConversationController.getInstance().get(conversationId);
const conversation = getConversationController().get(conversationId);
if (conversation.isMediumGroup()) {
// make sure all the members' convo exists so we can add or remove them
await Promise.all(
conversation
.get('members')
.map(m =>
ConversationController.getInstance().getOrCreateAndWait(m, ConversationTypeEnum.PRIVATE)
)
.map(m => getConversationController().getOrCreateAndWait(m, ConversationTypeEnum.PRIVATE))
);
}
window.inboxStore?.dispatch(updateGroupMembersModal({ conversationId }));
}
export function showLeaveGroupByConvoId(conversationId: string) {
const conversation = ConversationController.getInstance().get(conversationId);
const conversation = getConversationController().get(conversationId);
if (!conversation.isGroup()) {
throw new Error('showLeaveGroupDialog() called with a non group convo.');
@ -242,7 +238,7 @@ export function showInviteContactByConvoId(conversationId: string) {
window.inboxStore?.dispatch(updateInviteContactModal({ conversationId }));
}
export async function onMarkAllReadByConvoId(conversationId: string) {
const conversation = ConversationController.getInstance().get(conversationId);
const conversation = getConversationController().get(conversationId);
await conversation.markReadBouncy(Date.now());
}
@ -256,7 +252,7 @@ export function showRemoveModeratorsByConvoId(conversationId: string) {
}
export async function markAllReadByConvoId(conversationId: string) {
const conversation = ConversationController.getInstance().get(conversationId);
const conversation = getConversationController().get(conversationId);
await conversation.markReadBouncy(Date.now());
}
@ -264,7 +260,7 @@ export async function setNotificationForConvoId(
conversationId: string,
selected: ConversationNotificationSettingType
) {
const conversation = ConversationController.getInstance().get(conversationId);
const conversation = getConversationController().get(conversationId);
const existingSettings = conversation.get('triggerNotificationsFor');
if (existingSettings !== selected) {
@ -273,7 +269,7 @@ export async function setNotificationForConvoId(
}
}
export async function clearNickNameByConvoId(conversationId: string) {
const conversation = ConversationController.getInstance().get(conversationId);
const conversation = getConversationController().get(conversationId);
await conversation.setNickname('');
}
@ -282,7 +278,7 @@ export function showChangeNickNameByConvoId(conversationId: string) {
}
export async function deleteMessagesByConvoIdNoConfirmation(conversationId: string) {
const conversation = ConversationController.getInstance().get(conversationId);
const conversation = getConversationController().get(conversationId);
await removeAllMessagesInConversation(conversationId);
window.inboxStore?.dispatch(
conversationReset({
@ -325,7 +321,7 @@ export async function setDisappearingMessagesByConvoId(
conversationId: string,
seconds: number | undefined
) {
const conversation = ConversationController.getInstance().get(conversationId);
const conversation = getConversationController().get(conversationId);
if (!seconds || seconds <= 0) {
await conversation.updateExpirationTimer(null);
@ -340,7 +336,7 @@ export async function setDisappearingMessagesByConvoId(
* If this is a reupload, the old profileKey is used, otherwise a new one is generated
*/
export async function uploadOurAvatar(newAvatarDecrypted?: ArrayBuffer) {
const ourConvo = ConversationController.getInstance().get(UserUtils.getOurPubKeyStrFromCache());
const ourConvo = getConversationController().get(UserUtils.getOurPubKeyStrFromCache());
if (!ourConvo) {
window.log.warn('ourConvo not found... This is not a valid case');
return;

@ -4,7 +4,7 @@ import { ConversationModel } from '../models/conversation';
import { ApiV2 } from '../opengroup/opengroupV2';
import { joinOpenGroupV2WithUIEvents } from '../opengroup/opengroupV2/JoinOpenGroupV2';
import { isOpenGroupV2, openGroupV2CompleteURLRegex } from '../opengroup/utils/OpenGroupUtils';
import { ConversationController } from '../session/conversations';
import { getConversationController } from '../session/conversations';
import { PubKey } from '../session/types';
import { ToastUtils } from '../session/utils';
@ -29,7 +29,7 @@ export function banUser(userToBan: string, conversationId: string) {
message: window.i18n('banUserConfirm'),
onClickClose,
onClickOk: async () => {
const conversation = ConversationController.getInstance().get(conversationId);
const conversation = getConversationController().get(conversationId);
if (!conversation) {
window.log.info('cannot ban user, the corresponding conversation was not found.');
return;
@ -78,7 +78,7 @@ export function unbanUser(userToUnBan: string, conversationId: string) {
const onClickClose = () => window.inboxStore?.dispatch(updateConfirmModal(null));
const onClickOk = async () => {
const conversation = ConversationController.getInstance().get(conversationId);
const conversation = getConversationController().get(conversationId);
if (!conversation) {
// double check here. the convo might have been removed since the dialog was opened
@ -127,7 +127,7 @@ export function copyPubKey(sender: string) {
export async function removeSenderFromModerator(sender: string, convoId: string) {
try {
const pubKeyToRemove = PubKey.cast(sender);
const convo = ConversationController.getInstance().getOrThrow(convoId);
const convo = getConversationController().getOrThrow(convoId);
const roomInfo = convo.toOpenGroupV2();
const res = await ApiV2.removeModerator(pubKeyToRemove, roomInfo);
@ -147,7 +147,7 @@ export async function removeSenderFromModerator(sender: string, convoId: string)
export async function addSenderAsModerator(sender: string, convoId: string) {
try {
const pubKeyToAdd = PubKey.cast(sender);
const convo = ConversationController.getInstance().getOrThrow(convoId);
const convo = getConversationController().getOrThrow(convoId);
const roomInfo = convo.toOpenGroupV2();
const res = await ApiV2.addModerator(pubKeyToAdd, roomInfo);

@ -1,7 +1,7 @@
import Backbone from 'backbone';
import _ from 'lodash';
import { getMessageQueue } from '../session';
import { ConversationController } from '../session/conversations';
import { getConversationController } from '../session/conversations';
import { ClosedGroupVisibleMessage } from '../session/messages/outgoing/visibleMessage/ClosedGroupVisibleMessage';
import { PubKey } from '../session/types';
import { UserUtils } from '../session/utils';
@ -177,7 +177,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
constructor(attributes: ConversationAttributesOptionals) {
super(fillConvoAttributesWithDefaults(attributes));
// This may be overridden by ConversationController.getOrCreate, and signify
// This may be overridden by getConversationController().getOrCreate, and signify
// our first save to the database. Or first fetch from the database.
this.initialPromise = Promise.resolve();
autoBind(this);
@ -1075,7 +1075,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
// This function is wrongly named by signal
// This is basically an `update` function and thus we have overwritten it with such
public async getProfile(id: string) {
const c = await ConversationController.getInstance().getOrCreateAndWait(
const c = await getConversationController().getOrCreateAndWait(
id,
ConversationTypeEnum.PRIVATE
);
@ -1197,7 +1197,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
// title,
// message,
// resolve: () => {
// void ConversationController.getInstance().deleteContact(this.id);
// void getConversationController().deleteContact(this.id);
// },
// });
// }
@ -1346,7 +1346,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
}
}
const convo = await ConversationController.getInstance().getOrCreateAndWait(
const convo = await getConversationController().getOrCreateAndWait(
message.get('source'),
ConversationTypeEnum.PRIVATE
);

@ -4,7 +4,7 @@ import filesize from 'filesize';
import _ from 'lodash';
import { SignalService } from '../../ts/protobuf';
import { getMessageQueue, Utils } from '../../ts/session';
import { ConversationController } from '../../ts/session/conversations';
import { getConversationController } from '../../ts/session/conversations';
import { MessageController } from '../../ts/session/messages';
import { DataMessage } from '../../ts/session/messages/outgoing';
import { ClosedGroupVisibleMessage } from '../session/messages/outgoing/visibleMessage/ClosedGroupVisibleMessage';
@ -150,9 +150,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
) {
return window.i18n(
'leftTheGroup',
ConversationController.getInstance().getContactProfileNameOrShortenedPubKey(
groupUpdate.left
)
getConversationController().getContactProfileNameOrShortenedPubKey(groupUpdate.left)
);
}
if (groupUpdate.kicked === 'You') {
@ -168,7 +166,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
}
if (groupUpdate.joined && groupUpdate.joined.length) {
const names = groupUpdate.joined.map((pubKey: string) =>
ConversationController.getInstance().getContactProfileNameOrFullPubKey(pubKey)
getConversationController().getContactProfileNameOrFullPubKey(pubKey)
);
if (names.length > 1) {
@ -181,7 +179,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
if (groupUpdate.kicked && groupUpdate.kicked.length) {
const names = _.map(
groupUpdate.kicked,
ConversationController.getInstance().getContactProfileNameOrShortenedPubKey
getConversationController().getContactProfileNameOrShortenedPubKey
);
if (names.length > 1) {
@ -205,17 +203,13 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
if (dataExtraction.type === SignalService.DataExtractionNotification.Type.SCREENSHOT) {
return window.i18n(
'tookAScreenshot',
ConversationController.getInstance().getContactProfileNameOrShortenedPubKey(
dataExtraction.source
)
getConversationController().getContactProfileNameOrShortenedPubKey(dataExtraction.source)
);
}
return window.i18n(
'savedTheFile',
ConversationController.getInstance().getContactProfileNameOrShortenedPubKey(
dataExtraction.source
)
getConversationController().getContactProfileNameOrShortenedPubKey(dataExtraction.source)
);
}
return this.get('body');
@ -236,7 +230,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
const regex = new RegExp(`@${PubKey.regexForPubkeys}`, 'g');
const pubkeysInDesc = description.match(regex);
(pubkeysInDesc || []).forEach((pubkey: string) => {
const displayName = ConversationController.getInstance().getContactProfileNameOrShortenedPubKey(
const displayName = getConversationController().getContactProfileNameOrShortenedPubKey(
pubkey.slice(1)
);
if (displayName && displayName.length) {
@ -347,7 +341,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
}
public findContact(pubkey: string) {
return ConversationController.getInstance().get(pubkey);
return getConversationController().get(pubkey);
}
public findAndFormatContact(pubkey: string) {
@ -625,7 +619,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
}
const { author, id, referencedMessageNotFound } = quote;
const contact: ConversationModel = author && ConversationController.getInstance().get(author);
const contact: ConversationModel = author && getConversationController().get(author);
const authorName = contact ? contact.getContactProfileNameOrShortenedPubKey() : null;
@ -906,7 +900,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
// This needs to be an unsafe call, because this method is called during
// initial module setup. We may be in the middle of the initial fetch to
// the database.
return ConversationController.getInstance().getUnsafe(this.get('conversationId'));
return getConversationController().getUnsafe(this.get('conversationId'));
}
public getQuoteContact() {
@ -919,7 +913,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
return null;
}
return ConversationController.getInstance().get(author);
return getConversationController().get(author);
}
public getSource() {
@ -937,7 +931,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
return null;
}
return ConversationController.getInstance().getOrCreate(source, ConversationTypeEnum.PRIVATE);
return getConversationController().getOrCreate(source, ConversationTypeEnum.PRIVATE);
}
public isOutgoing() {

@ -1,5 +1,5 @@
import { getV2OpenGroupRoomByRoomId, OpenGroupV2Room } from '../../data/opengroups';
import { ConversationController } from '../../session/conversations';
import { getConversationController } from '../../session/conversations';
import { PromiseUtils, ToastUtils } from '../../session/utils';
import { forceSyncConfigurationNowIfNeeded } from '../../session/utils/syncUtils';
import {
@ -65,7 +65,7 @@ async function joinOpenGroupV2(room: OpenGroupV2Room, fromConfigMessage: boolean
const alreadyExist = await getV2OpenGroupRoomByRoomId({ serverUrl, roomId });
const conversationId = getOpenGroupV2ConversationId(serverUrl, roomId);
const existingConvo = ConversationController.getInstance().get(conversationId);
const existingConvo = getConversationController().get(conversationId);
if (alreadyExist && existingConvo) {
window?.log?.warn('Skipping join opengroupv2: already exists');
@ -73,7 +73,7 @@ async function joinOpenGroupV2(room: OpenGroupV2Room, fromConfigMessage: boolean
} else if (existingConvo) {
// we already have a convo associated with it. Remove everything related to it so we start fresh
window?.log?.warn('leaving before rejoining open group v2 room', conversationId);
await ConversationController.getInstance().deleteContact(conversationId);
await getConversationController().deleteContact(conversationId);
}
// Try to connect to server
@ -132,7 +132,7 @@ export async function joinOpenGroupV2WithUIEvents(
return false;
}
const conversationID = getOpenGroupV2ConversationId(parsedRoom.serverUrl, parsedRoom.roomId);
if (ConversationController.getInstance().get(conversationID)) {
if (getConversationController().get(conversationID)) {
if (showToasts) {
ToastUtils.pushToastError('publicChatExists', window.i18n('publicChatExists'));
}
@ -146,7 +146,7 @@ export async function joinOpenGroupV2WithUIEvents(
}
await joinOpenGroupV2(parsedRoom, fromConfigMessage);
const isConvoCreated = ConversationController.getInstance().get(conversationID);
const isConvoCreated = getConversationController().get(conversationID);
if (isConvoCreated) {
if (showToasts) {
ToastUtils.pushToastSuccess(

@ -6,7 +6,7 @@ import {
saveV2OpenGroupRoom,
} from '../../data/opengroups';
import { ConversationModel, ConversationTypeEnum } from '../../models/conversation';
import { ConversationController } from '../../session/conversations';
import { getConversationController } from '../../session/conversations';
import { allowOnlyOneAtATime } from '../../session/utils/Promise';
import { getOpenGroupV2ConversationId } from '../utils/OpenGroupUtils';
import { OpenGroupRequestCommonType } from './ApiUtil';
@ -167,7 +167,7 @@ export class OpenGroupManagerV2 {
): Promise<ConversationModel | undefined> {
const conversationId = getOpenGroupV2ConversationId(serverUrl, roomId);
if (ConversationController.getInstance().get(conversationId)) {
if (getConversationController().get(conversationId)) {
// Url incorrect or server not compatible
throw new Error(window.i18n('publicChatExists'));
}
@ -190,7 +190,7 @@ export class OpenGroupManagerV2 {
if (!roomInfos) {
throw new Error('Invalid open group roomInfo result');
}
const conversation = await ConversationController.getInstance().getOrCreateAndWait(
const conversation = await getConversationController().getOrCreateAndWait(
conversationId,
ConversationTypeEnum.GROUP
);

@ -1,5 +1,5 @@
import { AbortController } from 'abort-controller';
import { ConversationController } from '../../session/conversations';
import { getConversationController } from '../../session/conversations';
import { getOpenGroupV2ConversationId } from '../utils/OpenGroupUtils';
import { OpenGroupRequestCommonType } from './ApiUtil';
import {
@ -433,7 +433,7 @@ const handleCompactPollResults = async (
await Promise.all(
results.map(async res => {
const convoId = getOpenGroupV2ConversationId(serverUrl, res.roomId);
const convo = ConversationController.getInstance().get(convoId);
const convo = getConversationController().get(convoId);
// we want to do deletions even if we somehow lost the convo.
if (res.deletions.length) {
@ -462,7 +462,7 @@ const handleBase64AvatarUpdate = async (
await Promise.all(
avatarResults.map(async res => {
const convoId = getOpenGroupV2ConversationId(serverUrl, res.roomId);
const convo = ConversationController.getInstance().get(convoId);
const convo = getConversationController().get(convoId);
if (!convo) {
window?.log?.warn('Could not find convo for compactPoll', convoId);
return;
@ -511,7 +511,7 @@ async function handleAllMemberCount(
memberCountGotResults.map(async roomCount => {
const conversationId = getOpenGroupV2ConversationId(serverUrl, roomCount.roomId);
const convo = ConversationController.getInstance().get(conversationId);
const convo = getConversationController().get(conversationId);
if (!convo) {
window?.log?.warn('cannot update conversation memberCount as it does not exist');
return;

@ -3,7 +3,7 @@ import { removeFromCache } from './cache';
import { EnvelopePlus } from './types';
import { PubKey } from '../session/types';
import { toHex } from '../session/utils/String';
import { ConversationController } from '../session/conversations';
import { getConversationController } from '../session/conversations';
import * as ClosedGroup from '../session/group';
import { BlockedNumberController } from '../util';
import {
@ -188,7 +188,7 @@ export async function handleNewClosedGroup(
await removeFromCache(envelope);
return;
}
const maybeConvo = ConversationController.getInstance().get(groupId);
const maybeConvo = getConversationController().get(groupId);
const expireTimer = groupUpdate.expireTimer;
if (maybeConvo) {
@ -233,10 +233,7 @@ export async function handleNewClosedGroup(
const convo =
maybeConvo ||
(await ConversationController.getInstance().getOrCreateAndWait(
groupId,
ConversationTypeEnum.GROUP
));
(await getConversationController().getOrCreateAndWait(groupId, ConversationTypeEnum.GROUP));
// ***** Creating a new group *****
window?.log?.info('Received a new ClosedGroup of id:', groupId);
@ -336,7 +333,7 @@ async function handleClosedGroupEncryptionKeyPair(
return;
}
const groupConvo = ConversationController.getInstance().get(groupPublicKey);
const groupConvo = getConversationController().get(groupPublicKey);
if (!groupConvo) {
window?.log?.warn(
`Ignoring closed group encryption key pair for nonexistent group. ${groupPublicKey}`
@ -436,7 +433,7 @@ async function performIfValid(
const groupPublicKey = envelope.source;
const sender = envelope.senderIdentity;
const convo = ConversationController.getInstance().get(groupPublicKey);
const convo = getConversationController().get(groupPublicKey);
if (!convo) {
window?.log?.warn('dropping message for nonexistent group');
return removeFromCache(envelope);
@ -476,10 +473,7 @@ async function performIfValid(
return;
}
// make sure the conversation with this user exist (even if it's just hidden)
await ConversationController.getInstance().getOrCreateAndWait(
sender,
ConversationTypeEnum.PRIVATE
);
await getConversationController().getOrCreateAndWait(sender, ConversationTypeEnum.PRIVATE);
if (groupUpdate.type === Type.NAME_CHANGE) {
await handleClosedGroupNameChanged(envelope, groupUpdate, convo);
@ -566,7 +560,7 @@ async function handleClosedGroupMembersAdded(
// make sure the conversation with those members (even if it's just hidden)
await Promise.all(
members.map(async m =>
ConversationController.getInstance().getOrCreateAndWait(m, ConversationTypeEnum.PRIVATE)
getConversationController().getOrCreateAndWait(m, ConversationTypeEnum.PRIVATE)
)
);
@ -822,10 +816,7 @@ async function sendLatestKeyPairToUsers(
await Promise.all(
targetUsers.map(async member => {
window?.log?.info(`Sending latest closed group encryption key pair to: ${member}`);
await ConversationController.getInstance().getOrCreateAndWait(
member,
ConversationTypeEnum.PRIVATE
);
await getConversationController().getOrCreateAndWait(member, ConversationTypeEnum.PRIVATE);
const wrappers = await ClosedGroup.buildEncryptionKeyPairWrappers([member], keyPairToUse);
@ -878,7 +869,7 @@ export async function createClosedGroup(groupName: string, members: Array<string
const listOfMembers = [...setOfMembers];
// Create the group
const convo = await ConversationController.getInstance().getOrCreateAndWait(
const convo = await getConversationController().getOrCreateAndWait(
groupPublicKey,
ConversationTypeEnum.GROUP
);

@ -7,7 +7,7 @@ import {
} from '../opengroup/opengroupV2/JoinOpenGroupV2';
import { getOpenGroupV2ConversationId } from '../opengroup/utils/OpenGroupUtils';
import { SignalService } from '../protobuf';
import { ConversationController } from '../session/conversations';
import { getConversationController } from '../session/conversations';
import { UserUtils } from '../session/utils';
import { toHex } from '../session/utils/String';
import { configurationMessageReceived, trigger } from '../shims/events';
@ -28,7 +28,7 @@ async function handleOurProfileUpdate(
);
const { profileKey, profilePicture, displayName } = configMessage;
const ourConversation = ConversationController.getInstance().get(ourPubkey);
const ourConversation = getConversationController().get(ourPubkey);
if (!ourConversation) {
window?.log?.error('We need a convo with ourself at all times');
return;
@ -106,7 +106,7 @@ async function handleGroupsAndContactsFromConfigMessage(
continue;
}
const roomConvoId = getOpenGroupV2ConversationId(parsedRoom.serverUrl, parsedRoom.roomId);
if (!ConversationController.getInstance().get(roomConvoId)) {
if (!getConversationController().get(roomConvoId)) {
window?.log?.info(
`triggering join of public chat '${currentOpenGroupUrl}' from ConfigurationMessage`
);
@ -120,7 +120,7 @@ async function handleGroupsAndContactsFromConfigMessage(
if (!c.publicKey) {
return;
}
const contactConvo = await ConversationController.getInstance().getOrCreateAndWait(
const contactConvo = await getConversationController().getOrCreateAndWait(
toHex(c.publicKey),
ConversationTypeEnum.PRIVATE
);

@ -10,7 +10,7 @@ import { BlockedNumberController } from '../util/blockedNumberController';
import { GroupUtils, UserUtils } from '../session/utils';
import { fromHexToArray, toHex } from '../session/utils/String';
import { concatUInt8Array, getSodium } from '../session/crypto';
import { ConversationController } from '../session/conversations';
import { getConversationController } from '../session/conversations';
import { getAllEncryptionKeyPairsForGroup } from '../../ts/data/data';
import { ECKeyPair } from './keypairs';
import { KeyPairRequestManager } from './keyPairRequestManager';
@ -274,7 +274,7 @@ function shouldDropBlockedUserMessage(content: SignalService.Content): boolean {
}
const groupId = toHex(content.dataMessage.group.id);
const groupConvo = ConversationController.getInstance().get(groupId);
const groupConvo = getConversationController().get(groupId);
if (!groupConvo) {
return true;
}
@ -323,7 +323,7 @@ export async function innerHandleContentMessage(
}
}
await ConversationController.getInstance().getOrCreateAndWait(
await getConversationController().getOrCreateAndWait(
envelope.source,
ConversationTypeEnum.PRIVATE
);
@ -434,7 +434,7 @@ async function handleTypingMessage(
}
// typing message are only working with direct chats/ not groups
const conversation = ConversationController.getInstance().get(source);
const conversation = getConversationController().get(source);
const started = action === SignalService.TypingMessage.Action.STARTED;
@ -461,7 +461,7 @@ export async function handleDataExtractionNotification(
const { source, timestamp } = envelope;
await removeFromCache(envelope);
const convo = ConversationController.getInstance().get(source);
const convo = getConversationController().get(source);
if (!convo || !convo.isPrivate()) {
window?.log?.info('Got DataNotification for unknown or non private convo');
return;

@ -9,7 +9,7 @@ import { downloadAttachment } from './attachments';
import _ from 'lodash';
import { StringUtils, UserUtils } from '../session/utils';
import { getMessageQueue } from '../session';
import { ConversationController } from '../session/conversations';
import { getConversationController } from '../session/conversations';
import { handleClosedGroupControlMessage } from './closedGroups';
import { MessageModel } from '../models/message';
import { MessageModelType } from '../models/messageType';
@ -95,7 +95,7 @@ async function updateProfile(
newProfile.avatar = null;
}
const conv = await ConversationController.getInstance().getOrCreateAndWait(
const conv = await getConversationController().getOrCreateAndWait(
conversation.id,
ConversationTypeEnum.PRIVATE
);
@ -290,7 +290,7 @@ export async function handleDataMessage(
envelope.source = dataMessage.syncTarget;
}
const senderConversation = await ConversationController.getInstance().getOrCreateAndWait(
const senderConversation = await getConversationController().getOrCreateAndWait(
senderPubKey,
ConversationTypeEnum.PRIVATE
);
@ -430,15 +430,12 @@ async function handleProfileUpdate(
if (!isIncoming) {
// We update our own profileKey if it's different from what we have
const ourNumber = UserUtils.getOurPubKeyStrFromCache();
const me = ConversationController.getInstance().getOrCreate(
ourNumber,
ConversationTypeEnum.PRIVATE
);
const me = getConversationController().getOrCreate(ourNumber, ConversationTypeEnum.PRIVATE);
// Will do the save for us if needed
await me.setProfileKey(profileKey);
} else {
const sender = await ConversationController.getInstance().getOrCreateAndWait(
const sender = await getConversationController().getOrCreateAndWait(
convoId,
ConversationTypeEnum.PRIVATE
);
@ -618,10 +615,7 @@ export async function handleMessageEvent(event: MessageEvent): Promise<void> {
conversationId = source;
}
const conversation = await ConversationController.getInstance().getOrCreateAndWait(
conversationId,
type
);
const conversation = await getConversationController().getOrCreateAndWait(conversationId, type);
if (!conversation) {
window?.log?.warn('Skipping handleJob for unknown convo: ', conversationId);

@ -1,6 +1,6 @@
import { initIncomingMessage } from './dataMessage';
import { toNumber } from 'lodash';
import { ConversationController } from '../session/conversations';
import { getConversationController } from '../session/conversations';
import { MessageController } from '../session/messages';
import { actions as conversationActions } from '../state/ducks/conversations';
import { ConversationTypeEnum } from '../models/conversation';
@ -16,7 +16,7 @@ export async function onError(ev: any) {
await message.saveErrors(error || new Error('Error was null'));
const id = message.get('conversationId');
const conversation = await ConversationController.getInstance().getOrCreateAndWait(
const conversation = await getConversationController().getOrCreateAndWait(
id,
ConversationTypeEnum.PRIVATE
);

@ -5,7 +5,7 @@ import { PubKey } from '../session/types';
import _ from 'lodash';
import { SignalService } from '../protobuf';
import { StringUtils, UserUtils } from '../session/utils';
import { ConversationController } from '../session/conversations';
import { getConversationController } from '../session/conversations';
import { ConversationModel, ConversationTypeEnum } from '../models/conversation';
import { MessageModel } from '../models/message';
import { MessageController } from '../session/messages';
@ -344,7 +344,7 @@ async function handleRegularMessage(
});
}
const sendingDeviceConversation = await ConversationController.getInstance().getOrCreateAndWait(
const sendingDeviceConversation = await getConversationController().getOrCreateAndWait(
source,
ConversationTypeEnum.PRIVATE
);

@ -25,7 +25,7 @@ import {
import { getEnvelopeId } from './common';
import { StringUtils, UserUtils } from '../session/utils';
import { SignalService } from '../protobuf';
import { ConversationController } from '../session/conversations';
import { getConversationController } from '../session/conversations';
import { removeUnprocessed } from '../data/data';
import { ConversationTypeEnum } from '../models/conversation';
import {
@ -283,7 +283,7 @@ export async function handlePublicMessage(messageData: any) {
const isMe = UserUtils.isUsFromCache(source);
if (!isMe && profile) {
const conversation = await ConversationController.getInstance().getOrCreateAndWait(
const conversation = await getConversationController().getOrCreateAndWait(
source,
ConversationTypeEnum.PRIVATE
);
@ -336,7 +336,7 @@ export async function handleOpenGroupV2Message(
}
const dataMessage = idataMessage as SignalService.DataMessage;
if (!ConversationController.getInstance().get(conversationId)) {
if (!getConversationController().get(conversationId)) {
window?.log?.error('Received a message for an unknown convo. Skipping');
return;
}
@ -344,7 +344,7 @@ export async function handleOpenGroupV2Message(
// 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 conversation = await ConversationController.getInstance().getOrCreateAndWait(
const conversation = await getConversationController().getOrCreateAndWait(
conversationId,
ConversationTypeEnum.GROUP
);

@ -20,29 +20,33 @@ import { OpenGroupManagerV2 } from '../../opengroup/opengroupV2/OpenGroupManager
import { deleteAuthToken, DeleteAuthTokenRequest } from '../../opengroup/opengroupV2/ApiAuth';
import { deleteMessagesByConvoIdNoConfirmation } from '../../interactions/conversationInteractions';
let instance: ConversationController | null;
export const getConversationController = () => {
if (instance) {
return instance;
}
instance = new ConversationController();
return instance;
};
export class ConversationController {
private static instance: ConversationController | null;
private readonly conversations: ConversationCollection;
private _initialFetchComplete: boolean = false;
private _initialPromise?: Promise<any>;
private constructor() {
/**
* Do not call this constructor. You get the ConversationController through getConversationController() only
*/
constructor() {
this.conversations = new ConversationCollection();
}
public static getInstance() {
if (ConversationController.instance) {
return ConversationController.instance;
}
ConversationController.instance = new ConversationController();
return ConversationController.instance;
}
// FIXME this could return | undefined
public get(id: string): ConversationModel {
if (!this._initialFetchComplete) {
throw new Error('ConversationController.get() needs complete initial fetch');
throw new Error('getConversationController().get() needs complete initial fetch');
}
return this.conversations.get(id);
@ -50,7 +54,7 @@ export class ConversationController {
public getOrThrow(id: string): ConversationModel {
if (!this._initialFetchComplete) {
throw new Error('ConversationController.get() needs complete initial fetch');
throw new Error('getConversationController().get() needs complete initial fetch');
}
const convo = this.conversations.get(id);
@ -58,7 +62,7 @@ export class ConversationController {
if (convo) {
return convo;
}
throw new Error(`Conversation ${id} does not exist on ConversationController.get()`);
throw new Error(`Conversation ${id} does not exist on getConversationController().get()`);
}
// Needed for some model setup which happens during the initial fetch() call below
public getUnsafe(id: string): ConversationModel | undefined {
@ -79,7 +83,7 @@ export class ConversationController {
}
if (!this._initialFetchComplete) {
throw new Error('ConversationController.get() needs complete initial fetch');
throw new Error('getConversationController().get() needs complete initial fetch');
}
let conversation = this.conversations.get(id);
@ -130,7 +134,7 @@ export class ConversationController {
}
public getContactProfileNameOrShortenedPubKey(pubKey: string): string {
const conversation = ConversationController.getInstance().get(pubKey);
const conversation = getConversationController().get(pubKey);
if (!conversation) {
return pubKey;
}
@ -181,7 +185,7 @@ export class ConversationController {
public async deleteContact(id: string) {
if (!this._initialFetchComplete) {
throw new Error('ConversationController.get() needs complete initial fetch');
throw new Error('getConversationController().get() needs complete initial fetch');
}
window.log.info(`deleteContact with ${id}`);

@ -1 +1,3 @@
export * from './ConversationController';
import { getConversationController } from './ConversationController';
export { getConversationController };

@ -4,7 +4,7 @@ import _ from 'lodash';
import { fromHexToArray, toHex } from '../utils/String';
import { BlockedNumberController } from '../../util/blockedNumberController';
import { ConversationController } from '../conversations';
import { getConversationController } from '../conversations';
import {
addClosedGroupEncryptionKeyPair,
getLatestClosedGroupEncryptionKeyPair,
@ -69,7 +69,7 @@ export async function initiateGroupUpdate(
members: Array<string>,
avatar: any
) {
const convo = await ConversationController.getInstance().getOrCreateAndWait(
const convo = await getConversationController().getOrCreateAndWait(
groupId,
ConversationTypeEnum.GROUP
);
@ -214,7 +214,7 @@ function buildGroupDiff(convo: ConversationModel, update: GroupInfo): GroupDiff
export async function updateOrCreateClosedGroup(details: GroupInfo) {
const { id, weWereJustAdded } = details;
const conversation = await ConversationController.getInstance().getOrCreateAndWait(
const conversation = await getConversationController().getOrCreateAndWait(
id,
ConversationTypeEnum.GROUP
);
@ -284,7 +284,7 @@ export async function updateOrCreateClosedGroup(details: GroupInfo) {
}
export async function leaveClosedGroup(groupId: string) {
const convo = ConversationController.getInstance().get(groupId);
const convo = getConversationController().get(groupId);
if (!convo) {
window?.log?.error('Cannot leave non-existing group');
@ -402,7 +402,7 @@ async function sendAddedMembers(
});
const promises = addedMembers.map(async m => {
await ConversationController.getInstance().getOrCreateAndWait(m, ConversationTypeEnum.PRIVATE);
await getConversationController().getOrCreateAndWait(m, ConversationTypeEnum.PRIVATE);
const memberPubKey = PubKey.cast(m);
await getMessageQueue().sendToPubKey(memberPubKey, newClosedGroupUpdate);
});
@ -455,7 +455,7 @@ async function generateAndSendNewEncryptionKeyPair(
groupPublicKey: string,
targetMembers: Array<string>
) {
const groupConvo = ConversationController.getInstance().get(groupPublicKey);
const groupConvo = getConversationController().get(groupPublicKey);
const groupId = fromHexToArray(groupPublicKey);
if (!groupConvo) {
@ -545,7 +545,7 @@ export async function requestEncryptionKeyPair(groupPublicKey: string | PubKey)
throw new Error('useRequestEncryptionKeyPair is disabled');
}
const groupConvo = ConversationController.getInstance().get(PubKey.cast(groupPublicKey).key);
const groupConvo = getConversationController().get(PubKey.cast(groupPublicKey).key);
if (!groupConvo) {
window?.log?.warn(

@ -4,7 +4,7 @@ import { ContentMessage } from '..';
import { v4 as uuid } from 'uuid';
import { PubKey } from '../../../types';
import { getMessageQueue } from '../../..';
import { ConversationController } from '../../../conversations';
import { getConversationController } from '../../../conversations';
import { UserUtils } from '../../../utils';
interface DataExtractionNotificationMessageParams extends MessageParams {
referencedAttachmentTimestamp: number;
@ -48,7 +48,7 @@ export const sendDataExtractionNotification = async (
attachmentSender: string,
referencedAttachmentTimestamp?: number
) => {
const convo = ConversationController.getInstance().get(conversationId);
const convo = getConversationController().get(conversationId);
if (
!convo ||
!convo.isPrivate() ||

@ -267,7 +267,6 @@ export async function refreshRandomPool(forceRefresh = false): Promise<void> {
return;
}
// tslint:disable-next-line:no-parameter-reassignment
window?.log?.info("right before allowOnlyOneAtATime 'refreshRandomPool'");
return allowOnlyOneAtATime('refreshRandomPool', async () => {

@ -13,7 +13,7 @@ import {
} from '../../../ts/data/data';
import { StringUtils } from '../../session/utils';
import { ConversationController } from '../conversations';
import { getConversationController } from '../conversations';
import { ConversationModel } from '../../models/conversation';
type PubkeyToHash = { [key: string]: string };
@ -155,7 +155,7 @@ export class SwarmPolling {
private loadGroupIds() {
// Start polling for medium size groups as well (they might be in different swarms)
const convos = ConversationController.getInstance().getConversations();
const convos = getConversationController().getConversations();
const mediumGroupsOnly = convos.filter(
(c: ConversationModel) =>

@ -1,10 +1,10 @@
import _ from 'lodash';
import { PubKey } from '../types';
import { ConversationController } from '../conversations';
import { getConversationController } from '../conversations';
import { fromHexToArray } from './String';
export async function getGroupMembers(groupId: PubKey): Promise<Array<PubKey>> {
const groupConversation = ConversationController.getInstance().get(groupId.key);
const groupConversation = getConversationController().get(groupId.key);
const groupMembers = groupConversation ? groupConversation.get('members') : undefined;
if (!groupMembers) {
@ -15,7 +15,7 @@ export async function getGroupMembers(groupId: PubKey): Promise<Array<PubKey>> {
}
export function isMediumGroup(groupId: PubKey): boolean {
const conversation = ConversationController.getInstance().get(groupId.key);
const conversation = getConversationController().get(groupId.key);
if (!conversation) {
return false;

@ -4,7 +4,7 @@ import { getItemById } from '../../../ts/data/data';
import { KeyPair } from '../../../libtextsecure/libsignal-protocol';
import { PubKey } from '../types';
import { toHex } from './String';
import { ConversationController } from '../conversations';
import { getConversationController } from '../conversations';
export type HexKeyPair = {
pubKey: string;
@ -90,7 +90,7 @@ export function getOurProfile(): OurLokiProfile | undefined {
// Secondary devices have their profile stored
// in their primary device's conversation
const ourNumber = window.storage.get('primaryDevicePubKey');
const ourConversation = ConversationController.getInstance().get(ourNumber);
const ourConversation = getConversationController().get(ourNumber);
const profileKey = new Uint8Array(window.storage.get('profileKey'));
const avatarPointer = ourConversation.get('avatarPointer');

@ -4,7 +4,7 @@ import {
getLatestClosedGroupEncryptionKeyPair,
} from '../../../ts/data/data';
import { getMessageQueue } from '..';
import { ConversationController } from '../conversations';
import { getConversationController } from '../conversations';
import uuid from 'uuid';
import { UserUtils } from '.';
import { ECKeyPair } from '../../receiver/keypairs';
@ -48,7 +48,7 @@ export const syncConfigurationIfNeeded = async () => {
return;
}
const allConvos = ConversationController.getInstance().getConversations();
const allConvos = getConversationController().getConversations();
const configMessage = await getCurrentConfigurationMessage(allConvos);
try {
// window?.log?.info('syncConfigurationIfNeeded with', configMessage);
@ -65,7 +65,7 @@ export const syncConfigurationIfNeeded = async () => {
export const forceSyncConfigurationNowIfNeeded = async (waitForMessageSent = false) =>
new Promise(resolve => {
const allConvos = ConversationController.getInstance().getConversations();
const allConvos = getConversationController().getConversations();
// if we hang for more than 10sec, force resolve this promise.
setTimeout(() => {

@ -2,7 +2,7 @@ import _, { omit } from 'lodash';
import { Constants } from '../../session';
import { createAsyncThunk } from '@reduxjs/toolkit';
import { ConversationController } from '../../session/conversations';
import { getConversationController } from '../../session/conversations';
import { MessageModel } from '../../models/message';
import { getMessagesByConversation } from '../../data/data';
import { ConversationTypeEnum } from '../../models/conversation';
@ -98,7 +98,7 @@ async function getMessages(
conversationKey: string,
numMessages: number
): Promise<Array<MessageTypeInConvo>> {
const conversation = ConversationController.getInstance().get(conversationKey);
const conversation = getConversationController().get(conversationKey);
if (!conversation) {
// no valid conversation, early return
window?.log?.error('Failed to get convo on reducer.');

@ -17,7 +17,7 @@ describe('ClosedGroupUpdates', () => {
// const groupId = TestUtils.generateFakePubKey().key;
// const members = TestUtils.generateFakePubKeys(10);
// const sender = members[3].key;
// const getConvo = sandbox.stub(ConversationController.getInstance(), 'get');
// const getConvo = sandbox.stub(ConversationController, 'get');
// beforeEach(async () => {
// // Utils Stubs
// sandbox.stub(UserUtils, 'getCurrentDevicePubKey').resolves(ourNumber);

@ -17,7 +17,7 @@ describe('SyncUtils', () => {
describe('syncConfigurationIfNeeded', () => {
it('sync if last sync undefined', () => {
// TestUtils.stubData('getItemById').resolves(undefined);
// sandbox.stub(ConversationController.getInstance(), 'getConversations').returns([]);
// sandbox.stub(ConversationController, 'getConversations').returns([]);
// const getCurrentConfigurationMessageSpy = sandbox.spy(MessageUtils, 'getCurrentConfigurationMessage');
// await syncConfigurationIfNeeded();
// expect(getCurrentConfigurationMessageSpy.callCount).equal(1);

@ -1,4 +1,4 @@
import { ConversationController } from '../session/conversations';
import { getConversationController } from '../session/conversations';
import { getSodium } from '../session/crypto';
import { UserUtils } from '../session/utils';
import { fromArrayBufferToBase64, fromHex, toHex } from '../session/utils/String';
@ -197,7 +197,7 @@ async function registrationDone(ourPubkey: string, displayName: string) {
window.textsecure.storage.put('primaryDevicePubKey', ourPubkey);
// Ensure that we always have a conversation for ourself
const conversation = await ConversationController.getInstance().getOrCreateAndWait(
const conversation = await getConversationController().getOrCreateAndWait(
ourPubkey,
ConversationTypeEnum.PRIVATE
);

@ -1,5 +1,5 @@
import { ConversationModel } from '../models/conversation';
import { ConversationController } from '../session/conversations';
import { getConversationController } from '../session/conversations';
import { MentionsInputState } from '../state/ducks/mentionsInput';
// tslint:disable: no-unnecessary-class
@ -11,7 +11,7 @@ export class FindMember {
): Promise<ConversationModel | null> {
let groupMembers;
const groupConvos = ConversationController.getInstance()
const groupConvos = getConversationController()
.getConversations()
.filter((d: any) => {
return !d.isPrivate();
@ -33,13 +33,11 @@ export class FindMember {
const publicMembers = (await window.inboxStore?.getState()
.mentionsInput) as MentionsInputState;
const memberConversations = publicMembers
.map(publicMember =>
ConversationController.getInstance().get(publicMember.authorPhoneNumber)
)
.map(publicMember => getConversationController().get(publicMember.authorPhoneNumber))
.filter((c: any) => !!c);
groupMembers = memberConversations;
} else {
const privateConvos = ConversationController.getInstance()
const privateConvos = getConversationController()
.getConversations()
.filter((d: any) => d.isPrivate());
const members = thisConvo.attributes.members;

2
ts/window.d.ts vendored

@ -8,14 +8,12 @@ import { Libloki } from '../libloki';
import { LibTextsecure } from '../libtextsecure';
import { ConfirmationDialogParams } from '../background';
import { ConversationControllerType } from '../js/ConversationController';
import { Store } from 'redux';
import { MessageController } from './session/messages/MessageController';
import { DefaultTheme } from 'styled-components';
import { ConversationCollection, ConversationModel } from './models/conversation';
import { ConversationType } from './state/ducks/conversations';
import { ConversationController } from './session/conversations';
/*
We declare window stuff here instead of global.d.ts because we are importing other declarations.

Loading…
Cancel
Save