mirror of
https://github.com/oxen-io/session-desktop.git
synced 2023-12-14 02:12:57 +01:00
refactor friend request message props
This commit is contained in:
parent
a80d6bb868
commit
d5fafd4d78
3 changed files with 25 additions and 8 deletions
|
@ -243,6 +243,17 @@
|
|||
|
||||
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() {
|
||||
const result = {
|
||||
...this.format(),
|
||||
|
@ -420,6 +431,10 @@
|
|||
}
|
||||
|
||||
this.set({ keyExchangeCompleted: completed });
|
||||
|
||||
await window.Signal.Data.updateConversation(this.id, this.attributes, {
|
||||
Conversation: Whisper.Conversation,
|
||||
});
|
||||
},
|
||||
getFriendRequestStatus() {
|
||||
return this.get('friendRequestStatus');
|
||||
|
@ -667,7 +682,7 @@
|
|||
async addFriendRequest(body, options = {}) {
|
||||
const mergedOptions = {
|
||||
status: 'pending',
|
||||
type: 'incoming',
|
||||
direction: 'incoming',
|
||||
preKeyBundle: null,
|
||||
...options,
|
||||
};
|
||||
|
@ -708,8 +723,8 @@
|
|||
unread: 1,
|
||||
from: this.id,
|
||||
to: this.ourNumber,
|
||||
status: mergedOptions.status,
|
||||
requestType: mergedOptions.type,
|
||||
friendStatus: mergedOptions.status,
|
||||
direction: mergedOptions.direction,
|
||||
body,
|
||||
preKeyBundle: mergedOptions.preKeyBundle,
|
||||
};
|
||||
|
@ -936,6 +951,8 @@
|
|||
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({
|
||||
type: 'outgoing',
|
||||
body,
|
||||
|
|
|
@ -297,8 +297,8 @@
|
|||
getPropsForFriendRequest() {
|
||||
const source = this.get('from');
|
||||
const target = this.get('to');
|
||||
const status = this.get('status') || 'pending';
|
||||
const type = this.get('requestType') || 'incoming';
|
||||
const status = this.get('friendStatus') || 'pending';
|
||||
const type = this.get('direction') || 'incoming';
|
||||
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
|
||||
|
|
|
@ -943,7 +943,7 @@ MessageReceiver.prototype.extend({
|
|||
},
|
||||
// A handler function for when a friend request is accepted or declined
|
||||
async onFriendRequestUpdate(pubKey, message) {
|
||||
if (!message || !message.requestType || !message.status) return;
|
||||
if (!message || !message.requestType || !message.friendStatus) return;
|
||||
|
||||
// Update the conversation
|
||||
const conversation = ConversationController.get(pubKey);
|
||||
|
@ -953,7 +953,7 @@ MessageReceiver.prototype.extend({
|
|||
}
|
||||
|
||||
// Send our own prekeys as a response
|
||||
if (message.requestType === 'incoming' && message.status === 'accepted') {
|
||||
if (message.requestType === 'incoming' && message.friendStatus === 'accepted') {
|
||||
libloki.sendEmptyMessageWithPreKeys(pubKey);
|
||||
|
||||
// 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) {
|
||||
const content = textsecure.protobuf.Content.decode(plaintext);
|
||||
|
|
Loading…
Reference in a new issue