Beispiel #1
0
  public boolean isSpamMessage(
      Protocol protocol, Message message, boolean isSystem, boolean isPlain) {
    if (!Options.getBoolean(JLocale.getString(R.string.pref_antispam_enable))) {
      return false;
    }
    String uin = message.getSndrUin();
    if (isChecked(uin)) {
      return false;
    }
    denyAuth(protocol, message, isSystem);
    if (!isPlain) {
      return true;
    }
    String msg = message.getText();
    if (msg.length() < 256) {
      // MagicEye.addAction(protocol, uin, "antispam", msg);
    }
    if (message.isOffline()) {
      return true;
    }
    Contact contact = protocol.createTempContact(uin, false);

    String[] msgs =
        Util.explode(Options.getString(JLocale.getString(R.string.pref_antispam_answer)), '\n');
    for (int i = 0; i < msgs.length; ++i) {
      if (msg.equalsIgnoreCase(msgs[i])) {
        sendHelloMessage(protocol, contact);
        return true;
      }
    }
    sendQuestion(protocol, contact);
    return true;
  }
Beispiel #2
0
 public synchronized boolean hasLastMessage(Chat chat, Message message) {
   Contact contact = chat.getContact();
   boolean hasMessage = false;
   Cursor cursor = null;
   try {
     cursor =
         SawimApplication.getDatabaseHelper()
             .getReadableDatabase()
             .query(
                 DatabaseHelper.TABLE_CHAT_HISTORY,
                 null,
                 DatabaseHelper.CONTACT_ID + " = ?",
                 new String[] {uniqueUserId},
                 null,
                 null,
                 DatabaseHelper.DATE + " DESC",
                 String.valueOf(60));
     if (cursor.moveToLast()) {
       do {
         short rowData = cursor.getShort(cursor.getColumnIndex(DatabaseHelper.ROW_DATA));
         MessData mess =
             Chat.buildMessage(
                 contact,
                 message,
                 contact.isConference() ? message.getName() : chat.getFrom(message),
                 false,
                 Chat.isHighlight(message.getProcessedText(), contact.getMyName()));
         MessData messFromDataBase = buildMessage(chat, cursor);
         boolean isMessage =
             (rowData & MessData.PRESENCE) == 0
                 && (rowData & MessData.SERVICE) == 0
                 && (rowData & MessData.PROGRESS) == 0;
         if (isMessage) {
           hasMessage = hasMessage(mess, messFromDataBase);
           if (hasMessage) {
             return true;
           }
         }
       } while (cursor.moveToPrevious());
     }
   } catch (Exception e) {
     DebugLog.panic(e);
   } finally {
     if (cursor != null) {
       cursor.close();
     }
   }
   return hasMessage;
 }
Beispiel #3
0
 private void denyAuth(Protocol protocol, Message message, boolean isSystem) {
   if (isSystem) {
     SystemNotice notice = (SystemNotice) message;
     if (SystemNotice.SYS_NOTICE_AUTHREQ == notice.getSysnoteType()) {
       protocol.autoDenyAuth(message.getSndrUin());
     }
   }
 }
Beispiel #4
0
 public static boolean isSpam(
     Protocol protocol, Message message, boolean isSystem, boolean isPlain) {
   if (Options.getBoolean(JLocale.getString(R.string.pref_antispam_enable)))
     if (antiSpam.containsKeywords(message.getText())) {
       antiSpam.denyAuth(protocol, message, isSystem);
       return true;
     }
   return antiSpam.isSpamMessage(protocol, message, isSystem, isPlain);
 }
Beispiel #5
0
 public void addMessageToHistory(
     Contact contact, Message message, String from, boolean isSystemNotice) {
   addText(
       Chat.buildMessage(
           contact,
           message,
           from,
           isSystemNotice,
           Chat.isHighlight(message.getProcessedText(), contact.getMyName())));
 }
