Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlight conversations with unread mentions of the user #549

Merged
merged 1 commit into from Oct 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions js/models/conversations.js
Expand Up @@ -466,6 +466,7 @@
timestamp: this.get('timestamp'),
title: this.getTitle(),
unreadCount: this.get('unreadCount') || 0,
mentionedUs: this.get('mentionedUs') || false,
showFriendRequestIndicator: this.isPendingFriendRequest(),
isBlocked: this.isBlocked(),

Expand Down Expand Up @@ -2007,6 +2008,21 @@

const unreadCount = unreadMessages.length - read.length;
this.set({ unreadCount });

const mentionRead = (() => {
const stillUnread = unreadMessages.filter(
m => m.get('received_at') > newestUnreadDate
);
const ourNumber = textsecure.storage.user.getNumber();
return !stillUnread.some(
m => m.propsForMessage.text.indexOf(`@${ourNumber}`) !== -1
);
})();

if (mentionRead) {
this.set({ mentionedUs: false });
}

await window.Signal.Data.updateConversation(this.id, this.attributes, {
Conversation: Whisper.Conversation,
});
Expand Down
6 changes: 6 additions & 0 deletions js/models/messages.js
Expand Up @@ -1969,6 +1969,12 @@
c.onReadMessage(message);
}
} else {
const ourNumber = textsecure.storage.user.getNumber();

if (message.attributes.body.indexOf(`@${ourNumber}`) !== -1) {
conversation.set({ mentionedUs: true });
}

conversation.set({
unreadCount: conversation.get('unreadCount') + 1,
isArchived: false,
Expand Down
3 changes: 2 additions & 1 deletion js/views/conversation_view.js
Expand Up @@ -314,10 +314,11 @@
this.selectMember = this.selectMember.bind(this);

const updateMemberList = async () => {
const maxToFetch = 1000;
const allMessages = await window.Signal.Data.getMessagesByConversation(
this.model.id,
{
limit: Number.MAX_SAFE_INTEGER,
limit: maxToFetch,
MessageCollection: Whisper.MessageCollection,
}
);
Expand Down
29 changes: 29 additions & 0 deletions stylesheets/_mentions.scss
Expand Up @@ -67,3 +67,32 @@
}
}
}

.module-conversation-list-item--mentioned-us {
border-left: 4px solid #ffb000 !important;
}

.at-symbol {
background-color: #ffb000;

color: $color-black;
text-align: center;

padding-top: 1px;
padding-left: 3px;
padding-right: 3px;

position: absolute;
right: -6px;
top: 12px;

font-weight: 300;
font-size: 11px;
letter-spacing: 0.25px;

height: 16px;
min-width: 16px;
border-radius: 8px;

box-shadow: 0px 0px 0px 1px $color-dark-85;
}
2 changes: 1 addition & 1 deletion stylesheets/_modules.scss
Expand Up @@ -1895,7 +1895,7 @@

position: absolute;
right: -6px;
top: 6px;
top: -6px;

font-weight: 300;
font-size: 11px;
Expand Down
16 changes: 13 additions & 3 deletions ts/components/ConversationListItem.tsx
Expand Up @@ -26,6 +26,7 @@ export type PropsData = {

lastUpdated: number;
unreadCount: number;
mentionedUs: boolean;
isSelected: boolean;

isTyping: boolean;
Expand Down Expand Up @@ -93,12 +94,17 @@ export class ConversationListItem extends React.PureComponent<Props> {
}

public renderUnread() {
const { unreadCount } = this.props;
const { unreadCount, mentionedUs } = this.props;

if (unreadCount > 0) {
const atSymbol = mentionedUs ? <p className="at-symbol">@</p> : null;

return (
<div className="module-conversation-list-item__unread-count">
{unreadCount}
<div>
<p className="module-conversation-list-item__unread-count">
{unreadCount}
</p>
{atSymbol}
</div>
);
}
Expand Down Expand Up @@ -285,6 +291,7 @@ export class ConversationListItem extends React.PureComponent<Props> {
showFriendRequestIndicator,
isBlocked,
style,
mentionedUs,
} = this.props;

const triggerId = `${phoneNumber}-ctxmenu-${Date.now()}`;
Expand All @@ -305,6 +312,9 @@ export class ConversationListItem extends React.PureComponent<Props> {
unreadCount > 0
? 'module-conversation-list-item--has-unread'
: null,
unreadCount > 0 && mentionedUs
? 'module-conversation-list-item--mentioned-us'
: null,
isSelected ? 'module-conversation-list-item--is-selected' : null,
showFriendRequestIndicator
? 'module-conversation-list-item--has-friend-request'
Expand Down
1 change: 1 addition & 0 deletions ts/state/ducks/conversations.ts
Expand Up @@ -49,6 +49,7 @@ export type ConversationType = {
isClosable?: boolean;
lastUpdated: number;
unreadCount: number;
mentionedUs: boolean;
isSelected: boolean;
isTyping: boolean;
isFriend?: boolean;
Expand Down
5 changes: 5 additions & 0 deletions ts/test/state/selectors/conversations_test.ts
Expand Up @@ -24,6 +24,7 @@ describe('state/selectors/conversations', () => {
isMe: false,
lastUpdated: Date.now(),
unreadCount: 1,
mentionedUs: false,
isSelected: false,
isTyping: false,
},
Expand All @@ -39,6 +40,7 @@ describe('state/selectors/conversations', () => {
isMe: false,
lastUpdated: Date.now(),
unreadCount: 1,
mentionedUs: false,
isSelected: false,
isTyping: false,
},
Expand All @@ -54,6 +56,7 @@ describe('state/selectors/conversations', () => {
isMe: false,
lastUpdated: Date.now(),
unreadCount: 1,
mentionedUs: false,
isSelected: false,
isTyping: false,
},
Expand All @@ -69,6 +72,7 @@ describe('state/selectors/conversations', () => {
isMe: false,
lastUpdated: Date.now(),
unreadCount: 1,
mentionedUs: false,
isSelected: false,
isTyping: false,
},
Expand All @@ -84,6 +88,7 @@ describe('state/selectors/conversations', () => {
isMe: false,
lastUpdated: Date.now(),
unreadCount: 1,
mentionedUs: false,
isSelected: false,
isTyping: false,
},
Expand Down