Browse Source

send updated profile photo to all contacts any time its changed

hosting-provider
Evan Feenstra 5 years ago
parent
commit
c014920128
  1. 2
      api/controllers/confirmations.ts
  2. 37
      api/controllers/contacts.ts
  3. 2
      dist/api/controllers/confirmations.js
  4. 2
      dist/api/controllers/confirmations.js.map
  5. 32
      dist/api/controllers/contacts.js
  6. 2
      dist/api/controllers/contacts.js.map

2
api/controllers/confirmations.ts

@ -17,7 +17,7 @@ export function sendConfirmation({ chat, sender, msg_id }) {
}
export async function receiveConfirmation(payload) {
console.log('=> received confirmation', JSON.stringify(payload))
console.log('=> received confirmation', (payload.message&&payload.message.id))
const dat = payload.content || payload
const chat_uuid = dat.chat.uuid

37
api/controllers/contacts.ts

@ -72,13 +72,20 @@ const updateContact = async (req, res) => {
let attrs = extractAttrs(req.body)
const contact = await models.Contact.findOne({ where: { id: req.params.id }})
let shouldUpdateContactKey = (contact.isOwner && contact.contactKey == null && attrs["contact_key"] != null)
let shouldSendUpdatedSelf = (
contact.isOwner && (
(contact.contactKey == null && attrs["contact_key"] != null) || // CREATE CONTACT KEY!
attrs["contact_key"]==null // OR NO NEW CONTACT KEY
)
)
// update self
const owner = await contact.update(jsonUtils.jsonToContact(attrs))
success(res, jsonUtils.contactToJson(owner))
if (!shouldUpdateContactKey) return
if (!shouldSendUpdatedSelf) return
// send updated owner info to others
const contactIds = await models.Contact.findAll({where:{deleted:false}}).map(c => c.id)
if (contactIds.length == 0) return
@ -187,8 +194,8 @@ const deleteContact = async (req, res) => {
success(res, {})
}
const receiveConfirmContactKey = async (payload) => {
console.log(`=> confirm contact key for ${payload.sender&&payload.sender.pub_key}`, JSON.stringify(payload))
const receiveContactKey = async (payload) => {
console.log('=> received contact key', JSON.stringify(payload))
const dat = payload.content || payload
const sender_pub_key = dat.sender.pub_key
@ -196,7 +203,9 @@ const receiveConfirmContactKey = async (payload) => {
const sender_alias = dat.sender.alias || 'Unknown'
const sender_photo_url = dat.sender.photo_url
const owner = await models.Contact.findOne({ where: { isOwner: true }})
const sender = await models.Contact.findOne({ where: { publicKey: sender_pub_key, status: constants.contact_statuses.confirmed }})
if (sender_contact_key && sender) {
const objToUpdate:{[k:string]:any} = {contactKey: sender_contact_key}
if(sender_alias) objToUpdate.alias = sender_alias
@ -208,10 +217,16 @@ const receiveConfirmContactKey = async (payload) => {
response: jsonUtils.contactToJson(sender)
})
}
helpers.sendContactKeys({
contactPubKey: sender_pub_key,
sender: owner,
type: constants.message_types.contact_key_confirmation,
})
}
const receiveContactKey = async (payload) => {
console.log('=> received contact key', JSON.stringify(payload))
const receiveConfirmContactKey = async (payload) => {
console.log(`=> confirm contact key for ${payload.sender&&payload.sender.pub_key}`, JSON.stringify(payload))
const dat = payload.content || payload
const sender_pub_key = dat.sender.pub_key
@ -219,9 +234,7 @@ const receiveContactKey = async (payload) => {
const sender_alias = dat.sender.alias || 'Unknown'
const sender_photo_url = dat.sender.photo_url
const owner = await models.Contact.findOne({ where: { isOwner: true }})
const sender = await models.Contact.findOne({ where: { publicKey: sender_pub_key, status: constants.contact_statuses.confirmed }})
if (sender_contact_key && sender) {
const objToUpdate:{[k:string]:any} = {contactKey: sender_contact_key}
if(sender_alias) objToUpdate.alias = sender_alias
@ -233,12 +246,6 @@ const receiveContactKey = async (payload) => {
response: jsonUtils.contactToJson(sender)
})
}
helpers.sendContactKeys({
contactPubKey: sender_pub_key,
sender: owner,
type: constants.message_types.contact_key_confirmation,
})
}
const extractAttrs = body => {

2
dist/api/controllers/confirmations.js

@ -27,7 +27,7 @@ function sendConfirmation({ chat, sender, msg_id }) {
exports.sendConfirmation = sendConfirmation;
function receiveConfirmation(payload) {
return __awaiter(this, void 0, void 0, function* () {
console.log('=> received confirmation', JSON.stringify(payload));
console.log('=> received confirmation', (payload.message && payload.message.id));
const dat = payload.content || payload;
const chat_uuid = dat.chat.uuid;
const msg_id = dat.message.id;

2
dist/api/controllers/confirmations.js.map

@ -1 +1 @@
{"version":3,"file":"confirmations.js","sourceRoot":"","sources":["../../../api/controllers/confirmations.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 -70,11 +70,15 @@ const updateContact = (req, res) => __awaiter(void 0, void 0, void 0, function*
console.log('=> updateContact called', { body: req.body, params: req.params, query: req.query });
let attrs = extractAttrs(req.body);
const contact = yield models_1.models.Contact.findOne({ where: { id: req.params.id } });
let shouldUpdateContactKey = (contact.isOwner && contact.contactKey == null && attrs["contact_key"] != null);
let shouldSendUpdatedSelf = (contact.isOwner && ((contact.contactKey == null && attrs["contact_key"] != null) || // CREATE CONTACT KEY!
attrs["contact_key"] == null // OR NO NEW CONTACT KEY
));
// update self
const owner = yield contact.update(jsonUtils.jsonToContact(attrs));
res_1.success(res, jsonUtils.contactToJson(owner));
if (!shouldUpdateContactKey)
if (!shouldSendUpdatedSelf)
return;
// send updated owner info to others
const contactIds = yield models_1.models.Contact.findAll({ where: { deleted: false } }).map(c => c.id);
if (contactIds.length == 0)
return;
@ -172,13 +176,14 @@ const deleteContact = (req, res) => __awaiter(void 0, void 0, void 0, function*
res_1.success(res, {});
});
exports.deleteContact = deleteContact;
const receiveConfirmContactKey = (payload) => __awaiter(void 0, void 0, void 0, function* () {
console.log(`=> confirm contact key for ${payload.sender && payload.sender.pub_key}`, JSON.stringify(payload));
const receiveContactKey = (payload) => __awaiter(void 0, void 0, void 0, function* () {
console.log('=> received contact key', JSON.stringify(payload));
const dat = payload.content || payload;
const sender_pub_key = dat.sender.pub_key;
const sender_contact_key = dat.sender.contact_key;
const sender_alias = dat.sender.alias || 'Unknown';
const sender_photo_url = dat.sender.photo_url;
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
const sender = yield models_1.models.Contact.findOne({ where: { publicKey: sender_pub_key, status: constants.contact_statuses.confirmed } });
if (sender_contact_key && sender) {
const objToUpdate = { contactKey: sender_contact_key };
@ -192,16 +197,20 @@ const receiveConfirmContactKey = (payload) => __awaiter(void 0, void 0, void 0,
response: jsonUtils.contactToJson(sender)
});
}
helpers.sendContactKeys({
contactPubKey: sender_pub_key,
sender: owner,
type: constants.message_types.contact_key_confirmation,
});
});
exports.receiveConfirmContactKey = receiveConfirmContactKey;
const receiveContactKey = (payload) => __awaiter(void 0, void 0, void 0, function* () {
console.log('=> received contact key', JSON.stringify(payload));
exports.receiveContactKey = receiveContactKey;
const receiveConfirmContactKey = (payload) => __awaiter(void 0, void 0, void 0, function* () {
console.log(`=> confirm contact key for ${payload.sender && payload.sender.pub_key}`, JSON.stringify(payload));
const dat = payload.content || payload;
const sender_pub_key = dat.sender.pub_key;
const sender_contact_key = dat.sender.contact_key;
const sender_alias = dat.sender.alias || 'Unknown';
const sender_photo_url = dat.sender.photo_url;
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
const sender = yield models_1.models.Contact.findOne({ where: { publicKey: sender_pub_key, status: constants.contact_statuses.confirmed } });
if (sender_contact_key && sender) {
const objToUpdate = { contactKey: sender_contact_key };
@ -215,13 +224,8 @@ const receiveContactKey = (payload) => __awaiter(void 0, void 0, void 0, functio
response: jsonUtils.contactToJson(sender)
});
}
helpers.sendContactKeys({
contactPubKey: sender_pub_key,
sender: owner,
type: constants.message_types.contact_key_confirmation,
});
});
exports.receiveContactKey = receiveContactKey;
exports.receiveConfirmContactKey = receiveConfirmContactKey;
const extractAttrs = body => {
let fields_to_update = ["public_key", "node_alias", "alias", "photo_url", "device_id", "status", "contact_key", "from_group", "private_photo"];
let attrs = {};

2
dist/api/controllers/contacts.js.map

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save