Skip to content

Commit d0ab15c

Browse files
committed
added support for follow-up msg; auto-channel improvement
channelId = "<auto>" will now check for omnipresent assistant and "follow" the receiver to the active channel
1 parent cd713a4 commit d0ab15c

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

src/main/java/net/b07z/sepia/websockets/common/SocketMessage.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public static enum DataType{
3333
byebye, //has optional data entry "username"
3434
upgradeClient, //has "role" as data entry
3535
assistAnswer, //has data for assistant communication
36+
assistFollowUp, //mostly same as assistAnswer but given as self-initiated follow-up message (clients could theoretically block this to avoid spam)
3637
directCmd, //has a direct cmd for assistant
3738
remoteAction, //has a remote action like ASR trigger or hotkey submit
3839
errorMessage //combined with TextType.status this message will be displayed as error line in channel (ignores normal status msg settings)

src/main/java/net/b07z/sepia/websockets/server/SepiaSocketHandler.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,20 +157,31 @@ public void onMessage(Session userSession, String message) {
157157
}else if (channelId.equals("<auto>")){
158158
//get active channel
159159
if (user != null){
160-
channelId = user.getActiveChannel();
161-
channelAccepted = true;
162-
//check this channel here or assume that all "active channels" really exist and the user is allowed to use it?
160+
//do we have a user that can be in any channel? Then get the receiver active channel
161+
if (user.isOmnipresent()){
162+
SocketUser rec = SocketUserPool.getActiveUserById(msg.receiver);
163+
if (rec != null){
164+
channelId = rec.getActiveChannel(); //TODO: does it sense to broadcast this to all users with this ID not only active?
165+
msg.channelId = channelId; //refresh
166+
channelAccepted = true;
167+
}
168+
}else{
169+
channelId = user.getActiveChannel(); //Note: I wonder what happens when the user is the assistant that is active in all channels?
170+
msg.channelId = channelId; //refresh
171+
//check this channel here or assume that all "active channels" really exist and the user is allowed to use it?
172+
channelAccepted = true;
173+
}
163174
}
164175
}else{
165176
//validate channel - TODO: this procedure has potential to fail when channel operations are not in sync with user, I'm sure, I think, maybe ... ^^
166177
//user must exists if a message should be sent to channel
167178
if (user != null){
168-
sc = SocketChannelPool.getChannel(channelId);
179+
SocketChannel testSc = SocketChannelPool.getChannel(channelId);
169180
//channel exists?
170-
if (sc != null){
181+
if (testSc != null){
171182
//user is active in this channel?
172183
if (!user.getActiveChannel().equals(channelId)){
173-
if (sc.isUserMemberOfChannel(user)){
184+
if (testSc.isUserMemberOfChannel(user)){
174185
//user.setActiveChannel(channelId); //do this here?
175186
channelAccepted = true;
176187
}
@@ -203,7 +214,8 @@ public void onMessage(Session userSession, String message) {
203214
//simply broadcast
204215
if (dataType == null
205216
|| dataType.equals(DataType.openText.name())
206-
|| dataType.equals(DataType.assistAnswer.name())
217+
|| dataType.equals(DataType.assistAnswer.name())
218+
|| dataType.equals(DataType.assistFollowUp.name())
207219
|| dataType.equals(DataType.directCmd.name())
208220
){
209221
preBroadcastAction(user, msg, false, false, false);
@@ -522,7 +534,7 @@ public void broadcastMessage(SocketMessage msg){
522534
//Sends message to all active users of a certain channel - message assumes channelId was checked before
523535
@Override
524536
public void broadcastMessage(SocketMessage msg, String channelId){
525-
//TODO: check channel "<auto>"
537+
//TODO: check channel "<auto>" again? - should have been replaced in channel-check at start ...
526538
SocketChannel sc = SocketChannelPool.getChannel(channelId);
527539
List<SocketUser> activeChannelUsers = sc.getActiveMembers(false); //TODO: this one is tricky, for normal messages it should be "false"
528540
broadcastMessage(msg, activeChannelUsers);

0 commit comments

Comments
 (0)