mirror of
https://github.com/coracle-social/coracle.git
synced 2024-09-19 11:43:35 +00:00
Migrate user data from old version of coracle
This commit is contained in:
parent
7a85323b8f
commit
5138f14e00
@ -14,7 +14,7 @@
|
|||||||
import {timedelta, shuffle, now, sleep} from "src/util/misc"
|
import {timedelta, shuffle, now, sleep} from "src/util/misc"
|
||||||
import {displayPerson, isLike} from "src/util/nostr"
|
import {displayPerson, isLike} from "src/util/nostr"
|
||||||
import cmd from "src/agent/cmd"
|
import cmd from "src/agent/cmd"
|
||||||
import {onReady, relays} from "src/agent/tables"
|
import {onReady, relays, people} from "src/agent/tables"
|
||||||
import keys from "src/agent/keys"
|
import keys from "src/agent/keys"
|
||||||
import network from "src/agent/network"
|
import network from "src/agent/network"
|
||||||
import pool from "src/agent/pool"
|
import pool from "src/agent/pool"
|
||||||
@ -120,8 +120,19 @@
|
|||||||
|
|
||||||
initializeRelayList()
|
initializeRelayList()
|
||||||
|
|
||||||
if (user.getProfile()) {
|
const pubkey = user.getPubkey()
|
||||||
loadAppData(user.getPubkey())
|
|
||||||
|
if (pubkey) {
|
||||||
|
loadAppData(pubkey)
|
||||||
|
|
||||||
|
const person = people.get(pubkey)
|
||||||
|
|
||||||
|
// Temporary migration for version 0.2.18. We changed where user profile
|
||||||
|
// is stored, so if they appear to have an incomplete profile on page load,
|
||||||
|
// go ahead and copy the person record over.
|
||||||
|
if (person && user.getRelays().length === 0) {
|
||||||
|
user.profile.update($p => ({...$p, ...person}))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const interval = setInterval(async () => {
|
const interval = setInterval(async () => {
|
||||||
|
@ -13,7 +13,7 @@ import {
|
|||||||
hash,
|
hash,
|
||||||
} from "src/util/misc"
|
} from "src/util/misc"
|
||||||
import {Tags, roomAttrs, isRelay, isShareableRelay, normalizeRelayUrl} from "src/util/nostr"
|
import {Tags, roomAttrs, isRelay, isShareableRelay, normalizeRelayUrl} from "src/util/nostr"
|
||||||
import {people, userEvents, relays, rooms, routes} from "src/agent/tables"
|
import {people, relays, rooms, routes} from "src/agent/tables"
|
||||||
import {uniqByUrl} from "src/agent/relays"
|
import {uniqByUrl} from "src/agent/relays"
|
||||||
import user from "src/agent/user"
|
import user from "src/agent/user"
|
||||||
|
|
||||||
@ -25,15 +25,10 @@ const addHandler = (kind, f) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const processEvents = async events => {
|
const processEvents = async events => {
|
||||||
const userPubkey = user.getPubkey()
|
|
||||||
const chunks = chunk(100, ensurePlural(events).filter(identity))
|
const chunks = chunk(100, ensurePlural(events).filter(identity))
|
||||||
|
|
||||||
for (let i = 0; i < chunks.length; i++) {
|
for (let i = 0; i < chunks.length; i++) {
|
||||||
for (const event of chunks[i]) {
|
for (const event of chunks[i]) {
|
||||||
if (event.pubkey === userPubkey) {
|
|
||||||
userEvents.put(event)
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const handler of handlers[event.kind] || []) {
|
for (const handler of handlers[event.kind] || []) {
|
||||||
handler(event)
|
handler(event)
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,8 @@ import {pluck, all, identity} from "ramda"
|
|||||||
import {derived} from "svelte/store"
|
import {derived} from "svelte/store"
|
||||||
import {Table, listener, registry} from "src/agent/storage"
|
import {Table, listener, registry} from "src/agent/storage"
|
||||||
|
|
||||||
export const userEvents = new Table("userEvents", "id")
|
// Temporarily put no upper bound on people for 0.2.18 migration
|
||||||
export const people = new Table("people", "pubkey")
|
export const people = new Table("people", "pubkey", {maxEntries: 100000})
|
||||||
export const contacts = new Table("contacts", "pubkey")
|
export const contacts = new Table("contacts", "pubkey")
|
||||||
export const rooms = new Table("rooms", "id")
|
export const rooms = new Table("rooms", "id")
|
||||||
export const alerts = new Table("alerts", "id")
|
export const alerts = new Table("alerts", "id")
|
||||||
|
@ -3,7 +3,7 @@ import {max, find, pluck, propEq, partition, uniq} from "ramda"
|
|||||||
import {derived} from "svelte/store"
|
import {derived} from "svelte/store"
|
||||||
import {createMap} from "hurdak/lib/hurdak"
|
import {createMap} from "hurdak/lib/hurdak"
|
||||||
import {synced, tryJson, now, timedelta} from "src/util/misc"
|
import {synced, tryJson, now, timedelta} from "src/util/misc"
|
||||||
import {Tags, userKinds, isAlert, asDisplayEvent, findReplyId} from "src/util/nostr"
|
import {Tags, isAlert, asDisplayEvent, findReplyId} from "src/util/nostr"
|
||||||
import {getUserReadRelays} from "src/agent/relays"
|
import {getUserReadRelays} from "src/agent/relays"
|
||||||
import {alerts, contacts, rooms} from "src/agent/tables"
|
import {alerts, contacts, rooms} from "src/agent/tables"
|
||||||
import {watch} from "src/agent/storage"
|
import {watch} from "src/agent/storage"
|
||||||
@ -173,7 +173,6 @@ const listen = async pubkey => {
|
|||||||
delay: 10000,
|
delay: 10000,
|
||||||
relays: getUserReadRelays(),
|
relays: getUserReadRelays(),
|
||||||
filter: [
|
filter: [
|
||||||
{kinds: userKinds, authors: [pubkey], since},
|
|
||||||
{kinds: [4], authors: [pubkey], since},
|
{kinds: [4], authors: [pubkey], since},
|
||||||
{kinds: [1, 7, 4, 9735], "#p": [pubkey], since},
|
{kinds: [1, 7, 4, 9735], "#p": [pubkey], since},
|
||||||
{kinds: [42], "#e": roomIds, since},
|
{kinds: [42], "#e": roomIds, since},
|
||||||
|
@ -16,7 +16,8 @@ export const loadAppData = async pubkey => {
|
|||||||
// Start our listener, but don't wait for it
|
// Start our listener, but don't wait for it
|
||||||
alerts.listen(pubkey)
|
alerts.listen(pubkey)
|
||||||
|
|
||||||
// Make sure the user's network is loaded
|
// Make sure the user and their network is loaded
|
||||||
|
await network.loadPeople([pubkey], {force: true})
|
||||||
await network.loadPeople(getUserFollows())
|
await network.loadPeople(getUserFollows())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user