Skip to content

Commit d664bb0

Browse files
committed
Fix message history and new message reception
1 parent dec43fc commit d664bb0

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

components/ChatHistory.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const renderMessage = (data) => {
1818
const msgDate = new Date(data.When);
1919
const msgDateTime = msgDate.toLocaleDateString() + ' at ' + msgDate.toLocaleTimeString();
2020

21+
debugger;
2122
return (
2223
<View style={[ styles.flx1, styles.flxRow, styles.p1, styles.borderBHl, { borderColor: '#aaa' }]} key={data.When}>
2324
<View style={[styles.rounded6, styles.w2, styles.h2, styles.mt1,{ overflow: 'hidden' }]}>
@@ -68,9 +69,9 @@ export class ChatHistory extends Component {
6869
render() {
6970
const { props, state, onScroll, onContentSizeChange } = this;
7071

71-
const isValid = h => h.entry != null && h.entry.Who != null;
72+
const rows = props.history.filter(h => h.Who != null);
7273

73-
const source = this.historySource.cloneWithRows(props.history.filter(isValid));
74+
const source = this.historySource.cloneWithRows(rows);
7475

7576
return (
7677
<View style={[styles.flx1, styles.flxRow, styles.selfStretch]}>

components/Conversation.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class BareConversation extends Component {
8080
}
8181

8282
onMessageReceived(m) {
83-
this.props.addMessage([m.message]);
83+
this.props.addMessage(m.message);
8484
}
8585

8686
onPresenceChange(presenceData) {
@@ -108,12 +108,13 @@ class BareConversation extends Component {
108108
}
109109

110110
fetchHistory() {
111-
const { props } = this;
112-
history(channel, props.lastMessageTimestamp).then(response => {
111+
const {lastMessageTimestamp, addHistory} = this.props;
112+
113+
history(lastMessageTimestamp).then(response => {
113114
// make sure we're not duplicating our existing history
114115
if (response.messages.length > 0 &&
115-
props.lastMessageTimeStamp !== response.startTimeToken) {
116-
props.addHistory(response.messages, response.startTimeToken)
116+
lastMessageTimestamp !== response.startTimeToken) {
117+
addHistory(response.messages, response.startTimeToken)
117118
}
118119
})
119120
}

reducers/conversation.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,11 @@ export const conversationReducer = (state = initialState, action) => {
4040

4141
case ADD_HISTORY:
4242
return state
43-
.update('history', (messages) => messages.unshift(
44-
...action.payload.messages.map(msg => msg.entry)
45-
))
43+
.update('history', (messages) => messages.unshift(...action.payload.messages.map(msg => msg.entry)))
4644
.set('lastMessageTimestamp', action.payload.timestamp);
4745

4846
case ADD_MESSAGE:
49-
return state.update('history', message => messages.push(action.payload));
47+
return state.update('history', messages => messages.push(action.payload));
5048

5149
default:
5250
return state;

services/pubnub.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,14 @@ export const history = (startTime) =>
125125
start: startTime,
126126
count: messageCount,
127127
},
128-
(status, response) => resolve(response))
128+
(status, response) => {
129+
if (status.error) {
130+
reject(status.category);
131+
}
132+
else {
133+
resolve(response);
134+
}
135+
});
129136
})
130137
.catch(reject);
131138
});

0 commit comments

Comments
 (0)