UNPKG

@towns-protocol/sdk

Version:

For more details, visit the following resources:

56 lines 2.12 kB
import { Observable } from '../../observable/observable'; const EMPTY_TIMELINE = []; const EMPTY_RECORD = {}; export class MessageTimeline { streamId; userId; riverConnection; events = new Observable(EMPTY_TIMELINE); threads = new Observable(EMPTY_RECORD); threadsStats = new Observable(EMPTY_RECORD); reactions = new Observable(EMPTY_RECORD); tips = new Observable(EMPTY_RECORD); unsubFn; // TODO: figure out a better way to do online check // lastestEventByUser = new TimelineEvents() // TODO: we probably wont need this for a while filterFn = (_event, _kind) => { return true; }; constructor(streamId, userId, riverConnection) { this.streamId = streamId; this.userId = userId; this.riverConnection = riverConnection; // } initialize(stream) { this.reset(); this.unsubFn = stream.view.streamsView.timelinesView.subscribe((state) => { this.events.setValue(state.timelines[this.streamId] ?? EMPTY_TIMELINE); this.threads.setValue(state.threads[this.streamId] ?? EMPTY_RECORD); this.threadsStats.setValue(state.threadsStats[this.streamId] ?? EMPTY_RECORD); this.reactions.setValue(state.reactions[this.streamId] ?? EMPTY_RECORD); this.tips.setValue(state.tips[this.streamId] ?? EMPTY_RECORD); }, { fireImediately: true }); } async scrollback() { return this.riverConnection.callWithStream(this.streamId, async (client) => { return client .scrollback(this.streamId) .then(({ terminus, fromInclusiveMiniblockNum }) => ({ terminus, fromInclusiveMiniblockNum, })); }); } reset() { this.unsubFn?.(); this.unsubFn = undefined; this.events.setValue(EMPTY_TIMELINE); this.threads.setValue(EMPTY_RECORD); this.threadsStats.setValue(EMPTY_RECORD); this.reactions.setValue(EMPTY_RECORD); this.tips.setValue(EMPTY_RECORD); } } //# sourceMappingURL=timeline.js.map