Added blocking/unblocking from friend request.

Fixed incoming messages being deleted.
pull/47/head
Mikunj 7 years ago
parent ae2e2fa2ae
commit a82999818a

@ -1302,7 +1302,9 @@ async function getMessageBySender({ source, sourceDevice, sent_at }) {
async function getAllUnsentMessages() { async function getAllUnsentMessages() {
const rows = await db.all(` const rows = await db.all(`
SELECT json FROM messages WHERE NOT sent SELECT json FROM messages WHERE
type IN ('outgoing', 'friend-request') AND
NOT sent
ORDER BY sent_at DESC; ORDER BY sent_at DESC;
`); `);
return map(rows, row => jsonToObject(row.json)); return map(rows, row => jsonToObject(row.json));

@ -338,6 +338,11 @@
'expirationStartTimestamp' 'expirationStartTimestamp'
); );
// Make sure we only target outgoing messages
if (message.isFriendRequest() && message.get('direction') === 'incoming') {
return;
}
if (message.hasErrors()) { if (message.hasErrors()) {
return; return;
} }

@ -63,10 +63,16 @@
return null; return null;
}, },
unblockAll() {
const all = blockedNumbers.models;
all.forEach(number => {
storage.removeBlockedNumber(number);
blockedNumbers.remove(number);
})
},
isBlocked(number) { isBlocked(number) {
return storage.isBlocked(number); return storage.isBlocked(number);
}, },
}; };
})(); })();

@ -331,15 +331,27 @@
window.Whisper.events.trigger('deleteConversation', conversation); window.Whisper.events.trigger('deleteConversation', conversation);
}; };
const onBlockUser = () => {
conversation.block();
this.trigger('change');
};
const onUnblockUser = () => {
conversation.unblock();
this.trigger('change');
};
return { return {
text: this.createNonBreakingLastSeparator(this.get('body')), text: this.createNonBreakingLastSeparator(this.get('body')),
status: this.getMessagePropStatus(), status: this.getMessagePropStatus(),
direction, direction,
friendStatus, friendStatus,
isBlocked: conversation.isBlocked(),
onAccept, onAccept,
onDecline, onDecline,
onDeleteConversation, onDeleteConversation,
onRetrySend: () => this.retrySend(), onBlockUser,
onUnblockUser,
} }
}, },
findContact(phoneNumber) { findContact(phoneNumber) {

@ -150,6 +150,7 @@
mediaPermissionsDescription: i18n('mediaPermissionsDescription'), mediaPermissionsDescription: i18n('mediaPermissionsDescription'),
spellCheckHeader: i18n('spellCheck'), spellCheckHeader: i18n('spellCheck'),
spellCheckDescription: i18n('spellCheckDescription'), spellCheckDescription: i18n('spellCheckDescription'),
blockedHeader: 'Blocked Users',
}; };
}, },
onClose() { onClose() {

@ -109,6 +109,10 @@
<p>{{ clearDataExplanation }}</p> <p>{{ clearDataExplanation }}</p>
</div> </div>
</div> </div>
<hr>
<div class='blocked-user-setting'>
<h3>{{ blockedHeader }}</h3>
</div>
</div> </div>
</script> </script>
<script type='text/javascript' src='js/components.js'></script> <script type='text/javascript' src='js/components.js'></script>

@ -10,10 +10,13 @@ interface Props {
status: string; status: string;
friendStatus: 'pending' | 'accepted' | 'declined'; friendStatus: 'pending' | 'accepted' | 'declined';
i18n: Localizer; i18n: Localizer;
isBlocked: boolean;
onAccept: () => void; onAccept: () => void;
onDecline: () => void; onDecline: () => void;
onDeleteConversation: () => void; onDeleteConversation: () => void;
onRetrySend: () => void; onRetrySend: () => void;
onBlockUser: () => void;
onUnblockUser: () => void;
} }
export class FriendRequest extends React.Component<Props> { export class FriendRequest extends React.Component<Props> {
@ -50,7 +53,7 @@ export class FriendRequest extends React.Component<Props> {
} }
public renderButtons() { public renderButtons() {
const { friendStatus, direction, status, onAccept, onDecline, onDeleteConversation, onRetrySend } = this.props; const { i18n, friendStatus, direction, status, onAccept, onDecline, onDeleteConversation, onRetrySend, isBlocked, onBlockUser, onUnblockUser } = this.props;
if (direction === 'incoming') { if (direction === 'incoming') {
if (friendStatus === 'pending') { if (friendStatus === 'pending') {
@ -67,6 +70,8 @@ export class FriendRequest extends React.Component<Props> {
</div> </div>
); );
} else if (friendStatus === 'declined') { } else if (friendStatus === 'declined') {
const blockTitle = isBlocked ? i18n('unblockUser') : i18n('blockUser');
const blockHandler = isBlocked ? onUnblockUser : onBlockUser;
return ( return (
<div <div
className={classNames( className={classNames(
@ -76,6 +81,7 @@ export class FriendRequest extends React.Component<Props> {
)} )}
> >
<button onClick={onDeleteConversation}>Delete Conversation</button> <button onClick={onDeleteConversation}>Delete Conversation</button>
<button onClick={blockHandler}>{blockTitle}</button>
</div> </div>
); );
} }

Loading…
Cancel
Save