Skip to content

Commit e7d2538

Browse files
Merge branch 'master' of github.com:GetStream/stream-chat-react-native into vishal/CRNS-61
# Conflicts: # types/index.d.ts
2 parents 600b1d2 + 9d1c76a commit e7d2538

File tree

8 files changed

+80
-27
lines changed

8 files changed

+80
-27
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+
messageObject: { ...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: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,22 @@ 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+
* Formatter function for date of latest message.
82+
* @param date Message date
83+
* @returns Formatted date string
84+
*
85+
* By default today's date is shown in 'HH:mm A' format and other dates
86+
* are displayed in 'DD/MM/YY' format. props.latestMessage.created_at is the
87+
* default formated date. This default logic is part of ChannelPreview component.
88+
*/
89+
formatLatestMessageDate: PropTypes.func,
90+
};
91+
92+
static defaultProps = {
93+
latestMessageLength: 30,
7894
};
7995

8096
onSelectChannel = () => {
@@ -109,7 +125,7 @@ export const ChannelPreviewMessenger = themed(
109125
.map((member) => member.user.name || member.user.id || 'Unnamed User')
110126
.join(', ');
111127
}
112-
128+
const formatLatestMessageDate = this.props.formatLatestMessageDate;
113129
return (
114130
<Container onPress={this.onSelectChannel}>
115131
{this.renderAvatar(otherMembers)}
@@ -118,17 +134,22 @@ export const ChannelPreviewMessenger = themed(
118134
<Title ellipsizeMode="tail" numberOfLines={1}>
119135
{name}
120136
</Title>
121-
<Date>{this.props.latestMessage.created_at}</Date>
137+
<Date>
138+
{formatLatestMessageDate
139+
? formatLatestMessageDate(
140+
this.props.latestMessage.messageObject.created_at,
141+
)
142+
: this.props.latestMessage.created_at}
143+
</Date>
122144
</DetailsTop>
123145
<Message
124146
unread={this.props.unread > 0 ? this.props.unread : undefined}
125147
>
126148
{!this.props.latestMessage
127149
? 'Nothing yet...'
128-
: truncate(
129-
this.props.latestMessage.text.replace(/\n/g, ' '),
130-
14,
131-
)}
150+
: truncate(this.props.latestMessage.text.replace(/\n/g, ' '), {
151+
length: this.props.latestMessageLength,
152+
})}
132153
</Message>
133154
</Details>
134155
</Container>

src/components/LoadingIndicator.js

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
import React from 'react';
2-
import { View } from 'react-native';
32
import styled from '@stream-io/styled-components';
43
import PropTypes from 'prop-types';
54
import { Spinner } from './Spinner';
65

6+
const Container = styled.View`
7+
flex: 1;
8+
justify-content: center;
9+
align-items: center;
10+
${({ theme }) => theme.loadingIndicator.container.css}
11+
`;
712
const LoadingText = styled.Text`
813
margin-top: 20px;
914
font-size: 14px;
1015
font-weight: 600;
16+
${({ theme }) => theme.loadingIndicator.loadingText.css}
1117
`;
1218

1319
export class LoadingIndicator extends React.PureComponent {
1420
static propTypes = {
1521
listType: PropTypes.oneOf(['channel', 'message', 'default']),
22+
loadingText: PropTypes.string,
1623
};
1724

1825
static defaultProps = {
@@ -23,31 +30,35 @@ export class LoadingIndicator extends React.PureComponent {
2330
switch (this.props.listType) {
2431
case 'channel':
2532
return (
26-
<View
27-
style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}
28-
>
33+
<Container>
2934
<Spinner />
30-
<LoadingText>Loading channels ...</LoadingText>
31-
</View>
35+
<LoadingText>
36+
{this.props.loadingText
37+
? this.props.loadingText
38+
: 'Loading channels ...'}
39+
</LoadingText>
40+
</Container>
3241
);
3342
case 'message':
3443
return (
35-
<View
36-
style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}
37-
>
44+
<Container>
3845
<Spinner />
39-
<LoadingText>Loading messages ...</LoadingText>
40-
</View>
46+
<LoadingText>
47+
{this.props.loadingText
48+
? this.props.loadingText
49+
: 'Loading messages ...'}
50+
</LoadingText>
51+
</Container>
4152
);
4253
case 'default':
4354
default:
4455
return (
45-
<View
46-
style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}
47-
>
56+
<Container>
4857
<Spinner />
49-
<LoadingText>Loading ...</LoadingText>
50-
</View>
58+
<LoadingText>
59+
{this.props.loadingText ? this.props.loadingText : 'Loading ...'}
60+
</LoadingText>
61+
</Container>
5162
);
5263
}
5364
}

src/components/MessageSimple/MessageContent.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ export const MessageContent = themed(
249249
PropTypes.node,
250250
PropTypes.elementType,
251251
]),
252+
formatDate: PropTypes.func,
252253
};
253254

