return syncing user id from PendingEventEntry.sender

add User class where we later can track display name, avatar, ...
This commit is contained in:
Bruno Windels 2019-07-29 10:23:15 +02:00
parent b26f7df689
commit 56cee450d1
5 changed files with 24 additions and 5 deletions

View File

@ -45,7 +45,7 @@ export default class SessionViewModel extends EventEmitter {
}
this._currentRoomViewModel = new RoomViewModel({
room,
ownUserId: this._session.userId,
ownUserId: this._session.user.id,
closeCallback: () => this._closeCurrentRoom(),
});
this._currentRoomViewModel.load();

9
src/matrix/User.js Normal file
View File

@ -0,0 +1,9 @@
export default class User {
constructor(userId) {
this._userId = userId;
}
get id() {
return this._userId;
}
}

View File

@ -6,7 +6,7 @@ import FragmentIdComparer from "./timeline/FragmentIdComparer.js";
import SendQueue from "./sending/SendQueue.js";
export default class Room extends EventEmitter {
constructor({roomId, storage, hsApi, emitCollectionChange, sendScheduler, pendingEvents}) {
constructor({roomId, storage, hsApi, emitCollectionChange, sendScheduler, pendingEvents, user}) {
super();
this._roomId = roomId;
this._storage = storage;
@ -17,6 +17,7 @@ export default class Room extends EventEmitter {
this._emitCollectionChange = emitCollectionChange;
this._sendQueue = new SendQueue({roomId, storage, sendScheduler, pendingEvents});
this._timeline = null;
this._user = user;
}
async persistSync(roomResponse, membership, txn) {
@ -74,6 +75,7 @@ export default class Room extends EventEmitter {
fragmentIdComparer: this._fragmentIdComparer,
pendingEvents: this._sendQueue.pendingEvents,
closeCallback: () => this._timeline = null,
user: this._user,
});
await this._timeline.load();
return this._timeline;

View File

@ -1,9 +1,10 @@
import BaseEntry, {PENDING_FRAGMENT_ID} from "./BaseEntry.js";
export default class PendingEventEntry extends BaseEntry {
constructor(pendingEvent) {
constructor({pendingEvent, user}) {
super(null);
this._pendingEvent = pendingEvent;
this._user = user;
}
get fragmentId() {
@ -26,6 +27,10 @@ export default class PendingEventEntry extends BaseEntry {
return this._pendingEvent.eventType;
}
get sender() {
return this._user.id;
}
get id() {
return this._pendingEvent.txnId;
}

View File

@ -1,6 +1,7 @@
import Room from "./room/room.js";
import { ObservableMap } from "../observable/index.js";
import { SendScheduler, RateLimitingBackoff } from "./SendScheduler.js";
import User from "./User.js";
export default class Session {
// sessionInfo contains deviceId, userId and homeServer
@ -12,6 +13,7 @@ export default class Session {
this._rooms = new ObservableMap();
this._sendScheduler = new SendScheduler({hsApi, backoff: new RateLimitingBackoff()});
this._roomUpdateCallback = (room, params) => this._rooms.update(room.id, params);
this._user = new User(sessionInfo.userId);
}
async load() {
@ -69,6 +71,7 @@ export default class Session {
hsApi: this._hsApi,
sendScheduler: this._sendScheduler,
pendingEvents,
user: this._user,
});
this._rooms.add(roomId, room);
return room;
@ -85,7 +88,7 @@ export default class Session {
return this._session.syncToken;
}
get userId() {
return this._sessionInfo.userId;
get user() {
return this._user;
}
}