Browse Source

tribe mediaKey

feature/dockerfile-arm
Evan Feenstra 5 years ago
parent
commit
170b3b11a2
  1. 10
      api/utils/msg.ts
  2. 11
      dist/api/utils/msg.js
  3. 2
      dist/api/utils/msg.js.map

10
api/utils/msg.ts

@ -60,12 +60,18 @@ async function encryptTribeBroadcast(full:{[k:string]:any}, contact, isTribe:boo
return fillmsg(full, obj) return fillmsg(full, obj)
} }
function addInMediaKey(full:{[k:string]:any}, contactId){ function addInMediaKey(full:{[k:string]:any}, contactId, isTribe:boolean){
const m = full && full.message const m = full && full.message
if (!(m && m.mediaKey)) return full if (!(m && m.mediaKey)) return full
if (!(m && m.mediaTerms)) return full if (!(m && m.mediaTerms)) return full
if (!(typeof m.mediaKey==='object')) return full if (!(typeof m.mediaKey==='object')) return full
if(isTribe) {
if(Object.values(m.mediaKey).length===1) {
const tribeMediaKey = m.mediaTerms.skipSigning?'':Object.values(m.mediaKey)[0]
return fillmsg(full, {mediaKey:tribeMediaKey})
}
}
const mediaKey = m.mediaTerms.skipSigning ? '' : m.mediaKey[contactId+''] const mediaKey = m.mediaTerms.skipSigning ? '' : m.mediaKey[contactId+'']
return fillmsg(full, {mediaKey}) return fillmsg(full, {mediaKey})
} }
@ -136,7 +142,7 @@ async function personalizeMessage(m,contact,isTribeOwner:boolean){
const msgWithRemoteTxt = addInRemoteText(cloned, contactId, isTribe) const msgWithRemoteTxt = addInRemoteText(cloned, contactId, isTribe)
const cleanMsg = removeRecipientFromChatMembers(msgWithRemoteTxt, destkey) const cleanMsg = removeRecipientFromChatMembers(msgWithRemoteTxt, destkey)
const cleanerMsg = removeAllNonAdminMembersIfTribe(cleanMsg, destkey) const cleanerMsg = removeAllNonAdminMembersIfTribe(cleanMsg, destkey)
const msgWithMediaKey = addInMediaKey(cleanerMsg, contactId) const msgWithMediaKey = addInMediaKey(cleanerMsg, contactId, isTribe)
const msgWithMediaToken = await finishTermsAndReceipt(msgWithMediaKey, destkey) const msgWithMediaToken = await finishTermsAndReceipt(msgWithMediaKey, destkey)
const encMsg = await encryptTribeBroadcast(msgWithMediaToken, contact, isTribe, isTribeOwner) const encMsg = await encryptTribeBroadcast(msgWithMediaToken, contact, isTribe, isTribeOwner)
return encMsg return encMsg

11
dist/api/utils/msg.js

@ -71,7 +71,7 @@ function encryptTribeBroadcast(full, contact, isTribe, isTribeOwner) {
return fillmsg(full, obj); return fillmsg(full, obj);
}); });
} }
function addInMediaKey(full, contactId) { function addInMediaKey(full, contactId, isTribe) {
const m = full && full.message; const m = full && full.message;
if (!(m && m.mediaKey)) if (!(m && m.mediaKey))
return full; return full;
@ -79,6 +79,13 @@ function addInMediaKey(full, contactId) {
return full; return full;
if (!(typeof m.mediaKey === 'object')) if (!(typeof m.mediaKey === 'object'))
return full; return full;
if (isTribe) {
// if just one, send it (for tribe remote_text_map... is there a better way?)
if (Object.values(m.mediaKey).length === 1) {
const tribeMediaKey = m.mediaTerms.skipSigning ? '' : Object.values(m.mediaKey)[0];
return fillmsg(full, { mediaKey: tribeMediaKey });
}
}
const mediaKey = m.mediaTerms.skipSigning ? '' : m.mediaKey[contactId + '']; const mediaKey = m.mediaTerms.skipSigning ? '' : m.mediaKey[contactId + ''];
return fillmsg(full, { mediaKey }); return fillmsg(full, { mediaKey });
} }
@ -149,7 +156,7 @@ function personalizeMessage(m, contact, isTribeOwner) {
const msgWithRemoteTxt = addInRemoteText(cloned, contactId, isTribe); const msgWithRemoteTxt = addInRemoteText(cloned, contactId, isTribe);
const cleanMsg = removeRecipientFromChatMembers(msgWithRemoteTxt, destkey); const cleanMsg = removeRecipientFromChatMembers(msgWithRemoteTxt, destkey);
const cleanerMsg = removeAllNonAdminMembersIfTribe(cleanMsg, destkey); const cleanerMsg = removeAllNonAdminMembersIfTribe(cleanMsg, destkey);
const msgWithMediaKey = addInMediaKey(cleanerMsg, contactId); const msgWithMediaKey = addInMediaKey(cleanerMsg, contactId, isTribe);
const msgWithMediaToken = yield finishTermsAndReceipt(msgWithMediaKey, destkey); const msgWithMediaToken = yield finishTermsAndReceipt(msgWithMediaKey, destkey);
const encMsg = yield encryptTribeBroadcast(msgWithMediaToken, contact, isTribe, isTribeOwner); const encMsg = yield encryptTribeBroadcast(msgWithMediaToken, contact, isTribe, isTribeOwner);
return encMsg; return encMsg;

2
dist/api/utils/msg.js.map

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