Merge pull request #2659 from overleaf/em-binary-file-history-fix

Fix binary file diffs

GitOrigin-RevId: 1773e8918a0f82a1945470630ca691dfa4b13026
This commit is contained in:
Eric Mc Sween 2020-03-05 11:36:12 -05:00 committed by Copybot
parent 6379f15815
commit 58017d4480
2 changed files with 14 additions and 2 deletions

View file

@ -112,7 +112,12 @@ async function injectUserDetails(data) {
// service. v1 ids will be `numbers`
let userIds = new Set()
let v1UserIds = new Set()
for (const entry of data.diff || data.updates || []) {
const entries = Array.isArray(data.diff)
? data.diff
: Array.isArray(data.updates)
? data.updates
: []
for (const entry of entries) {
for (const user of (entry.meta && entry.meta.users) || []) {
if (typeof user === 'string') {
userIds.add(user)
@ -138,7 +143,7 @@ async function injectUserDetails(data) {
for (const user of v1IdentifiedUsersArray) {
users[user.overleaf.id] = _userView(user)
}
for (const entry of data.diff || data.updates || []) {
for (const entry of entries) {
if (entry.meta != null) {
entry.meta.users = ((entry.meta && entry.meta.users) || []).map(user => {
if (typeof user === 'string' || typeof user === 'number') {

View file

@ -195,6 +195,13 @@ describe('HistoryManager', function() {
expect(diff.diff[0].meta.users).to.deep.equal([this.user1_view])
expect(diff.diff[1].meta.users).to.deep.equal([this.user2_view])
})
it('should handle a binary diff marker', async function() {
const diff = await this.HistoryManager.promises.injectUserDetails({
diff: { binary: true }
})
expect(diff.diff.binary).to.be.true
})
})
describe('with a list of updates', function() {