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

consolidate join/leave messages #18849

Merged
merged 19 commits into from Aug 11, 2019

typing

  • Loading branch information...
mmaxim committed Aug 8, 2019
commit fbca46e794dabc5bc114b385fdececb3057812fc
@@ -48,8 +48,6 @@ class MessageAction extends React.PureComponent<Props> {
case 'systemChangeRetention':
case 'systemGitPush':
case 'systemInviteAccepted':
case 'systemJoined':
case 'systemLeft':
case 'systemSimpleToComplex':
case 'systemText':
case 'systemUsersAddedToConversation':
@@ -70,8 +70,8 @@ const noEmoji = {

const mapStateToProps = (state, ownProps: OwnProps) => {
const me = state.config.username || ''
const message = Constants.getMessage(state, ownProps.conversationIDKey, ownProps.ordinal)
if (!message || message.type === 'placeholder' || message.type === 'deleted') {
const message = Constants.getDecoratedMessage(state, ownProps.conversationIDKey, ownProps.ordinal)
if (!message) {
return noEmoji
}
const reaction = message.reactions.get(ownProps.emoji || '')
@@ -29,8 +29,8 @@ const emptyStateProps = {
}

const mapStateToProps = (state, ownProps: OwnProps) => {
const message = Constants.getMessage(state, ownProps.conversationIDKey, ownProps.ordinal)
if (!message || message.type === 'placeholder' || message.type === 'deleted') {
const message = Constants.getDecoratedMessage(state, ownProps.conversationIDKey, ownProps.ordinal)
if (!message) {
return emptyStateProps
}
const _reactions = message.reactions
@@ -25,8 +25,8 @@ export type OwnProps = {

export default namedConnect(
(state, ownProps: OwnProps) => {
const message = Constants.getMessage(state, ownProps.conversationIDKey, ownProps.ordinal)
if (!message || message.type === 'placeholder' || message.type === 'deleted') {
const message = Constants.getDecoratedMessage(state, ownProps.conversationIDKey, ownProps.ordinal)
if (!message) {
// nothing to see here
return {_reactions: null}
}
@@ -287,8 +287,6 @@ class _WrapperMessage extends React.Component<Props & Kb.OverlayParentProps, Sta
this.props.message.type === 'systemChangeRetention' ||
this.props.message.type === 'systemGitPush' ||
this.props.message.type === 'systemInviteAccepted' ||
this.props.message.type === 'systemJoined' ||
this.props.message.type === 'systemLeft' ||
this.props.message.type === 'systemSimpleToComplex' ||
this.props.message.type === 'systemText' ||
this.props.message.type === 'systemUsersAddedToConversation') &&
@@ -506,20 +504,22 @@ class _WrapperMessage extends React.Component<Props & Kb.OverlayParentProps, Sta
)}
{showMenuButton ? (
<Kb.Box className="WrapperMessage-buttons">
{!this._shouldShowReactionsRow() && !this.props.showingMenu && (
<EmojiRow
className={Styles.classNames({
'WrapperMessage-emojiRow': !this.props.isLastInThread,
})}
conversationIDKey={this.props.conversationIDKey}
onShowingEmojiPicker={this._setShowingPicker}
ordinal={message.ordinal}
style={Styles.collapseStyles([
styles.emojiRow,
this.props.isLastInThread && styles.emojiRowLast,
])}
/>
)}
{!this._shouldShowReactionsRow() &&
!!Constants.makeDecoratedMessage(this.props.message) &&
!this.props.showingMenu && (
<EmojiRow
className={Styles.classNames({
'WrapperMessage-emojiRow': !this.props.isLastInThread,
})}
conversationIDKey={this.props.conversationIDKey}
onShowingEmojiPicker={this._setShowingPicker}
ordinal={message.ordinal}
style={Styles.collapseStyles([
styles.emojiRow,
this.props.isLastInThread && styles.emojiRowLast,
])}
/>
)}
<Kb.Box>
{this.props.shouldShowPopup && (
<Kb.Icon
@@ -170,6 +170,34 @@ export const getMessage = (
id: Types.ConversationIDKey,
ordinal: Types.Ordinal
): Types.Message | null => state.chat2.messageMap.getIn([id, ordinal])
export const getDecoratedMessage = (
This conversation was marked as resolved by mmaxim

This comment has been minimized.

Copy link
@chrisnojima

chrisnojima Aug 11, 2019

Contributor

likely better to just make this a type guard instead of this message or null function
https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards

state: TypedState,
id: Types.ConversationIDKey,
ordinal: Types.Ordinal
): Types.DecoratedMessage | null => {
const message = state.chat2.messageMap.getIn([id, ordinal])
if (!message) {
return null
}
return !(
message.type === 'placeholder' ||
message.type === 'deleted' ||
message.type === 'systemJoined' ||
message.type === 'systemLeft'
)
? message
: null
}
export const makeDecoratedMessage = (message: Types.Message): Types.DecoratedMessage | null => {
return !(
message.type === 'placeholder' ||
message.type === 'deleted' ||
message.type === 'systemJoined' ||
message.type === 'systemLeft'
)
? message
: null
}
export const getMessageKey = (message: Types.Message) =>
`${message.conversationIDKey}:${Types.ordinalToNumber(message.ordinal)}`
export const getHasBadge = (state: TypedState, id: Types.ConversationIDKey) =>
@@ -292,14 +292,12 @@ export const makeMessageSendPayment = I.Record<MessageTypes._MessageSendPayment>
const makeMessageSystemJoined = I.Record<MessageTypes._MessageSystemJoined>({
...makeMessageCommonNoDeleteNoEdit,
joiners: [],
reactions: I.Map(),
type: 'systemJoined',
})

const makeMessageSystemLeft = I.Record<MessageTypes._MessageSystemLeft>({
...makeMessageCommonNoDeleteNoEdit,
leavers: [],
reactions: I.Map(),
type: 'systemLeft',
})

@@ -843,13 +841,11 @@ const validUIMessagetoMessage = (
return makeMessageSystemJoined({
...common,
joiners: m.messageBody.join ? m.messageBody.join.joiners || [] : [],
reactions,
})
case RPCChatTypes.MessageType.leave:
return makeMessageSystemLeft({
...common,
leavers: m.messageBody.leave ? m.messageBody.leave.leavers || [] : [],
reactions,
})
case RPCChatTypes.MessageType.system:
return m.messageBody.system
@@ -1244,8 +1240,6 @@ export const shouldShowPopup = (state: TypedState, message: Types.Message) => {
case 'systemChangeRetention':
case 'systemGitPush':
case 'systemInviteAccepted':
case 'systemJoined':
case 'systemLeft':
case 'systemSimpleToComplex':
case 'systemText':
case 'systemUsersAddedToConversation':
@@ -330,7 +330,6 @@ export type _MessageSystemJoined = {
isDeleteable: boolean
isEditable: boolean
joiners: Array<string>
reactions: Reactions
timestamp: number
type: 'systemJoined'
} & _MessageCommon
@@ -345,7 +344,6 @@ export type _MessageSystemLeft = {
isDeleteable: boolean
isEditable: boolean
leavers: Array<string>
reactions: Reactions
timestamp: number
type: 'systemLeft'
} & _MessageCommon
@@ -439,8 +437,6 @@ export type MessageWithReactionPopup =
| MessageSystemChangeRetention
| MessageSystemGitPush
| MessageSystemInviteAccepted
| MessageSystemJoined
| MessageSystemLeft
| MessageSystemSimpleToComplex
| MessageSystemText
| MessageSystemUsersAddedToConversation
@@ -901,8 +901,9 @@ const rootReducer = (
const {conversationIDKey, emoji, targetOrdinal, username} = action.payload
return state.update('messageMap', messageMap =>
messageMap.update(conversationIDKey, I.Map(), (map: I.Map<Types.Ordinal, Types.Message>) => {
return map.update(targetOrdinal, message => {
if (!message || message.type === 'deleted' || message.type === 'placeholder') {
return map.update(targetOrdinal, inmessage => {
const message = Constants.makeDecoratedMessage(inmessage)
if (!message) {
return message
}
const reactions = message.reactions
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.