use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.
the class HttpFileUploadManager method uploadFile.
public void uploadFile(final AccountJid account, final UserJid user, final List<String> filePaths, final List<Uri> fileUris, String existMessageId, Context context) {
if (isUploading) {
progressSubscribe.onNext(new ProgressData(0, 0, "Uploading already started", false, null));
return;
}
isUploading = true;
final Jid uploadServerUrl = uploadServers.get(account.getFullJid().asBareJid());
if (uploadServerUrl == null) {
progressSubscribe.onNext(new ProgressData(0, 0, "Upload server not found", false, null));
isUploading = false;
return;
}
Intent intent = new Intent(context, UploadService.class);
intent.putExtra(UploadService.KEY_RECEIVER, new UploadReceiver(new Handler()));
intent.putExtra(UploadService.KEY_ACCOUNT_JID, (Parcelable) account);
intent.putExtra(UploadService.KEY_USER_JID, user);
intent.putStringArrayListExtra(UploadService.KEY_FILE_PATHS, (ArrayList<String>) filePaths);
intent.putParcelableArrayListExtra(UploadService.KEY_FILE_URIS, (ArrayList<Uri>) fileUris);
intent.putExtra(UploadService.KEY_UPLOAD_SERVER_URL, (CharSequence) uploadServerUrl);
intent.putExtra(UploadService.KEY_MESSAGE_ID, existMessageId);
context.startService(intent);
}
use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.
the class ChatStateManager method onStanza.
@Override
public void onStanza(ConnectionItem connection, Stanza stanza) {
if (stanza.getFrom() == null) {
return;
}
final Resourcepart resource = stanza.getFrom().getResourceOrNull();
if (resource == null) {
return;
}
final AccountJid account = ((AccountItem) connection).getAccount();
final UserJid bareUserJid;
try {
bareUserJid = UserJid.from(stanza.getFrom()).getBareUserJid();
} catch (UserJid.UserJidCreateException e) {
return;
}
if (stanza instanceof Presence) {
Presence presence = (Presence) stanza;
if (presence.getType() != Type.unavailable) {
return;
}
chatStates.remove(account.toString(), bareUserJid.toString(), resource);
removeCallback(account, bareUserJid.getBareJid(), resource);
supports.remove(account.toString(), bareUserJid.toString(), resource);
} else if (stanza instanceof Message) {
boolean support = false;
for (ExtensionElement extension : stanza.getExtensions()) if (extension instanceof ChatStateExtension) {
removeCallback(account, bareUserJid.getBareJid(), resource);
ChatState chatState = ((ChatStateExtension) extension).getChatState();
chatStates.put(account.toString(), bareUserJid.toString(), resource, chatState);
if (chatState != ChatState.active) {
Runnable runnable = new Runnable() {
@Override
public void run() {
if (this != stateCleaners.get(account.toString(), bareUserJid.toString(), resource)) {
return;
}
chatStates.remove(account.toString(), bareUserJid.toString(), resource);
removeCallback(account, bareUserJid.getBareJid(), resource);
RosterManager.onChatStateChanged(account, bareUserJid);
}
};
handler.postDelayed(runnable, REMOVE_STATE_DELAY);
stateCleaners.put(account.toString(), bareUserJid.toString(), resource, runnable);
}
RosterManager.onChatStateChanged(account, bareUserJid);
support = true;
break;
}
Message message = (Message) stanza;
if (message.getType() != Message.Type.chat && message.getType() != Message.Type.groupchat) {
return;
}
if (support) {
supports.put(account.toString(), bareUserJid.toString(), resource, true);
} else if (supports.get(account.toString(), bareUserJid.toString(), resource) == null) {
// Disable only if there no information about support.
supports.put(account.toString(), bareUserJid.toString(), resource, false);
}
}
}
use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.
the class ChatMarkerManager method isClientSupportChatMarkers.
private boolean isClientSupportChatMarkers(AccountJid account, UserJid user) {
AccountItem accountItem = AccountManager.getInstance().getAccount(account);
if (accountItem == null)
return false;
XMPPConnection connection = accountItem.getConnection();
final List<Presence> allPresences = RosterManager.getInstance().getPresences(account, user.getJid());
boolean isChatMarkersSupport = false;
for (Presence presence : allPresences) {
Jid fromJid = presence.getFrom();
DiscoverInfo discoverInfo = null;
try {
discoverInfo = ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(fromJid);
} catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | InterruptedException | ClassCastException e) {
e.printStackTrace();
}
isChatMarkersSupport = discoverInfo != null && discoverInfo.containsFeature(ChatMarkersElements.NAMESPACE);
if (isChatMarkersSupport)
break;
}
return isChatMarkersSupport;
}
use of com.xabber.android.data.entity.UserJid 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.entity.UserJid in project xabber-android by redsolution.
the class MessageNotificationManager method performAction.
public void performAction(FullAction action) {
AccountJid accountJid = action.getAccountJid();
UserJid userJid = action.getUserJid();
switch(action.getActionType()) {
case read:
AbstractChat chat = MessageManager.getInstance().getChat(accountJid, userJid);
if (chat != null) {
AccountManager.getInstance().stopGracePeriod(chat.getAccount());
chat.markAsReadAll(true);
callUiUpdate();
}
break;
case snooze:
AbstractChat chat1 = MessageManager.getInstance().getChat(accountJid, userJid);
if (chat1 != null) {
chat1.setNotificationState(new NotificationState(NotificationState.NotificationMode.snooze2h, (int) (System.currentTimeMillis() / 1000L)), true);
callUiUpdate();
}
break;
case reply:
MessageManager.getInstance().sendMessage(accountJid, userJid, action.getReplyText().toString());
}
}
Aggregations