Update messenger.js
- merge conflicts
This commit is contained in:
parent
392f3a112b
commit
285136b1e9
@ -1,6 +1,15 @@
|
|||||||
(function() {
|
(function() {
|
||||||
const messenger = window.messenger = {};
|
const messenger = window.messenger = {};
|
||||||
|
|
||||||
|
const user = {
|
||||||
|
get id() {
|
||||||
|
return floDapps.user.id
|
||||||
|
},
|
||||||
|
get public() {
|
||||||
|
return floDapps.user.public
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const expiredKeys = {};
|
const expiredKeys = {};
|
||||||
|
|
||||||
const UI = {
|
const UI = {
|
||||||
@ -162,7 +171,7 @@
|
|||||||
data.rmMembers = dataSet[vc].message.split("|")
|
data.rmMembers = dataSet[vc].message.split("|")
|
||||||
data.note = dataSet[vc].comment
|
data.note = dataSet[vc].comment
|
||||||
groupInfo.members = groupInfo.members.filter(m => !data.rmMembers.includes(m))
|
groupInfo.members = groupInfo.members.filter(m => !data.rmMembers.includes(m))
|
||||||
if (data.rmMembers.includes(myFloID)) {
|
if (data.rmMembers.includes(user.id)) {
|
||||||
disableGroup(groupID);
|
disableGroup(groupID);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -181,7 +190,7 @@
|
|||||||
if (data.message)
|
if (data.message)
|
||||||
data.message = decrypt(data.message);
|
data.message = decrypt(data.message);
|
||||||
newInbox.messages[vc] = data;
|
newInbox.messages[vc] = data;
|
||||||
if (data.sender !== myFloID)
|
if (data.sender !== user.id)
|
||||||
addMark(data.groupID, "unread")
|
addMark(data.groupID, "unread")
|
||||||
if (!_loaded.appendix[`lastReceived_${groupID}`] ||
|
if (!_loaded.appendix[`lastReceived_${groupID}`] ||
|
||||||
_loaded.appendix[`lastReceived_${groupID}`] < vc)
|
_loaded.appendix[`lastReceived_${groupID}`] < vc)
|
||||||
@ -221,12 +230,14 @@
|
|||||||
groups: {},
|
groups: {},
|
||||||
gkeys: {},
|
gkeys: {},
|
||||||
blocked: {},
|
blocked: {},
|
||||||
|
flodata: {},
|
||||||
appendix: {},
|
appendix: {},
|
||||||
userSettings: {}
|
userSettings: {}
|
||||||
}
|
}
|
||||||
compactIDB.initDB(`${floGlobals.application}_${myFloID}`, obj).then(result => {
|
let user_db = `${floGlobals.application}_${user.id}`;
|
||||||
|
compactIDB.initDB(user_db, obj).then(result => {
|
||||||
console.info(result)
|
console.info(result)
|
||||||
compactIDB.setDefaultDB(`${floGlobals.application}_${myFloID}`);
|
compactIDB.setDefaultDB(user_db);
|
||||||
resolve("Messenger UserDB Initated Successfully")
|
resolve("Messenger UserDB Initated Successfully")
|
||||||
}).catch(error => reject(error));
|
}).catch(error => reject(error));
|
||||||
})
|
})
|
||||||
@ -290,7 +301,7 @@
|
|||||||
let promises = recipients.map(r => sendRaw(JSON.stringify(mail), r, "MAIL"))
|
let promises = recipients.map(r => sendRaw(JSON.stringify(mail), r, "MAIL"))
|
||||||
Promise.allSettled(promises).then(results => {
|
Promise.allSettled(promises).then(results => {
|
||||||
mail.time = Date.now();
|
mail.time = Date.now();
|
||||||
mail.from = myFloID
|
mail.from = user.id
|
||||||
mail.to = []
|
mail.to = []
|
||||||
results.forEach(r => {
|
results.forEach(r => {
|
||||||
if (r.status === "fulfilled")
|
if (r.status === "fulfilled")
|
||||||
@ -331,7 +342,7 @@
|
|||||||
if (_loaded.blocked.has(dataSet[vc].senderID) && dataSet[vc].type !== "REVOKE_KEY")
|
if (_loaded.blocked.has(dataSet[vc].senderID) && dataSet[vc].type !== "REVOKE_KEY")
|
||||||
throw "blocked-user";
|
throw "blocked-user";
|
||||||
if (dataSet[vc].message instanceof Object && "secret" in dataSet[vc].message)
|
if (dataSet[vc].message instanceof Object && "secret" in dataSet[vc].message)
|
||||||
dataSet[vc].message = floCrypto.decryptData(dataSet[vc].message, myPrivKey)
|
dataSet[vc].message = floDapps.user.decrypt(dataSet[vc].message);
|
||||||
if (dataSet[vc].type === "MESSAGE") {
|
if (dataSet[vc].type === "MESSAGE") {
|
||||||
//process as message
|
//process as message
|
||||||
let dm = {
|
let dm = {
|
||||||
@ -354,7 +365,7 @@
|
|||||||
let mail = {
|
let mail = {
|
||||||
time: dataSet[vc].time,
|
time: dataSet[vc].time,
|
||||||
from: dataSet[vc].senderID,
|
from: dataSet[vc].senderID,
|
||||||
to: [myFloID],
|
to: [user.id],
|
||||||
subject: data.subject,
|
subject: data.subject,
|
||||||
content: encrypt(data.content),
|
content: encrypt(data.content),
|
||||||
ref: data.ref,
|
ref: data.ref,
|
||||||
@ -412,7 +423,7 @@
|
|||||||
UI.direct(newInbox)
|
UI.direct(newInbox)
|
||||||
}
|
}
|
||||||
floCloudAPI.requestApplicationData(null, {
|
floCloudAPI.requestApplicationData(null, {
|
||||||
receiverID: myFloID,
|
receiverID: user.id,
|
||||||
lowerVectorClock: _loaded.appendix.lastReceived + 1,
|
lowerVectorClock: _loaded.appendix.lastReceived + 1,
|
||||||
callback: callbackFn
|
callback: callbackFn
|
||||||
}).then(conn_id => directConnID = conn_id)
|
}).then(conn_id => directConnID = conn_id)
|
||||||
@ -464,7 +475,7 @@
|
|||||||
data.appendix.lastReceived = data.appendix.lastReceived || '0';
|
data.appendix.lastReceived = data.appendix.lastReceived || '0';
|
||||||
if (data.appendix.AESKey) {
|
if (data.appendix.AESKey) {
|
||||||
try {
|
try {
|
||||||
let AESKey = floCrypto.decryptData(data.appendix.AESKey, myPrivKey);
|
let AESKey = floDapps.user.decrypt(data.appendix.AESKey);
|
||||||
data.appendix.AESKey = AESKey;
|
data.appendix.AESKey = AESKey;
|
||||||
if (dataList.includes("messages"))
|
if (dataList.includes("messages"))
|
||||||
for (let m in data.messages)
|
for (let m in data.messages)
|
||||||
@ -481,13 +492,14 @@
|
|||||||
data.gkeys[k] = decrypt(data.gkeys[k], AESKey);
|
data.gkeys[k] = decrypt(data.gkeys[k], AESKey);
|
||||||
resolve(data)
|
resolve(data)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
reject("Corrupted AES Key");
|
reject("Corrupted AES Key");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (Object.keys(data.mails).length)
|
if (Object.keys(data.mails).length)
|
||||||
return reject("AES Key not Found")
|
return reject("AES Key not Found")
|
||||||
let AESKey = floCrypto.randString(32, false);
|
let AESKey = floCrypto.randString(32, false);
|
||||||
let encryptedKey = floCrypto.encryptData(AESKey, myPubKey);
|
let encryptedKey = floCrypto.encryptData(AESKey, user.public);
|
||||||
compactIDB.addData("appendix", encryptedKey, "AESKey").then(result => {
|
compactIDB.addData("appendix", encryptedKey, "AESKey").then(result => {
|
||||||
data.appendix.AESKey = AESKey;
|
data.appendix.AESKey = AESKey;
|
||||||
resolve(data);
|
resolve(data);
|
||||||
@ -565,11 +577,11 @@
|
|||||||
data.pubKeys = floGlobals.pubKeys;
|
data.pubKeys = floGlobals.pubKeys;
|
||||||
data = btoa(unescape(encodeURIComponent(JSON.stringify(data))))
|
data = btoa(unescape(encodeURIComponent(JSON.stringify(data))))
|
||||||
let blobData = {
|
let blobData = {
|
||||||
floID: myFloID,
|
floID: user.id,
|
||||||
pubKey: myPubKey,
|
pubKey: user.public,
|
||||||
data: encrypt(data, myPrivKey),
|
data: floDapps.user.encipher(data),
|
||||||
}
|
}
|
||||||
blobData.sign = floCrypto.signData(blobData.data, myPrivKey);
|
blobData.sign = floDapps.sign(blobData.data);
|
||||||
resolve(new Blob([JSON.stringify(blobData)], {
|
resolve(new Blob([JSON.stringify(blobData)], {
|
||||||
type: 'application/json'
|
type: 'application/json'
|
||||||
}));
|
}));
|
||||||
@ -585,11 +597,11 @@
|
|||||||
var blobData = JSON.parse(evt.target.result);
|
var blobData = JSON.parse(evt.target.result);
|
||||||
if (!floCrypto.verifySign(blobData.data, blobData.sign, blobData.pubKey))
|
if (!floCrypto.verifySign(blobData.data, blobData.sign, blobData.pubKey))
|
||||||
reject("Corrupted Backup file: Signature verification failed");
|
reject("Corrupted Backup file: Signature verification failed");
|
||||||
else if (myFloID !== blobData.floID || myPubKey !== blobData.pubKey)
|
else if (user.id !== blobData.floID || user.public !== blobData.pubKey)
|
||||||
reject("Invalid Backup file: Incorrect floID");
|
reject("Invalid Backup file: Incorrect floID");
|
||||||
else {
|
else {
|
||||||
try {
|
try {
|
||||||
let data = decrypt(blobData.data, myPrivKey)
|
let data = floDapps.user.decipher(blobData.data);
|
||||||
try {
|
try {
|
||||||
data = JSON.parse(decodeURIComponent(escape(atob(data))));
|
data = JSON.parse(decodeURIComponent(escape(atob(data))));
|
||||||
resolve(data)
|
resolve(data)
|
||||||
@ -681,11 +693,11 @@
|
|||||||
let groupInfo = {
|
let groupInfo = {
|
||||||
groupID: id.floID,
|
groupID: id.floID,
|
||||||
pubKey: id.pubKey,
|
pubKey: id.pubKey,
|
||||||
admin: myFloID,
|
admin: user.id,
|
||||||
name: groupname,
|
name: groupname,
|
||||||
description: description,
|
description: description,
|
||||||
created: Date.now(),
|
created: Date.now(),
|
||||||
members: [myFloID]
|
members: [user.id]
|
||||||
}
|
}
|
||||||
let h = ["groupID", "created", "admin"].map(x => groupInfo[x]).join('|')
|
let h = ["groupID", "created", "admin"].map(x => groupInfo[x]).join('|')
|
||||||
groupInfo.hash = floCrypto.signData(h, id.privKey)
|
groupInfo.hash = floCrypto.signData(h, id.privKey)
|
||||||
@ -705,7 +717,7 @@
|
|||||||
messenger.changeGroupName = function(groupID, name) {
|
messenger.changeGroupName = function(groupID, name) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let groupInfo = _loaded.groups[groupID]
|
let groupInfo = _loaded.groups[groupID]
|
||||||
if (myFloID !== groupInfo.admin)
|
if (user.id !== groupInfo.admin)
|
||||||
return reject("Access denied: Admin only!")
|
return reject("Access denied: Admin only!")
|
||||||
let message = encrypt(name, groupInfo.eKey)
|
let message = encrypt(name, groupInfo.eKey)
|
||||||
sendRaw(message, groupID, "UP_NAME", false)
|
sendRaw(message, groupID, "UP_NAME", false)
|
||||||
@ -717,7 +729,7 @@
|
|||||||
messenger.changeGroupDescription = function(groupID, description) {
|
messenger.changeGroupDescription = function(groupID, description) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let groupInfo = _loaded.groups[groupID]
|
let groupInfo = _loaded.groups[groupID]
|
||||||
if (myFloID !== groupInfo.admin)
|
if (user.id !== groupInfo.admin)
|
||||||
return reject("Access denied: Admin only!")
|
return reject("Access denied: Admin only!")
|
||||||
let message = encrypt(description, groupInfo.eKey)
|
let message = encrypt(description, groupInfo.eKey)
|
||||||
sendRaw(message, groupID, "UP_DESCRIPTION", false)
|
sendRaw(message, groupID, "UP_DESCRIPTION", false)
|
||||||
@ -743,7 +755,7 @@
|
|||||||
return reject(`Invalid Members (pubKey not available): ${imem2}`)
|
return reject(`Invalid Members (pubKey not available): ${imem2}`)
|
||||||
//send new newMem list to existing members
|
//send new newMem list to existing members
|
||||||
let groupInfo = _loaded.groups[groupID]
|
let groupInfo = _loaded.groups[groupID]
|
||||||
if (myFloID !== groupInfo.admin)
|
if (user.id !== groupInfo.admin)
|
||||||
return reject("Access denied: Admin only!")
|
return reject("Access denied: Admin only!")
|
||||||
let k = groupInfo.eKey;
|
let k = groupInfo.eKey;
|
||||||
//send groupInfo to new newMem
|
//send groupInfo to new newMem
|
||||||
@ -773,7 +785,7 @@
|
|||||||
let imem = rmMem.filter(m => !groupInfo.members.includes(m))
|
let imem = rmMem.filter(m => !groupInfo.members.includes(m))
|
||||||
if (imem.length)
|
if (imem.length)
|
||||||
return reject(`Invalid members: ${imem}`)
|
return reject(`Invalid members: ${imem}`)
|
||||||
if (myFloID !== groupInfo.admin)
|
if (user.id !== groupInfo.admin)
|
||||||
return reject("Access denied: Admin only!")
|
return reject("Access denied: Admin only!")
|
||||||
let message = encrypt(rmMem.join("|"), groupInfo.eKey)
|
let message = encrypt(rmMem.join("|"), groupInfo.eKey)
|
||||||
let p1 = sendRaw(message, groupID, "RM_MEMBERS", false, note)
|
let p1 = sendRaw(message, groupID, "RM_MEMBERS", false, note)
|
||||||
@ -788,7 +800,7 @@
|
|||||||
const revokeKey = messenger.revokeKey = function(groupID) {
|
const revokeKey = messenger.revokeKey = function(groupID) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let groupInfo = _loaded.groups[groupID]
|
let groupInfo = _loaded.groups[groupID]
|
||||||
if (myFloID !== groupInfo.admin)
|
if (user.id !== groupInfo.admin)
|
||||||
return reject("Access denied: Admin only!")
|
return reject("Access denied: Admin only!")
|
||||||
let newKey = floCrypto.randString(16, false);
|
let newKey = floCrypto.randString(16, false);
|
||||||
Promise.all(groupInfo.members.map(m => sendRaw(JSON.stringify({
|
Promise.all(groupInfo.members.map(m => sendRaw(JSON.stringify({
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user