diff --git a/keyserver/src/responders/thread-responders.js b/keyserver/src/responders/thread-responders.js --- a/keyserver/src/responders/thread-responders.js +++ b/keyserver/src/responders/thread-responders.js @@ -18,6 +18,7 @@ type ThreadFetchMediaResult, type ThreadFetchMediaRequest, type ToggleMessagePinRequest, + type ToggleMessagePinResult, threadTypes, } from 'lib/types/thread-types.js'; import { values } from 'lib/utils/objects.js'; @@ -202,10 +203,10 @@ async function toggleMessagePinResponder( viewer: Viewer, input: any, -): Promise { +): Promise { const request: ToggleMessagePinRequest = input; await validateInput(viewer, toggleMessagePinRequestInputValidator, request); - await toggleMessagePinForThread(viewer, request); + return await toggleMessagePinForThread(viewer, request); } export { diff --git a/keyserver/src/updaters/thread-updaters.js b/keyserver/src/updaters/thread-updaters.js --- a/keyserver/src/updaters/thread-updaters.js +++ b/keyserver/src/updaters/thread-updaters.js @@ -25,6 +25,7 @@ type ServerThreadJoinRequest, type ThreadJoinResult, type ToggleMessagePinRequest, + type ToggleMessagePinResult, threadPermissions, threadTypes, } from 'lib/types/thread-types.js'; @@ -849,7 +850,7 @@ async function toggleMessagePinForThread( viewer: Viewer, request: ToggleMessagePinRequest, -): Promise { +): Promise { const { messageID, action } = request; const targetMessage = await fetchMessageInfoByID(viewer, messageID); @@ -903,9 +904,10 @@ fetchServerThreadInfos(SQL`t.id = ${threadID}`), dbQuery(togglePinQuery), dbQuery(updateThreadQuery), - createMessages(viewer, [messageData]), ]); + const newMessageInfos = await createMessages(viewer, [messageData]); + const time = Date.now(); const updates = []; for (const member of serverThreadInfos[threadID].members) { @@ -917,6 +919,11 @@ }); } await createUpdates(updates); + + return { + newMessageInfos, + threadID, + }; } export { diff --git a/lib/actions/thread-actions.js b/lib/actions/thread-actions.js --- a/lib/actions/thread-actions.js +++ b/lib/actions/thread-actions.js @@ -13,6 +13,7 @@ ThreadFetchMediaRequest, ThreadFetchMediaResult, ToggleMessagePinRequest, + ToggleMessagePinResult, } from '../types/thread-types.js'; import type { CallServerEndpoint } from '../utils/call-server-endpoint.js'; import { values } from '../utils/objects.js'; @@ -175,12 +176,21 @@ return response; }; +const toggleMessagePinActionTypes = Object.freeze({ + started: 'TOGGLE_MESSAGE_PIN_STARTED', + success: 'TOGGLE_MESSAGE_PIN_SUCCESS', + failed: 'TOGGLE_MESSAGE_PIN_FAILED', +}); const toggleMessagePin = ( callServerEndpoint: CallServerEndpoint, - ): ((request: ToggleMessagePinRequest) => Promise) => + ): ((request: ToggleMessagePinRequest) => Promise) => async request => { - await callServerEndpoint('toggle_message_pin', request); + const response = await callServerEndpoint('toggle_message_pin', request); + return { + newMessageInfos: response.newMessageInfos, + threadID: response.threadID, + }; }; export { @@ -199,5 +209,6 @@ leaveThreadActionTypes, leaveThread, fetchThreadMedia, + toggleMessagePinActionTypes, toggleMessagePin, }; diff --git a/lib/reducers/message-reducer.js b/lib/reducers/message-reducer.js --- a/lib/reducers/message-reducer.js +++ b/lib/reducers/message-reducer.js @@ -43,6 +43,7 @@ removeUsersFromThreadActionTypes, changeThreadMemberRolesActionTypes, joinThreadActionTypes, + toggleMessagePinActionTypes, } from '../actions/thread-actions.js'; import { updateMultimediaMessageMediaActionType } from '../actions/upload-actions.js'; import { @@ -849,7 +850,8 @@ action.type === changeThreadMemberRolesActionTypes.success || action.type === createEntryActionTypes.success || action.type === saveEntryActionTypes.success || - action.type === restoreEntryActionTypes.success + action.type === restoreEntryActionTypes.success || + action.type === toggleMessagePinActionTypes.success ) { return mergeNewMessages( messageStore, diff --git a/lib/types/redux-types.js b/lib/types/redux-types.js --- a/lib/types/redux-types.js +++ b/lib/types/redux-types.js @@ -81,6 +81,7 @@ LeaveThreadPayload, NewThreadResult, ThreadJoinPayload, + ToggleMessagePinResult, } from './thread-types.js'; import type { ClientUpdatesResultWithUserInfos } from './update-types.js'; import type { CurrentUserInfo, UserStore } from './user-types.js'; @@ -934,6 +935,22 @@ +error: true, +payload: Error, +loadingInfo: LoadingInfo, + } + | { + +type: 'TOGGLE_MESSAGE_PIN_STARTED', + +loadingInfo?: LoadingInfo, + +payload?: void, + } + | { + +type: 'TOGGLE_MESSAGE_PIN_SUCCESS', + +payload: ToggleMessagePinResult, + +loadingInfo: LoadingInfo, + } + | { + +type: 'TOGGLE_MESSAGE_PIN_FAILED', + +error: true, + +payload: Error, + +loadingInfo: LoadingInfo, }; export type ActionPayload = ?(Object | Array<*> | $ReadOnlyArray<*> | string); diff --git a/lib/types/thread-types.js b/lib/types/thread-types.js --- a/lib/types/thread-types.js +++ b/lib/types/thread-types.js @@ -488,6 +488,11 @@ +action: 'pin' | 'unpin', }; +export type ToggleMessagePinResult = { + +newMessageInfos: $ReadOnlyArray, + +threadID: string, +}; + // We can show a max of 3 sidebars inline underneath their parent in the chat // tab. If there are more, we show a button that opens a modal to see the rest export const maxReadSidebars = 3;