diff --git a/ts/components/ConversationListItem.tsx b/ts/components/ConversationListItem.tsx index d08a0085a..8919a6c9d 100644 --- a/ts/components/ConversationListItem.tsx +++ b/ts/components/ConversationListItem.tsx @@ -79,14 +79,14 @@ class ConversationListItem extends React.PureComponent { unreadCountDiv =

{unreadCount}

; } - const pinIcon = (conversationListItemType === ConversationListItemType.Conversation && isPinned) ? - - : - null; - + const pinIcon = + conversationListItemType === ConversationListItemType.Conversation && isPinned ? ( + + ) : null; return (
@@ -97,7 +97,6 @@ class ConversationListItem extends React.PureComponent { )} > {this.renderUser()} -
{pinIcon} diff --git a/ts/components/session/LeftPaneMessageSection.tsx b/ts/components/session/LeftPaneMessageSection.tsx index bbe691efb..4e06057a3 100644 --- a/ts/components/session/LeftPaneMessageSection.tsx +++ b/ts/components/session/LeftPaneMessageSection.tsx @@ -1,7 +1,5 @@ import React from 'react'; -import _ from 'lodash'; import { AutoSizer, List } from 'react-virtualized'; - import { MainViewController } from '../MainViewController'; import { ConversationListItemProps, @@ -11,7 +9,7 @@ import { import { ConversationType as ReduxConversationType } from '../../state/ducks/conversations'; import { SearchResults, SearchResultsProps } from '../SearchResults'; import { SessionSearchInput } from './SessionSearchInput'; -import { debounce } from 'lodash'; +import _, { debounce } from 'lodash'; import { cleanSearchTerm } from '../../util/cleanSearchTerm'; import { SearchOptions } from '../../types/Search'; import { RowRendererParamsType } from '../LeftPane'; @@ -31,8 +29,6 @@ import autoBind from 'auto-bind'; import { onsNameRegex } from '../../session/snode_api/SNodeAPI'; import { SNodeAPI } from '../../session/snode_api'; -import { createClosedGroup } from '../../receiver/closedGroups'; - export interface Props { searchTerm: string; @@ -89,8 +85,8 @@ export class LeftPaneMessageSection extends React.Component { throw new Error('renderRow: Tried to render without conversations'); } - conversations = _.sortBy([...conversations], (convo) => { - return convo.isPinned ? -1 : 1 + conversations = _.sortBy([...conversations], convo => { + return convo.isPinned ? -1 : 1; }); const conversation = conversations[index]; @@ -107,8 +103,7 @@ export class LeftPaneMessageSection extends React.Component { }; public renderList(): JSX.Element | Array { - let { conversations } = this.props; - const { openConversationExternal, searchResults } = this.props; + const { conversations, openConversationExternal, searchResults } = this.props; const contacts = searchResults?.contacts || []; if (searchResults) { diff --git a/ts/components/session/menu/ConversationListItemContextMenu.tsx b/ts/components/session/menu/ConversationListItemContextMenu.tsx index dc92a8d6e..0717b593d 100644 --- a/ts/components/session/menu/ConversationListItemContextMenu.tsx +++ b/ts/components/session/menu/ConversationListItemContextMenu.tsx @@ -13,7 +13,7 @@ import { getInviteContactMenuItem, getLeaveGroupMenuItem, getMarkAllReadMenuItem, - MenuItemPinConversation + MenuItemPinConversation, } from './Menu'; export type PropsContextConversationItem = { @@ -47,7 +47,9 @@ export const ConversationListItemContextMenu = (props: PropsContextConversationI const isGroup = type === 'group'; const isConversation = conversationListItemType === ConversationListItemType.Conversation; - const pinMenuItem = isConversation ? : null; + const pinMenuItem = isConversation ? ( + + ) : null; return ( <> diff --git a/ts/components/session/menu/Menu.tsx b/ts/components/session/menu/Menu.tsx index 12a91216f..42f94b18b 100644 --- a/ts/components/session/menu/Menu.tsx +++ b/ts/components/session/menu/Menu.tsx @@ -5,10 +5,7 @@ import { Item, Submenu } from 'react-contexify'; import { ConversationNotificationSettingType } from '../../../models/conversation'; import { useDispatch } from 'react-redux'; import { actions as conversationActions } from '../../../state/ducks/conversations'; -import { - changeNickNameModal, - updateConfirmModal, -} from '../../../state/ducks/modalDialog'; +import { changeNickNameModal, updateConfirmModal } from '../../../state/ducks/modalDialog'; import { getConversationController } from '../../../session/conversations'; import { blockConvoById, @@ -129,21 +126,26 @@ export interface PinConversationMenuItemProps { conversationId: string; } -export const MenuItemPinConversation = (props: PinConversationMenuItemProps): JSX.Element | null => { +export const MenuItemPinConversation = ( + props: PinConversationMenuItemProps +): JSX.Element | null => { const { conversationId } = props; - const conversation = getConversationController().get(conversationId).getProps(); + const conversation = getConversationController() + .get(conversationId) + .getProps(); const { isPinned } = conversation; const togglePinConversation = () => { - window.inboxStore?.dispatch(conversationActions.conversationChanged(conversationId, - { + window.inboxStore?.dispatch( + conversationActions.conversationChanged(conversationId, { ...conversation, - isPinned: !isPinned - })) - } - const menuText = isPinned ? window.i18n('unpinConversation'): window.i18n('pinConversation'); - return {menuText} -} + isPinned: !isPinned, + }) + ); + }; + const menuText = isPinned ? window.i18n('unpinConversation') : window.i18n('pinConversation'); + return {menuText}; +}; export function getDeleteContactMenuItem( isMe: boolean | undefined, @@ -317,7 +319,7 @@ export function getDisappearingMenuItem( // Remove the && false to make context menu work with RTL support {(timerOptions || []).map(item => ( {(notificationForConvoOptions || []).map(item => { const disabled = item.value === currentNotificationSetting; diff --git a/ts/models/conversation.ts b/ts/models/conversation.ts index 4ecf6253a..aa179de25 100644 --- a/ts/models/conversation.ts +++ b/ts/models/conversation.ts @@ -408,14 +408,10 @@ export class ConversationModel extends Backbone.Model { left: !!this.get('left'), groupAdmins, members, - isPinned: this.getIsPinned() || false + isPinned: this.getIsPinned() || false, }; } - private getIsPinned() { - return window.inboxStore?.getState().conversations.conversationLookup[this.id].isPinned; - } - public async updateGroupAdmins(groupAdmins: Array) { const existingAdmins = _.uniq(_.sortBy(this.getGroupAdmins())); const newAdmins = _.uniq(_.sortBy(groupAdmins)); @@ -506,9 +502,9 @@ export class ConversationModel extends Backbone.Model { fileName: fileName || null, thumbnail: thumbnail ? { - ...(await loadAttachmentData(thumbnail)), - objectUrl: getAbsoluteAttachmentPath(thumbnail.path), - } + ...(await loadAttachmentData(thumbnail)), + objectUrl: getAbsoluteAttachmentPath(thumbnail.path), + } : null, }; }) @@ -531,9 +527,9 @@ export class ConversationModel extends Backbone.Model { fileName: null, thumbnail: image ? { - ...(await loadAttachmentData(image)), - objectUrl: getAbsoluteAttachmentPath(image.path), - } + ...(await loadAttachmentData(image)), + objectUrl: getAbsoluteAttachmentPath(image.path), + } : null, }; }) @@ -1441,6 +1437,10 @@ export class ConversationModel extends Backbone.Model { return typeof expireTimer === 'number' && expireTimer > 0; } + + private getIsPinned() { + return window.inboxStore?.getState().conversations.conversationLookup[this.id].isPinned; + } } export class ConversationCollection extends Backbone.Collection { diff --git a/ts/state/createStore.ts b/ts/state/createStore.ts index ed0ac4b38..196ed439f 100644 --- a/ts/state/createStore.ts +++ b/ts/state/createStore.ts @@ -29,7 +29,7 @@ const logger = createLogger({ export const persistConfig = { key: 'root', storage, - whitelist: ['userConfig'] + whitelist: ['userConfig'], }; const persistedReducer = persistReducer(persistConfig, allReducers); diff --git a/ts/state/ducks/conversations.ts b/ts/state/ducks/conversations.ts index 6c1df156d..a5ecb17bb 100644 --- a/ts/state/ducks/conversations.ts +++ b/ts/state/ducks/conversations.ts @@ -82,7 +82,7 @@ export interface ConversationType { avatarPath?: string; // absolute filepath to the avatar groupAdmins?: Array; // admins for closed groups and moderators for open groups members?: Array; // members for closed groups only - isPinned?: boolean + isPinned?: boolean; } export type ConversationLookupType = { diff --git a/ts/state/reducer.ts b/ts/state/reducer.ts index 65ee3cc3c..1c2aaf731 100644 --- a/ts/state/reducer.ts +++ b/ts/state/reducer.ts @@ -16,6 +16,8 @@ import { userConfigReducer as userConfig, UserConfigState } from './ducks/userCo // tslint:disable-next-line: no-submodule-imports match-default-export-name import storage from 'redux-persist/lib/storage'; + +// tslint:disable-next-line: no-submodule-imports match-default-export-name import persistReducer from 'redux-persist/lib/persistReducer'; export type StateType = { @@ -34,8 +36,8 @@ export type StateType = { const conversationsPersistConfig = { key: 'conversations', storage, - whitelist: ['conversationLookup'] -} + whitelist: ['conversationLookup'], +}; export const reducers = { search, diff --git a/ts/util/accountManager.ts b/ts/util/accountManager.ts index 2151b15de..f02dd94f2 100644 --- a/ts/util/accountManager.ts +++ b/ts/util/accountManager.ts @@ -137,7 +137,7 @@ async function bouncyDeleteAccount(reason?: string) { window.localStorage.setItem('restart-reason', reason || ''); if (window.inboxStore) { // warrick: this part might be redundant due to localStorage getting cleared. - persistStore(window.inboxStore).purge(); + await persistStore(window.inboxStore).purge(); } }; try {