Add explicit isSecondary flag to conversation list items so they can remain hidden in the menu after they become friends etc

pull/580/head
Beaudan Brown 6 years ago
parent d97eced37b
commit 08ad913105

@ -1008,6 +1008,12 @@
"message": "Send a message", "message": "Send a message",
"description": "Placeholder text in the message entry field" "description": "Placeholder text in the message entry field"
}, },
"sendMessageDisabledSecondary": {
"message":
"This pubkey belongs to a secondary device. You should never see this message",
"description":
"Placeholder text in the message entry field when it is disabled because a secondary device conversation is visible"
},
"sendMessageDisabled": { "sendMessageDisabled": {
"message": "Waiting for friend request approval", "message": "Waiting for friend request approval",
"description": "description":

@ -469,6 +469,7 @@
mentionedUs: this.get('mentionedUs') || false, mentionedUs: this.get('mentionedUs') || false,
showFriendRequestIndicator: this.isPendingFriendRequest(), showFriendRequestIndicator: this.isPendingFriendRequest(),
isBlocked: this.isBlocked(), isBlocked: this.isBlocked(),
isSecondary: !!this.get('secondaryStatus'),
phoneNumber: format(this.id, { phoneNumber: format(this.id, {
ourRegionCode: regionCode, ourRegionCode: regionCode,
@ -691,6 +692,17 @@
throw new Error('Invalid friend request state'); throw new Error('Invalid friend request state');
} }
}, },
isSecondaryDevice() {
return !!this.get('secondaryStatus');
},
async setSecondaryStatus(newStatus) {
if (this.get('secondaryStatus') !== newStatus) {
this.set({ secondaryStatus: newStatus });
await window.Signal.Data.updateConversation(this.id, this.attributes, {
Conversation: Whisper.Conversation,
});
}
},
async setFriendRequestStatus(newStatus) { async setFriendRequestStatus(newStatus) {
// Ensure that the new status is a valid FriendStatusEnum value // Ensure that the new status is a valid FriendStatusEnum value
if (!(newStatus in Object.values(FriendRequestStatusEnum))) { if (!(newStatus in Object.values(FriendRequestStatusEnum))) {

@ -436,6 +436,9 @@
case 'disabled': case 'disabled':
placeholder = i18n('sendMessageDisabled'); placeholder = i18n('sendMessageDisabled');
break; break;
case 'secondary':
placeholder = i18n('sendMessageDisabledSecondary');
break;
default: default:
placeholder = i18n('sendMessage'); placeholder = i18n('sendMessage');
break; break;

@ -155,7 +155,9 @@
}, },
user: { user: {
regionCode: window.storage.get('regionCode'), regionCode: window.storage.get('regionCode'),
ourNumber: textsecure.storage.user.getNumber(), ourNumber:
window.storage.get('primaryDevicePubKey') ||
textsecure.storage.user.getNumber(),
isSecondaryDevice: !!window.storage.get('isSecondaryDevice'), isSecondaryDevice: !!window.storage.get('isSecondaryDevice'),
i18n: window.i18n, i18n: window.i18n,
}, },

@ -1,4 +1,5 @@
/* global window, libsignal, textsecure, Signal, lokiFileServerAPI */ /* global window, libsignal, textsecure,
Signal, lokiFileServerAPI, ConversationController */
// eslint-disable-next-line func-names // eslint-disable-next-line func-names
(function() { (function() {
@ -149,8 +150,14 @@
); );
} }
function savePairingAuthorisation(authorisation) { async function savePairingAuthorisation(authorisation) {
return window.Signal.Data.createOrUpdatePairingAuthorisation(authorisation); // Ensure that we have a conversation for all the devices
const conversation = await ConversationController.getOrCreateAndWait(
authorisation.secondaryDevicePubKey,
'private'
);
await conversation.setSecondaryStatus(true);
await window.Signal.Data.createOrUpdatePairingAuthorisation(authorisation);
} }
function removePairingAuthorisationForSecondaryPubKey(pubKey) { function removePairingAuthorisationForSecondaryPubKey(pubKey) {

@ -1107,6 +1107,7 @@ MessageReceiver.prototype.extend({
// along with each friend request. // along with each friend request.
window.storage.remove('secondaryDeviceStatus'); window.storage.remove('secondaryDeviceStatus');
window.storage.put('isSecondaryDevice', true); window.storage.put('isSecondaryDevice', true);
window.storage.put('primaryDevicePubKey', primaryDevicePubKey);
Whisper.events.trigger('secondaryDeviceRegistration'); Whisper.events.trigger('secondaryDeviceRegistration');
// Update profile name // Update profile name
if (dataMessage && dataMessage.profile) { if (dataMessage && dataMessage.profile) {

@ -41,6 +41,7 @@ export type PropsData = {
isOnline?: boolean; isOnline?: boolean;
hasNickname?: boolean; hasNickname?: boolean;
isFriendItem?: boolean; isFriendItem?: boolean;
isSecondary?: boolean;
}; };
type PropsHousekeeping = { type PropsHousekeeping = {

@ -55,7 +55,15 @@ export class LeftPane extends React.Component<Props, any> {
const { conversations, friends } = this.props; const { conversations, friends } = this.props;
const { currentTab } = this.state; const { currentTab } = this.state;
return currentTab === 'conversations' ? conversations : friends; let conversationList =
currentTab === 'conversations' ? conversations : friends;
if (conversationList !== undefined) {
conversationList = conversationList.filter(
conversation => !conversation.isSecondary
);
}
return conversationList;
} }
public renderTabs(): JSX.Element { public renderTabs(): JSX.Element {

Loading…
Cancel
Save