Beispiel #6
0
 public static Drawable getImageChat(Chat chat, boolean showMess) {
   if (chat.getContact().isTyping()) {
     return Message.getIcon(Message.ICON_TYPE);
   } else {
     Icon icStatus =
         RosterHelper.getInstance()
             .getProtocol()
             .getStatusInfo()
             .getIcon(chat.getContact().getStatusIndex());
     Drawable icMess = Message.getIcon(chat.getNewMessageIcon());
     if (icMess != null) {
       if (icMess == SawimResources.PERSONAL_MESSAGE_ICON) {
         icMess = icMess.getConstantState().newDrawable();
         icMess.setColorFilter(
             Scheme.getColor(R.attr.personal_unread_message), PorterDuff.Mode.MULTIPLY);
       } else {
         icMess = icMess.getConstantState().newDrawable();
         icMess.setColorFilter(Scheme.getColor(R.attr.unread_message), PorterDuff.Mode.MULTIPLY);
       }
     }
     return icMess == null || !showMess ? icStatus.getImage() : icMess;
   }
 }
Beispiel #7
0
  void populateFromContact(
      final RosterItemView rosterItemView, RosterHelper roster, Protocol p, Contact item) {
    if (p == null || item == null) return;
    rosterItemView.itemNameColor = Scheme.getColor(item.getTextTheme());
    rosterItemView.itemNameFont = item.hasChat() ? Typeface.DEFAULT_BOLD : Typeface.DEFAULT;
    rosterItemView.itemName =
        (item.subcontactsS() == 0)
            ? item.getText()
            : item.getText() + " (" + item.subcontactsS() + ")";

    String statusMessage = roster.getStatusMessage(p, item);
    rosterItemView.itemDescColor = Scheme.getColor(R.attr.contact_status);
    rosterItemView.itemDesc = statusMessage;

    if (Options.getBoolean(JLocale.getString(R.string.pref_users_avatars))) {
      AvatarCache.getInstance()
          .load(
              item.getUserId(),
              item.avatarHash,
              item.getText(),
              new AvatarCache.OnImageLoadListener() {
                @Override
                public void onLoad(Bitmap avatar) {
                  rosterItemView.itemFirstImage = avatar;
                  rosterItemView.repaint();
                }
              });
      rosterItemView.avatarBorderColor = Contact.getStatusColor(item.getStatusIndex());
    }
    // Icon icStatus = item.getLeftIcon(p);
    // if (icStatus != null)
    //    rosterItemView.itemSecondImage = icStatus.getImage().getBitmap();
    if (item.isTyping()) {
      rosterItemView.itemSecondImage = Message.getIcon(Message.ICON_TYPE);
    } else {
      Drawable icMess = ChatHistory.instance.getUnreadMessageIcon(item);
      if (icMess != null) {
        if (icMess == SawimResources.PERSONAL_MESSAGE_ICON) {
          icMess = icMess.getConstantState().newDrawable();
          icMess.setColorFilter(
              Scheme.getColor(R.attr.personal_unread_message), PorterDuff.Mode.MULTIPLY);
        } else {
          icMess = icMess.getConstantState().newDrawable();
          icMess.setColorFilter(Scheme.getColor(R.attr.unread_message), PorterDuff.Mode.MULTIPLY);
        }
        rosterItemView.itemSecondImage = icMess;
      }
    }

    if (item.getXStatusIndex() != XStatusInfo.XSTATUS_NONE) {
      XStatusInfo xStatusInfo = p.getXStatusInfo();
      if (xStatusInfo != null)
        rosterItemView.itemThirdImage =
            xStatusInfo.getIcon(item.getXStatusIndex()).getImage().getBitmap();
    }

    if (!item.isTemp()) {
      if (item.isAuth()) {
        int privacyList = -1;
        if (item.inIgnoreList()) {
          privacyList = 0;
        } else if (item.inInvisibleList()) {
          privacyList = 1;
        } else if (item.inVisibleList()) {
          privacyList = 2;
        }
        if (privacyList != -1)
          rosterItemView.itemThirdImage =
              Contact.serverListsIcons.iconAt(privacyList).getImage().getBitmap();
      } else {
        rosterItemView.itemFourthImage = SawimResources.AUTH_ICON.getBitmap();
      }
    }

    Icon icClient = (null != p.clientInfo) ? p.clientInfo.getIcon(item.clientIndex) : null;
    if (icClient != null && !SawimApplication.hideIconsClient)
      rosterItemView.itemSixthImage = icClient.getImage().getBitmap();
  }