From 37f17727050d2dbd297efb6e588e937ec21ee7b9 Mon Sep 17 00:00:00 2001 From: heavyrian2012 Date: Sat, 23 Mar 2024 12:32:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E7=BA=BF=E7=8A=B6=E6=80=81=E5=9B=9E?= =?UTF-8?q?=E8=B0=83=E6=B7=BB=E5=8A=A0=E5=85=B6=E4=BB=96=E7=AB=AF=E7=9A=84?= =?UTF-8?q?=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../moquette/spi/impl/ProtocolProcessor.java | 23 ++++++++++++++++++- .../moquette/spi/impl/Qos1PublishHandler.java | 2 +- .../pojos/OutputCheckUserOnline.java | 11 ++++++--- .../wildfirechat/pojos/UserOnlineStatus.java | 5 ++++ 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/broker/src/main/java/io/moquette/spi/impl/ProtocolProcessor.java b/broker/src/main/java/io/moquette/spi/impl/ProtocolProcessor.java index 175b6390d..f5491aea2 100755 --- a/broker/src/main/java/io/moquette/spi/impl/ProtocolProcessor.java +++ b/broker/src/main/java/io/moquette/spi/impl/ProtocolProcessor.java @@ -17,6 +17,7 @@ package io.moquette.spi.impl; import cn.wildfirechat.common.ErrorCode; +import cn.wildfirechat.pojos.OutputCheckUserOnline; import cn.wildfirechat.pojos.UserOnlineStatus; import cn.wildfirechat.proto.ProtoConstants; import cn.wildfirechat.proto.WFCMessage; @@ -266,7 +267,27 @@ public void forwardOnlineStatusEvent(String userId, String clientId, int platfor if (!StringUtil.isNullOrEmpty(mUserOnlineStatusCallback)) { mServer.getCallbackScheduler().execute(() -> { try { - HttpUtils.httpJsonPost(mUserOnlineStatusCallback, GsonUtil.gson.toJson(new UserOnlineStatus(userId, clientId, platform, status, packageName)), HttpUtils.HttpPostType.POST_TYPE_User_Online_Event_Callback); + int sessionstatus; + Collection useSessions = m_sessionsStore.sessionForUser(userId); + UserOnlineStatus userOnlineStatus = new UserOnlineStatus(userId, clientId, platform, status, packageName); + userOnlineStatus.sessions = new ArrayList<>(); + + for (MemorySessionStore.Session session : useSessions) { + if (session.getDeleted() > 0) { + continue; + } + + ConnectionDescriptor descriptor = connectionDescriptors.getConnection(session.getClientID()); + if (descriptor == null) { + sessionstatus = 1; + } else { + sessionstatus = 0; + } + + userOnlineStatus.sessions.add(new OutputCheckUserOnline.Session(userId, session.getClientID(), session.getPlatform(), sessionstatus, session.getLastActiveTime(), session.getAppName())); + } + + HttpUtils.httpJsonPost(mUserOnlineStatusCallback, GsonUtil.gson.toJson(userOnlineStatus), HttpUtils.HttpPostType.POST_TYPE_User_Online_Event_Callback); } catch (Exception e) { e.printStackTrace(); Utility.printExecption(LOG, e, EVENT_CALLBACK_Exception); diff --git a/broker/src/main/java/io/moquette/spi/impl/Qos1PublishHandler.java b/broker/src/main/java/io/moquette/spi/impl/Qos1PublishHandler.java index cc6df820c..63b4d9c11 100755 --- a/broker/src/main/java/io/moquette/spi/impl/Qos1PublishHandler.java +++ b/broker/src/main/java/io/moquette/spi/impl/Qos1PublishHandler.java @@ -141,7 +141,7 @@ void checkUserOnlineHandler(byte[] payloadContent, RouteCallback callback) { status = 0; } - out.addSession(userId, session.getClientID(), session.getPlatform(), status, session.getLastActiveTime()); + out.addSession(userId, session.getClientID(), session.getPlatform(), status, session.getLastActiveTime(), session.getAppName()); } callback.onRouteHandled(GsonUtil.gson.toJson(out).getBytes()); diff --git a/common/src/main/java/cn/wildfirechat/pojos/OutputCheckUserOnline.java b/common/src/main/java/cn/wildfirechat/pojos/OutputCheckUserOnline.java index b93ed2dc0..735f7a5db 100644 --- a/common/src/main/java/cn/wildfirechat/pojos/OutputCheckUserOnline.java +++ b/common/src/main/java/cn/wildfirechat/pojos/OutputCheckUserOnline.java @@ -19,18 +19,23 @@ public static class Session { public int platform; public int status; //0 online, 1 have session offline public long lastSeen; + public String packageName; - public Session(String clientId, String userId, int platform, int status, long lastSeen) { + public Session() { + } + + public Session(String clientId, String userId, int platform, int status, long lastSeen, String packageName) { this.clientId = clientId; this.userId = userId; this.platform = platform; this.status = status; this.lastSeen = lastSeen; + this.packageName = packageName; } } - public void addSession(String userId, String clientId, int platform, int status, long lastSeen) { - Session session = new Session(clientId, userId, platform, status, lastSeen); + public void addSession(String userId, String clientId, int platform, int status, long lastSeen, String packageName) { + Session session = new Session(clientId, userId, platform, status, lastSeen, packageName); sessions.add(session); } diff --git a/common/src/main/java/cn/wildfirechat/pojos/UserOnlineStatus.java b/common/src/main/java/cn/wildfirechat/pojos/UserOnlineStatus.java index 242402ede..a03a2f7e6 100644 --- a/common/src/main/java/cn/wildfirechat/pojos/UserOnlineStatus.java +++ b/common/src/main/java/cn/wildfirechat/pojos/UserOnlineStatus.java @@ -1,5 +1,7 @@ package cn.wildfirechat.pojos; +import java.util.List; + public class UserOnlineStatus { public static final int ONLINE = 0; public static final int OFFLINE = 1; @@ -11,6 +13,9 @@ public class UserOnlineStatus { public int status; public long timestamp; public String packageName; + public int customState; + public String customText; + public List sessions; public UserOnlineStatus() { }