mereg devel
This commit is contained in:
+38
-47
@@ -85,7 +85,7 @@ class MessagesView extends React.Component {
|
|||||||
this.handleScrollEvent = this.handleScrollEvent.bind(this);
|
this.handleScrollEvent = this.handleScrollEvent.bind(this);
|
||||||
this.handleDescChange = this.handleDescChange.bind(this);
|
this.handleDescChange = this.handleDescChange.bind(this);
|
||||||
this.handleSubsUpdated = this.handleSubsUpdated.bind(this);
|
this.handleSubsUpdated = this.handleSubsUpdated.bind(this);
|
||||||
this.handleNewMessage = this.handleNewMessage.bind(this);
|
this.handleMessageUpdate = this.handleMessageUpdate.bind(this);
|
||||||
this.handleAllMessagesReceived = this.handleAllMessagesReceived.bind(this);
|
this.handleAllMessagesReceived = this.handleAllMessagesReceived.bind(this);
|
||||||
this.handleInfoReceipt = this.handleInfoReceipt.bind(this);
|
this.handleInfoReceipt = this.handleInfoReceipt.bind(this);
|
||||||
this.handleImagePostview = this.handleImagePostview.bind(this);
|
this.handleImagePostview = this.handleImagePostview.bind(this);
|
||||||
@@ -125,7 +125,7 @@ class MessagesView extends React.Component {
|
|||||||
// or vertical shrinking.
|
// or vertical shrinking.
|
||||||
componentDidUpdate(prevProps, prevState) {
|
componentDidUpdate(prevProps, prevState) {
|
||||||
if (this.messagesScroller) {
|
if (this.messagesScroller) {
|
||||||
if (prevState.topic != this.state.topic || prevState.messages.length != this.state.messages.length) {
|
if (prevState.topic != this.state.topic || prevState.latestMsgSeq != this.state.latestMsgSeq) {
|
||||||
// New message
|
// New message
|
||||||
this.messagesScroller.scrollTop = this.messagesScroller.scrollHeight - this.state.scrollPosition;
|
this.messagesScroller.scrollTop = this.messagesScroller.scrollHeight - this.state.scrollPosition;
|
||||||
} else if (prevProps.viewportHeight > this.props.viewportHeight) {
|
} else if (prevProps.viewportHeight > this.props.viewportHeight) {
|
||||||
@@ -141,7 +141,7 @@ class MessagesView extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (topic) {
|
if (topic) {
|
||||||
topic.onData = this.handleNewMessage;
|
topic.onData = this.handleMessageUpdate;
|
||||||
topic.onAllMessagesReceived = this.handleAllMessagesReceived;
|
topic.onAllMessagesReceived = this.handleAllMessagesReceived;
|
||||||
topic.onInfo = this.handleInfoReceipt;
|
topic.onInfo = this.handleInfoReceipt;
|
||||||
topic.onMetaDesc = this.handleDescChange;
|
topic.onMetaDesc = this.handleDescChange;
|
||||||
@@ -209,7 +209,8 @@ class MessagesView extends React.Component {
|
|||||||
if (!nextProps.topic) {
|
if (!nextProps.topic) {
|
||||||
// Default state: no topic.
|
// Default state: no topic.
|
||||||
nextState = {
|
nextState = {
|
||||||
messages: [],
|
latestMsgSeq: -1,
|
||||||
|
latestClearId: -1,
|
||||||
onlineSubs: [],
|
onlineSubs: [],
|
||||||
topic: null,
|
topic: null,
|
||||||
title: '',
|
title: '',
|
||||||
@@ -240,7 +241,6 @@ class MessagesView extends React.Component {
|
|||||||
|
|
||||||
if (topic) {
|
if (topic) {
|
||||||
// Topic exists.
|
// Topic exists.
|
||||||
const msgs = [];
|
|
||||||
const subs = [];
|
const subs = [];
|
||||||
|
|
||||||
if (nextProps.connected) {
|
if (nextProps.connected) {
|
||||||
@@ -251,14 +251,7 @@ class MessagesView extends React.Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
topic.messages(function(msg) {
|
|
||||||
if (!msg.deleted) {
|
|
||||||
msgs.push(msg);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Object.assign(nextState, {
|
Object.assign(nextState, {
|
||||||
messages: msgs,
|
|
||||||
onlineSubs: subs
|
onlineSubs: subs
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -285,12 +278,15 @@ class MessagesView extends React.Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
Object.assign(nextState, {
|
Object.assign(nextState, {
|
||||||
|
latestMsgSeq: topic.maxMsgSeq(),
|
||||||
|
latestClearId: topic.maxClearId(),
|
||||||
channel: topic.isChannelType()
|
channel: topic.isChannelType()
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Invalid topic.
|
// Invalid topic.
|
||||||
Object.assign(nextState, {
|
Object.assign(nextState, {
|
||||||
messages: [],
|
latestMsgSeq: -1,
|
||||||
|
latestClearId: -1,
|
||||||
onlineSubs: [],
|
onlineSubs: [],
|
||||||
title: '',
|
title: '',
|
||||||
avatar: null,
|
avatar: null,
|
||||||
@@ -500,33 +496,32 @@ class MessagesView extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleNewMessage(msg) {
|
// The 'msg' could be false-ish if some message ranges were deleted.
|
||||||
// Regenerate messages list
|
handleMessageUpdate(msg) {
|
||||||
const topic = this.props.tinode.getTopic(this.state.topic);
|
const topic = this.props.tinode.getTopic(this.state.topic);
|
||||||
const newState = {messages: []};
|
if (!msg) {
|
||||||
topic.messages((m) => {
|
// msg could be null if one or more messages were deleted.
|
||||||
if (!m.deleted) {
|
// Updating state to force redraw.
|
||||||
newState.messages.push(m);
|
this.setState({latestClearId: topic.maxClearId()});
|
||||||
}
|
return;
|
||||||
});
|
|
||||||
|
|
||||||
// msg could be null if one or more messages were deleted.
|
|
||||||
if (msg && !msg.deleted) {
|
|
||||||
// If the message is added to the end of the message list,
|
|
||||||
// scroll to the bottom.
|
|
||||||
if (topic.isNewMessage(msg.seq)) {
|
|
||||||
newState.scrollPosition = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Aknowledge messages except own messages. They are
|
|
||||||
// automatically assumed to be read and recived.
|
|
||||||
const status = topic.msgStatus(msg, true);
|
|
||||||
if (status >= Tinode.MESSAGE_STATUS_SENT && msg.from != this.props.myUserId) {
|
|
||||||
this.postReadNotification(msg.seq);
|
|
||||||
}
|
|
||||||
this.props.onData(msg);
|
|
||||||
}
|
}
|
||||||
this.setState(newState);
|
|
||||||
|
this.setState({latestMsgSeq: topic.maxMsgSeq()});
|
||||||
|
|
||||||
|
// If the message is added to the end of the message list,
|
||||||
|
// scroll to the bottom.
|
||||||
|
if (topic.isNewMessage(msg.seq)) {
|
||||||
|
this.setState({scrollPosition: 0});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aknowledge messages except own messages. They are
|
||||||
|
// automatically assumed to be read and recived.
|
||||||
|
const status = topic.msgStatus(msg, true);
|
||||||
|
if (status >= Tinode.MESSAGE_STATUS_SENT && msg.from != this.props.myUserId) {
|
||||||
|
this.postReadNotification(msg.seq);
|
||||||
|
}
|
||||||
|
// This will send "received" notifications right away.
|
||||||
|
this.props.onData(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleAllMessagesReceived(count) {
|
handleAllMessagesReceived(count) {
|
||||||
@@ -777,7 +772,8 @@ class MessagesView extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleCancelUpload(seq, uploader) {
|
handleCancelUpload(seq, uploader) {
|
||||||
const found = this.state.messages.find(msg => msg.seq == seq);
|
const topic = this.props.tinode.getTopic(this.state.topic);
|
||||||
|
const found = topic.findMessage(seq);
|
||||||
if (found) {
|
if (found) {
|
||||||
found._cancelled = true;
|
found._cancelled = true;
|
||||||
}
|
}
|
||||||
@@ -840,13 +836,8 @@ class MessagesView extends React.Component {
|
|||||||
let messageNodes = [];
|
let messageNodes = [];
|
||||||
let previousFrom = null;
|
let previousFrom = null;
|
||||||
let chatBoxClass = null;
|
let chatBoxClass = null;
|
||||||
for (let i=0; i<this.state.messages.length; i++) {
|
topic.messages((msg, prev, next, i) => {
|
||||||
let msg = this.state.messages[i];
|
let nextFrom = next ? (next.from || null) : 'chan';
|
||||||
let nextFrom = null;
|
|
||||||
|
|
||||||
if (i + 1 < this.state.messages.length) {
|
|
||||||
nextFrom = this.state.messages[i+1].from || 'chan';
|
|
||||||
}
|
|
||||||
|
|
||||||
let sequence = 'single';
|
let sequence = 'single';
|
||||||
let thisFrom = msg.from || 'chan';
|
let thisFrom = msg.from || 'chan';
|
||||||
@@ -900,7 +891,7 @@ class MessagesView extends React.Component {
|
|||||||
onCancelUpload={this.handleCancelUpload}
|
onCancelUpload={this.handleCancelUpload}
|
||||||
key={msg.seq} />
|
key={msg.seq} />
|
||||||
);
|
);
|
||||||
}
|
});
|
||||||
|
|
||||||
let lastSeen = null;
|
let lastSeen = null;
|
||||||
if (isChannel) {
|
if (isChannel) {
|
||||||
|
|||||||
@@ -92,8 +92,10 @@ export default class ChatMessage extends React.Component {
|
|||||||
attachments.push(<Attachment
|
attachments.push(<Attachment
|
||||||
tinode={this.props.tinode}
|
tinode={this.props.tinode}
|
||||||
downloadUrl={Drafty.getDownloadUrl(att)}
|
downloadUrl={Drafty.getDownloadUrl(att)}
|
||||||
filename={att.name} uploading={Drafty.isProcessing(att)}
|
filename={att.name}
|
||||||
mimetype={att.mime} size={Drafty.getEntitySize(att)}
|
uploading={Drafty.isProcessing(att)}
|
||||||
|
mimetype={att.mime}
|
||||||
|
size={Drafty.getEntitySize(att)}
|
||||||
progress={this.state.progress}
|
progress={this.state.progress}
|
||||||
onCancelUpload={this.handleCancelUpload}
|
onCancelUpload={this.handleCancelUpload}
|
||||||
onError={this.props.onError}
|
onError={this.props.onError}
|
||||||
|
|||||||
+37
-46
@@ -2781,7 +2781,7 @@ class MessagesView extends (react__WEBPACK_IMPORTED_MODULE_0___default().Compone
|
|||||||
this.handleScrollEvent = this.handleScrollEvent.bind(this);
|
this.handleScrollEvent = this.handleScrollEvent.bind(this);
|
||||||
this.handleDescChange = this.handleDescChange.bind(this);
|
this.handleDescChange = this.handleDescChange.bind(this);
|
||||||
this.handleSubsUpdated = this.handleSubsUpdated.bind(this);
|
this.handleSubsUpdated = this.handleSubsUpdated.bind(this);
|
||||||
this.handleNewMessage = this.handleNewMessage.bind(this);
|
this.handleMessageUpdate = this.handleMessageUpdate.bind(this);
|
||||||
this.handleAllMessagesReceived = this.handleAllMessagesReceived.bind(this);
|
this.handleAllMessagesReceived = this.handleAllMessagesReceived.bind(this);
|
||||||
this.handleInfoReceipt = this.handleInfoReceipt.bind(this);
|
this.handleInfoReceipt = this.handleInfoReceipt.bind(this);
|
||||||
this.handleImagePostview = this.handleImagePostview.bind(this);
|
this.handleImagePostview = this.handleImagePostview.bind(this);
|
||||||
@@ -2816,7 +2816,7 @@ class MessagesView extends (react__WEBPACK_IMPORTED_MODULE_0___default().Compone
|
|||||||
|
|
||||||
componentDidUpdate(prevProps, prevState) {
|
componentDidUpdate(prevProps, prevState) {
|
||||||
if (this.messagesScroller) {
|
if (this.messagesScroller) {
|
||||||
if (prevState.topic != this.state.topic || prevState.messages.length != this.state.messages.length) {
|
if (prevState.topic != this.state.topic || prevState.latestMsgSeq != this.state.latestMsgSeq) {
|
||||||
this.messagesScroller.scrollTop = this.messagesScroller.scrollHeight - this.state.scrollPosition;
|
this.messagesScroller.scrollTop = this.messagesScroller.scrollHeight - this.state.scrollPosition;
|
||||||
} else if (prevProps.viewportHeight > this.props.viewportHeight) {
|
} else if (prevProps.viewportHeight > this.props.viewportHeight) {
|
||||||
this.messagesScroller.scrollTop += prevProps.viewportHeight - this.props.viewportHeight;
|
this.messagesScroller.scrollTop += prevProps.viewportHeight - this.props.viewportHeight;
|
||||||
@@ -2831,7 +2831,7 @@ class MessagesView extends (react__WEBPACK_IMPORTED_MODULE_0___default().Compone
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (topic) {
|
if (topic) {
|
||||||
topic.onData = this.handleNewMessage;
|
topic.onData = this.handleMessageUpdate;
|
||||||
topic.onAllMessagesReceived = this.handleAllMessagesReceived;
|
topic.onAllMessagesReceived = this.handleAllMessagesReceived;
|
||||||
topic.onInfo = this.handleInfoReceipt;
|
topic.onInfo = this.handleInfoReceipt;
|
||||||
topic.onMetaDesc = this.handleDescChange;
|
topic.onMetaDesc = this.handleDescChange;
|
||||||
@@ -2896,7 +2896,8 @@ class MessagesView extends (react__WEBPACK_IMPORTED_MODULE_0___default().Compone
|
|||||||
|
|
||||||
if (!nextProps.topic) {
|
if (!nextProps.topic) {
|
||||||
nextState = {
|
nextState = {
|
||||||
messages: [],
|
latestMsgSeq: -1,
|
||||||
|
latestClearId: -1,
|
||||||
onlineSubs: [],
|
onlineSubs: [],
|
||||||
topic: null,
|
topic: null,
|
||||||
title: '',
|
title: '',
|
||||||
@@ -2926,7 +2927,6 @@ class MessagesView extends (react__WEBPACK_IMPORTED_MODULE_0___default().Compone
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (topic) {
|
if (topic) {
|
||||||
const msgs = [];
|
|
||||||
const subs = [];
|
const subs = [];
|
||||||
|
|
||||||
if (nextProps.connected) {
|
if (nextProps.connected) {
|
||||||
@@ -2937,13 +2937,7 @@ class MessagesView extends (react__WEBPACK_IMPORTED_MODULE_0___default().Compone
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
topic.messages(function (msg) {
|
|
||||||
if (!msg.deleted) {
|
|
||||||
msgs.push(msg);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Object.assign(nextState, {
|
Object.assign(nextState, {
|
||||||
messages: msgs,
|
|
||||||
onlineSubs: subs
|
onlineSubs: subs
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -2972,11 +2966,14 @@ class MessagesView extends (react__WEBPACK_IMPORTED_MODULE_0___default().Compone
|
|||||||
}
|
}
|
||||||
|
|
||||||
Object.assign(nextState, {
|
Object.assign(nextState, {
|
||||||
|
latestMsgSeq: topic.maxMsgSeq(),
|
||||||
|
latestClearId: topic.maxClearId(),
|
||||||
channel: topic.isChannelType()
|
channel: topic.isChannelType()
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
Object.assign(nextState, {
|
Object.assign(nextState, {
|
||||||
messages: [],
|
latestMsgSeq: -1,
|
||||||
|
latestClearId: -1,
|
||||||
onlineSubs: [],
|
onlineSubs: [],
|
||||||
title: '',
|
title: '',
|
||||||
avatar: null,
|
avatar: null,
|
||||||
@@ -3200,32 +3197,33 @@ class MessagesView extends (react__WEBPACK_IMPORTED_MODULE_0___default().Compone
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleNewMessage(msg) {
|
handleMessageUpdate(msg) {
|
||||||
const topic = this.props.tinode.getTopic(this.state.topic);
|
const topic = this.props.tinode.getTopic(this.state.topic);
|
||||||
const newState = {
|
|
||||||
messages: []
|
|
||||||
};
|
|
||||||
topic.messages(m => {
|
|
||||||
if (!m.deleted) {
|
|
||||||
newState.messages.push(m);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (msg && !msg.deleted) {
|
if (!msg) {
|
||||||
if (topic.isNewMessage(msg.seq)) {
|
this.setState({
|
||||||
newState.scrollPosition = 0;
|
latestClearId: topic.maxClearId()
|
||||||
}
|
});
|
||||||
|
return;
|
||||||
const status = topic.msgStatus(msg, true);
|
|
||||||
|
|
||||||
if (status >= (tinode_sdk__WEBPACK_IMPORTED_MODULE_2___default().MESSAGE_STATUS_SENT) && msg.from != this.props.myUserId) {
|
|
||||||
this.postReadNotification(msg.seq);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.props.onData(msg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setState(newState);
|
this.setState({
|
||||||
|
latestMsgSeq: topic.maxMsgSeq()
|
||||||
|
});
|
||||||
|
|
||||||
|
if (topic.isNewMessage(msg.seq)) {
|
||||||
|
this.setState({
|
||||||
|
scrollPosition: 0
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const status = topic.msgStatus(msg, true);
|
||||||
|
|
||||||
|
if (status >= (tinode_sdk__WEBPACK_IMPORTED_MODULE_2___default().MESSAGE_STATUS_SENT) && msg.from != this.props.myUserId) {
|
||||||
|
this.postReadNotification(msg.seq);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.props.onData(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleAllMessagesReceived(count) {
|
handleAllMessagesReceived(count) {
|
||||||
@@ -3485,7 +3483,8 @@ class MessagesView extends (react__WEBPACK_IMPORTED_MODULE_0___default().Compone
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleCancelUpload(seq, uploader) {
|
handleCancelUpload(seq, uploader) {
|
||||||
const found = this.state.messages.find(msg => msg.seq == seq);
|
const topic = this.props.tinode.getTopic(this.state.topic);
|
||||||
|
const found = topic.findMessage(seq);
|
||||||
|
|
||||||
if (found) {
|
if (found) {
|
||||||
found._cancelled = true;
|
found._cancelled = true;
|
||||||
@@ -3559,15 +3558,8 @@ class MessagesView extends (react__WEBPACK_IMPORTED_MODULE_0___default().Compone
|
|||||||
let messageNodes = [];
|
let messageNodes = [];
|
||||||
let previousFrom = null;
|
let previousFrom = null;
|
||||||
let chatBoxClass = null;
|
let chatBoxClass = null;
|
||||||
|
topic.messages((msg, prev, next, i) => {
|
||||||
for (let i = 0; i < this.state.messages.length; i++) {
|
let nextFrom = next ? next.from || null : 'chan';
|
||||||
let msg = this.state.messages[i];
|
|
||||||
let nextFrom = null;
|
|
||||||
|
|
||||||
if (i + 1 < this.state.messages.length) {
|
|
||||||
nextFrom = this.state.messages[i + 1].from || 'chan';
|
|
||||||
}
|
|
||||||
|
|
||||||
let sequence = 'single';
|
let sequence = 'single';
|
||||||
let thisFrom = msg.from || 'chan';
|
let thisFrom = msg.from || 'chan';
|
||||||
|
|
||||||
@@ -3622,8 +3614,7 @@ class MessagesView extends (react__WEBPACK_IMPORTED_MODULE_0___default().Compone
|
|||||||
onCancelUpload: this.handleCancelUpload,
|
onCancelUpload: this.handleCancelUpload,
|
||||||
key: msg.seq
|
key: msg.seq
|
||||||
}));
|
}));
|
||||||
}
|
});
|
||||||
|
|
||||||
let lastSeen = null;
|
let lastSeen = null;
|
||||||
|
|
||||||
if (isChannel) {
|
if (isChannel) {
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
+1
-1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+127
-26
File diff suppressed because one or more lines are too long
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user