use of com.xabber.android.data.database.messagerealm.Attachment in project xabber-android by redsolution.
the class ImageGridBuilder method bindOneImage.
private void bindOneImage(final Attachment attachment, View parent, final ImageView imageView) {
String imagePath = attachment.getFilePath();
String imageUrl = attachment.getFileUrl();
Integer imageWidth = attachment.getImageWidth();
Integer imageHeight = attachment.getImageHeight();
final String uniqId = attachment.getUniqueId();
if (imagePath != null) {
boolean result = FileManager.loadImageFromFile(parent.getContext(), imagePath, imageView);
if (!result) {
MessageManager.setAttachmentLocalPathToNull(uniqId);
}
} else {
final ViewGroup.LayoutParams layoutParams = imageView.getLayoutParams();
if (imageWidth != null && imageHeight != null) {
FileManager.scaleImage(layoutParams, imageHeight, imageWidth);
Glide.with(parent.getContext()).load(imageUrl).into(imageView);
} else {
Glide.with(parent.getContext()).asBitmap().load(imageUrl).into(new CustomTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
final int width = resource.getWidth();
final int height = resource.getHeight();
if (width <= 0 || height <= 0) {
return;
}
final Realm realm = MessageDatabaseManager.getInstance().getRealmUiThread();
realm.executeTransactionAsync(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
Attachment first = realm.where(Attachment.class).equalTo(Attachment.Fields.UNIQUE_ID, uniqId).findFirst();
if (first != null) {
first.setImageWidth(width);
first.setImageHeight(height);
}
}
});
FileManager.scaleImage(layoutParams, height, width);
imageView.setImageBitmap(resource);
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
}
});
}
}
}
use of com.xabber.android.data.database.messagerealm.Attachment in project xabber-android by redsolution.
the class ImageViewerActivity method onShareClick.
private void onShareClick() {
int position = viewPager.getCurrentItem();
Attachment attachment = imageAttachments.get(position);
String path = attachment.getFilePath();
if (path != null) {
File file = new File(path);
if (file.exists()) {
startActivityForResult(FileManager.getIntentForShareFile(file), SHARE_ACTIVITY_REQUEST_CODE);
return;
} else
Toast.makeText(this, R.string.FILE_NOT_FOUND, Toast.LENGTH_SHORT).show();
} else {
waitForSharing = true;
onImageDownloadClick();
}
}
use of com.xabber.android.data.database.messagerealm.Attachment in project xabber-android by redsolution.
the class NextMamManager method parseMessage.
@Nullable
private MessageItem parseMessage(AccountItem accountItem, AccountJid account, UserJid user, Forwarded forwarded, String prevID) {
if (!(forwarded.getForwardedStanza() instanceof Message)) {
return null;
}
Message message = (Message) forwarded.getForwardedStanza();
DelayInformation delayInformation = forwarded.getDelayInformation();
DelayInformation messageDelay = DelayInformation.from(message);
String body = message.getBody();
net.java.otr4j.io.messages.AbstractMessage otrMessage;
try {
otrMessage = SerializationUtils.toMessage(body);
} catch (IOException e) {
return null;
}
boolean encrypted = false;
if (otrMessage != null) {
if (otrMessage.messageType != net.java.otr4j.io.messages.AbstractMessage.MESSAGE_PLAINTEXT) {
encrypted = true;
try {
// this transforming just decrypt message if have keys. No action as injectMessage or something else
body = OTRManager.getInstance().transformReceivingIfSessionExist(account, user, body);
if (OTRManager.getInstance().isEncrypted(body)) {
return null;
}
} catch (Exception e) {
return null;
}
} else
body = ((PlainTextMessage) otrMessage).cleanText;
}
// forward comment (to support previous forwarded xep)
String forwardComment = ForwardManager.parseForwardComment(message);
if (forwardComment != null)
body = forwardComment;
// modify body with references
Pair<String, String> bodies = ReferencesManager.modifyBodyWithReferences(message, body);
body = bodies.first;
String markupBody = bodies.second;
boolean incoming = message.getFrom().asBareJid().equals(user.getJid().asBareJid());
String uid = UUID.randomUUID().toString();
MessageItem messageItem = new MessageItem(uid);
messageItem.setPreviousId(prevID);
String archivedId = ArchivedHelper.getArchivedId(forwarded.getForwardedStanza());
if (archivedId != null)
messageItem.setArchivedId(archivedId);
long timestamp = delayInformation.getStamp().getTime();
messageItem.setAccount(account);
messageItem.setUser(user);
messageItem.setResource(user.getJid().getResourceOrNull());
messageItem.setText(body);
if (markupBody != null)
messageItem.setMarkupText(markupBody);
messageItem.setTimestamp(timestamp);
if (messageDelay != null) {
messageItem.setDelayTimestamp(messageDelay.getStamp().getTime());
}
messageItem.setIncoming(incoming);
messageItem.setStanzaId(AbstractChat.getStanzaId(message));
messageItem.setPacketId(message.getStanzaId());
messageItem.setReceivedFromMessageArchive(true);
messageItem.setRead(timestamp <= accountItem.getStartHistoryTimestamp());
messageItem.setSent(true);
messageItem.setEncrypted(encrypted);
// attachments
FileManager.processFileMessage(messageItem);
RealmList<Attachment> attachments = HttpFileUploadManager.parseFileMessage(message);
if (attachments.size() > 0)
messageItem.setAttachments(attachments);
// forwarded
messageItem.setOriginalStanza(message.toXML().toString());
messageItem.setOriginalFrom(message.getFrom().toString());
// groupchat
RefUser groupchatUser = ReferencesManager.getGroupchatUserFromReferences(message);
if (groupchatUser != null) {
GroupchatUserManager.getInstance().saveGroupchatUser(groupchatUser, timestamp);
messageItem.setGroupchatUserId(groupchatUser.getId());
}
return messageItem;
}
use of com.xabber.android.data.database.messagerealm.Attachment in project xabber-android by redsolution.
the class RoomChat method parseInnerMessage.
@Override
protected String parseInnerMessage(boolean ui, Message message, Date timestamp, String parentMessageId) {
if (message.getType() == Message.Type.error)
return null;
final org.jxmpp.jid.Jid from = message.getFrom();
final Resourcepart resource = from.getResourceOrNull();
String text = message.getBody();
final String subject = message.getSubject();
if (text == null)
return null;
if (subject != null)
return null;
RealmList<Attachment> attachments = HttpFileUploadManager.parseFileMessage(message);
String uid = UUID.randomUUID().toString();
RealmList<ForwardId> forwardIds = parseForwardedMessage(ui, message, uid);
String originalStanza = message.toXML().toString();
String originalFrom = message.getFrom().toString();
boolean fromMUC = message.getType().equals(Type.groupchat);
// forward comment (to support previous forwarded xep)
String forwardComment = ForwardManager.parseForwardComment(message);
if (forwardComment != null)
text = forwardComment;
// modify body with references
Pair<String, String> bodies = ReferencesManager.modifyBodyWithReferences(message, text);
text = bodies.first;
String markupText = bodies.second;
// create message with file-attachments
if (attachments.size() > 0)
createAndSaveFileMessage(ui, uid, resource, text, markupText, null, timestamp, getDelayStamp(message), true, false, false, false, getStanzaId(message), attachments, originalStanza, parentMessageId, originalFrom, fromMUC, true, null);
else
// create message without attachments
createAndSaveNewMessage(ui, uid, resource, text, markupText, null, timestamp, getDelayStamp(message), true, false, false, false, getStanzaId(message), originalStanza, parentMessageId, originalFrom, forwardIds, fromMUC, true, null);
return uid;
}
use of com.xabber.android.data.database.messagerealm.Attachment in project xabber-android by redsolution.
the class RoomChat method onPacket.
@Override
protected boolean onPacket(UserJid bareAddress, Stanza stanza, boolean isCarbons) {
if (!super.onPacket(bareAddress, stanza, isCarbons)) {
return false;
}
// MUCUser mucUserExtension = MUCUser.from(stanza);
// if (mucUserExtension != null && mucUserExtension.getInvite() != null) {
// return false;
// }
final org.jxmpp.jid.Jid from = stanza.getFrom();
final Resourcepart resource = from.getResourceOrNull();
if (stanza instanceof Message) {
final Message message = (Message) stanza;
if (message.getType() == Message.Type.error) {
UserJid invite = invites.remove(message.getStanzaId());
if (invite != null) {
newAction(nickname, invite.toString(), ChatAction.invite_error, true);
}
return true;
}
MUCUser mucUser = MUCUser.from(stanza);
if (mucUser != null && mucUser.getDecline() != null) {
onInvitationDeclined(mucUser.getDecline().getFrom(), mucUser.getDecline().getReason());
return true;
}
if (mucUser != null && mucUser.getStatus() != null && mucUser.getStatus().contains(MUCUser.Status.create("100")) && ChatManager.getInstance().isSuppress100(account, user)) {
// 'This room is not anonymous'
return true;
}
String text = message.getBody();
final String subject = message.getSubject();
if (text == null && subject == null) {
return true;
}
if (subject != null) {
if (this.subject.equals(subject)) {
return true;
}
this.subject = subject;
RosterManager.onContactChanged(account, bareAddress);
newAction(resource, subject, ChatAction.subject, true);
} else {
boolean notify = true;
Date delay = getDelayStamp(message);
if (delay != null) {
notify = false;
}
// forward comment (to support previous forwarded xep)
String forwardComment = ForwardManager.parseForwardComment(stanza);
if (forwardComment != null)
text = forwardComment;
// modify body with references
Pair<String, String> bodies = ReferencesManager.modifyBodyWithReferences(message, text);
text = bodies.first;
String markupText = bodies.second;
String originalFrom = stanza.getFrom().toString();
String messageUId = getMessageIdIfInHistory(getStanzaId(message), text);
if (messageUId != null) {
if (isSelf(resource)) {
markMessageAsDelivered(messageUId, originalFrom);
}
return true;
}
if (isSelf(resource)) {
notify = false;
}
updateThreadId(message.getThread());
RealmList<Attachment> attachments = HttpFileUploadManager.parseFileMessage(stanza);
String uid = UUID.randomUUID().toString();
RealmList<ForwardId> forwardIds = parseForwardedMessage(true, stanza, uid);
String originalStanza = stanza.toXML().toString();
// create message with file-attachments
if (attachments.size() > 0)
createAndSaveFileMessage(true, uid, resource, text, markupText, null, null, delay, true, notify, false, false, getStanzaId(message), attachments, originalStanza, null, originalFrom, true, false, null);
else
// create message without attachments
createAndSaveNewMessage(true, uid, resource, text, markupText, null, null, delay, true, notify, false, false, getStanzaId(message), originalStanza, null, originalFrom, forwardIds, true, false, null);
EventBus.getDefault().post(new NewIncomingMessageEvent(account, user));
}
} else if (stanza instanceof Presence) {
Presence presence = (Presence) stanza;
if (presence.getType() == Presence.Type.available) {
Occupant oldOccupant = occupants.get(resource);
Occupant newOccupant = createOccupant(resource, presence);
newOccupant.setJid(from);
occupants.put(resource, newOccupant);
if (oldOccupant == null) {
onAvailable(resource);
RosterManager.onContactChanged(account, user);
} else {
boolean changed = false;
if (oldOccupant.getAffiliation() != newOccupant.getAffiliation()) {
changed = true;
onAffiliationChanged(resource, newOccupant.getAffiliation());
}
if (oldOccupant.getRole() != newOccupant.getRole()) {
changed = true;
onRoleChanged(resource, newOccupant.getRole());
}
if (oldOccupant.getStatusMode() != newOccupant.getStatusMode() || !oldOccupant.getStatusText().equals(newOccupant.getStatusText())) {
changed = true;
onStatusChanged(resource, newOccupant.getStatusMode(), newOccupant.getStatusText());
}
if (changed) {
RosterManager.onContactChanged(account, user);
}
}
} else if (presence.getType() == Presence.Type.unavailable && state == RoomState.available) {
occupants.remove(resource);
MUCUser mucUser = MUCUser.from(presence);
if (mucUser != null && mucUser.getStatus() != null) {
if (mucUser.getStatus().contains(MUCUser.Status.KICKED_307)) {
onKick(resource, mucUser.getItem().getActor());
} else if (mucUser.getStatus().contains(MUCUser.Status.BANNED_301)) {
onBan(resource, mucUser.getItem().getActor());
} else if (mucUser.getStatus().contains(MUCUser.Status.NEW_NICKNAME_303)) {
Resourcepart newNick = mucUser.getItem().getNick();
if (newNick == null) {
return true;
}
onRename(resource, newNick);
Occupant occupant = createOccupant(newNick, presence);
occupants.put(newNick, occupant);
} else if (mucUser.getStatus().contains(MUCUser.Status.REMOVED_AFFIL_CHANGE_321)) {
onRevoke(resource, mucUser.getItem().getActor());
}
} else {
onLeave(resource);
}
RosterManager.onContactChanged(account, user);
}
}
return true;
}
Aggregations