-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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: translate channel log #32612
fix: translate channel log #32612
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
type MessageElementBase = { | ||
readonly kind: string; | ||
readonly content: string; | ||
}; | ||
|
||
type MessageTextElement = { | ||
readonly kind: 'text'; | ||
readonly content: string; | ||
} & MessageElementBase; | ||
|
||
export type {MessageElementBase, MessageTextElement}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,21 +5,37 @@ import OnyxUtils from 'react-native-onyx/lib/utils'; | |
import {ValueOf} from 'type-fest'; | ||
import CONST from '@src/CONST'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import {ActionName} from '@src/types/onyx/OriginalMessage'; | ||
import {ActionName, ChangeLog} from '@src/types/onyx/OriginalMessage'; | ||
import Report from '@src/types/onyx/Report'; | ||
import ReportAction, {ReportActions} from '@src/types/onyx/ReportAction'; | ||
import ReportAction, {Message, ReportActions} from '@src/types/onyx/ReportAction'; | ||
import {EmptyObject, isEmptyObject} from '@src/types/utils/EmptyObject'; | ||
import * as CollectionUtils from './CollectionUtils'; | ||
import * as Environment from './Environment/Environment'; | ||
import isReportMessageAttachment from './isReportMessageAttachment'; | ||
import * as Localize from './Localize'; | ||
import Log from './Log'; | ||
import {MessageElementBase, MessageTextElement} from './MessageElement'; | ||
import * as PersonalDetailsUtils from './PersonalDetailsUtils'; | ||
|
||
type LastVisibleMessage = { | ||
lastMessageTranslationKey?: string; | ||
lastMessageText: string; | ||
lastMessageHtml?: string; | ||
}; | ||
|
||
type MemberChangeMessageUserMentionElement = { | ||
readonly kind: 'userMention'; | ||
readonly accountID: number; | ||
} & MessageElementBase; | ||
|
||
type MemberChangeMessageRoomReferenceElement = { | ||
readonly kind: 'roomReference'; | ||
readonly roomName: string; | ||
readonly roomID: number; | ||
} & MessageElementBase; | ||
|
||
type MemberChangeMessageElement = MessageTextElement | MemberChangeMessageUserMentionElement | MemberChangeMessageRoomReferenceElement; | ||
|
||
const allReports: OnyxCollection<Report> = {}; | ||
Onyx.connect({ | ||
key: ONYXKEYS.COLLECTION.REPORT, | ||
|
@@ -104,7 +120,7 @@ function isReimbursementQueuedAction(reportAction: OnyxEntry<ReportAction>) { | |
return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENTQUEUED; | ||
} | ||
|
||
function isChannelLogMemberAction(reportAction: OnyxEntry<ReportAction>) { | ||
function isMemberChangeAction(reportAction: OnyxEntry<ReportAction>) { | ||
return ( | ||
reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM || | ||
reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.REMOVE_FROM_ROOM || | ||
|
@@ -113,6 +129,10 @@ function isChannelLogMemberAction(reportAction: OnyxEntry<ReportAction>) { | |
); | ||
} | ||
|
||
function isInviteMemberAction(reportAction: OnyxEntry<ReportAction>) { | ||
return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM || reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG.INVITE_TO_ROOM; | ||
} | ||
|
||
function isReimbursementDeQueuedAction(reportAction: OnyxEntry<ReportAction>): boolean { | ||
return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENTDEQUEUED; | ||
} | ||
|
@@ -653,6 +673,89 @@ function isNotifiableReportAction(reportAction: OnyxEntry<ReportAction>): boolea | |
return actions.includes(reportAction.actionName); | ||
} | ||
|
||
function getMemberChangeMessageElements(reportAction: OnyxEntry<ReportAction>): readonly MemberChangeMessageElement[] { | ||
const isInviteAction = isInviteMemberAction(reportAction); | ||
|
||
// Currently, we only render messages when members are invited | ||
const verb = isInviteAction ? Localize.translateLocal('workspace.invite.invited') : Localize.translateLocal('workspace.invite.removed'); | ||
|
||
const originalMessage = reportAction?.originalMessage as ChangeLog; | ||
const targetAccountIDs: number[] = originalMessage?.targetAccountIDs ?? []; | ||
const personalDetails = PersonalDetailsUtils.getPersonalDetailsByIDs(targetAccountIDs, 0); | ||
|
||
const mentionElements = targetAccountIDs.map((accountID): MemberChangeMessageUserMentionElement => { | ||
const personalDetail = personalDetails.find((personal) => personal.accountID === accountID); | ||
const handleText = PersonalDetailsUtils.getEffectiveDisplayName(personalDetail) ?? Localize.translateLocal('common.hidden'); | ||
|
||
return { | ||
kind: 'userMention', | ||
content: `@${handleText}`, | ||
accountID, | ||
}; | ||
}); | ||
|
||
const buildRoomElements = (): readonly MemberChangeMessageElement[] => { | ||
const roomName = originalMessage?.roomName; | ||
|
||
if (roomName) { | ||
const preposition = isInviteAction ? ` ${Localize.translateLocal('workspace.invite.to')} ` : ` ${Localize.translateLocal('workspace.invite.from')} `; | ||
|
||
if (originalMessage.reportID) { | ||
return [ | ||
{ | ||
kind: 'text', | ||
content: preposition, | ||
}, | ||
{ | ||
kind: 'roomReference', | ||
roomName, | ||
roomID: originalMessage.reportID, | ||
content: roomName, | ||
}, | ||
]; | ||
} | ||
} | ||
|
||
return []; | ||
}; | ||
|
||
return [ | ||
{ | ||
kind: 'text', | ||
content: `${verb} `, | ||
}, | ||
...Localize.formatMessageElementList(mentionElements), | ||
...buildRoomElements(), | ||
]; | ||
} | ||
|
||
function getMemberChangeMessageFragment(reportAction: OnyxEntry<ReportAction>): Message { | ||
const messageElements: readonly MemberChangeMessageElement[] = getMemberChangeMessageElements(reportAction); | ||
const html = messageElements | ||
.map((messageElement) => { | ||
switch (messageElement.kind) { | ||
case 'userMention': | ||
return `<mention-user accountID=${messageElement.accountID}></mention-user>`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @namhihi237 Why didn't we include the mentioned display name here? Did it cause any regression? For example: `<mention-user accountID=${messageElement.accountID}>${messageElement.content}</mention-user>` There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tienifr As I know currently mention-user use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think if we use like you mention i think the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah thanks! I just want to make sure adding |
||
case 'roomReference': | ||
return `<a href="${environmentURL}/r/${messageElement.roomID}" target="_blank">${messageElement.roomName}</a>`; | ||
default: | ||
return messageElement.content; | ||
} | ||
}) | ||
.join(''); | ||
|
||
return { | ||
html: `<muted-text>${html}</muted-text>`, | ||
text: reportAction?.message ? reportAction?.message[0].text : '', | ||
type: CONST.REPORT.MESSAGE.TYPE.COMMENT, | ||
}; | ||
} | ||
|
||
function getMemberChangeMessagePlainText(reportAction: OnyxEntry<ReportAction>): string { | ||
const messageElements = getMemberChangeMessageElements(reportAction); | ||
return messageElements.map((element) => element.content).join(''); | ||
} | ||
|
||
/** | ||
* Helper method to determine if the provided accountID has made a request on the specified report. | ||
* | ||
|
@@ -716,7 +819,9 @@ export { | |
shouldReportActionBeVisibleAsLastAction, | ||
hasRequestFromCurrentAccount, | ||
getFirstVisibleReportActionID, | ||
isChannelLogMemberAction, | ||
isMemberChangeAction, | ||
getMemberChangeMessageFragment, | ||
getMemberChangeMessagePlainText, | ||
isReimbursementDeQueuedAction, | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this related?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, Currently the error happen because
required cycle
. Inen.ts
importReportActionsUtils
andReportActionsUtils.ts
we importLocalize.ts
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#30927 (comment)