Added dynamic profile fetching in conversation.

Added setting profile when sending DataMessage.
pull/61/head
Mikunj 6 years ago
parent 0e6c14eb5c
commit 774c52a407

@ -608,6 +608,7 @@
<script type='text/javascript' src='js/models/messages.js'></script>
<script type='text/javascript' src='js/models/conversations.js'></script>
<script type='text/javascript' src='js/models/blockedNumbers.js'></script>
<script type='text/javascript' src='js/models/profile.js'></script>
<script type='text/javascript' src='js/expiring_messages.js'></script>
<script type='text/javascript' src='js/chromium.js'></script>

@ -1736,7 +1736,21 @@
this.getProfiles();
}
},
// Update profile variables dynamically
async updateProfile() {
const profile = await storage.getProfile(this.id);
if (!profile) {
this.set({ profileName: null });
} else {
this.set({ profileName: profile.name.displayName });
}
if (this.hasChanged()) {
await window.Signal.Data.updateConversation(this.id, this.attributes, {
Conversation: Whisper.Conversation,
});
}
},
getProfiles() {
// request all conversation members' keys
let ids = [];
@ -1866,6 +1880,7 @@
}
}
},
// Signal profile name
async setProfileName(encryptedName) {
if (!encryptedName) {
return;

@ -1,4 +1,4 @@
/* global storage */
/* global storage, _ */
/* global storage: false */
/* eslint-disable more/no-then */
@ -18,14 +18,17 @@
storage.saveProfile = async (number, profile) => {
const profiles = storage.get(PROFILE_ID, {});
if (profiles[number]) {
const storedProfile = profiles[number];
// Only store the profile if we have a different object
if (storedProfile && _.isEqual(storedProfile, profile)) {
return;
}
window.log.info('adding profile ', profile, 'for ', number);
await storage.put(PROFILE_ID, {
...profiles,
number: profile,
[number]: profile,
});
}

@ -66,7 +66,7 @@ function idForLogging(message) {
exports._validate = (contact, options = {}) => {
const { messageId } = options;
const { name, number, email, address, organization } = contact;
const { name, organization } = contact;
if ((!name || !name.displayName) && !organization) {
return new Error(
@ -74,15 +74,16 @@ exports._validate = (contact, options = {}) => {
);
}
if (
(!number || !number.length) &&
(!email || !email.length) &&
(!address || !address.length)
) {
return new Error(
`Message ${messageId}: Contact had no included numbers, email or addresses`
);
}
// Disabled as we don't require the users to provide this
// if (
// (!number || !number.length) &&
// (!email || !email.length) &&
// (!address || !address.length)
// ) {
// return new Error(
// `Message ${messageId}: Contact had no included numbers, email or addresses`
// );
// }
return null;
};

@ -25,6 +25,7 @@ function Message(options) {
this.needsSync = options.needsSync;
this.expireTimer = options.expireTimer;
this.profileKey = options.profileKey;
this.profile = options.profile;
if (!(this.recipients instanceof Array) || this.recipients.length < 1) {
throw new Error('Invalid recipient list');
@ -132,6 +133,12 @@ Message.prototype = {
proto.profileKey = this.profileKey;
}
if (this.profile) {
const contact = new textsecure.protobuf.DataMessage.Contact();
contact.name = this.profile.name;
proto.contact.push(contact);
}
this.dataMessage = proto;
return proto;
},
@ -656,6 +663,8 @@ MessageSender.prototype = {
profileKey,
options
) {
const myNumber = textsecure.storage.user.getNumber();
const profile = textsecure.storage.impl.getProfile(myNumber);
return this.sendMessage(
{
recipients: [number],
@ -666,6 +675,7 @@ MessageSender.prototype = {
needsSync: true,
expireTimer,
profileKey,
profile,
},
options
);

Loading…
Cancel
Save