use of com.xabber.android.data.database.messagerealm.MessageItem in project xabber-android by redsolution.
the class AbstractChat method createMessageItem.
protected MessageItem createMessageItem(Resourcepart resource, String text, ChatAction action, Date delayTimestamp, boolean incoming, boolean notify, boolean encrypted, boolean offline, String stanzaId) {
final boolean visible = MessageManager.getInstance().isVisibleChat(this);
boolean read = incoming ? visible : true;
boolean send = incoming;
if (action == null && text == null) {
throw new IllegalArgumentException();
}
if (text == null) {
text = " ";
}
if (action != null) {
read = true;
send = true;
}
final Date timestamp = new Date();
if (text.trim().isEmpty()) {
notify = false;
}
if (notify || !incoming) {
openChat();
}
if (!incoming) {
notify = false;
}
if (isPrivateMucChat) {
if (!isPrivateMucChatAccepted) {
notify = false;
}
}
MessageItem messageItem = new MessageItem();
messageItem.setAccount(account);
messageItem.setUser(user);
if (resource == null) {
messageItem.setResource(Resourcepart.EMPTY);
} else {
messageItem.setResource(resource);
}
if (action != null) {
messageItem.setAction(action.toString());
}
messageItem.setText(text);
messageItem.setTimestamp(timestamp.getTime());
if (delayTimestamp != null) {
messageItem.setDelayTimestamp(delayTimestamp.getTime());
}
messageItem.setIncoming(incoming);
messageItem.setRead(read);
messageItem.setSent(send);
messageItem.setEncrypted(encrypted);
messageItem.setOffline(offline);
messageItem.setStanzaId(stanzaId);
FileManager.processFileMessage(messageItem);
if (notify && notifyAboutMessage() && !visible) {
NotificationManager.getInstance().onMessageNotification(messageItem);
}
// unread message count
if (!visible && action == null) {
if (incoming)
increaseUnreadMessageCount();
else
resetUnreadMessageCount();
}
// remove notifications if get outgoing message
if (!incoming)
NotificationManager.getInstance().removeMessageNotification(account, user);
// when getting new message, unarchive chat if chat not muted
if (this.notifyAboutMessage())
this.archived = false;
return messageItem;
}
use of com.xabber.android.data.database.messagerealm.MessageItem in project xabber-android by redsolution.
the class MessageManager method onLoad.
@Override
public void onLoad() {
Realm realm = MessageDatabaseManager.getInstance().getNewBackgroundRealm();
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
RealmResults<MessageItem> messagesToSend = realm.where(MessageItem.class).equalTo(MessageItem.Fields.SENT, false).findAll();
for (MessageItem messageItem : messagesToSend) {
AccountJid account = messageItem.getAccount();
UserJid user = messageItem.getUser();
if (account != null && user != null) {
if (getChat(account, user) == null) {
createChat(account, user);
}
}
}
}
});
realm.close();
NotificationManager.getInstance().registerNotificationProvider(mucPrivateChatRequestProvider);
}
use of com.xabber.android.data.database.messagerealm.MessageItem in project xabber-android by redsolution.
the class MessageManager method updateFileMessage.
public void updateFileMessage(AccountJid account, UserJid user, final String messageId, final String url) {
final AbstractChat chat = getChat(account, user);
if (chat == null) {
return;
}
Realm realm = MessageDatabaseManager.getInstance().getNewBackgroundRealm();
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
MessageItem messageItem = realm.where(MessageItem.class).equalTo(MessageItem.Fields.UNIQUE_ID, messageId).findFirst();
if (messageItem != null) {
messageItem.setText(url);
messageItem.setSent(false);
messageItem.setInProgress(false);
}
}
});
realm.close();
chat.sendMessages();
}
use of com.xabber.android.data.database.messagerealm.MessageItem in project xabber-android by redsolution.
the class MessageManager method updateMessageWithError.
public void updateMessageWithError(final String messageId, final String errorDescription) {
Realm realm = MessageDatabaseManager.getInstance().getNewBackgroundRealm();
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
MessageItem messageItem = realm.where(MessageItem.class).equalTo(MessageItem.Fields.UNIQUE_ID, messageId).findFirst();
if (messageItem != null) {
messageItem.setError(true);
messageItem.setErrorDescription(errorDescription);
messageItem.setInProgress(false);
}
}
});
realm.close();
}
use of com.xabber.android.data.database.messagerealm.MessageItem in project xabber-android by redsolution.
the class ReceiptManager method markAsDelivered.
private void markAsDelivered(final Jid toJid, final String receiptId) {
Realm realm = MessageDatabaseManager.getInstance().getNewBackgroundRealm();
realm.beginTransaction();
MessageItem first = realm.where(MessageItem.class).equalTo(MessageItem.Fields.STANZA_ID, receiptId).findFirst();
if (first != null) {
first.setDelivered(true);
}
realm.commitTransaction();
realm.close();
EventBus.getDefault().post(new MessageUpdateEvent());
}
Aggregations