/** * Finds the children of a blip, defined as all blips in all reply threads. * * @param blip the blip. * @return the children of the given blip. */ @Override public List<ConversationBlip> findBlipChildren(ConversationBlip blip) { List<ConversationBlip> children = Lists.newArrayList(); // Add all children from the inline reply threads. for (LocatedReplyThread<? extends ConversationThread> thread : blip.locateReplyThreads()) { for (ConversationBlip child : thread.getThread().getBlips()) { children.add(child); } } return children; }
@Override public BlipData toBlipData(ConversationBlip blip, Wavelet wavelet, EventMessageBundle eventMessageBundle) { BlipData blipData = super.toBlipData(blip, wavelet, eventMessageBundle); String threadId = blip.getThread().getId(); blipData.setThreadId(threadId); // If it's the root thread, that doesn't have thread id, then skip. if (!threadId.isEmpty()) { ConversationThread thread = blip.getThread(); addThread(eventMessageBundle, thread, -1, wavelet); } // Add the inline reply threads. List<String> threadIds = Lists.newLinkedList(); for (LocatedReplyThread<? extends ConversationThread> thread : blip.locateReplyThreads()) { String replyThreadId = thread.getThread().getId(); threadIds.add(replyThreadId); addThread(eventMessageBundle, thread.getThread(), thread.getLocation(), wavelet); } blipData.setReplyThreadIds(threadIds); return blipData; }
parent.locateReplyThreads()) { if (thread.getId().equals(inlineReplyThread.getThread().getId())) { location = inlineReplyThread.getLocation();
public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { Point<N> startText = doc.locate(locateAfterLineElement(doc)); doc.insertText(startText, "cd"); // Insert reply between c|d. N bodyNode = DocHelper.getElementWithTagName(doc, Blips.BODY_TAGNAME); N textNode = doc.getFirstChild(bodyNode); textNode = doc.getNextSibling(textNode); int replyLocation = doc.getLocation(Point.inText(textNode, 1)); blip.addReplyThread(replyLocation); // Insert text to give abc|d startText = Point.before(doc, textNode); doc.insertText(startText, "ab"); int newLocation = blip.locateReplyThreads().iterator().next().getLocation(); assertEquals(replyLocation + 2, newLocation); } });
public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { Point<N> startText = doc.locate(locateAfterLineElement(doc)); doc.insertText(startText, "cd"); // Insert reply between c|d. N bodyNode = DocHelper.getElementWithTagName(doc, Blips.BODY_TAGNAME); N textNode = doc.getFirstChild(bodyNode); textNode = doc.getNextSibling(textNode); int replyLocation = doc.getLocation(Point.inText(textNode, 1)); blip.addReplyThread(replyLocation); // Insert text to give abc|d startText = Point.before(doc, textNode); doc.insertText(startText, "ab"); int newLocation = blip.locateReplyThreads().iterator().next().getLocation(); assertEquals(replyLocation + 2, newLocation); } });
public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { Point<N> startText = doc.locate(locateAfterLineElement(doc)); doc.insertText(startText, "cd"); // Insert reply between c|d. N bodyNode = DocHelper.getElementWithTagName(doc, Blips.BODY_TAGNAME); N textNode = doc.getFirstChild(bodyNode); textNode = doc.getNextSibling(textNode); int replyLocation = doc.getLocation(Point.inText(textNode, 1)); ConversationThread replyThread = blip.addReplyThread(replyLocation); // Delete text and anchor. doc.deleteRange(Point.before(doc, textNode), Point.inElement(bodyNode, null)); int newLocation = blip.locateReplyThreads().iterator().next().getLocation(); assertEquals(Blips.INVALID_INLINE_LOCATION, newLocation); } });
public void testInlineReplyWithMultipleAnchorsUsesFirst() { ConversationBlip blip = target.getRootThread().appendBlip(); MutableDocument<?, ?, ?> doc = blip.getContent(); final int location = locateAfterLineElement(doc); ConversationThread thread = blip.addReplyThread(location); // Duplicate the anchor. doc.with(new Action() { public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { E anchor = Point.elementAfter(doc, doc.locate(location)); E anchorParent = doc.getParentElement(anchor); doc.createChildElement(anchorParent, doc.getTagName(anchor), doc.getAttributes(anchor)); } }); assertEquals(Collections.singletonList(LocatedReplyThread.of(thread, location)), blip.locateReplyThreads()); }
public void testInlineReplyWithMultipleAnchorsUsesFirst() { ConversationBlip blip = target.getRootThread().appendBlip(); MutableDocument<?, ?, ?> doc = blip.getContent(); final int location = locateAfterLineElement(doc); ConversationThread thread = blip.addReplyThread(location); // Duplicate the anchor. doc.with(new Action() { public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { E anchor = Point.elementAfter(doc, doc.locate(location)); E anchorParent = doc.getParentElement(anchor); doc.createChildElement(anchorParent, doc.getTagName(anchor), doc.getAttributes(anchor)); } }); assertEquals(Collections.singletonList(LocatedReplyThread.of(thread, location)), blip.locateReplyThreads()); }
public void testAppendInlineReplyCreatesInlineThread() { ConversationBlip blip = target.getRootThread().appendBlip(); MutableDocument<?, ?, ?> doc = blip.getContent(); int location = locateAfterLineElement(doc); ConversationThread thread = blip.addReplyThread(location); assertSame(blip, thread.getParentBlip()); assertEquals(Collections.singletonList(LocatedReplyThread.of(thread, location)), blip.locateReplyThreads()); assertThreadChildrenConsistent(blip); }
public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { Point<N> startText = doc.locate(locateAfterLineElement(doc)); doc.insertText(startText, "cd"); // Insert reply between c|d. N bodyNode = DocHelper.getElementWithTagName(doc, Blips.BODY_TAGNAME); N textNode = doc.getFirstChild(bodyNode); textNode = doc.getNextSibling(textNode); int replyLocation = doc.getLocation(Point.inText(textNode, 1)); ConversationThread replyThread = blip.addReplyThread(replyLocation); // Delete text and anchor. doc.deleteRange(Point.before(doc, textNode), Point.inElement(bodyNode, null)); int newLocation = blip.locateReplyThreads().iterator().next().getLocation(); assertEquals(Blips.INVALID_INLINE_LOCATION, newLocation); } });
public void testAppendInlineReplyCreatesInlineThread() { ConversationBlip blip = target.getRootThread().appendBlip(); MutableDocument<?, ?, ?> doc = blip.getContent(); int location = locateAfterLineElement(doc); ConversationThread thread = blip.addReplyThread(location); assertSame(blip, thread.getParentBlip()); assertEquals(Collections.singletonList(LocatedReplyThread.of(thread, location)), blip.locateReplyThreads()); assertThreadChildrenConsistent(blip); }
public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { Point<N> startText = doc.locate(locateAfterLineElement(doc)); int replyLocation = doc.getLocation(startText); ConversationThread t1 = blip.addReplyThread(replyLocation); t1.appendBlip(); // In front of t1. ConversationThread t2 = blip.addReplyThread(replyLocation); t2.appendBlip(); // In front of the others. ConversationThread t3 = blip.addReplyThread(replyLocation); t3.appendBlip(); // Delete t3's anchor. E anchorToDelete = Point.elementAfter(doc, doc.locate(replyLocation)); doc.deleteNode(anchorToDelete); List<LocatedReplyThread<ConversationThread>> expected = new ArrayList<LocatedReplyThread<ConversationThread>>(); expected.add(LocatedReplyThread.of(t2, replyLocation)); expected.add(LocatedReplyThread.of(t1, replyLocation + 2)); expected.add(LocatedReplyThread.of(t3, Blips.INVALID_INLINE_LOCATION)); List<LocatedReplyThread<? extends ConversationThread>> threads = CollectionUtils.newArrayList(blip.locateReplyThreads()); assertEquals(expected, threads); } });
public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { Point<N> startText = doc.locate(locateAfterLineElement(doc)); int replyLocation = doc.getLocation(startText); ConversationThread t1 = blip.addReplyThread(replyLocation); t1.appendBlip(); // In front of t1. ConversationThread t2 = blip.addReplyThread(replyLocation); t2.appendBlip(); // In front of the others. ConversationThread t3 = blip.addReplyThread(replyLocation); t3.appendBlip(); // Delete t3's anchor. E anchorToDelete = Point.elementAfter(doc, doc.locate(replyLocation)); doc.deleteNode(anchorToDelete); List<LocatedReplyThread<ConversationThread>> expected = new ArrayList<LocatedReplyThread<ConversationThread>>(); expected.add(LocatedReplyThread.of(t2, replyLocation)); expected.add(LocatedReplyThread.of(t1, replyLocation + 2)); expected.add(LocatedReplyThread.of(t3, Blips.INVALID_INLINE_LOCATION)); List<LocatedReplyThread<? extends ConversationThread>> threads = CollectionUtils.newArrayList(blip.locateReplyThreads()); assertEquals(expected, threads); } });
/** * Asserts that the state-querying methods on a blip can be called. */ protected static void assertBlipAccessible(ConversationBlip blip) { blip.getReplyThreads(); blip.getAuthorId(); blip.getContent(); blip.getContributorIds(); blip.getConversation(); blip.getId(); blip.locateReplyThreads(); blip.getLastModifiedTime(); blip.getLastModifiedVersion(); blip.getReplyThreads(); blip.getThread(); blip.hackGetRaw(); blip.isRoot(); }
/** * Asserts that the state-querying methods on a blip can be called. */ protected static void assertBlipAccessible(ConversationBlip blip) { blip.getReplyThreads(); blip.getAuthorId(); blip.getContent(); blip.getContributorIds(); blip.getConversation(); blip.getId(); blip.locateReplyThreads(); blip.getLastModifiedTime(); blip.getLastModifiedVersion(); blip.getReplyThreads(); blip.getThread(); blip.hackGetRaw(); blip.isRoot(); }