コード例 #1
0
 public JSONMessage text(String text) {
   MessagePart latest = latest();
   if (latest.hasText()) {
     throw new IllegalStateException("text for this message part is already set");
   }
   latest.text = text;
   dirty = true;
   return this;
 }
コード例 #2
0
 public String toJSONString() {
   if (!dirty && jsonString != null) {
     return jsonString;
   }
   StringWriter string = new StringWriter();
   JsonWriter json = new JsonWriter(string);
   try {
     if (messageParts.size() == 1) {
       latest().writeJson(json);
     } else {
       json.beginObject().name("text").value("").name("extra").beginArray();
       for (final MessagePart part : messageParts) {
         part.writeJson(json);
       }
       json.endArray().endObject();
       json.close();
     }
   } catch (Exception e) {
     throw new RuntimeException("invalid message");
   }
   jsonString = string.toString();
   dirty = false;
   return jsonString;
 }
コード例 #3
0
 private void onHover(final String name, final String data) {
   final MessagePart latest = latest();
   latest.hoverActionName = name;
   latest.hoverActionData = data;
   dirty = true;
 }
コード例 #4
0
 private void onClick(final String name, final String data) {
   final MessagePart latest = latest();
   latest.clickActionName = name;
   latest.clickActionData = data;
   dirty = true;
 }