2018-01-19 04:25:34 +00:00
|
|
|
// Merge two lists of statuses for the same timeline, e.g. one from IDB
|
|
|
|
// and another from the network. In case of duplicates, prefer the fresh.
|
2018-01-24 02:15:14 +00:00
|
|
|
export function mergeStatuses(leftStatusIds, rightStatusIds) {
|
2018-01-19 04:25:34 +00:00
|
|
|
let leftIndex = 0
|
|
|
|
let rightIndex = 0
|
|
|
|
let merged = []
|
2018-01-24 02:15:14 +00:00
|
|
|
while (leftIndex < leftStatusIds.length || rightIndex < rightStatusIds.length) {
|
|
|
|
if (leftIndex === leftStatusIds.length) {
|
|
|
|
merged.push(rightStatusIds[rightIndex])
|
2018-01-19 04:25:34 +00:00
|
|
|
rightIndex++
|
|
|
|
continue
|
|
|
|
}
|
2018-01-24 02:15:14 +00:00
|
|
|
if (rightIndex === rightStatusIds.length) {
|
|
|
|
merged.push(leftStatusIds[leftIndex])
|
2018-01-19 04:25:34 +00:00
|
|
|
leftIndex++
|
|
|
|
continue
|
|
|
|
}
|
2018-01-24 02:15:14 +00:00
|
|
|
let left = leftStatusIds[leftIndex]
|
|
|
|
let right = rightStatusIds[rightIndex]
|
|
|
|
if (right === left) {
|
2018-01-19 04:25:34 +00:00
|
|
|
rightIndex++
|
|
|
|
leftIndex++
|
2018-01-24 02:15:14 +00:00
|
|
|
} else if (parseInt(right, 10) > parseInt(left, 10)) {
|
2018-01-19 04:25:34 +00:00
|
|
|
merged.push(right)
|
|
|
|
rightIndex++
|
|
|
|
} else {
|
|
|
|
merged.push(left)
|
|
|
|
leftIndex++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return merged
|
|
|
|
}
|