ConversationView: Move setPin to redux

This commit is contained in:
Scott Nonnenberg
2022-12-06 17:00:02 -08:00
committed by GitHub
parent e9b7a74b32
commit ff6750e4fd
11 changed files with 135 additions and 86 deletions

View File

@@ -909,6 +909,7 @@ export const actions = {
setIsNearBottom,
setMessageLoadingState,
setMuteExpiration,
setPinned,
setPreJoinConversation,
setSelectedConversationHeaderTitle,
setSelectedConversationPanelDepth,
@@ -1161,6 +1162,40 @@ function setMuteExpiration(
};
}
function setPinned(
conversationId: string,
value: boolean
): NoopActionType | ShowToastActionType {
const conversation = window.ConversationController.get(conversationId);
if (!conversation) {
throw new Error('setPinned: No conversation found');
}
if (value) {
const pinnedConversationIds = window.storage.get(
'pinnedConversationIds',
new Array<string>()
);
if (pinnedConversationIds.length >= 4) {
return {
type: SHOW_TOAST,
payload: {
toastType: ToastType.PinnedConversationsFull,
},
};
}
conversation.pin();
} else {
conversation.unpin();
}
return {
type: 'NOOP',
payload: null,
};
}
function destroyMessages(
conversationId: string
): ThunkAction<void, RootStateType, unknown, NoopActionType> {

View File

@@ -13,6 +13,7 @@ export enum ToastType {
Error = 'Error',
FailedToDeleteUsername = 'FailedToDeleteUsername',
MessageBodyTooLong = 'MessageBodyTooLong',
PinnedConversationsFull = 'PinnedConversationsFull',
ReportedSpamAndBlocked = 'ReportedSpamAndBlocked',
StoryMuted = 'StoryMuted',
StoryReact = 'StoryReact',

View File

@@ -34,7 +34,6 @@ export type OwnProps = {
onMarkUnread: () => void;
onMoveToInbox: () => void;
onSearchInConversation: () => void;
onSetPin: (value: boolean) => void;
onShowAllMedia: () => void;
onShowConversationDetails: () => void;
onShowGroupMembers: () => void;