Page MenuHomePhabricator

D7237.id24856.diff
No OneTemporary

D7237.id24856.diff

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 { updateUserAvatarRequestValidator } from 'lib/utils/avatar-utils.js';
@@ -204,10 +205,10 @@
async function toggleMessagePinResponder(
viewer: Viewer,
input: any,
-): Promise<void> {
+): Promise<ToggleMessagePinResult> {
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';
@@ -862,7 +863,7 @@
async function toggleMessagePinForThread(
viewer: Viewer,
request: ToggleMessagePinRequest,
-): Promise<void> {
+): Promise<ToggleMessagePinResult> {
const { messageID, action } = request;
const targetMessage = await fetchMessageInfoByID(viewer, messageID);
@@ -918,9 +919,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) {
@@ -932,6 +934,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<void>) =>
+ ): ((request: ToggleMessagePinRequest) => Promise<ToggleMessagePinResult>) =>
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
@@ -44,6 +44,7 @@
removeUsersFromThreadActionTypes,
changeThreadMemberRolesActionTypes,
joinThreadActionTypes,
+ toggleMessagePinActionTypes,
} from '../actions/thread-actions.js';
import { updateMultimediaMessageMediaActionType } from '../actions/upload-actions.js';
import {
@@ -850,7 +851,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
@@ -82,6 +82,7 @@
LeaveThreadPayload,
NewThreadResult,
ThreadJoinPayload,
+ ToggleMessagePinResult,
} from './thread-types.js';
import type { ClientUpdatesResultWithUserInfos } from './update-types.js';
import type { CurrentUserInfo, UserStore } from './user-types.js';
@@ -952,6 +953,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
@@ -498,6 +498,11 @@
+action: 'pin' | 'unpin',
};
+export type ToggleMessagePinResult = {
+ +newMessageInfos: $ReadOnlyArray<RawMessageInfo>,
+ +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;

File Metadata

Mime Type
text/plain
Expires
Sun, Dec 1, 2:28 PM (20 h, 28 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2605222
Default Alt Text
D7237.id24856.diff (5 KB)

Event Timeline