public StatusViewModel(TimelineViewModelBase parent, StatusModel status,
IEnumerable<long> initialBoundAccounts)
{
_parent = parent;
// get status model
Model = status;
RetweetedOriginalModel = status.RetweetedOriginal;
// bind accounts
_bindingAccounts = initialBoundAccounts.Guard().ToArray();
// initialize users information
CompositeDisposable.Add(
_favoritedUsers = ViewModelHelperRx.CreateReadOnlyDispatcherCollectionRx(
Model.FavoritedUsers, user => new UserViewModel(user),
DispatcherHelper.UIDispatcher, DispatcherPriority.Background));
CompositeDisposable.Add(
_favoritedUsers.ListenCollectionChanged(_ =>
{
RaisePropertyChanged(() => IsFavorited);
RaisePropertyChanged(() => IsFavoritedUserExists);
RaisePropertyChanged(() => FavoriteCount);
}));
CompositeDisposable.Add(
_retweetedUsers = ViewModelHelperRx.CreateReadOnlyDispatcherCollectionRx(
Model.RetweetedUsers, user => new UserViewModel(user),
DispatcherHelper.UIDispatcher, DispatcherPriority.Background));
CompositeDisposable.Add(
_retweetedUsers.ListenCollectionChanged(_ =>
{
RaisePropertyChanged(() => IsRetweeted);
RaisePropertyChanged(() => IsRetweetedUserExists);
RaisePropertyChanged(() => RetweetCount);
}));
if (RetweetedOriginalModel != null)
{
CompositeDisposable.Add(
RetweetedOriginalModel.FavoritedUsers.ListenCollectionChanged(
_ => RaisePropertyChanged(() => IsFavorited)));
CompositeDisposable.Add(
RetweetedOriginalModel.RetweetedUsers.ListenCollectionChanged(
_ => RaisePropertyChanged(() => IsRetweeted)));
}
// listen settings
CompositeDisposable.Add(
new EventListener<Action<bool>>(
h => Setting.AllowFavoriteMyself.ValueChanged += h,
h => Setting.AllowFavoriteMyself.ValueChanged -= h,
_ => RaisePropertyChanged(() => CanFavorite)));
CompositeDisposable.Add(
new EventListener<Action<ThumbnailMode>>(
h => Setting.ThumbnailMode.ValueChanged += h,
h => Setting.ThumbnailMode.ValueChanged -= h,
_ =>
{
RaisePropertyChanged(() => IsThumbnailAvailable);
RaisePropertyChanged(() => IsThumbnailsAvailable);
}));
CompositeDisposable.Add(
new EventListener<Action<TweetDisplayMode>>(
h => Setting.TweetDisplayMode.ValueChanged += h,
h => Setting.TweetDisplayMode.ValueChanged -= h,
_ =>
{
RaisePropertyChanged(() => IsExpanded);
RaisePropertyChanged(() => IsSingleLine);
}));
// when account is added/removed, all timelines are regenerated.
// so, we don't have to listen any events which notify accounts addition/deletion.
CompositeDisposable.Add(_images = ViewModelHelperRx.CreateReadOnlyDispatcherCollectionRx(
Model.Images, m => new ThumbnailImageViewModel(m), DispatcherHelper.UIDispatcher));
// resolve images
CompositeDisposable.Add(_images.ListenCollectionChanged(_ =>
{
RaisePropertyChanged(() => ThumbnailImage);
RaisePropertyChanged(() => IsImageAvailable);
RaisePropertyChanged(() => IsThumbnailAvailable);
RaisePropertyChanged(() => IsThumbnailsAvailable);
}));
// look-up in-reply-to
_isInReplyToExists = Status.InReplyToStatusId.HasValue && Status.InReplyToStatusId != 0;
}