|
|
@ -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) {
|
|
|
|