enable back the logic of displaying avatar for first message in serie

pull/1387/head
Audric Ackermann 5 years ago
parent 0b4400837b
commit c0cf53cdfa
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -412,6 +412,7 @@ textarea {
display: inline-flex; display: inline-flex;
margin-inline-end: 20px; margin-inline-end: 20px;
padding-top: 5px; padding-top: 5px;
margin-bottom: auto;
} }
.module-message__container { .module-message__container {

@ -183,6 +183,7 @@
letter-spacing: 0.03em; letter-spacing: 0.03em;
margin-top: 3px; margin-top: 3px;
margin-bottom: 3px; margin-bottom: 3px;
display: flex;
} }
.composition-container { .composition-container {

@ -96,6 +96,7 @@ export interface Props {
isKickedFromGroup: boolean; isKickedFromGroup: boolean;
// whether or not to show check boxes // whether or not to show check boxes
multiSelectMode: boolean; multiSelectMode: boolean;
firstMessageOfSeries: boolean;
onClickAttachment?: (attachment: AttachmentType) => void; onClickAttachment?: (attachment: AttachmentType) => void;
onClickLinkPreview?: (url: string) => void; onClickLinkPreview?: (url: string) => void;
@ -709,6 +710,7 @@ export class Message extends React.PureComponent<Props, State> {
conversationType, conversationType,
direction, direction,
onShowUserDetails, onShowUserDetails,
firstMessageOfSeries,
} = this.props; } = this.props;
if ( if (
@ -720,6 +722,10 @@ export class Message extends React.PureComponent<Props, State> {
} }
const userName = authorName || authorProfileName || authorPhoneNumber; const userName = authorName || authorProfileName || authorPhoneNumber;
if (!firstMessageOfSeries) {
return <div style={{ marginInlineEnd: '60px' }} />;
}
return ( return (
<div className="module-message__author-avatar"> <div className="module-message__author-avatar">
<Avatar <Avatar
@ -971,6 +977,7 @@ export class Message extends React.PureComponent<Props, State> {
conversationType, conversationType,
isPublic, isPublic,
text, text,
firstMessageOfSeries,
} = this.props; } = this.props;
const { expired, expiring } = this.state; const { expired, expiring } = this.state;

@ -332,20 +332,11 @@ export class SessionConversation extends React.Component<Props, State> {
// in the conversation model. // in the conversation model.
// The only time we need to call getMessages() is to grab more messages on scroll. // The only time we need to call getMessages() is to grab more messages on scroll.
const { initialFetchComplete } = this.state; const { initialFetchComplete } = this.state;
const { conversationKey } = this.props;
if (initialFetchComplete) { if (initialFetchComplete) {
return; return;
} }
const messageSet = await window.Signal.Data.getMessagesByConversation( return this.getMessages(Constants.CONVERSATION.DEFAULT_MESSAGE_FETCH_COUNT);
conversationKey,
{
limit: Constants.CONVERSATION.DEFAULT_MESSAGE_FETCH_COUNT,
MessageCollection: window.Whisper.MessageCollection,
}
);
this.setState({ messages: messageSet.models });
} }
public async getMessages(numMessages?: number) { public async getMessages(numMessages?: number) {
@ -372,16 +363,27 @@ export class SessionConversation extends React.Component<Props, State> {
const messageModels = messageSet.models; const messageModels = messageSet.models;
const messages = []; const messages = [];
let previousSender; // no need to do that `firstMessageOfSeries` on a private chat
if (this.props.conversation.type === 'direct') {
this.setState({ messages: messageSet.models });
return;
}
// messages are got from the more recent to the oldest, so we need to check if
// the next messages in the list is still the same author.
// The message is the first of the series if the next message is not from the same authori
for (let i = 0; i < messageModels.length; i++) { for (let i = 0; i < messageModels.length; i++) {
// Handle firstMessageOfSeries for conditional avatar rendering // Handle firstMessageOfSeries for conditional avatar rendering
let firstMessageOfSeries = true; let firstMessageOfSeries = true;
if (i > 0 && previousSender === messageModels[i].authorPhoneNumber) { const currentSender = messageModels[i].propsForMessage?.authorPhoneNumber;
const nextSender =
i < messageModels.length - 1
? messageModels[i + 1].propsForMessage?.authorPhoneNumber
: undefined;
if (i > 0 && currentSender === nextSender) {
firstMessageOfSeries = false; firstMessageOfSeries = false;
} }
messages.push({ ...messageModels[i], firstMessageOfSeries }); messages.push({ ...messageModels[i], firstMessageOfSeries });
previousSender = messageModels[i].authorPhoneNumber;
} }
this.setState({ messages }); this.setState({ messages });

Loading…
Cancel
Save