Пример #1
0
  public void doSendText(
      @NotNull Peer peer,
      @NotNull String text,
      @Nullable ArrayList<Integer> mentions, /*Ignored*/
      @Nullable String markDownText,
      boolean autoDetect) {

    text = text.trim();

    long rid = RandomUtils.nextRid();
    long date = createPendingDate();
    long sortDate = date + 365 * 24 * 60 * 60 * 1000L;

    if (autoDetect) {
      mentions = new ArrayList<>();
      if (peer.getPeerType() == PeerType.GROUP) {
        Group group = getGroup(peer.getPeerId());
        String lowText = text.toLowerCase();
        if (group.getMembers() != null) {
          for (GroupMember member : group.getMembers()) {
            User user = getUser(member.getUid());
            if (user.getNick() != null) {
              String nick = "@" + user.getNick().toLowerCase();
              // TODO: Better filtering
              if (lowText.contains(nick + ":")
                  || lowText.contains(nick + " ")
                  || lowText.contains(" " + nick)
                  || lowText.endsWith(nick)
                  || lowText.equals(nick)) {
                mentions.add(user.getUid());
              }
            }
          }
        }
      }
    }

    TextContent content = TextContent.create(text, null, mentions);

    Message message = new Message(rid, sortDate, date, myUid(), MessageState.PENDING, content);

    context().getMessagesModule().getRouter().onOutgoingMessage(peer, message);

    pendingMessages.getPendingMessages().add(new PendingMessage(peer, rid, content));
    savePending();

    performSendContent(peer, rid, content);
  }
Пример #2
0
  /**
   * INTERNAL API Create User View Model
   *
   * @param user Initial User value
   * @param modules im.actor.android.modules reference
   */
  public UserVM(@NotNull User user, @NotNull ModuleContext modules) {
    super(user);

    id = user.getUid();
    sex = user.getSex();
    isBot = user.isBot();
    name = new StringValueModel("user." + id + ".name", user.getName());
    localName = new StringValueModel("user." + id + ".local_name", user.getLocalName());
    serverName = new StringValueModel("user." + id + ".server_name", user.getServerName());
    nick = new StringValueModel("user." + id + ".nick", user.getNick());
    about = new StringValueModel("user." + id + ".about", user.getAbout());
    avatar = new AvatarValueModel("user." + id + ".avatar", user.getAvatar());
    isContact =
        new BooleanValueModel(
            "user." + id + ".contact", modules.getContactsModule().isUserContact(id));
    isInPhoneBook =
        new BooleanValueModel(
            "user." + id + ".in_pb", modules.getContactsModule().isUserInPhoneBook(id));
    isBlocked = new BooleanValueModel("user." + id + ".blocked", user.isBlocked());
    isVerified = new BooleanValueModel("user." + id + ".is_verified", user.isVerified());
    timeZone = new StringValueModel("user." + id + ".time_zone", user.getTimeZone());
    presence =
        new ValueModelUserPresence(
            "user." + id + ".presence", new UserPresence(UserPresence.State.UNKNOWN));
    phones = new ValueModelUserPhone("user." + id + ".phones", buildPhones(user.getRecords()));
    emails = new ValueModelUserEmail("user." + id + ".emails", buildEmails(user.getRecords()));
    links = new ValueModelUserLink("user." + id + ".links", buildLinks(user.getRecords()));
    contacts =
        new ValueModelContactRecord(
            "user." + id + ".contacts", new ArrayListContactRecord(user.getRecords()));
    botCommands =
        new ValueModelBotCommands(
            "user." + id + ".bot_commands", new ArrayListBotCommands(user.getCommands()));
    // Notify about presence change every minute as text representation can change
    presenceTimer =
        new CommonTimer(
            new Runnable() {
              @Override
              public void run() {
                presence.forceNotify();
                presenceTimer.schedule(PRESENCE_UPDATE_DELAY);
              }
            });
    presenceTimer.schedule(PRESENCE_UPDATE_DELAY);
  }
Пример #3
0
  @Override
  protected void updateValues(@NotNull User rawObj) {
    boolean isChanged = name.change(rawObj.getName());
    isChanged |= localName.change(rawObj.getLocalName());
    isChanged |= serverName.change(rawObj.getServerName());
    isChanged |= nick.change(rawObj.getNick());
    isChanged |= timeZone.change(rawObj.getTimeZone());
    isChanged |= about.change(rawObj.getAbout());
    isChanged |= avatar.change(rawObj.getAvatar());
    isChanged |= isBlocked.change(rawObj.isBlocked());
    isChanged |= isVerified.change(rawObj.isVerified());
    isChanged |= botCommands.change(new ArrayListBotCommands(rawObj.getCommands()));

    // TODO: better changed checking?
    isChanged |= phones.change(buildPhones(rawObj.getRecords()));
    isChanged |= emails.change(buildEmails(rawObj.getRecords()));
    isChanged |= links.change(buildLinks(rawObj.getRecords()));
    isChanged |= contacts.change(new ArrayListContactRecord(rawObj.getRecords()));

    if (isChanged) {
      notifyChange();
    }
  }