use of org.jivesoftware.smackx.muc.Occupant in project Zom-Android by zom.
the class XmppConnection method handleMessage.
private void handleMessage(org.jivesoftware.smack.packet.Message smackMessage, boolean isOmemo, boolean notifyUser) {
String body = smackMessage.getBody();
boolean isGroupMessage = smackMessage.getType() == org.jivesoftware.smack.packet.Message.Type.groupchat;
if (smackMessage.getError() != null) {
// smackMessage.getError().getCode();
String error = "Error " + smackMessage.getError() + " (" + smackMessage.getError().getCondition() + "): " + smackMessage.getError().getConditionText();
debug(TAG, error);
return;
}
if (body == null) {
Collection<org.jivesoftware.smack.packet.Message.Body> mColl = smackMessage.getBodies();
for (org.jivesoftware.smack.packet.Message.Body bodyPart : mColl) {
String msg = bodyPart.getMessage();
if (msg != null) {
body = msg;
break;
}
}
}
ChatSession session = findOrCreateSession(smackMessage.getFrom().toString(), isGroupMessage);
if (// not subscribed so don't do anything
session != null) {
if (body != null && session != null) {
Message rec = new Message(body);
rec.setTo(new XmppAddress(smackMessage.getTo().toString()));
rec.setFrom(new XmppAddress(smackMessage.getFrom().toString()));
rec.setDateTime(new Date());
rec.setID(smackMessage.getStanzaId());
if (isOmemo)
rec.setType(Imps.MessageType.INCOMING_ENCRYPTED_VERIFIED);
else
rec.setType(Imps.MessageType.INCOMING);
// Detect if this was said by us, and mark message as outgoing
if (isGroupMessage) {
if (TextUtils.isEmpty(rec.getFrom().getResource())) {
// do nothing if there is no resource since that is a system message
return;
} else if (rec.getFrom().getResource().equals(rec.getTo().getUser())) {
try {
// rec.setType(Imps.MessageType.OUTGOING);
Occupant oc = mChatGroupManager.getMultiUserChat(rec.getFrom().getBareAddress()).getOccupant(JidCreate.entityFullFrom(rec.getFrom().getAddress()));
if (oc != null && oc.getJid().equals(mUser.getAddress().getAddress()))
// do nothing if it is from us
return;
} catch (Exception e) {
debug(TAG, "error parsing address", e);
}
}
}
boolean good = session.onReceiveMessage(rec, notifyUser);
if (smackMessage.getExtension("request", DeliveryReceipt.NAMESPACE) != null) {
if (good) {
debug(TAG, "sending delivery receipt");
// got XEP-0184 request, send receipt
sendReceipt(smackMessage);
session.onReceiptsExpected(true);
} else {
debug(TAG, "not sending delivery receipt due to processing error");
}
} else {
// no request for delivery receipt
session.onReceiptsExpected(false);
}
}
}
}
use of org.jivesoftware.smackx.muc.Occupant in project Spark by igniterealtime.
the class UserManager method getOccupant.
/**
* Returns the occupant of the room identified by their nickname.
*
* @param groupChatRoom the GroupChatRoom.
* @param nickname the users nickname.
* @return the Occupant found.
*/
public Occupant getOccupant(GroupChatRoom groupChatRoom, String nickname) {
String userJID = groupChatRoom.getRoomname() + "/" + nickname;
Occupant occ = null;
try {
occ = groupChatRoom.getMultiUserChat().getOccupant(userJID);
} catch (Exception e) {
Log.error(e);
}
return occ;
}
Aggregations