refactor friend request message props

pull/33/head
Mikunj 7 years ago
parent a80d6bb868
commit d5fafd4d78

@ -243,6 +243,17 @@
return false; return false;
}, },
async getPendingFriendRequests(direction) {
// Theoretically all ouur messages could be friend requests, thus we have to unfortunately go through each one :(
// We are most likely to find the friend request in the more recent conversations first
const messages = await window.Signal.Data.getMessagesByConversation(this.id, {
MessageCollection: Whisper.MessageCollection,
limit: Number.MAX_VALUE,
}).reverse();
// Get the messages that are matching the direction and the friendStatus
return messages.filter(m => (m.direction === direction && m.friendStatus === 'pending'));
},
getPropsForListItem() { getPropsForListItem() {
const result = { const result = {
...this.format(), ...this.format(),
@ -420,6 +431,10 @@
} }
this.set({ keyExchangeCompleted: completed }); this.set({ keyExchangeCompleted: completed });
await window.Signal.Data.updateConversation(this.id, this.attributes, {
Conversation: Whisper.Conversation,
});
}, },
getFriendRequestStatus() { getFriendRequestStatus() {
return this.get('friendRequestStatus'); return this.get('friendRequestStatus');
@ -667,7 +682,7 @@
async addFriendRequest(body, options = {}) { async addFriendRequest(body, options = {}) {
const mergedOptions = { const mergedOptions = {
status: 'pending', status: 'pending',
type: 'incoming', direction: 'incoming',
preKeyBundle: null, preKeyBundle: null,
...options, ...options,
}; };
@ -708,8 +723,8 @@
unread: 1, unread: 1,
from: this.id, from: this.id,
to: this.ourNumber, to: this.ourNumber,
status: mergedOptions.status, friendStatus: mergedOptions.status,
requestType: mergedOptions.type, direction: mergedOptions.direction,
body, body,
preKeyBundle: mergedOptions.preKeyBundle, preKeyBundle: mergedOptions.preKeyBundle,
}; };
@ -936,6 +951,8 @@
now now
); );
// TODO: Maybe create the friend request here?
// TODO: Make sure we're not adding duplicate messages if keys haven't been exchanged
const messageWithSchema = await upgradeMessageSchema({ const messageWithSchema = await upgradeMessageSchema({
type: 'outgoing', type: 'outgoing',
body, body,

@ -297,8 +297,8 @@
getPropsForFriendRequest() { getPropsForFriendRequest() {
const source = this.get('from'); const source = this.get('from');
const target = this.get('to'); const target = this.get('to');
const status = this.get('status') || 'pending'; const status = this.get('friendStatus') || 'pending';
const type = this.get('requestType') || 'incoming'; const type = this.get('direction') || 'incoming';
const conversation = this.getConversation(); const conversation = this.getConversation();
// I.e do we send a network request from the model? or call a function in the conversation to send the new status // I.e do we send a network request from the model? or call a function in the conversation to send the new status

@ -943,7 +943,7 @@ MessageReceiver.prototype.extend({
}, },
// A handler function for when a friend request is accepted or declined // A handler function for when a friend request is accepted or declined
async onFriendRequestUpdate(pubKey, message) { async onFriendRequestUpdate(pubKey, message) {
if (!message || !message.requestType || !message.status) return; if (!message || !message.requestType || !message.friendStatus) return;
// Update the conversation // Update the conversation
const conversation = ConversationController.get(pubKey); const conversation = ConversationController.get(pubKey);
@ -953,7 +953,7 @@ MessageReceiver.prototype.extend({
} }
// Send our own prekeys as a response // Send our own prekeys as a response
if (message.requestType === 'incoming' && message.status === 'accepted') { if (message.requestType === 'incoming' && message.friendStatus === 'accepted') {
libloki.sendEmptyMessageWithPreKeys(pubKey); libloki.sendEmptyMessageWithPreKeys(pubKey);
// Register the preKeys used for communication // Register the preKeys used for communication
@ -965,7 +965,7 @@ MessageReceiver.prototype.extend({
} }
} }
console.log(`Friend request for ${pubKey} was ${message.status}`, message); console.log(`Friend request for ${pubKey} was ${message.friendStatus}`, message);
}, },
async innerHandleContentMessage(envelope, plaintext) { async innerHandleContentMessage(envelope, plaintext) {
const content = textsecure.protobuf.Content.decode(plaintext); const content = textsecure.protobuf.Content.decode(plaintext);

Loading…
Cancel
Save