+
+ try {
+ m.sendQuitGroupMessage(decodeGroupId(ns.getString("group")));
+ } catch (IOException e) {
+ handleIOException(e);
+ } catch (EncapsulatedExceptions e) {
+ handleEncapsulatedExceptions(e);
+ } catch (AssertionError e) {
+ handleAssertionError(e);
+ } catch (GroupNotFoundException e) {
+ handleGroupNotFoundException(e);
+ }
+
+ break;
+ case "updateGroup":
+ if (!m.isRegistered()) {
+ System.err.println("User is not registered.");
+ System.exit(1);
+ }
+
+ try {
+ byte[] groupId = null;
+ if (ns.getString("group") != null) {
+ groupId = decodeGroupId(ns.getString("group"));
+ }
+ byte[] newGroupId = m.sendUpdateGroupMessage(groupId, ns.getString("name"), ns.<String>getList("member"), ns.getString("avatar"));
+ if (groupId == null) {
+ System.out.println("Creating new group \"" + Base64.encodeBytes(newGroupId) + "\" …");
+ }
+ } catch (IOException e) {
+ handleIOException(e);
+ } catch (AttachmentInvalidException e) {
+ System.err.println("Failed to add avatar attachment (\"" + e.getAttachment() + ") for group\": " + e.getMessage());
+ System.err.println("Aborting sending.");
+ System.exit(1);
+ } catch (GroupNotFoundException e) {
+ handleGroupNotFoundException(e);
+ } catch (EncapsulatedExceptions e) {
+ handleEncapsulatedExceptions(e);
+ }
+
+ break;
+ case "daemon":
+ if (!m.isRegistered()) {
+ System.err.println("User is not registered.");
+ System.exit(1);
+ }
+ try {
+ int busType;
+ if (ns.getBoolean("system")) {
+ busType = DBusConnection.SYSTEM;
+ } else {
+ busType = DBusConnection.SESSION;
+ }
+ DBusConnection conn = DBusConnection.getConnection(busType);
+ conn.requestBusName("org.asamk.TextSecure");
+ conn.exportObject("/org/asamk/TextSecure", m);
+ } catch (DBusException e) {
+ e.printStackTrace();
+ System.exit(3);
+ }
+ try {
+ m.receiveMessages(3600, false, new ReceiveMessageHandler(m));
+ } catch (IOException e) {
+ System.err.println("Error while receiving messages: " + e.getMessage());
+ System.exit(3);
+ } catch (AssertionError e) {
+ handleAssertionError(e);
+ }
+