|
|
@ -153,12 +153,14 @@ function replayChatHistory(chat, contact) { |
|
|
|
if (!(chat && chat.id && contact && contact.id)) { |
|
|
|
return console.log('[tribes] cant replay history'); |
|
|
|
} |
|
|
|
console.log('network.typesToReplay', network.typesToReplay); |
|
|
|
const msgs = yield models_1.models.Message.findAll({ |
|
|
|
where: { chatId: chat.id, type: { [sequelize_1.Op.in]: network.typesToReplay } }, |
|
|
|
order: [['id', 'desc']], |
|
|
|
limit: 40 |
|
|
|
}); |
|
|
|
msgs.reverse(); |
|
|
|
console.log('msgs.length', msgs.length); |
|
|
|
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } }); |
|
|
|
asyncForEach(msgs, (m) => __awaiter(this, void 0, void 0, function* () { |
|
|
|
if (!network.typesToReplay.includes(m.type)) |
|
|
@ -175,12 +177,15 @@ function replayChatHistory(chat, contact) { |
|
|
|
if (m.type === constants.message_types.attachment) { |
|
|
|
if (m.mediaKey && m.mediaToken) { |
|
|
|
const muid = m.mediaToken.split('.').length && m.mediaToken.split('.')[1]; |
|
|
|
const mediaKey = yield models_1.models.MediaKey.findOne({ where: { |
|
|
|
muid, chatId: chat.id, |
|
|
|
} }); |
|
|
|
// console.log("FOUND MEDIA KEY!!",mediaKey.dataValues)
|
|
|
|
mediaKeyMap = { chat: mediaKey.key }; |
|
|
|
newMediaTerms = { muid: mediaKey.muid }; |
|
|
|
console.log('muid', muid); |
|
|
|
if (muid) { |
|
|
|
const mediaKey = yield models_1.models.MediaKey.findOne({ where: { |
|
|
|
muid, chatId: chat.id, |
|
|
|
} }); |
|
|
|
// console.log("FOUND MEDIA KEY!!",mediaKey.dataValues)
|
|
|
|
mediaKeyMap = { chat: mediaKey.key }; |
|
|
|
newMediaTerms = { muid: mediaKey.muid }; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
let msg = network.newmsg(m.type, chat, sender, Object.assign(Object.assign(Object.assign(Object.assign({ content }, mediaKeyMap && { mediaKey: mediaKeyMap }), newMediaTerms && { mediaToken: newMediaTerms }), m.mediaType && { mediaType: m.mediaType }), dateString && { date: dateString })); |
|
|
|