userEvents method
Implementation
Future<Stream<UserEvents>> userEvents(
UserId id,
Future<UserVersion?> Function() ver,
) async {
Log.debug('userEvents($id)', '$runtimeType');
final Stream events = await _graphQlProvider.userEvents(id, ver);
return events.asyncExpand((event) async* {
Log.trace('userEvents($id): ${event.data}', '$runtimeType');
final events = UserEvents$Subscription.fromJson(event.data!).userEvents;
if (events.$$typename == 'SubscriptionInitialized') {
events as UserEvents$Subscription$UserEvents$SubscriptionInitialized;
yield const UserEventsInitialized();
} else if (events.$$typename == 'User') {
final mixin = events as UserEvents$Subscription$UserEvents$User;
yield UserEventsUser(mixin.toDto());
} else if (events.$$typename == 'UserEventsVersioned') {
final mixin = events as UserEventsVersionedMixin;
yield UserEventsEvent(
UserEventsVersioned(
mixin.events.map((e) => _userEvent(e)).toList(),
mixin.ver,
),
);
} else if (events.$$typename == 'BlocklistEventsVersioned') {
final mixin = events as BlocklistEventsVersionedMixin;
yield UserEventsBlocklistEventsEvent(
BlocklistEventsVersioned(
mixin.events.map((e) => _blocklistEvent(e)).toList(),
mixin.blocklistVer,
),
);
} else if (events.$$typename == 'isBlocked') {
final node = events as UserEvents$Subscription$UserEvents$IsBlocked;
yield UserEventsIsBlocked(
node.record == null
? null
: BlocklistRecord(
userId: id,
reason: node.record!.reason,
at: node.record!.at,
),
node.myVer,
);
}
});
}