/** * Creates a new conversation thread. * * @param manifestThread data for the thread * @param parentBlip blip to which this thread is a reply (null for root) * @param helper provides conversation components */ static WaveletBasedConversationThread create(ObservableManifestThread manifestThread, WaveletBasedConversationBlip parentBlip, WaveletBasedConversation.ComponentHelper helper) { WaveletBasedConversationThread thread = new WaveletBasedConversationThread(manifestThread, parentBlip, helper); for (ObservableManifestBlip manifestBlip : manifestThread.getBlips()) { Blip blip = helper.getBlip(manifestBlip.getId()); if (blip != null) { thread.adaptBlip(manifestBlip, blip); } } manifestThread.addListener(thread); return thread; }
/** * Very basic test to see that we can create the object with a document and use it. */ public void testSimpleUsageWithDocument() { ObservableManifestThread thread = buildThreadElement( ConversationTestUtils.createManifestDocument(), "t1"); ManifestBlip blip = thread.appendBlip("b+1"); assertNotNull(blip); assertEquals("b+1", blip.getId()); assertFalse(thread.isInline()); }
@Override public WaveletBasedConversationBlip getFirstBlip() { WaveletBasedConversationBlip result = null; if (!blips.isEmpty()) { ObservableManifestBlip manifestBlip = manifestThread.getBlip(0); result = blips.get(manifestBlip.getId()); if (result == null) { // Very uncommon case: the first blip in the manifest doesn't have a // corresponding blip object. Fall back to iterating since iteration // handles this correctly. for (WaveletBasedConversationBlip firstBlip : getBlips()) { result = firstBlip; break; } } } return result; }
/** * Appends a blip. * * @param content optional content * @return new blip. */ private WaveletBasedConversationBlip appendBlipWithContent(DocInitialization content) { Blip blip = helper.createBlip(content); String blipId = blip.getId(); manifestThread.appendBlip(blipId); return blips.get(blipId); }
verify(thread).detachListeners();
@Override public WaveletBasedConversationBlip insertBlip(ConversationBlip successor) { checkIsUsable(); if (!blips.containsKey(successor.getId())) { Preconditions.illegalArgument( "Can't insert blip before blip " + successor + " not from this thread"); } WaveletBasedConversationBlip insertBefore = (WaveletBasedConversationBlip) successor; int index = manifestThread.indexOf(insertBefore.getManifestBlip()); Blip blip = helper.createBlip(null); String blipId = blip.getId(); manifestThread.insertBlip(index, blipId); return blips.get(blipId); }
@Override public String getId() { return (this == getConversation().getRootThread()) ? "" : manifestThread.getId(); }
@Override public Iterable<WaveletBasedConversationBlip> getBlips() { final Iterable<? extends ObservableManifestBlip> manifestBlips = manifestThread.getBlips(); return new Iterable<WaveletBasedConversationBlip>() { @Override public Iterator<WaveletBasedConversationBlip> iterator() { return WrapperIterator.create(manifestBlips.iterator(), blips); } }; }
/** * Very basic test to see that we can create the object with a document and use it. */ public void testSimpleUsageWithDocument() { ObservableManifestThread thread = buildThreadElement( ConversationTestUtils.createManifestDocument(), "t1"); ManifestBlip blip = thread.appendBlip("b+1"); assertNotNull(blip); assertEquals("b+1", blip.getId()); assertFalse(thread.isInline()); }
public void testObsoleteThreadThenRestoreRemoveBlipDoesntDie() { WaveletBasedConversationBlip first = target.getRootThread().appendBlip(); WaveletBasedConversationThread willBecomeEmpty = first.addReplyThread(); ConversationBlip toggleBlip = willBecomeEmpty.appendBlip(); String toggleBlipId = toggleBlip.getId(); // Make the thread empty by remotely removing its blip. ManifestBlip manifestRootBlip = target.getManifest().getRootThread().getBlip(0); ManifestThread manifestReply = manifestRootBlip.getReply(0); manifestReply.removeBlip(manifestReply.getBlip(0)); assertThreadValid(willBecomeEmpty); // Re-add then remove the blip, as can happen in playback. manifestReply.appendBlip(toggleBlipId); manifestReply.removeBlip(manifestReply.getBlip(0)); }
verify(thread).detachListeners();
@Override public void onReplyRemoved(final ObservableManifestThread thread) { forgetThread(replies.get(thread.getId())); }
public void testObsoleteThreadThenRestoreRemoveBlipDoesntDie() { WaveletBasedConversationBlip first = target.getRootThread().appendBlip(); WaveletBasedConversationThread willBecomeEmpty = first.addReplyThread(); ConversationBlip toggleBlip = willBecomeEmpty.appendBlip(); String toggleBlipId = toggleBlip.getId(); // Make the thread empty by remotely removing its blip. ManifestBlip manifestRootBlip = target.getManifest().getRootThread().getBlip(0); ManifestThread manifestReply = manifestRootBlip.getReply(0); manifestReply.removeBlip(manifestReply.getBlip(0)); assertThreadValid(willBecomeEmpty); // Re-add then remove the blip, as can happen in playback. manifestReply.appendBlip(toggleBlipId); manifestReply.removeBlip(manifestReply.getBlip(0)); }
public void testRemoveRestoreThreadAfterObsoleteThreadDoesntDie() { WaveletBasedConversationBlip first = target.getRootThread().appendBlip(); WaveletBasedConversationThread reply11 = first.addReplyThread(); ConversationBlip blip1 = reply11.appendBlip(); String blip1Id = blip1.getId(); WaveletBasedConversationThread reply2 = first.addReplyThread(); // Make first thread empty by removing its blip. ManifestBlip manifestRootBlip = target.getManifest().getRootThread().getBlip(0); ManifestThread manifestReply1 = manifestRootBlip.getReply(0); manifestReply1.removeBlip(manifestReply1.getBlip(0)); assertThreadValid(reply11); // Remove and re-add second thread, as can happen in playback. String thread2Id = reply2.getId(); ManifestThread manifestReply2 = manifestRootBlip.getReply(1); manifestRootBlip.removeReply(manifestReply2); manifestRootBlip.appendReply(thread2Id, false); assertThreadInvalid(reply2); }
public void testRemoveRestoreThreadAfterObsoleteThreadDoesntDie() { WaveletBasedConversationBlip first = target.getRootThread().appendBlip(); WaveletBasedConversationThread reply11 = first.addReplyThread(); ConversationBlip blip1 = reply11.appendBlip(); String blip1Id = blip1.getId(); WaveletBasedConversationThread reply2 = first.addReplyThread(); // Make first thread empty by removing its blip. ManifestBlip manifestRootBlip = target.getManifest().getRootThread().getBlip(0); ManifestThread manifestReply1 = manifestRootBlip.getReply(0); manifestReply1.removeBlip(manifestReply1.getBlip(0)); assertThreadValid(reply11); // Remove and re-add second thread, as can happen in playback. String thread2Id = reply2.getId(); ManifestThread manifestReply2 = manifestRootBlip.getReply(1); manifestRootBlip.removeReply(manifestReply2); manifestRootBlip.appendReply(thread2Id, false); assertThreadInvalid(reply2); }