UI fixes.

pull/50/head
Mikunj 7 years ago
parent 4ebdfab633
commit 110387508f

@ -1259,7 +1259,7 @@
async function initIncomingMessage(data, options = {}) { async function initIncomingMessage(data, options = {}) {
const { isError } = options; const { isError } = options;
const message = new Whisper.Message({ let messageData = {
source: data.source, source: data.source,
sourceDevice: data.sourceDevice, sourceDevice: data.sourceDevice,
sent_at: data.timestamp, sent_at: data.timestamp,
@ -1268,7 +1268,19 @@
unidentifiedDeliveryReceived: data.unidentifiedDeliveryReceived, unidentifiedDeliveryReceived: data.unidentifiedDeliveryReceived,
type: 'incoming', type: 'incoming',
unread: 1, unread: 1,
}); };
if (data.type === 'friend-request') {
messageData = {
...messageData,
type: 'friend-request',
friendStatus: 'pending',
preKeyBundle: data.preKeyBundle || null,
direction: 'incoming',
}
}
const message = new Whisper.Message(messageData);
// If we don't return early here, we can get into infinite error loops. So, no // If we don't return early here, we can get into infinite error loops. So, no
// delivery receipts for sealed sender errors. // delivery receipts for sealed sender errors.

@ -144,10 +144,6 @@
this.on('expiration-change', this.updateAndMerge); this.on('expiration-change', this.updateAndMerge);
this.on('expired', this.onExpired); this.on('expired', this.onExpired);
setTimeout(() => {
this.setFriendRequestTimer();
}, 0);
const sealedSender = this.get('sealedSender'); const sealedSender = this.get('sealedSender');
if (sealedSender === undefined) { if (sealedSender === undefined) {
this.set({ sealedSender: SEALED_SENDER.UNKNOWN }); this.set({ sealedSender: SEALED_SENDER.UNKNOWN });
@ -472,14 +468,23 @@
Conversation: Whisper.Conversation, Conversation: Whisper.Conversation,
}); });
}, },
async waitingForFriendRequestApproval() {
// Check if we have an incoming friend request
// Or any successful outgoing ones
const incoming = await this.getPendingFriendRequests('incoming');
const outgoing = await this.getPendingFriendRequests('outgoing');
const successfulOutgoing = outgoing.filter(o => !o.hasErrors());
return (incoming.length > 0 || successfulOutgoing.length > 0);
},
async isFriend() { async isFriend() {
// We are a friend IF: // We are a friend IF:
// - We have the preKey bundle of the user OR // - We have the preKey bundle of the user OR
// - We have a session with the user // - We have a session with the user
const preKeys = await window.Signal.Data.getContactPreKeyByIdentityKey(this.id); const preKeys = await window.Signal.Data.getContactPreKeyByIdentityKey(this.id);
const session = await window.Signal.Data.getSessionsByNumber(this.id); // const session = await window.Signal.Data.getSessionsByNumber(this.id);
return !!(preKeys || session); return !!preKeys;
}, },
// Update any pending friend requests for the current user // Update any pending friend requests for the current user
async updateFriendRequestUI() { async updateFriendRequestUI() {
@ -1114,14 +1119,9 @@
// Check if we need to disable the text field // Check if we need to disable the text field
const isFriend = await this.isFriend(); const isFriend = await this.isFriend();
if (isFriend) { if (isFriend) {
// Check if we have an incoming friend request // Disable the input if we're waiting for friend request approval
// Or any successful outgoing ones const waiting = await this.waitingForFriendRequestApproval();
const incoming = await this.getPendingFriendRequests('incoming'); if (waiting) {
const outgoing = await this.getPendingFriendRequests('outgoing');
const successfulOutgoing = outgoing.filter(o => !o.hasErrors());
// Disable the input
if (incoming.length > 0 || successfulOutgoing.length > 0) {
this.trigger('disable:input', true); this.trigger('disable:input', true);
this.trigger('change:placeholder', 'disabled'); this.trigger('change:placeholder', 'disabled');
return; return;

@ -70,14 +70,10 @@
template: $('#conversation').html(), template: $('#conversation').html(),
render_attributes() { render_attributes() {
let sendMessagePlaceholder = 'sendMessageFriendRequest'; let sendMessagePlaceholder = 'sendMessageFriendRequest';
const sendDisabled = this.model.waitingForFriendRequestApproval(); if (this.model.isFriend()) {
if (sendDisabled) {
sendMessagePlaceholder = 'sendMessageDisabled';
} else if (this.model.getFriendRequestStatus() === null) {
sendMessagePlaceholder = 'sendMessage'; sendMessagePlaceholder = 'sendMessage';
} }
return { return {
'disable-inputs': sendDisabled,
'send-message': i18n(sendMessagePlaceholder), 'send-message': i18n(sendMessagePlaceholder),
'android-length-warning': i18n('androidMessageLengthWarning'), 'android-length-warning': i18n('androidMessageLengthWarning'),
}; };
@ -240,6 +236,8 @@
this.$('.send-message').blur(this.unfocusBottomBar.bind(this)); this.$('.send-message').blur(this.unfocusBottomBar.bind(this));
this.$emojiPanelContainer = this.$('.emoji-panel-container'); this.$emojiPanelContainer = this.$('.emoji-panel-container');
this.model.updateFriendRequestUI();
}, },
events: { events: {

@ -929,7 +929,10 @@ MessageReceiver.prototype.extend({
}) })
); );
}, },
handleDataMessage(envelope, msg) { async handleFriendRequestMessage(envelope, msg) {
return this.handleDataMessage(envelope, msg, 'friend-request');
},
handleDataMessage(envelope, msg, type = 'data') {
window.log.info('data message from', this.getEnvelopeId(envelope)); window.log.info('data message from', this.getEnvelopeId(envelope));
let p = Promise.resolve(); let p = Promise.resolve();
// eslint-disable-next-line no-bitwise // eslint-disable-next-line no-bitwise
@ -946,6 +949,13 @@ MessageReceiver.prototype.extend({
message.group.type === textsecure.protobuf.GroupContext.Type.QUIT message.group.type === textsecure.protobuf.GroupContext.Type.QUIT
); );
if (type === 'friend-request' && isMe) {
window.log.info(
'refusing to add a friend request to ourselves'
);
throw new Error('Cannot add a friend request for ourselves!')
}
if (groupId && isBlocked && !(isMe && isLeavingGroup)) { if (groupId && isBlocked && !(isMe && isLeavingGroup)) {
window.log.warn( window.log.warn(
`Message ${this.getEnvelopeId( `Message ${this.getEnvelopeId(
@ -955,15 +965,19 @@ MessageReceiver.prototype.extend({
return this.removeFromCache(envelope); return this.removeFromCache(envelope);
} }
const preKeyBundle = envelope.preKeyBundleMessage && this.decodePreKeyBundleMessage(envelope.preKeyBundleMessage);
const ev = new Event('message'); const ev = new Event('message');
ev.confirm = this.removeFromCache.bind(this, envelope); ev.confirm = this.removeFromCache.bind(this, envelope);
ev.data = { ev.data = {
type,
source: envelope.source, source: envelope.source,
sourceDevice: envelope.sourceDevice, sourceDevice: envelope.sourceDevice,
timestamp: envelope.timestamp.toNumber(), timestamp: envelope.timestamp.toNumber(),
receivedAt: envelope.receivedAt, receivedAt: envelope.receivedAt,
unidentifiedDeliveryReceived: envelope.unidentifiedDeliveryReceived, unidentifiedDeliveryReceived: envelope.unidentifiedDeliveryReceived,
message, message,
preKeyBundle: preKeyBundle || null,
}; };
return this.dispatchAndWait(ev); return this.dispatchAndWait(ev);
}) })
@ -1046,17 +1060,7 @@ MessageReceiver.prototype.extend({
} }
if (envelope.type === textsecure.protobuf.Envelope.Type.FRIEND_REQUEST) { if (envelope.type === textsecure.protobuf.Envelope.Type.FRIEND_REQUEST) {
// only prompt friend request if there is no conversation yet return this.handleFriendRequestMessage(envelope, content.dataMessage);
if (!conversation) {
this.promptUserToAcceptFriendRequest(
envelope,
content.dataMessage.body,
envelope.preKeyBundleMessage
);
}
// Exit early since the friend request reply will be a regular empty message
return null;
} else if (envelope.type === textsecure.protobuf.Envelope.Type.CIPHERTEXT) { } else if (envelope.type === textsecure.protobuf.Envelope.Type.CIPHERTEXT) {
// If we get a cipher text and we are friends then we can mark keys as exchanged // If we get a cipher text and we are friends then we can mark keys as exchanged
if (conversation && conversation.isFriend()) { if (conversation && conversation.isFriend()) {

Loading…
Cancel
Save