|
|
@ -4,6 +4,7 @@
|
|
|
|
log,
|
|
|
|
log,
|
|
|
|
i18n,
|
|
|
|
i18n,
|
|
|
|
Backbone,
|
|
|
|
Backbone,
|
|
|
|
|
|
|
|
libloki,
|
|
|
|
ConversationController,
|
|
|
|
ConversationController,
|
|
|
|
MessageController,
|
|
|
|
MessageController,
|
|
|
|
storage,
|
|
|
|
storage,
|
|
|
@ -245,6 +246,12 @@
|
|
|
|
this.messageCollection.forEach(m => m.trigger('change'));
|
|
|
|
this.messageCollection.forEach(m => m.trigger('change'));
|
|
|
|
},
|
|
|
|
},
|
|
|
|
async acceptFriendRequest() {
|
|
|
|
async acceptFriendRequest() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log(`[vince][fr] accepting friend request from conversations.js`);
|
|
|
|
|
|
|
|
console.log('[vince][fr] this.id:', this.id);
|
|
|
|
|
|
|
|
console.log(`[vince][fr] primary pubkey`, this.getPrimaryDevicePubKey());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Friend request messages are always send to primary device conversation
|
|
|
|
const messages = await window.Signal.Data.getMessagesByConversation(
|
|
|
|
const messages = await window.Signal.Data.getMessagesByConversation(
|
|
|
|
this.id,
|
|
|
|
this.id,
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -253,6 +260,24 @@
|
|
|
|
type: 'friend-request',
|
|
|
|
type: 'friend-request',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const priamryMessages = await window.Signal.Data.getMessagesByConversation(
|
|
|
|
|
|
|
|
this.getPrimaryDevicePubKey(),
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
limit: 1,
|
|
|
|
|
|
|
|
MessageCollection: Whisper.MessageCollection,
|
|
|
|
|
|
|
|
type: 'friend-request',
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log(`[vince][fr] messages: `, messages);
|
|
|
|
|
|
|
|
console.log(`[vince][fr] Primary messages: `, priamryMessages);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// LAST MODEL IS POINTING TO THE PRIMARY DEVICE'S LASTMODEL. NOT SECONDARY FOR A2 --> B
|
|
|
|
const lastMessageModel = messages.at(0);
|
|
|
|
const lastMessageModel = messages.at(0);
|
|
|
|
if (lastMessageModel) {
|
|
|
|
if (lastMessageModel) {
|
|
|
|
lastMessageModel.acceptFriendRequest();
|
|
|
|
lastMessageModel.acceptFriendRequest();
|
|
|
@ -970,35 +995,75 @@
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
async respondToAllFriendRequests(options) {
|
|
|
|
async respondToAllFriendRequests(options) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log(`[vince][fr] respondToAllFriendRequests: IM BIENG CALLLLEDED`);
|
|
|
|
|
|
|
|
console.log(`[vince][fr] respondToAllFriendRequests: IM BIENG CALLLLEDED`);
|
|
|
|
|
|
|
|
console.log(`[vince][fr] respondToAllFriendRequests: IM BIENG CALLLLEDED`);
|
|
|
|
|
|
|
|
console.log(`[vince][fr] respondToAllFriendRequests: IM BIENG CALLLLEDED`);
|
|
|
|
|
|
|
|
console.log(`[vince][fr] respondToAllFriendRequests: IM BIENG CALLLLEDED`);
|
|
|
|
|
|
|
|
console.log(`[vince][fr] respondToAllFriendRequests: IM BIENG CALLLLEDED`);
|
|
|
|
|
|
|
|
console.log(`[vince][fr] respondToAllFriendRequests: IM BIENG CALLLLEDED`);
|
|
|
|
|
|
|
|
console.log(`[vince][fr] respondToAllFriendRequests: IM BIENG CALLLLEDED`);
|
|
|
|
|
|
|
|
|
|
|
|
const { response, status, direction = null } = options;
|
|
|
|
const { response, status, direction = null } = options;
|
|
|
|
// Ignore if no response supplied
|
|
|
|
// Ignore if no response supplied
|
|
|
|
if (!response) {
|
|
|
|
if (!response) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const primaryConversation = ConversationController.get(
|
|
|
|
|
|
|
|
|
|
|
|
// const primaryConversation = ConversationController.get(
|
|
|
|
|
|
|
|
// this.getPrimaryDevicePubKey()
|
|
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // Should never happen
|
|
|
|
|
|
|
|
// if (!primaryConversation) {
|
|
|
|
|
|
|
|
// return;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// const pending = await primaryConversation.getFriendRequests(
|
|
|
|
|
|
|
|
// direction,
|
|
|
|
|
|
|
|
// status
|
|
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
// await Promise.all(
|
|
|
|
|
|
|
|
// pending.map(async request => {
|
|
|
|
|
|
|
|
// if (request.hasErrors()) {
|
|
|
|
|
|
|
|
// return;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// request.set({ friendStatus: response });
|
|
|
|
|
|
|
|
// await window.Signal.Data.saveMessage(request.attributes, {
|
|
|
|
|
|
|
|
// Message: Whisper.Message,
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// primaryConversation.trigger('updateMessage', request);
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Accept FRs from all the user's devices
|
|
|
|
|
|
|
|
const allDevices = await libloki.storage.getAllDevicePubKeysForPrimaryPubKey(
|
|
|
|
this.getPrimaryDevicePubKey()
|
|
|
|
this.getPrimaryDevicePubKey()
|
|
|
|
);
|
|
|
|
);
|
|
|
|
// Should never happen
|
|
|
|
|
|
|
|
if (!primaryConversation) {
|
|
|
|
const allConversationsWithUser = allDevices.map(d => ConversationController.get(d));
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const pending = await primaryConversation.getFriendRequests(
|
|
|
|
console.log(`[vince][fr] allDevices: `, allDevices);
|
|
|
|
direction,
|
|
|
|
console.log('[vince][fr] allConversationsWithUser:', allConversationsWithUser);
|
|
|
|
status
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
await Promise.all(
|
|
|
|
|
|
|
|
pending.map(async request => {
|
|
|
|
|
|
|
|
if (request.hasErrors()) {
|
|
|
|
if (!allDevices.length) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
request.set({ friendStatus: response });
|
|
|
|
const pendingRequests = allConversationsWithUser.map(async c => {
|
|
|
|
await window.Signal.Data.saveMessage(request.attributes, {
|
|
|
|
await c.getFriendRequests(direction, status);
|
|
|
|
Message: Whisper.Message,
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
primaryConversation.trigger('updateMessage', request);
|
|
|
|
|
|
|
|
})
|
|
|
|
console.log(`[vince][fr] Pending requests: `, pendingRequests);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
async respondToAllPendingFriendRequests(options) {
|
|
|
|
async respondToAllPendingFriendRequests(options) {
|
|
|
|
return this.respondToAllFriendRequests({
|
|
|
|
return this.respondToAllFriendRequests({
|
|
|
|