Эх сурвалжийг харах

Add "reaction" event to CallParticipantModel observer

The CallParticipantModel observer now also emits one-time events that
are not reflected in the model state.

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Daniel Calviño Sánchez 1 жил өмнө
parent
commit
92d655080d

+ 4 - 0
app/src/main/java/com/nextcloud/talk/activities/CallActivity.java

@@ -2861,6 +2861,10 @@ public class CallActivity extends CallBaseActivity {
                 addParticipantDisplayItem(callParticipantModel, "screen");
             }
         }
+
+        @Override
+        public void onReaction(String reaction) {
+        }
     }
 
     private class InternalSignalingMessageSender implements SignalingMessageSender {

+ 10 - 1
app/src/main/java/com/nextcloud/talk/adapters/ParticipantDisplayItem.java

@@ -34,7 +34,16 @@ public class ParticipantDisplayItem {
 
     private final CallParticipantModel callParticipantModel;
 
-    private final CallParticipantModel.Observer callParticipantModelObserver = this::updateFromModel;
+    private final CallParticipantModel.Observer callParticipantModelObserver = new CallParticipantModel.Observer() {
+        @Override
+        public void onChange() {
+            updateFromModel();
+        }
+
+        @Override
+        public void onReaction(String reaction) {
+        }
+    };
 
     private String userId;
     private PeerConnection.IceConnectionState iceConnectionState;

+ 1 - 0
app/src/main/java/com/nextcloud/talk/call/CallParticipant.java

@@ -42,6 +42,7 @@ public class CallParticipant {
 
         @Override
         public void onReaction(String reaction) {
+            callParticipantModel.emitReaction(reaction);
         }
 
         @Override

+ 5 - 1
app/src/main/java/com/nextcloud/talk/call/CallParticipantModel.java

@@ -42,11 +42,15 @@ import java.util.Objects;
  * Getters called after receiving a notification are guaranteed to provide at least the value that triggered the
  * notification, but it may return even a more up to date one (so getting the value again on the following
  * notification may return the same value as before).
+ *
+ * Besides onChange(), which notifies about changes in the model values, CallParticipantModel.Observer provides
+ * additional methods to be notified about one-time events that are not reflected in the model values, like reactions.
  */
 public class CallParticipantModel {
 
     public interface Observer {
         void onChange();
+        void onReaction(String reaction);
     }
 
     protected class Data<T> {
@@ -68,7 +72,7 @@ public class CallParticipantModel {
         }
     }
 
-    private final CallParticipantModelNotifier callParticipantModelNotifier = new CallParticipantModelNotifier();
+    protected final CallParticipantModelNotifier callParticipantModelNotifier = new CallParticipantModelNotifier();
 
     protected final String sessionId;
 

+ 12 - 0
app/src/main/java/com/nextcloud/talk/call/CallParticipantModelNotifier.java

@@ -83,4 +83,16 @@ class CallParticipantModelNotifier {
             }
         }
     }
+
+    public synchronized void notifyReaction(String reaction) {
+        for (CallParticipantModelObserverOn observerOn : new ArrayList<>(callParticipantModelObserversOn)) {
+            if (observerOn.handler == null || observerOn.handler.getLooper() == Looper.myLooper()) {
+                observerOn.observer.onReaction(reaction);
+            } else {
+                observerOn.handler.post(() -> {
+                    observerOn.observer.onReaction(reaction);
+                });
+            }
+        }
+    }
 }

+ 4 - 0
app/src/main/java/com/nextcloud/talk/call/MutableCallParticipantModel.java

@@ -72,4 +72,8 @@ public class MutableCallParticipantModel extends CallParticipantModel {
     public void setScreenMediaStream(MediaStream screenMediaStream) {
         this.screenMediaStream.setValue(screenMediaStream);
     }
+
+    public void emitReaction(String reaction) {
+        this.callParticipantModelNotifier.notifyReaction(reaction);
+    }
 }

+ 7 - 0
app/src/test/java/com/nextcloud/talk/call/CallParticipantModelTest.kt

@@ -55,4 +55,11 @@ class CallParticipantModelTest {
         callParticipantModel!!.setRaisedHand(true, 4815162342L)
         Mockito.verify(mockedCallParticipantModelObserver, Mockito.only())?.onChange()
     }
+
+    @Test
+    fun testEmitReaction() {
+        callParticipantModel!!.addObserver(mockedCallParticipantModelObserver)
+        callParticipantModel!!.emitReaction("theReaction")
+        Mockito.verify(mockedCallParticipantModelObserver, Mockito.only())?.onReaction("theReaction")
+    }
 }