Skip to content

Commit

Permalink
Added last-message's author to group conversation list in left pane
Browse files Browse the repository at this point in the history
  • Loading branch information
alvaro-signal committed Aug 25, 2022
1 parent eadef45 commit ca6300a
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 5 deletions.
4 changes: 4 additions & 0 deletions stylesheets/components/MessageBody.scss
Expand Up @@ -54,4 +54,8 @@
background-color: $color-black-alpha-40;
}
}

&__author {
@include font-body-2-bold;
}
}
16 changes: 16 additions & 0 deletions ts/components/conversation/MessageBody.tsx
Expand Up @@ -27,6 +27,7 @@ type OpenConversationActionType = (
export type Props = {
direction?: 'incoming' | 'outgoing';
text: string;
author?: string;
textAttachment?: Pick<AttachmentType, 'pending' | 'digest' | 'key'>;
/** If set, all emoji will be the same size. Otherwise, just one emoji will be large. */
disableJumbomoji?: boolean;
Expand Down Expand Up @@ -74,6 +75,7 @@ export function MessageBody({
onIncreaseTextLength,
openConversation,
text,
author,
textAttachment,
kickOffBodyDownload,
}: Props): JSX.Element {
Expand Down Expand Up @@ -144,6 +146,20 @@ export function MessageBody({

return (
<span>
{author && (
<>
<span className="MessageBody__author">
{renderEmoji({
i18n,
text: author,
sizeClass,
key: 0,
renderNonEmoji: renderNewLines,
})}
</span>
:{' '}
</>
)}
{disableLinks ? (
renderEmoji({
i18n,
Expand Down
1 change: 1 addition & 0 deletions ts/components/conversationList/ConversationListItem.tsx
Expand Up @@ -148,6 +148,7 @@ export const ConversationListItem: FunctionComponent<Props> = React.memo(
messageText = (
<MessageBody
text={truncateMessageText(lastMessage.text)}
author={type === 'group' ? lastMessage.author : undefined}
disableJumbomoji
disableLinks
i18n={i18n}
Expand Down
1 change: 1 addition & 0 deletions ts/model-types.d.ts
Expand Up @@ -281,6 +281,7 @@ export type ConversationAttributesType = {
isPinned?: boolean;
lastMessageDeletedForEveryone?: boolean;
lastMessageStatus?: LastMessageStatus | null;
lastMessageAuthor?: string | null;
markedUnread?: boolean;
messageCount?: number;
messageCountBeforeMessageRequests?: number | null;
Expand Down
5 changes: 5 additions & 0 deletions ts/models/conversations.ts
Expand Up @@ -1703,6 +1703,7 @@ export class ConversationModel extends window.Backbone
| {
status?: LastMessageStatus;
text: string;
author?: string;
deletedForEveryone: false;
}
| { deletedForEveryone: true };
Expand All @@ -1715,6 +1716,7 @@ export class ConversationModel extends window.Backbone
lastMessage = {
status: dropNull(this.get('lastMessageStatus')),
text: lastMessageText,
author: dropNull(this.get('lastMessageAuthor')),
deletedForEveryone: false,
};
}
Expand Down Expand Up @@ -3992,6 +3994,7 @@ export class ConversationModel extends window.Backbone
draft: null,
draftTimestamp: null,
lastMessage: model.getNotificationText(),
lastMessageAuthor: model.getAuthorText(),
lastMessageStatus: 'sending' as const,
};

Expand Down Expand Up @@ -4121,6 +4124,7 @@ export class ConversationModel extends window.Backbone
this.set({
lastMessage:
(previewMessage ? previewMessage.getNotificationText() : '') || '',
lastMessageAuthor: previewMessage?.getAuthorText(),
lastMessageStatus:
(previewMessage
? getMessagePropStatus(previewMessage.attributes, ourConversationId)
Expand Down Expand Up @@ -4875,6 +4879,7 @@ export class ConversationModel extends window.Backbone
async destroyMessages(): Promise<void> {
this.set({
lastMessage: null,
lastMessageAuthor: null,
timestamp: null,
active_at: null,
pendingUniversalTimer: undefined,
Expand Down
18 changes: 15 additions & 3 deletions ts/models/messages.ts
Expand Up @@ -833,6 +833,17 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
return body;
}

getAuthorText(): string | undefined {
// if it's outgoing, it must be self-authored
const selfAuthor = isOutgoing(this.attributes)
? window.i18n('you')
: undefined;

// if it's not selfAuthor and there's no incoming contact,
// it might be a group notification, so we return undefined
return selfAuthor ?? this.getIncomingContact()?.getTitle();
}

getNotificationText(): string {
const { text, emoji } = this.getNotificationData();
const { attributes } = this;
Expand Down Expand Up @@ -1258,12 +1269,12 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
if (!isIncoming(this.attributes)) {
return null;
}
const source = this.get('source');
if (!source) {
const sourceUuid = this.get('sourceUuid');
if (!sourceUuid) {
return null;
}

return window.ConversationController.getOrCreate(source, 'private');
return window.ConversationController.getOrCreate(sourceUuid, 'private');
}

async retrySend(): Promise<void> {
Expand Down Expand Up @@ -2723,6 +2734,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
) {
conversation.set({
lastMessage: message.getNotificationText(),
lastMessageAuthor: message.getAuthorText(),
timestamp: message.get('sent_at'),
});
}
Expand Down
1 change: 1 addition & 0 deletions ts/state/ducks/conversations.ts
Expand Up @@ -150,6 +150,7 @@ export type ConversationType = {
| {
status?: LastMessageStatus;
text: string;
author?: string;
deletedForEveryone: false;
}
| { deletedForEveryone: true };
Expand Down
4 changes: 2 additions & 2 deletions ts/test-mock/benchmarks/group_send_bench.ts
Expand Up @@ -124,8 +124,8 @@ const LAST_MESSAGE = 'start sending messages now';

const item = leftPane.locator(
'_react=BaseConversationListItem' +
`[title = ${JSON.stringify(group.title)}]` +
`>> ${JSON.stringify(LAST_MESSAGE)}`
`[title = ${JSON.stringify(group.title)}] ` +
`>> text=${LAST_MESSAGE}`
);
await item.click();
}
Expand Down

0 comments on commit ca6300a

Please sign in to comment.