/// <summary> /// ストリームエレメントを処理します。 /// </summary> /// <param name="info">ストリームエレメントを受信したアカウント</param> /// <param name="elem">ストリームエレメント</param> private static void RegisterStreamElement(AccountInfo info, StreamingEvent elem) { switch (elem.Kind) { case ElementKind.Status: case ElementKind.DirectMessage: // 通常ステータスを受信した TweetStorage.Register(elem.Status); break; case ElementKind.Favorite: var avm = TweetStorage.Register(elem.Status); if (avm == null) return; var uavm = UserStorage.Get(elem.SourceUser); if (avm.RegisterFavored(uavm)) EventStorage.OnFavored(avm, uavm); break; case ElementKind.Unfavorite: var rvm = TweetStorage.Register(elem.Status); if (rvm == null) return; var urvm = UserStorage.Get(elem.SourceUser); if (rvm.RemoveFavored(urvm)) EventStorage.OnUnfavored(rvm, urvm); break; case ElementKind.Delete: TweetStorage.Remove(elem.DeletedStatusId); break; /* * TODO:Implements later? case ElementKind.ListUpdated: break; case ElementKind.ListMemberAdded: if (ListStorage.IsListMemberCached(elem.TargetList.User.ScreenName, elem.TargetList.Name)) { var members = ListStorage.GetListMembers(elem.TargetList.User.ScreenName, elem.TargetList.Name); } break; case ElementKind.ListMemberRemoved: case ElementKind.ListSubscribed: case ElementKind.ListUnsubscribed: // TODO: do something break; */ case ElementKind.Follow: case ElementKind.Unfollow: var affect = AccountStorage.Get(elem.SourceUser.ScreenName); var effect = AccountStorage.Get(elem.TargetUser.ScreenName); if (affect != null) { // Add/Remove followings if (elem.Kind == ElementKind.Follow) affect.RegisterFollowing(elem.TargetUser.NumericId); else affect.RemoveFollowing(elem.TargetUser.NumericId); } if (effect != null) { // Add/Remove followers if (elem.Kind == ElementKind.Follow) effect.RegisterFollower(elem.SourceUser.NumericId); else effect.RemoveFollower(elem.SourceUser.NumericId); } if (elem.Kind == ElementKind.Follow) EventStorage.OnFollowed(UserStorage.Get(elem.SourceUser), UserStorage.Get(elem.TargetUser)); else EventStorage.OnRemoved(UserStorage.Get(elem.SourceUser), UserStorage.Get(elem.TargetUser)); break; case ElementKind.Blocked: if (info == null) break; info.RemoveFollowing(elem.TargetUser.NumericId); info.RemoveFollower(elem.TargetUser.NumericId); info.RegisterBlocking(elem.TargetUser.NumericId); // TODO: notify events break; case ElementKind.Unblocked: if (info == null) break; info.RemoveBlocking(elem.TargetUser.NumericId); // TODO: Notify events break; default: System.Diagnostics.Debug.WriteLine("unknown:" + elem.ToString()); break; } }