Merge remote-tracking branch 'vinc/fr-fixes' into integration-test-logs-rebased

pull/1137/head
Audric Ackermann 5 years ago
commit f9f3117101
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -4,6 +4,7 @@
log, log,
i18n, i18n,
Backbone, Backbone,
libloki,
ConversationController, ConversationController,
MessageController, MessageController,
storage, storage,
@ -245,6 +246,8 @@
this.messageCollection.forEach(m => m.trigger('change')); this.messageCollection.forEach(m => m.trigger('change'));
}, },
async acceptFriendRequest() { async acceptFriendRequest() {
// Friend request message conmfirmations (Accept / Decline) are always
// sent to the primary device conversation
const messages = await window.Signal.Data.getMessagesByConversation( const messages = await window.Signal.Data.getMessagesByConversation(
this.id, this.id,
{ {
@ -253,6 +256,7 @@
type: 'friend-request', type: 'friend-request',
} }
); );
const lastMessageModel = messages.at(0); const lastMessageModel = messages.at(0);
if (lastMessageModel) { if (lastMessageModel) {
lastMessageModel.acceptFriendRequest(); lastMessageModel.acceptFriendRequest();
@ -549,6 +553,7 @@
MessageCollection: Whisper.MessageCollection, MessageCollection: Whisper.MessageCollection,
} }
); );
if (typeof status === 'string') { if (typeof status === 'string') {
// eslint-disable-next-line no-param-reassign // eslint-disable-next-line no-param-reassign
status = [status]; status = [status];
@ -584,7 +589,6 @@
const result = { const result = {
id: this.id, id: this.id,
isArchived: this.get('isArchived'), isArchived: this.get('isArchived'),
activeAt: this.get('active_at'), activeAt: this.get('active_at'),
avatarPath: this.getAvatarPath(), avatarPath: this.getAvatarPath(),
@ -976,19 +980,42 @@
if (!response) { if (!response) {
return; return;
} }
const primaryConversation = ConversationController.get(
// Accept FRs from all the user's devices
const allDevices = await libloki.storage.getAllDevicePubKeysForPrimaryPubKey(
this.getPrimaryDevicePubKey() this.getPrimaryDevicePubKey()
); );
// Should never happen
if (!primaryConversation) { if (!allDevices.length) {
return; return;
} }
const pending = await primaryConversation.getFriendRequests(
direction, const allConversationsWithUser = allDevices.map(d =>
status ConversationController.get(d)
); );
// Search through each conversation (device) for friend request messages
const pendingRequestPromises = allConversationsWithUser.map(
async conversation => {
const request = (await conversation.getFriendRequests(
direction,
status
))[0];
return { conversation, request };
}
);
let pendingRequests = await Promise.all(pendingRequestPromises);
// Filter out all undefined requests
pendingRequests = pendingRequests.filter(p => Boolean(p.request));
// We set all friend request messages from all devices
// from a user here to accepted where possible
await Promise.all( await Promise.all(
pending.map(async request => { pendingRequests.map(async friendRequest => {
const { conversation, request } = friendRequest;
if (request.hasErrors()) { if (request.hasErrors()) {
return; return;
} }
@ -997,7 +1024,7 @@
await window.Signal.Data.saveMessage(request.attributes, { await window.Signal.Data.saveMessage(request.attributes, {
Message: Whisper.Message, Message: Whisper.Message,
}); });
primaryConversation.trigger('updateMessage', request); conversation.trigger('updateMessage', request);
}) })
); );
}, },
@ -1658,6 +1685,7 @@
const model = this.addSingleMessage(attributes); const model = this.addSingleMessage(attributes);
const message = MessageController.register(model.id, model); const message = MessageController.register(model.id, model);
await window.Signal.Data.saveMessage(message.attributes, { await window.Signal.Data.saveMessage(message.attributes, {
forceSave: true, forceSave: true,
Message: Whisper.Message, Message: Whisper.Message,
@ -2439,7 +2467,6 @@
}, },
// LOKI PROFILES // LOKI PROFILES
async setNickname(nickname) { async setNickname(nickname) {
const trimmed = nickname && nickname.trim(); const trimmed = nickname && nickname.trim();
if (this.get('nickname') === trimmed) { if (this.get('nickname') === trimmed) {

@ -415,24 +415,57 @@
}, },
async acceptFriendRequest() { async acceptFriendRequest() {
const primaryDevicePubKey = this.attributes.conversationId;
if (this.get('friendStatus') !== 'pending') { if (this.get('friendStatus') !== 'pending') {
return; return;
} }
const conversation = await this.getSourceDeviceConversation();
// If we somehow received an old friend request (e.g. after having restored const allDevices = await libloki.storage.getAllDevicePubKeysForPrimaryPubKey(
// from seed, we won't be able to accept it, we should initiate our own primaryDevicePubKey
// friend request to reset the session: );
if (conversation.get('sessionRestoreSeen')) {
conversation.sendMessage('', null, null, null, null, { // Set profile name to primary conversation
sessionRestoration: true, let profileName;
}); const allConversationsWithUser = allDevices.map(d =>
return; ConversationController.get(d)
);
allConversationsWithUser.forEach(conversation => {
// If we somehow received an old friend request (e.g. after having restored
// from seed, we won't be able to accept it, we should initiate our own
// friend request to reset the session:
if (conversation.get('sessionRestoreSeen')) {
conversation.sendMessage('', null, null, null, null, {
sessionRestoration: true,
});
return;
}
profileName = conversation.getProfileName() || profileName;
conversation.onAcceptFriendRequest();
});
// If you don't have a profile name for this device, and profileName is set,
// add profileName to conversation.
const primaryConversation = allConversationsWithUser.find(
c => c.id === primaryDevicePubKey
);
if (!primaryConversation.getProfileName() && profileName) {
await primaryConversation.setNickname(profileName);
} }
this.set({ friendStatus: 'accepted' });
await window.Signal.Data.saveMessage(this.attributes, { await window.Signal.Data.saveMessage(this.attributes, {
Message: Whisper.Message, Message: Whisper.Message,
}); });
conversation.onAcceptFriendRequest();
this.set({ friendStatus: 'accepted' });
// Update redux store
window.Signal.Data.updateConversation(
primaryConversation.id,
primaryConversation.attributes,
{ Conversation: Whisper.Conversation }
);
}, },
async declineFriendRequest() { async declineFriendRequest() {
if (this.get('friendStatus') !== 'pending') { if (this.get('friendStatus') !== 'pending') {
@ -2220,6 +2253,7 @@
let attributes = { let attributes = {
...conversation.attributes, ...conversation.attributes,
}; };
if (dataMessage.group) { if (dataMessage.group) {
let groupUpdate = null; let groupUpdate = null;
attributes = { attributes = {
@ -2509,6 +2543,7 @@
- We are friends with the user, - We are friends with the user,
and that user just sent us a friend request. and that user just sent us a friend request.
*/ */
const isFriend = sendingDeviceConversation.isFriend(); const isFriend = sendingDeviceConversation.isFriend();
const hasSentFriendRequest = sendingDeviceConversation.hasSentFriendRequest(); const hasSentFriendRequest = sendingDeviceConversation.hasSentFriendRequest();
autoAccept = isFriend || hasSentFriendRequest; autoAccept = isFriend || hasSentFriendRequest;
@ -2534,7 +2569,6 @@
} }
} }
// We need to map the original message source to the primary device
if (source !== ourNumber) { if (source !== ourNumber) {
message.set({ source: primarySource }); message.set({ source: primarySource });
} }

@ -97,7 +97,7 @@ export class LeftPaneMessageSection extends React.Component<Props, any> {
if (conversationList !== undefined) { if (conversationList !== undefined) {
conversationList = conversationList.filter( conversationList = conversationList.filter(
conversation => conversation =>
!conversation.isSecondary && !conversation.isPendingFriendRequest !conversation.isPendingFriendRequest && !conversation.isSecondary
); );
} }

@ -55,6 +55,7 @@ export type ConversationType = {
isFriend?: boolean; isFriend?: boolean;
isSecondary?: boolean; isSecondary?: boolean;
primaryDevice: string; primaryDevice: string;
isPendingFriendRequest?: boolean;
hasReceivedFriendRequest?: boolean; hasReceivedFriendRequest?: boolean;
hasSentFriendRequest?: boolean; hasSentFriendRequest?: boolean;
}; };

@ -129,7 +129,15 @@ export const _getLeftPaneLists = (
} }
if (conversation.hasReceivedFriendRequest) { if (conversation.hasReceivedFriendRequest) {
allReceivedFriendsRequest.push(conversation); // Friend requests should always appear as coming from primary
const primaryConversation =
conversations.find(c => c.id === conversation.primaryDevice) ||
conversation;
primaryConversation.hasReceivedFriendRequest =
conversation.hasReceivedFriendRequest;
primaryConversation.isPendingFriendRequest =
conversation.isPendingFriendRequest;
allReceivedFriendsRequest.push(primaryConversation);
} else if ( } else if (
unreadCount < 9 && unreadCount < 9 &&
conversation.isFriend && conversation.isFriend &&
@ -160,22 +168,23 @@ export const _getLeftPaneLists = (
group: Array<ConversationType | ConversationListItemPropsType> group: Array<ConversationType | ConversationListItemPropsType>
): T => { ): T => {
const secondariesToRemove: Array<string> = []; const secondariesToRemove: Array<string> = [];
group.forEach(device => { group.forEach(device => {
if (!device.isSecondary) { if (!device.isSecondary) {
return; return;
} }
const devicePrimary = group.find(c => c.id === device.primaryDevice); const devicePrimary = group.find(c => c.id === device.primaryDevice);
// Remove secondary where primary already exists in group // Remove secondary where primary already exists in group
if (group.some(c => c === devicePrimary)) { if (group.some(c => c === devicePrimary)) {
secondariesToRemove.push(device.id); secondariesToRemove.push(device.id);
} }
}); });
// tslint:disable-next-line: no-unnecessary-local-variable const filteredGroup = [
const filteredGroup = group.filter( ...new Set(group.filter(c => !secondariesToRemove.find(s => s === c.id))),
c => !secondariesToRemove.find(s => s === c.id) ];
);
return filteredGroup as T; return filteredGroup as T;
}; };

Loading…
Cancel
Save