Skip to content

Commit ef5b887

Browse files
CRNS-58: Adding support for custom message length in Channel preview
Fixes #122
1 parent fa5e2b6 commit ef5b887

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

src/components/ChannelPreview.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export class ChannelPreview extends PureComponent {
6060
const latestMessage = {
6161
text: '',
6262
created_at: '',
63+
originalMessageObject: { ...message },
6364
};
6465

6566
if (!message) {
@@ -72,7 +73,7 @@ export class ChannelPreview extends PureComponent {
7273
}
7374

7475
if (message.text) {
75-
latestMessage.text = message.text.slice(0, 20);
76+
latestMessage.text = message.text;
7677
} else {
7778
if (message.command) {
7879
latestMessage.text = '/' + message.command;

src/components/ChannelPreviewMessenger.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ export const ChannelPreviewMessenger = themed(
7575
latestMessage: PropTypes.object,
7676
/** Number of unread messages on channel */
7777
unread: PropTypes.number,
78+
/** Length at which latest message should be truncated */
79+
latestMessageLength: PropTypes.number,
80+
};
81+
82+
static defaultProps = {
83+
latestMessageLength: 30,
7884
};
7985

8086
onSelectChannel = () => {
@@ -125,10 +131,9 @@ export const ChannelPreviewMessenger = themed(
125131
>
126132
{!this.props.latestMessage
127133
? 'Nothing yet...'
128-
: truncate(
129-
this.props.latestMessage.text.replace(/\n/g, ' '),
130-
14,
131-
)}
134+
: truncate(this.props.latestMessage.text.replace(/\n/g, ' '), {
135+
length: this.props.latestMessageLength,
136+
})}
132137
</Message>
133138
</Details>
134139
</Container>

types/index.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,10 @@ export interface ChannelPreviewUIComponentProps
324324
latestMessage: {
325325
text: string;
326326
created_at: string;
327+
originalMessageObject: Client.MessageResponse;
327328
};
329+
/** Length at which latest message should be truncated */
330+
latestMessageLength: number;
328331
}
329332

330333
export interface MessageListProps extends ChannelContextValue {

0 commit comments

Comments
 (0)