Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix When we set description of a room for the first time, optimistically it is shown as a comment in the LHN and later updates to system message #47208

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/libs/API/parameters/UpdateRoomDescriptionParams.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
type UpdateRoomDescriptionParams = {
reportID: string;
description: string;
reportActionID: string;
};

export default UpdateRoomDescriptionParams;
38 changes: 38 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ type OptimisticRenamedReportAction = Pick<
'actorAccountID' | 'automatic' | 'avatar' | 'created' | 'message' | 'person' | 'reportActionID' | 'shouldShow' | 'pendingAction' | 'actionName' | 'originalMessage'
>;

type OptimisticRoomDescriptionUpdatedReportAction = Pick<
ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.ROOM_CHANGE_LOG.UPDATE_ROOM_DESCRIPTION>,
'actorAccountID' | 'created' | 'message' | 'person' | 'reportActionID' | 'pendingAction' | 'actionName' | 'originalMessage'
>;

type OptimisticChatReport = Pick<
Report,
| 'type'
Expand Down Expand Up @@ -4998,6 +5003,38 @@ function buildOptimisticRenamedRoomReportAction(newName: string, oldName: string
};
}

/**
* Returns the necessary reportAction onyx data to indicate that the room description has been updated
*/
function buildOptimisticRoomDescriptionUpdatedReportAction(description: string): OptimisticRoomDescriptionUpdatedReportAction {
const now = DateUtils.getDBTime();
return {
reportActionID: NumberUtils.rand64(),
actionName: CONST.REPORT.ACTIONS.TYPE.ROOM_CHANGE_LOG.UPDATE_ROOM_DESCRIPTION,
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
actorAccountID: currentUserAccountID,
message: [
{
type: CONST.REPORT.MESSAGE.TYPE.COMMENT,
text: description ? `set the room description to: ${Parser.htmlToText(description)}` : 'cleared the room description',
html: description ? `<muted-text>set the room description to: ${description}</muted-text>` : '<muted-text>cleared the room description</muted-text>',
},
],
person: [
{
type: CONST.REPORT.MESSAGE.TYPE.TEXT,
style: 'strong',
text: getCurrentUserDisplayNameOrEmail(),
},
],
originalMessage: {
description,
lastModified: now,
},
created: now,
};
}

/**
* Returns the necessary reportAction onyx data to indicate that the transaction has been put on hold optimistically
* @param [created] - Action created time
Expand Down Expand Up @@ -7524,6 +7561,7 @@ export {
buildOptimisticMovedReportAction,
buildOptimisticMovedTrackedExpenseModifiedReportAction,
buildOptimisticRenamedRoomReportAction,
buildOptimisticRoomDescriptionUpdatedReportAction,
buildOptimisticReportPreview,
buildOptimisticActionableTrackExpenseWhisper,
buildOptimisticSubmittedReportAction,
Expand Down
41 changes: 38 additions & 3 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2020,19 +2020,47 @@ function updateDescription(reportID: string, previousValue: string, newValue: st
}

const parsedDescription = ReportUtils.getParsedComment(newValue, {reportID});
const optimisticDescriptionUpdatedReportAction = ReportUtils.buildOptimisticRoomDescriptionUpdatedReportAction(parsedDescription);
const report = ReportUtils.getReport(reportID);

const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {description: parsedDescription, pendingFields: {description: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE}},
value: {
description: parsedDescription,
pendingFields: {description: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE},
lastActorAccountID: currentUserAccountID,
lastVisibleActionCreated: optimisticDescriptionUpdatedReportAction.created,
lastMessageText: (optimisticDescriptionUpdatedReportAction?.message as Message[])?.[0]?.text,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`,
value: {
[optimisticDescriptionUpdatedReportAction.reportActionID]: optimisticDescriptionUpdatedReportAction,
},
},
];
const failureData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {description: previousValue, pendingFields: {description: null}},
value: {
description: previousValue,
pendingFields: {description: null},
lastActorAccountID: report?.lastActorAccountID,
lastVisibleActionCreated: report?.lastVisibleActionCreated,
lastMessageText: report?.lastMessageText,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`,
value: {
[optimisticDescriptionUpdatedReportAction.reportActionID]: null,
},
},
];
const successData: OnyxUpdate[] = [
Expand All @@ -2041,9 +2069,16 @@ function updateDescription(reportID: string, previousValue: string, newValue: st
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {pendingFields: {description: null}},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`,
value: {
[optimisticDescriptionUpdatedReportAction.reportActionID]: {pendingAction: null},
},
},
];

const parameters: UpdateRoomDescriptionParams = {reportID, description: parsedDescription};
const parameters: UpdateRoomDescriptionParams = {reportID, description: parsedDescription, reportActionID: optimisticDescriptionUpdatedReportAction.reportActionID};

API.write(WRITE_COMMANDS.UPDATE_ROOM_DESCRIPTION, parameters, {optimisticData, failureData, successData});
Navigation.goBack(ROUTES.REPORT_WITH_ID_DETAILS.getRoute(reportID));
Expand Down
3 changes: 3 additions & 0 deletions src/types/onyx/OriginalMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ type OriginalMessageChangeLog = {

/** ID of the report */
reportID?: number;

/** When was it last modified */
lastModified?: string;
};

/** Model of `join policy changelog` report action */
Expand Down
Loading