254255
static defaultProps = {
@@ -534,7 +535,9 @@ export const MessageContent = themed(
534535
{!MessageFooter && showTime ? (
535536
<MetaContainer>
536537
<MetaText alignment={pos}>
537-
{moment(message.created_at).format('h:mmA')}
538+
{this.props.formatDate
539+
? this.props.formatDate(message.created_at)
540+
: moment(message.created_at).format('h:mmA')}
538541
</MetaText>
539542
</MetaContainer>
540543
) : null}

src/components/MessageSimple/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ export const MessageSimple = themed(
169169
PropTypes.node,
170170
PropTypes.elementType,
171171
]),
172+
formatDate: PropTypes.func,
172173
};
173174

174175
static defaultProps = {

src/components/MessageSystem.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ const MessageSystem = ({ message }) => (
5151
<TextContainer>
5252
<Text>{message.text.toUpperCase()}</Text>
5353
<DateText>
54-
{Moment(message.received_at)
54+
{Moment(message.created_at)
5555
.format('dddd')
5656
.toUpperCase()}{' '}
5757
at{' '}
58-
{Moment(message.received_at)
58+
{Moment(message.created_at)
5959
.format('hh:mm A')
6060
.toUpperCase()}
6161
</DateText>

src/styles/theme.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,10 @@ export const defaultTheme = {
161161
cancelButtonText: {},
162162
},
163163
},
164-
164+
loadingIndicator: {
165+
container: {},
166+
loadingText: {},
167+
},
165168
messageInput: {
166169
container: {
167170
conditionalPadding: 20,

types/index.d.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ export interface MessageInputProps
218218
actionSheetStyles?: object;
219219
AttachmentFileIcon?: React.ElementType<FileIconUIComponentProps>;
220220
AttachButton?: React.ElementType<AttachButtonProps>;
221+
SendButton: React.ElementType<SendButtonProps>;
221222
}
222223

223224
export interface AttachmentProps extends MessageContentContextValue {
@@ -325,7 +326,10 @@ export interface ChannelPreviewUIComponentProps
325326
latestMessage: {
326327
text: string;
327328
created_at: string;
329+
messageObject: Client.MessageResponse;
328330
};
331+
/** Length at which latest message should be truncated */
332+
latestMessageLength: number;
329333
}
330334

331335
export interface MessageListProps extends ChannelContextValue {
@@ -459,6 +463,7 @@ export interface MessageUIComponentProps
459463
/** https://github.com/beefe/react-native-actionsheet/blob/master/lib/styles.js */
460464
actionSheetStyles?: object;
461465
AttachmentFileIcon?: React.ElementType<FileIconUIComponentProps>;
466+
formatDate(date: string): string;
462467
}
463468

464469
export interface MessageRepliesUIComponentProps {
@@ -639,6 +644,7 @@ export interface LoadingErrorIndicatorProps {
639644
}
640645
export interface LoadingIndicatorProps {
641646
listType?: listType;
647+
loadingText?: string;
642648
}
643649
export interface MentionsItemProps {
644650
item: {
@@ -720,6 +726,12 @@ export interface AttachButtonProps {
720726
handleOnPress(): void;
721727
}
722728

729+
export interface SendButtonProps {
730+
title: string;
731+
editing: Client.MessageResponse | boolean;
732+
sendMessage(): void;
733+
}
734+
723735
//================================================================================================
724736
//================================================================================================
725737
//
@@ -816,6 +828,7 @@ export class TypingIndicator extends React.PureComponent<
816828
export class MessageInput extends React.PureComponent<MessageInputProps, any> {}
817829

818830
export class AttachButton extends React.PureComponent<AttachButtonProps, any> {}
831+
export class SendButton extends React.PureComponent<SendButtonProps> {}
819832
export class MessageSimple extends React.PureComponent<
820833
MessageUIComponentProps,
821834
any

0 commit comments

Comments
 (0)