Browse Source

replay msg, group join/leave types, parse out correnctly

feature/dockerfile-arm
Evan Feenstra 5 years ago
parent
commit
d834d38e61
  1. 4
      api/controllers/chatTribes.ts
  2. 8
      api/controllers/chats.ts
  3. 3
      api/network/index.ts
  4. 7
      api/network/receive.ts
  5. 2
      dist/api/controllers/chatTribes.js
  6. 2
      dist/api/controllers/chatTribes.js.map
  7. 4
      dist/api/controllers/chats.js
  8. 2
      dist/api/controllers/chats.js.map
  9. 1
      dist/api/network/index.js
  10. 2
      dist/api/network/index.js.map
  11. 7
      dist/api/network/receive.js
  12. 2
      dist/api/network/receive.js.map

4
api/controllers/chatTribes.ts

@ -156,7 +156,7 @@ async function replayChatHistory(chat, contact) {
})
const owner = await models.Contact.findOne({ where: { isOwner: true } })
asyncForEach(msgs, async m=>{
if(m.type!==constants.message_types.message) return // only for message for now
if(!network.typesToReplay.includes(m.type)) return // only for message for now
const sender = {
...owner.dataValues,
...m.senderAlias && {alias: m.senderAlias},
@ -165,7 +165,7 @@ async function replayChatHistory(chat, contact) {
try {content = JSON.parse(m.remoteMessageContent)} catch(e) {}
if(!content) return
let msg = network.newmsg(m.type, chat, sender, {
content, // replace with the remoteMessageContent (u are owner)
content, // replaced with the remoteMessageContent (u are owner) {}
...m.mediaKey && {mediaKey: m.mediaKey},
...m.mediaType && {mediaType: m.mediaType},
...m.mediaToken && {mediaToken: m.mediaToken}

8
api/controllers/chats.ts

@ -259,8 +259,8 @@ async function receiveGroupJoin(payload) {
type: constants.message_types.group_join,
sender: (theSender && theSender.id) || 0,
date: date,
messageContent: `${senderAlias} has joined the group`,
remoteMessageContent: '',
messageContent:'',//`${senderAlias} has joined the group`,
remoteMessageContent:'',
status: constants.statuses.confirmed,
createdAt: date,
updatedAt: date
@ -314,8 +314,8 @@ async function receiveGroupLeave(payload) {
type: constants.message_types.group_leave,
sender: (sender && sender.id) || 0,
date: date,
messageContent: `${sender_alias} has left the group`,
remoteMessageContent: '',
messageContent:'', //`${sender_alias} has left the group`,
remoteMessageContent:'',
status: constants.statuses.confirmed,
createdAt: date,
updatedAt: date

3
api/network/index.ts

@ -1,5 +1,5 @@
import {sendMessage,signAndSend,newmsg} from './send'
import {initGrpcSubscriptions,initTribesSubscriptions,parseKeysendInvoice} from './receive'
import {initGrpcSubscriptions,initTribesSubscriptions,parseKeysendInvoice,typesToReplay} from './receive'
/*
Abstracts between lightning network and MQTT depending on Chat type and sender
@ -10,5 +10,6 @@ export {
initGrpcSubscriptions,
initTribesSubscriptions,
parseKeysendInvoice,
typesToReplay,
}

7
api/network/receive.ts

@ -21,6 +21,9 @@ const typesToModify=[
const typesThatNeedPricePerMessage = [
msgtypes.message, msgtypes.attachment
]
export const typesToReplay=[ // should match typesToForward
msgtypes.message, msgtypes.group_join, msgtypes.group_leave
]
async function onReceive(payload){
// if tribe, owner must forward to MQTT
let doAction = true
@ -58,12 +61,14 @@ async function doTheAction(data){
let payload = data
if(payload.isTribeOwner) {
const ogContent = data.message && data.message.content
// decrypt and re-encrypt with phone's pubkey for storage
// const ogMediaKey = data.message && data.message.mediaKey
/* decrypt and re-encrypt with phone's pubkey for storage */
const chat = await models.Chat.findOne({where:{uuid:payload.chat.uuid}})
const pld = await decryptMessage(data, chat)
const me = await models.Contact.findOne({where:{isOwner:true}})
payload = await encryptTribeBroadcast(pld, me, true) // true=isTribeOwner
if(ogContent) payload.message.remoteContent = JSON.stringify({'chat':ogContent}) // this is the key
//if(ogMediaKey) payload.message.remoteMediaKey = JSON.stringify({'chat':ogMediaKey})
}
if(ACTIONS[payload.type]) {
ACTIONS[payload.type](payload)

2
dist/api/controllers/chatTribes.js

@ -154,7 +154,7 @@ function replayChatHistory(chat, contact) {
});
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
asyncForEach(msgs, (m) => __awaiter(this, void 0, void 0, function* () {
if (m.type !== constants.message_types.message)
if (!network.typesToReplay.includes(m.type))
return; // only for message for now
const sender = Object.assign(Object.assign({}, owner.dataValues), m.senderAlias && { alias: m.senderAlias });
let content = '';

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

File diff suppressed because one or more lines are too long

4
dist/api/controllers/chats.js

@ -247,7 +247,7 @@ function receiveGroupJoin(payload) {
type: constants.message_types.group_join,
sender: (theSender && theSender.id) || 0,
date: date,
messageContent: `${senderAlias} has joined the group`,
messageContent: '',
remoteMessageContent: '',
status: constants.statuses.confirmed,
createdAt: date,
@ -300,7 +300,7 @@ function receiveGroupLeave(payload) {
type: constants.message_types.group_leave,
sender: (sender && sender.id) || 0,
date: date,
messageContent: `${sender_alias} has left the group`,
messageContent: '',
remoteMessageContent: '',
status: constants.statuses.confirmed,
createdAt: date,

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

File diff suppressed because one or more lines are too long

1
dist/api/network/index.js

@ -8,4 +8,5 @@ const receive_1 = require("./receive");
exports.initGrpcSubscriptions = receive_1.initGrpcSubscriptions;
exports.initTribesSubscriptions = receive_1.initTribesSubscriptions;
exports.parseKeysendInvoice = receive_1.parseKeysendInvoice;
exports.typesToReplay = receive_1.typesToReplay;
//# sourceMappingURL=index.js.map

2
dist/api/network/index.js.map

@ -1 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../api/network/index.ts"],"names":[],"mappings":";;AAAA,iCAAqD;AAQjD,sBARI,kBAAW,CAQJ;AAAC,sBARI,kBAAW,CAQJ;AAAC,iBARI,aAAM,CAQJ;AAPlC,uCAA2F;AAQvF,gCARI,+BAAqB,CAQJ;AACrB,kCAT0B,iCAAuB,CAS1B;AACvB,8BAVkD,6BAAmB,CAUlD"}
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../api/network/index.ts"],"names":[],"mappings":";;AAAA,iCAAqD;AAQjD,sBARI,kBAAW,CAQJ;AAAC,sBARI,kBAAW,CAQJ;AAAC,iBARI,aAAM,CAQJ;AAPlC,uCAAyG;AAQrG,gCARI,+BAAqB,CAQJ;AACrB,kCAT0B,iCAAuB,CAS1B;AACvB,8BAVkD,6BAAmB,CAUlD;AACnB,wBAXsE,uBAAa,CAWtE"}

7
dist/api/network/receive.js

@ -30,6 +30,9 @@ const typesToModify = [
const typesThatNeedPricePerMessage = [
msgtypes.message, msgtypes.attachment
];
exports.typesToReplay = [
msgtypes.message, msgtypes.group_join, msgtypes.group_leave
];
function onReceive(payload) {
return __awaiter(this, void 0, void 0, function* () {
// if tribe, owner must forward to MQTT
@ -75,13 +78,15 @@ function doTheAction(data) {
let payload = data;
if (payload.isTribeOwner) {
const ogContent = data.message && data.message.content;
// decrypt and re-encrypt with phone's pubkey for storage
// const ogMediaKey = data.message && data.message.mediaKey
/* decrypt and re-encrypt with phone's pubkey for storage */
const chat = yield models_1.models.Chat.findOne({ where: { uuid: payload.chat.uuid } });
const pld = yield msg_1.decryptMessage(data, chat);
const me = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
payload = yield msg_1.encryptTribeBroadcast(pld, me, true); // true=isTribeOwner
if (ogContent)
payload.message.remoteContent = JSON.stringify({ 'chat': ogContent }); // this is the key
//if(ogMediaKey) payload.message.remoteMediaKey = JSON.stringify({'chat':ogMediaKey})
}
if (controllers_1.ACTIONS[payload.type]) {
controllers_1.ACTIONS[payload.type](payload);

2
dist/api/network/receive.js.map

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