use of de.pixart.messenger.entities.Message in project Pix-Art-Messenger by kriztan.
the class ConversationFragment method updateDateBubbles.
protected void updateDateBubbles() {
synchronized (this.messageList) {
for (int i = 0; i < this.messageList.size(); ++i) {
final Message current = this.messageList.get(i);
if (i == 0 || !UIHelper.sameDay(this.messageList.get(i - 1).getTimeSent(), current.getTimeSent())) {
this.messageList.add(i, Message.createDateSeparator(current));
i++;
}
}
}
}
use of de.pixart.messenger.entities.Message in project Pix-Art-Messenger by kriztan.
the class ConversationFragment method updateStatusMessages.
protected void updateStatusMessages() {
updateDateBubbles();
synchronized (this.messageList) {
if (showLoadMoreMessages(conversation)) {
this.messageList.add(0, Message.createLoadMoreMessage(conversation));
}
if (conversation.getMode() == Conversation.MODE_MULTI) {
final MucOptions mucOptions = conversation.getMucOptions();
final List<MucOptions.User> allUsers = mucOptions.getUsers();
final Set<ReadByMarker> addedMarkers = new HashSet<>();
ChatState state = ChatState.COMPOSING;
List<MucOptions.User> users = conversation.getMucOptions().getUsersWithChatState(state, 5);
if (users.size() == 0) {
state = ChatState.PAUSED;
users = conversation.getMucOptions().getUsersWithChatState(state, 5);
}
if (mucOptions.isPrivateAndNonAnonymous()) {
for (int i = this.messageList.size() - 1; i >= 0; --i) {
final Set<ReadByMarker> markersForMessage = messageList.get(i).getReadByMarkers();
final List<MucOptions.User> shownMarkers = new ArrayList<>();
for (ReadByMarker marker : markersForMessage) {
if (!ReadByMarker.contains(marker, addedMarkers)) {
// may be put outside this condition. set should do dedup anyway
addedMarkers.add(marker);
MucOptions.User user = mucOptions.findUser(marker);
shownMarkers.add(user);
}
}
final ReadByMarker markerForSender = ReadByMarker.from(messageList.get(i));
final Message statusMessage;
final int size = shownMarkers.size();
if (size > 1) {
final String body;
if (size <= 4) {
body = getString(R.string.contacts_have_read_up_to_this_point, UIHelper.concatNames(shownMarkers));
} else {
body = getString(R.string.contacts_and_n_more_have_read_up_to_this_point, UIHelper.concatNames(shownMarkers, 3), size - 3);
}
statusMessage = Message.createStatusMessage(conversation, body);
statusMessage.setCounterparts(shownMarkers);
} else if (size == 1) {
statusMessage = Message.createStatusMessage(conversation, getString(R.string.contact_has_read_up_to_this_point, UIHelper.getDisplayName(shownMarkers.get(0))));
statusMessage.setCounterpart(shownMarkers.get(0).getFullJid());
statusMessage.setTrueCounterpart(shownMarkers.get(0).getRealJid());
} else {
statusMessage = null;
}
if (statusMessage != null) {
this.messageList.add(i + 1, statusMessage);
}
addedMarkers.add(markerForSender);
if (ReadByMarker.allUsersRepresented(allUsers, addedMarkers)) {
break;
}
}
}
}
}
}
use of de.pixart.messenger.entities.Message in project Pix-Art-Messenger by kriztan.
the class XmppConnectionService method markRead.
public boolean markRead(final Conversation conversation, boolean clear) {
if (clear) {
mNotificationService.clear(conversation);
}
final List<Message> readMessages = conversation.markRead();
if (readMessages.size() > 0) {
Runnable runnable = new Runnable() {
@Override
public void run() {
for (Message message : readMessages) {
databaseBackend.updateMessage(message);
}
}
};
mDatabaseWriterExecutor.execute(runnable);
updateUnreadCountBadge();
return true;
} else {
return false;
}
}
use of de.pixart.messenger.entities.Message in project Pix-Art-Messenger by kriztan.
the class XmppConnectionService method attachFileToConversation.
public void attachFileToConversation(final Conversation conversation, final Uri uri, final String type, final UiCallback<Message> callback) {
if (FileBackend.weOwnFile(this, uri)) {
Log.d(Config.LOGTAG, "trying to attach file that belonged to us");
callback.error(R.string.security_error_invalid_file_access, null);
return;
}
final Message message;
if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
message = new Message(conversation, "", Message.ENCRYPTION_DECRYPTED);
} else {
message = new Message(conversation, "", conversation.getNextEncryption());
}
message.setCounterpart(conversation.getNextCounterpart());
message.setType(Message.TYPE_FILE);
final AttachFileToConversationRunnable runnable = new AttachFileToConversationRunnable(this, uri, type, message, callback);
if (runnable.isVideoMessage()) {
mVideoCompressionExecutor.execute(runnable);
} else {
mFileAddingExecutor.execute(runnable);
}
}
use of de.pixart.messenger.entities.Message in project Pix-Art-Messenger by kriztan.
the class XmppConnectionService method resendFailedMessages.
public void resendFailedMessages(final Message message) {
final Collection<Message> messages = new ArrayList<>();
Message current = message;
while (current.getStatus() == Message.STATUS_SEND_FAILED) {
messages.add(current);
if (current.mergeable(current.next())) {
current = current.next();
} else {
break;
}
}
for (final Message msg : messages) {
msg.setTime(System.currentTimeMillis());
markMessage(msg, Message.STATUS_WAITING);
this.resendMessage(msg, false);
}
message.getConversation().sort();
updateConversationUi();
}
Aggregations