|
|
|
@ -5,16 +5,17 @@ import { SessionCompositionBox } from './SessionCompositionBox';
|
|
|
|
|
import { SessionProgress } from './SessionProgress'
|
|
|
|
|
|
|
|
|
|
import { Message } from '../conversation/Message';
|
|
|
|
|
import { TimerNotification } from '../conversation/TimerNotification';
|
|
|
|
|
|
|
|
|
|
import { SessionSpinner } from './SessionSpinner';
|
|
|
|
|
import { SessionScrollButton } from './SessionScrollButton';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// interface Props {
|
|
|
|
|
// getHeaderProps: any;
|
|
|
|
|
// conversationKey: any;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface State {
|
|
|
|
|
sendingProgess: number;
|
|
|
|
|
prevSendingProgess: number;
|
|
|
|
@ -33,13 +34,12 @@ export class SessionConversation extends React.Component<any, State> {
|
|
|
|
|
constructor(props: any) {
|
|
|
|
|
super(props);
|
|
|
|
|
const conversationKey = this.props.conversations.selectedConversation;
|
|
|
|
|
const messages = this.props.conversations.conversationLookup[conversationKey].messages;
|
|
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
|
sendingProgess: 0,
|
|
|
|
|
prevSendingProgess: 0,
|
|
|
|
|
conversationKey,
|
|
|
|
|
messages,
|
|
|
|
|
messages: [],
|
|
|
|
|
doneInitialScroll: false,
|
|
|
|
|
scrollPositionPc: 0,
|
|
|
|
|
scrollPositionPx: 0,
|
|
|
|
@ -48,47 +48,29 @@ export class SessionConversation extends React.Component<any, State> {
|
|
|
|
|
this.scrollToUnread = this.scrollToUnread.bind(this);
|
|
|
|
|
this.scrollToBottom = this.scrollToBottom.bind(this);
|
|
|
|
|
|
|
|
|
|
this.renderMessage = this.renderMessage.bind(this);
|
|
|
|
|
this.renderTimerNotification = this.renderTimerNotification.bind(this);
|
|
|
|
|
|
|
|
|
|
this.messagesEndRef = React.createRef();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public componentDidMount() {
|
|
|
|
|
public async componentWillMount() {
|
|
|
|
|
const { conversationKey } = this.state;
|
|
|
|
|
await this.getMessages(conversationKey);
|
|
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.scrollToBottom(true);
|
|
|
|
|
}, 20);
|
|
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
|
doneInitialScroll: true,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}, 0);
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.setState({
|
|
|
|
|
doneInitialScroll: true,
|
|
|
|
|
});
|
|
|
|
|
}, 100);
|
|
|
|
|
|
|
|
|
|
public componentWillUpdate () {
|
|
|
|
|
console.log(`[vince][update] State:`, this.state);
|
|
|
|
|
console.log(`[vince][update] Props:`, this.props);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public componentWillReceiveProps() {
|
|
|
|
|
const { conversationKey, messages } = this.state;
|
|
|
|
|
const conversation = this.props.conversations.conversationLookup[conversationKey];
|
|
|
|
|
|
|
|
|
|
// Check if another message came through
|
|
|
|
|
const shouldLoad = !messages.length || (conversation.lastUpdated > messages[messages.length - 1]?.received_at);
|
|
|
|
|
|
|
|
|
|
console.log(`[vince][update] conversation:`, conversation);
|
|
|
|
|
console.log(`[vince][update] conversation.lastupdated: `, conversation.lastUpdated)
|
|
|
|
|
console.log(`[vince][update] last message received at: `, messages[messages.length - 1]?.received_at)
|
|
|
|
|
console.log(`[vince][update] Should Update: `, shouldLoad)
|
|
|
|
|
console.log(`[vince][update] called ComponentWillRevieceProps. Messages: `, this.state.messages)
|
|
|
|
|
|
|
|
|
|
// if (conversationKey && shouldLoad){
|
|
|
|
|
// this.setState({
|
|
|
|
|
// messages: await window.getMessagesByKey(conversationKey, true)
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// this.setState({
|
|
|
|
|
// messages: this.props.conversations.conversationLookup[conversationKey]?.messsages,
|
|
|
|
|
// });
|
|
|
|
|
public async componentWillReceiveProps() {
|
|
|
|
|
const { conversationKey } = this.state;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -98,17 +80,18 @@ export class SessionConversation extends React.Component<any, State> {
|
|
|
|
|
|
|
|
|
|
// const headerProps = this.props.getHeaderProps;
|
|
|
|
|
const { messages, conversationKey, doneInitialScroll } = this.state;
|
|
|
|
|
const loading = !doneInitialScroll
|
|
|
|
|
const loading = !doneInitialScroll || messages.length === 0;
|
|
|
|
|
|
|
|
|
|
console.log(`[vince] Loading: `, loading);
|
|
|
|
|
console.log(`[vince] My conversation key is: `, conversationKey);
|
|
|
|
|
console.log(`[vince][messages]`, messages);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TMEPORARY SOLUTION TO GETTING CONVERSATION UNTIL
|
|
|
|
|
// SessionConversationStack is created
|
|
|
|
|
|
|
|
|
|
// Get conversation by Key (NOT cid)
|
|
|
|
|
const conversation = this.props.conversations.conversationLookup[conversationKey]
|
|
|
|
|
const conversationType = conversation.type;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="conversation-item">
|
|
|
|
@ -125,12 +108,12 @@ export class SessionConversation extends React.Component<any, State> {
|
|
|
|
|
<div className="messages-wrapper">
|
|
|
|
|
{ loading && (
|
|
|
|
|
<div className="messages-container__loading">
|
|
|
|
|
<SessionSpinner/>
|
|
|
|
|
{/* <SessionSpinner/> */}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
<div className="messages-container">
|
|
|
|
|
{this.renderMessages(conversationKey, conversationType)}
|
|
|
|
|
{this.renderMessages(conversationKey)}
|
|
|
|
|
<div ref={this.messagesEndRef} />
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
@ -146,50 +129,31 @@ export class SessionConversation extends React.Component<any, State> {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public renderMessages(conversationKey: string, conversationType: 'group' | 'direct') {
|
|
|
|
|
public renderMessages() {
|
|
|
|
|
const { messages } = this.state;
|
|
|
|
|
|
|
|
|
|
console.log(`[vince][messages]`, messages);
|
|
|
|
|
|
|
|
|
|
// FIND FOR EACH MESSAGE
|
|
|
|
|
const isExpired = false;
|
|
|
|
|
const isDeletable = false;
|
|
|
|
|
const messageType = 'direct';
|
|
|
|
|
const selected = false;
|
|
|
|
|
const preview:any = [];
|
|
|
|
|
const multiSelectMode = false;
|
|
|
|
|
const onSelectMessage = () => null;
|
|
|
|
|
const onSelectMessageUnchecked = () => null;
|
|
|
|
|
const onShowDetail = () => null;
|
|
|
|
|
const onShowUserDetails = () => null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// FIXME PAY ATTENTION; ONLY RENDER MESSAGES THAT ARE VISIBLE
|
|
|
|
|
return (
|
|
|
|
|
<>{
|
|
|
|
|
messages.map((message: any) => {
|
|
|
|
|
|
|
|
|
|
return message.body && (
|
|
|
|
|
<Message
|
|
|
|
|
text = {message.body || ''}
|
|
|
|
|
direction = {'incoming'}
|
|
|
|
|
timestamp = {1581565995228}
|
|
|
|
|
i18n = {window.i18n}
|
|
|
|
|
authorPhoneNumber = {message.source}
|
|
|
|
|
conversationType = {conversationType}
|
|
|
|
|
previews = {preview}
|
|
|
|
|
isExpired = {isExpired}
|
|
|
|
|
isDeletable = {isDeletable}
|
|
|
|
|
convoId = {conversationKey}
|
|
|
|
|
selected = {selected}
|
|
|
|
|
multiSelectMode = {multiSelectMode}
|
|
|
|
|
onSelectMessage = {onSelectMessage}
|
|
|
|
|
onSelectMessageUnchecked = {onSelectMessageUnchecked}
|
|
|
|
|
onShowDetail = {onShowDetail}
|
|
|
|
|
onShowUserDetails = {onShowUserDetails}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
)
|
|
|
|
|
const messageProps = message.propsForMessage;
|
|
|
|
|
const timerProps = message.propsForTimerNotification;
|
|
|
|
|
const attachmentProps = message.propsForAttachment;
|
|
|
|
|
const quoteProps = message.propsForQuote;
|
|
|
|
|
|
|
|
|
|
console.log(`[vince][props] messageProps`, messageProps);
|
|
|
|
|
console.log(`[vince][props] timerProps`, timerProps);
|
|
|
|
|
console.log(`[vince][props] attachmentProps`, attachmentProps);
|
|
|
|
|
console.log(`[vince][props] quoteProps`, quoteProps);
|
|
|
|
|
|
|
|
|
|
let item;
|
|
|
|
|
item = messageProps ? this.renderMessage(messageProps) : item;
|
|
|
|
|
item = timerProps ? this.renderTimerNotification(timerProps) : item;
|
|
|
|
|
item = attachmentProps ? this.renderMessage(timerProps) : item;
|
|
|
|
|
item = quoteProps ? this.renderMessage(timerProps) : item;
|
|
|
|
|
|
|
|
|
|
return item;
|
|
|
|
|
})
|
|
|
|
|
}</>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
@ -251,4 +215,54 @@ export class SessionConversation extends React.Component<any, State> {
|
|
|
|
|
{ behavior: firstLoad ? 'auto' : 'smooth' }
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async getMessages(conversationKey: string, limit = window.CONSTANTS.DEFAULT_MESSAGE_FETCH_COUNT){
|
|
|
|
|
const messageSet = await window.Signal.Data.getMessagesByConversation(
|
|
|
|
|
conversationKey,
|
|
|
|
|
{ limit, MessageCollection: window.Whisper.MessageCollection },
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
console.log(`[vince][messages] MessageSet!!!`, messageSet);32
|
|
|
|
|
|
|
|
|
|
const messages = messageSet.models;
|
|
|
|
|
this.setState({ messages });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public renderMessage(messageProps: any) {
|
|
|
|
|
return (
|
|
|
|
|
<Message
|
|
|
|
|
text = {messageProps.text || ''}
|
|
|
|
|
direction = {messageProps.direction}
|
|
|
|
|
timestamp = {messageProps.timestamp}
|
|
|
|
|
i18n = {window.i18n}
|
|
|
|
|
authorPhoneNumber = {messageProps.source}
|
|
|
|
|
conversationType = {messageProps.conversationType}
|
|
|
|
|
previews = {messageProps.previews}
|
|
|
|
|
isExpired = {messageProps.isExpired}
|
|
|
|
|
isDeletable = {messageProps.isDeletable}
|
|
|
|
|
convoId = {messageProps.convoId}
|
|
|
|
|
selected = {messageProps.selected}
|
|
|
|
|
multiSelectMode = {messageProps.multiSelectMode}
|
|
|
|
|
onSelectMessage = {messageProps.onSelectMessage}
|
|
|
|
|
onSelectMessageUnchecked = {messageProps.onSelectMessageUnchecked}
|
|
|
|
|
onShowDetail = {messageProps.onShowDetail}
|
|
|
|
|
onShowUserDetails = {messageProps.onShowUserDetails}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public renderTimerNotification(timerProps: any) {
|
|
|
|
|
return (
|
|
|
|
|
<TimerNotification
|
|
|
|
|
type={timerProps.type}
|
|
|
|
|
phoneNumber={timerProps.phoneNumber}
|
|
|
|
|
profileName={timerProps.profileName}
|
|
|
|
|
name={timerProps.name}
|
|
|
|
|
disabled={timerProps.disabled}
|
|
|
|
|
timespan={timerProps.timespan}
|
|
|
|
|
i18n={window.i18n}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|