java endo_Java Conversation.endOtrIfNeeded方法代码示例

编程知识 更新时间:2023-05-02 21:09:14

import eu.siacs.conversations.entities.Conversation; //导入方法依赖的package包/类

private Message parseOtrChat(String body, Jid from, String id, Conversation conversation) {

String presence;

if (from.isBareJid()) {

presence = "";

} else {

presence = from.getResourcepart();

}

if (body.matches("^\\?OTRv\\d{1,2}\\?.*")) {

conversation.endOtrIfNeeded();

}

if (!conversation.hasValidOtrSession()) {

conversation.startOtrSession(presence,false);

} else {

String foreignPresence = conversation.getOtrSession().getSessionID().getUserID();

if (!foreignPresence.equals(presence)) {

conversation.endOtrIfNeeded();

conversation.startOtrSession(presence, false);

}

}

try {

conversation.setLastReceivedOtrMessageId(id);

Session otrSession = conversation.getOtrSession();

body = otrSession.transformReceiving(body);

SessionStatus status = otrSession.getSessionStatus();

if (body == null && status == SessionStatus.ENCRYPTED) {

mXmppConnectionService.onOtrSessionEstablished(conversation);

return null;

} else if (body == null && status == SessionStatus.FINISHED) {

conversation.resetOtrSession();

mXmppConnectionService.updateConversationUi();

return null;

} else if (body == null || (body.isEmpty())) {

return null;

}

if (body.startsWith(CryptoHelper.FILETRANSFER)) {

String key = body.substring(CryptoHelper.FILETRANSFER.length());

conversation.setSymmetricKey(CryptoHelper.hexToBytes(key));

return null;

}

Message finishedMessage = new Message(conversation, body, Message.ENCRYPTION_OTR, Message.STATUS_RECEIVED);

conversation.setLastReceivedOtrMessageId(null);

return finishedMessage;

} catch (Exception e) {

conversation.resetOtrSession();

return null;

}

}

更多推荐

java endo_Java Conversation.endOtrIfNeeded方法代码示例

本文发布于:2023-04-28 16:35:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/0fc1c74921bd2436157aa97be62a8fc6.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:示例   代码   方法   endo_Java   java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 109119文章数
  • 27705阅读数
  • 0评论数