Switched conversation pin state.

pull/1745/head
Warrick Corfe-Tan 4 years ago
parent 08db057ad9
commit 36cf05db1b

@ -23,11 +23,8 @@ import { DefaultTheme, withTheme } from 'styled-components';
import { PubKey } from '../session/types'; import { PubKey } from '../session/types';
import { ConversationType, openConversationExternal } from '../state/ducks/conversations'; import { ConversationType, openConversationExternal } from '../state/ducks/conversations';
import { SessionIcon, SessionIconSize, SessionIconType } from './session/icon'; import { SessionIcon, SessionIconSize, SessionIconType } from './session/icon';
import { useSelector } from 'react-redux';
export enum ConversationListItemType { import { SectionType } from './session/ActionsPanel';
Conversation = 'conversation',
Contact = 'contact',
}
export interface ConversationListItemProps extends ConversationType { export interface ConversationListItemProps extends ConversationType {
index?: number; // used to force a refresh when one conversation is removed on top of the list index?: number; // used to force a refresh when one conversation is removed on top of the list
@ -37,7 +34,6 @@ export interface ConversationListItemProps extends ConversationType {
type PropsHousekeeping = { type PropsHousekeeping = {
style?: Object; style?: Object;
theme: DefaultTheme; theme: DefaultTheme;
conversationListItemType: ConversationListItemType;
}; };
type Props = ConversationListItemProps & PropsHousekeeping; type Props = ConversationListItemProps & PropsHousekeeping;
@ -70,7 +66,7 @@ class ConversationListItem extends React.PureComponent<Props> {
} }
public renderHeader() { public renderHeader() {
const { unreadCount, mentionedUs, activeAt, isPinned, conversationListItemType } = this.props; const { unreadCount, mentionedUs, activeAt, isPinned } = this.props;
let atSymbol = null; let atSymbol = null;
let unreadCountDiv = null; let unreadCountDiv = null;
@ -79,8 +75,11 @@ class ConversationListItem extends React.PureComponent<Props> {
unreadCountDiv = <p className="module-conversation-list-item__unread-count">{unreadCount}</p>; unreadCountDiv = <p className="module-conversation-list-item__unread-count">{unreadCount}</p>;
} }
const isMessagesSection =
window.inboxStore?.getState().section.focusedSection === SectionType.Message;
const pinIcon = const pinIcon =
conversationListItemType === ConversationListItemType.Conversation && isPinned ? ( isMessagesSection && isPinned ? (
<SessionIcon <SessionIcon
iconType={SessionIconType.Pin} iconType={SessionIconType.Pin}
iconColor={this.props.theme.colors.textColorSubtle} iconColor={this.props.theme.colors.textColorSubtle}

@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
import { ConversationListItemType, ConversationListItemWithDetails } from '../ConversationListItem'; import { ConversationListItemWithDetails } from '../ConversationListItem';
import { RowRendererParamsType } from '../LeftPane'; import { RowRendererParamsType } from '../LeftPane';
import { AutoSizer, List } from 'react-virtualized'; import { AutoSizer, List } from 'react-virtualized';
import { ConversationType as ReduxConversationType } from '../../state/ducks/conversations'; import { ConversationType as ReduxConversationType } from '../../state/ducks/conversations';
@ -39,7 +39,6 @@ export class LeftPaneContactSection extends React.Component<Props> {
return ( return (
<ConversationListItemWithDetails <ConversationListItemWithDetails
conversationListItemType={ConversationListItemType.Contact}
key={item.id} key={item.id}
style={style} style={style}
{...item} {...item}

@ -3,7 +3,6 @@ import { AutoSizer, List } from 'react-virtualized';
import { MainViewController } from '../MainViewController'; import { MainViewController } from '../MainViewController';
import { import {
ConversationListItemProps, ConversationListItemProps,
ConversationListItemType,
ConversationListItemWithDetails, ConversationListItemWithDetails,
} from '../ConversationListItem'; } from '../ConversationListItem';
import { ConversationType as ReduxConversationType } from '../../state/ducks/conversations'; import { ConversationType as ReduxConversationType } from '../../state/ducks/conversations';
@ -94,7 +93,6 @@ export class LeftPaneMessageSection extends React.Component<Props, State> {
return ( return (
<ConversationListItemWithDetails <ConversationListItemWithDetails
key={key} key={key}
conversationListItemType={ConversationListItemType.Conversation}
style={style} style={style}
{...conversation} {...conversation}
onClick={openConversationExternal} onClick={openConversationExternal}

@ -1,7 +1,7 @@
import React, { useState } from 'react'; import React from 'react';
import { animation, Menu } from 'react-contexify'; import { animation, Menu } from 'react-contexify';
import { ConversationTypeEnum } from '../../../models/conversation'; import { ConversationTypeEnum } from '../../../models/conversation';
import { ConversationListItemType } from '../../ConversationListItem'; import { SectionType } from '../ActionsPanel';
import { import {
getBlockMenuItem, getBlockMenuItem,
@ -20,7 +20,6 @@ export type PropsContextConversationItem = {
id: string; id: string;
triggerId: string; triggerId: string;
type: ConversationTypeEnum; type: ConversationTypeEnum;
conversationListItemType: ConversationListItemType;
isMe: boolean; isMe: boolean;
isPublic?: boolean; isPublic?: boolean;
isBlocked?: boolean; isBlocked?: boolean;
@ -41,13 +40,13 @@ export const ConversationListItemContextMenu = (props: PropsContextConversationI
type, type,
left, left,
isKickedFromGroup, isKickedFromGroup,
conversationListItemType,
} = props; } = props;
const isGroup = type === 'group'; const isGroup = type === 'group';
const isConversation = conversationListItemType === ConversationListItemType.Conversation; const isMessagesSection =
const pinMenuItem = isConversation ? ( window.inboxStore?.getState().section.focusedSection === SectionType.Message;
const pinMenuItem = isMessagesSection ? (
<MenuItemPinConversation conversationId={conversationId} /> <MenuItemPinConversation conversationId={conversationId} />
) : null; ) : null;

@ -130,18 +130,11 @@ export const MenuItemPinConversation = (
props: PinConversationMenuItemProps props: PinConversationMenuItemProps
): JSX.Element | null => { ): JSX.Element | null => {
const { conversationId } = props; const { conversationId } = props;
const conversation = getConversationController() const conversation = getConversationController().get(conversationId);
.get(conversationId) let isPinned = conversation.getIsPinned();
.getProps();
const { isPinned } = conversation; const togglePinConversation = async () => {
await conversation.setIsPinned(!isPinned);
const togglePinConversation = () => {
window.inboxStore?.dispatch(
conversationActions.conversationChanged(conversationId, {
...conversation,
isPinned: !isPinned,
})
);
}; };
const menuText = isPinned ? window.i18n('unpinConversation') : window.i18n('pinConversation'); const menuText = isPinned ? window.i18n('unpinConversation') : window.i18n('pinConversation');
return <Item onClick={togglePinConversation}>{menuText}</Item>; return <Item onClick={togglePinConversation}>{menuText}</Item>;

@ -16,7 +16,6 @@ import {
getMessagesByConversation, getMessagesByConversation,
getUnreadByConversation, getUnreadByConversation,
getUnreadCountByConversation, getUnreadCountByConversation,
removeAllMessagesInConversation,
removeMessage as dataRemoveMessage, removeMessage as dataRemoveMessage,
saveMessages, saveMessages,
updateConversation, updateConversation,
@ -40,11 +39,7 @@ import { ConversationInteraction } from '../interactions';
import { OpenGroupVisibleMessage } from '../session/messages/outgoing/visibleMessage/OpenGroupVisibleMessage'; import { OpenGroupVisibleMessage } from '../session/messages/outgoing/visibleMessage/OpenGroupVisibleMessage';
import { OpenGroupRequestCommonType } from '../opengroup/opengroupV2/ApiUtil'; import { OpenGroupRequestCommonType } from '../opengroup/opengroupV2/ApiUtil';
import { getOpenGroupV2FromConversationId } from '../opengroup/utils/OpenGroupUtils'; import { getOpenGroupV2FromConversationId } from '../opengroup/utils/OpenGroupUtils';
import { NotificationForConvoOption } from '../components/conversation/ConversationHeader';
import { useDispatch } from 'react-redux';
import { updateConfirmModal } from '../state/ducks/modalDialog';
import { createTaskWithTimeout } from '../session/utils/TaskWithTimeout'; import { createTaskWithTimeout } from '../session/utils/TaskWithTimeout';
import { DURATION, SWARM_POLLING_TIMEOUT } from '../session/constants';
export enum ConversationTypeEnum { export enum ConversationTypeEnum {
GROUP = 'group', GROUP = 'group',
@ -96,6 +91,7 @@ export interface ConversationAttributes {
accessKey?: any; accessKey?: any;
triggerNotificationsFor: ConversationNotificationSettingType; triggerNotificationsFor: ConversationNotificationSettingType;
isTrustedForAttachmentDownload: boolean; isTrustedForAttachmentDownload: boolean;
isPinned?: boolean;
} }
export interface ConversationAttributesOptionals { export interface ConversationAttributesOptionals {
@ -133,6 +129,7 @@ export interface ConversationAttributesOptionals {
accessKey?: any; accessKey?: any;
triggerNotificationsFor?: ConversationNotificationSettingType; triggerNotificationsFor?: ConversationNotificationSettingType;
isTrustedForAttachmentDownload?: boolean; isTrustedForAttachmentDownload?: boolean;
isPinned?: boolean;
} }
/** /**
@ -162,6 +159,7 @@ export const fillConvoAttributesWithDefaults = (
active_at: 0, active_at: 0,
triggerNotificationsFor: 'all', // if the settings is not set in the db, this is the default triggerNotificationsFor: 'all', // if the settings is not set in the db, this is the default
isTrustedForAttachmentDownload: false, // we don't trust a contact until we say so isTrustedForAttachmentDownload: false, // we don't trust a contact until we say so
isPinned: false,
}); });
}; };
@ -409,7 +407,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
left: !!this.get('left'), left: !!this.get('left'),
groupAdmins, groupAdmins,
members, members,
isPinned: this.getIsPinned() || false, isPinned: this.getIsPinned(),
}; };
} }
@ -1095,6 +1093,17 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
await this.commit(); await this.commit();
} }
} }
public async setIsPinned(value: boolean) {
if (value !== this.get('isPinned')) {
this.set({
isPinned: value,
});
await this.commit();
console.log(this);
}
}
public async setGroupName(name: string) { public async setGroupName(name: string) {
const profileName = this.get('name'); const profileName = this.get('name');
if (profileName !== name) { if (profileName !== name) {
@ -1226,6 +1235,10 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
return this.get('name') || window.i18n('unknown'); return this.get('name') || window.i18n('unknown');
} }
public getIsPinned() {
return this.get('isPinned');
}
public getTitle() { public getTitle() {
if (this.isPrivate()) { if (this.isPrivate()) {
const profileName = this.getProfileName(); const profileName = this.getProfileName();
@ -1438,10 +1451,6 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
return typeof expireTimer === 'number' && expireTimer > 0; return typeof expireTimer === 'number' && expireTimer > 0;
} }
private getIsPinned() {
return window.inboxStore?.getState().conversations.conversationLookup[this.id].isPinned;
}
} }
export class ConversationCollection extends Backbone.Collection<ConversationModel> { export class ConversationCollection extends Backbone.Collection<ConversationModel> {

@ -14,12 +14,6 @@ import { defaultOnionReducer as onionPaths, OnionState } from './ducks/onion';
import { modalReducer as modals, ModalState } from './ducks/modalDialog'; import { modalReducer as modals, ModalState } from './ducks/modalDialog';
import { userConfigReducer as userConfig, UserConfigState } from './ducks/userConfig'; import { userConfigReducer as userConfig, UserConfigState } from './ducks/userConfig';
// 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 = { export type StateType = {
search: SearchStateType; search: SearchStateType;
user: UserStateType; user: UserStateType;
@ -33,15 +27,9 @@ export type StateType = {
userConfig: UserConfigState; userConfig: UserConfigState;
}; };
const conversationsPersistConfig = {
key: 'conversations',
storage,
whitelist: ['conversationLookup'],
};
export const reducers = { export const reducers = {
search, search,
conversations: persistReducer(conversationsPersistConfig, conversations), conversations,
user, user,
theme, theme,
section, section,

@ -135,10 +135,6 @@ async function bouncyDeleteAccount(reason?: string) {
await window.Signal.Data.removeOtherData(); await window.Signal.Data.removeOtherData();
// 'unlink' => toast will be shown on app restart // 'unlink' => toast will be shown on app restart
window.localStorage.setItem('restart-reason', reason || ''); window.localStorage.setItem('restart-reason', reason || '');
if (window.inboxStore) {
// warrick: this part might be redundant due to localStorage getting cleared.
await persistStore(window.inboxStore).purge();
}
}; };
try { try {
window?.log?.info('DeleteAccount => Sending a last SyncConfiguration'); window?.log?.info('DeleteAccount => Sending a last SyncConfiguration');

Loading…
Cancel
Save