- synchronized (posts) {
- if (!soneRescueMode) {
- for (Post post : storedSone.getPosts()) {
- posts.remove(post.getId());
- if (!sone.getPosts().contains(post)) {
- eventBus.post(new PostRemovedEvent(post));
- }
- }
- }
- List<Post> storedPosts = storedSone.getPosts();
- synchronized (knownPosts) {
- for (Post post : sone.getPosts()) {
- PostBuilder postBuilder = postBuilderFactory.newPostBuilder();
- postBuilder.copyPost(post).from(storedSone);
- Post newPost = postBuilder.build().setKnown(knownPosts.contains(post.getId()));
- if (!storedPosts.contains(newPost)) {
- if (newPost.getTime() < getSoneFollowingTime(sone)) {
- knownPosts.add(newPost.getId());
- newPost.setKnown(true);
- } else if (!knownPosts.contains(newPost.getId())) {
- eventBus.post(new NewPostFoundEvent(newPost));
- }
- }
- posts.put(newPost.getId(), newPost);
- }
- }
- }
- synchronized (replies) {
- if (!soneRescueMode) {
- for (PostReply reply : storedSone.getReplies()) {
- replies.remove(reply.getId());
- if (!sone.getReplies().contains(reply)) {
- eventBus.post(new PostReplyRemovedEvent(reply));
- }
+ /* find removed posts. */
+ SoneChangeDetector soneChangeDetector = new SoneChangeDetector(storedSone.get());
+ soneChangeDetector.onNewPosts(new PostProcessor() {
+ @Override
+ public void processPost(Post post) {
+ if (post.getTime() < getSoneFollowingTime(sone)) {
+ post.setKnown(true);
+ } else if (!post.isKnown()) {
+ eventBus.post(new NewPostFoundEvent(post));