@automerge/automerge-repo-react-hooks 2.5.2-alpha.3 → 2.5.2-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -6758,7 +6758,7 @@ class PeerStateView {
6758
6758
  getLastSeenPeer(peers) {
6759
6759
  let freshestLastSeenAt;
6760
6760
  return peers.reduce((freshest, curr) => {
6761
- const lastSeenAt = this.value[curr]?.lastActiveAt;
6761
+ const lastSeenAt = this.value[curr]?.lastSeenAt;
6762
6762
  if (!lastSeenAt) {
6763
6763
  return freshest;
6764
6764
  }
@@ -6852,7 +6852,8 @@ class PeerPresenceInfo {
6852
6852
  ...this.#peerStates.value,
6853
6853
  [peerId]: {
6854
6854
  ...this.#peerStates.value[peerId],
6855
- lastSeen: Date.now(),
6855
+ peerId,
6856
+ lastSeenAt: Date.now(),
6856
6857
  },
6857
6858
  });
6858
6859
  }
@@ -6874,7 +6875,7 @@ class PeerPresenceInfo {
6874
6875
  deviceId,
6875
6876
  userId,
6876
6877
  lastActiveAt: now,
6877
- lastUpdateAt: now,
6878
+ lastSeenAt: now,
6878
6879
  value: {
6879
6880
  ...existingState,
6880
6881
  ...value,
@@ -6898,8 +6899,8 @@ class PeerPresenceInfo {
6898
6899
  */
6899
6900
  prune() {
6900
6901
  const threshold = Date.now() - this.ttl;
6901
- this.#peerStates = new PeerStateView(Object.fromEntries(Object.entries(this.#peerStates).filter(([, state]) => {
6902
- return state.lastActiveAt >= threshold;
6902
+ this.#peerStates = new PeerStateView(Object.fromEntries(Object.entries(this.#peerStates.value).filter(([, state]) => {
6903
+ return state.lastSeenAt >= threshold;
6903
6904
  })));
6904
6905
  }
6905
6906
  /**
@@ -7184,12 +7185,18 @@ function usePresence({
7184
7185
  presence.stop();
7185
7186
  };
7186
7187
  }, [presence, userId, deviceId, firstInitialState, firstOpts]);
7187
- const start = useCallback(() => {
7188
- presence.start({
7189
- initialState: presence.getLocalState(),
7190
- ...firstOpts.current
7191
- });
7192
- }, [presence, firstOpts]);
7188
+ const start = useCallback(
7189
+ (config) => {
7190
+ const initialState2 = config?.initialState ?? presence.getLocalState();
7191
+ const opts = {
7192
+ ...firstOpts.current,
7193
+ ...config,
7194
+ initialState: initialState2
7195
+ };
7196
+ presence.start(opts);
7197
+ },
7198
+ [presence, firstOpts]
7199
+ );
7193
7200
  const stop = useCallback(() => {
7194
7201
  presence.stop();
7195
7202
  }, [presence]);