1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-22 22:32:06 +01:00

Avoid getInstanceOf() in listener as it is a costly operation

This commit is contained in:
Florian Schmaus 2018-09-06 18:41:19 +02:00
parent 547138b325
commit 830f3661e7

View file

@ -92,6 +92,8 @@ public final class ChatMarkersManager extends Manager {
private final AsyncButOrdered<Chat> asyncButOrdered = new AsyncButOrdered<>(); private final AsyncButOrdered<Chat> asyncButOrdered = new AsyncButOrdered<>();
private final ChatManager chatManager;
/** /**
* Get the singleton instance of ChatMarkersManager. * Get the singleton instance of ChatMarkersManager.
* *
@ -111,6 +113,9 @@ public final class ChatMarkersManager extends Manager {
private ChatMarkersManager(XMPPConnection connection) { private ChatMarkersManager(XMPPConnection connection) {
super(connection); super(connection);
chatManager = ChatManager.getInstanceFor(connection);
connection.addStanzaInterceptor(new StanzaListener() { connection.addStanzaInterceptor(new StanzaListener() {
@Override @Override
public void processStanza(Stanza packet) public void processStanza(Stanza packet)
@ -135,7 +140,7 @@ public final class ChatMarkersManager extends Manager {
EntityFullJid fullFrom = message.getFrom().asEntityFullJidIfPossible(); EntityFullJid fullFrom = message.getFrom().asEntityFullJidIfPossible();
EntityBareJid bareFrom = fullFrom.asEntityBareJid(); EntityBareJid bareFrom = fullFrom.asEntityBareJid();
final Chat chat = ChatManager.getInstanceFor(connection()).chatWith(bareFrom); final Chat chat = chatManager.chatWith(bareFrom);
asyncButOrdered.performAsyncButOrdered(chat, new Runnable() { asyncButOrdered.performAsyncButOrdered(chat, new Runnable() {
@Override @Override