forked from mystiq/hydrogen-web
return syncing user id from PendingEventEntry.sender
add User class where we later can track display name, avatar, ...
This commit is contained in:
parent
b26f7df689
commit
56cee450d1
5 changed files with 24 additions and 5 deletions
|
@ -45,7 +45,7 @@ export default class SessionViewModel extends EventEmitter {
|
||||||
}
|
}
|
||||||
this._currentRoomViewModel = new RoomViewModel({
|
this._currentRoomViewModel = new RoomViewModel({
|
||||||
room,
|
room,
|
||||||
ownUserId: this._session.userId,
|
ownUserId: this._session.user.id,
|
||||||
closeCallback: () => this._closeCurrentRoom(),
|
closeCallback: () => this._closeCurrentRoom(),
|
||||||
});
|
});
|
||||||
this._currentRoomViewModel.load();
|
this._currentRoomViewModel.load();
|
||||||
|
|
9
src/matrix/User.js
Normal file
9
src/matrix/User.js
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
export default class User {
|
||||||
|
constructor(userId) {
|
||||||
|
this._userId = userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
get id() {
|
||||||
|
return this._userId;
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,7 +6,7 @@ import FragmentIdComparer from "./timeline/FragmentIdComparer.js";
|
||||||
import SendQueue from "./sending/SendQueue.js";
|
import SendQueue from "./sending/SendQueue.js";
|
||||||
|
|
||||||
export default class Room extends EventEmitter {
|
export default class Room extends EventEmitter {
|
||||||
constructor({roomId, storage, hsApi, emitCollectionChange, sendScheduler, pendingEvents}) {
|
constructor({roomId, storage, hsApi, emitCollectionChange, sendScheduler, pendingEvents, user}) {
|
||||||
super();
|
super();
|
||||||
this._roomId = roomId;
|
this._roomId = roomId;
|
||||||
this._storage = storage;
|
this._storage = storage;
|
||||||
|
@ -17,6 +17,7 @@ export default class Room extends EventEmitter {
|
||||||
this._emitCollectionChange = emitCollectionChange;
|
this._emitCollectionChange = emitCollectionChange;
|
||||||
this._sendQueue = new SendQueue({roomId, storage, sendScheduler, pendingEvents});
|
this._sendQueue = new SendQueue({roomId, storage, sendScheduler, pendingEvents});
|
||||||
this._timeline = null;
|
this._timeline = null;
|
||||||
|
this._user = user;
|
||||||
}
|
}
|
||||||
|
|
||||||
async persistSync(roomResponse, membership, txn) {
|
async persistSync(roomResponse, membership, txn) {
|
||||||
|
@ -74,6 +75,7 @@ export default class Room extends EventEmitter {
|
||||||
fragmentIdComparer: this._fragmentIdComparer,
|
fragmentIdComparer: this._fragmentIdComparer,
|
||||||
pendingEvents: this._sendQueue.pendingEvents,
|
pendingEvents: this._sendQueue.pendingEvents,
|
||||||
closeCallback: () => this._timeline = null,
|
closeCallback: () => this._timeline = null,
|
||||||
|
user: this._user,
|
||||||
});
|
});
|
||||||
await this._timeline.load();
|
await this._timeline.load();
|
||||||
return this._timeline;
|
return this._timeline;
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
import BaseEntry, {PENDING_FRAGMENT_ID} from "./BaseEntry.js";
|
import BaseEntry, {PENDING_FRAGMENT_ID} from "./BaseEntry.js";
|
||||||
|
|
||||||
export default class PendingEventEntry extends BaseEntry {
|
export default class PendingEventEntry extends BaseEntry {
|
||||||
constructor(pendingEvent) {
|
constructor({pendingEvent, user}) {
|
||||||
super(null);
|
super(null);
|
||||||
this._pendingEvent = pendingEvent;
|
this._pendingEvent = pendingEvent;
|
||||||
|
this._user = user;
|
||||||
}
|
}
|
||||||
|
|
||||||
get fragmentId() {
|
get fragmentId() {
|
||||||
|
@ -26,6 +27,10 @@ export default class PendingEventEntry extends BaseEntry {
|
||||||
return this._pendingEvent.eventType;
|
return this._pendingEvent.eventType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get sender() {
|
||||||
|
return this._user.id;
|
||||||
|
}
|
||||||
|
|
||||||
get id() {
|
get id() {
|
||||||
return this._pendingEvent.txnId;
|
return this._pendingEvent.txnId;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import Room from "./room/room.js";
|
import Room from "./room/room.js";
|
||||||
import { ObservableMap } from "../observable/index.js";
|
import { ObservableMap } from "../observable/index.js";
|
||||||
import { SendScheduler, RateLimitingBackoff } from "./SendScheduler.js";
|
import { SendScheduler, RateLimitingBackoff } from "./SendScheduler.js";
|
||||||
|
import User from "./User.js";
|
||||||
|
|
||||||
export default class Session {
|
export default class Session {
|
||||||
// sessionInfo contains deviceId, userId and homeServer
|
// sessionInfo contains deviceId, userId and homeServer
|
||||||
|
@ -12,6 +13,7 @@ export default class Session {
|
||||||
this._rooms = new ObservableMap();
|
this._rooms = new ObservableMap();
|
||||||
this._sendScheduler = new SendScheduler({hsApi, backoff: new RateLimitingBackoff()});
|
this._sendScheduler = new SendScheduler({hsApi, backoff: new RateLimitingBackoff()});
|
||||||
this._roomUpdateCallback = (room, params) => this._rooms.update(room.id, params);
|
this._roomUpdateCallback = (room, params) => this._rooms.update(room.id, params);
|
||||||
|
this._user = new User(sessionInfo.userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
async load() {
|
async load() {
|
||||||
|
@ -69,6 +71,7 @@ export default class Session {
|
||||||
hsApi: this._hsApi,
|
hsApi: this._hsApi,
|
||||||
sendScheduler: this._sendScheduler,
|
sendScheduler: this._sendScheduler,
|
||||||
pendingEvents,
|
pendingEvents,
|
||||||
|
user: this._user,
|
||||||
});
|
});
|
||||||
this._rooms.add(roomId, room);
|
this._rooms.add(roomId, room);
|
||||||
return room;
|
return room;
|
||||||
|
@ -85,7 +88,7 @@ export default class Session {
|
||||||
return this._session.syncToken;
|
return this._session.syncToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
get userId() {
|
get user() {
|
||||||
return this._sessionInfo.userId;
|
return this._user;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue