Browse Source

add coedition notif

tripeur 4 years ago
parent
commit
9ef9e8c0c5

+ 32 - 22
src/PlannerApp.vue

@@ -78,6 +78,7 @@ export default defineComponent({
       explanation: "",
       showExplanation: false,
       lastToast: null as null | Toast,
+      coeditors: new Set() as Set<string>,
       tabs,
     };
   },
@@ -94,11 +95,15 @@ export default defineComponent({
     username(): string {
       return this.$store.state.username;
     },
+    shareCommit(): boolean {
+      return this.coeditors.size > 0;
+    },
   },
   watch: {
     uuid(val: string, old: string) {
       if (old && this.stompClient?.connected) this.stompClient.unsubscribe("/planning/" + old);
       this.subscribe(val);
+      if (old != val) this.coeditors = new Set();
     },
   },
   beforeMount() {
@@ -160,16 +165,6 @@ export default defineComponent({
     subscribe(uuid: string) {
       if (uuid && this.stompClient?.connected) {
         this.stompClient.subscribe("/planning/" + uuid, (msg) => this.handlePlanningChange(msg));
-        this.stompClient.send(
-          "/app/notify",
-          {},
-          JSON.stringify({
-            uuid,
-            user: this.username,
-            method: "toast",
-            payload: `L'utilisateur ${this.username} vient de se connecter`,
-          })
-        );
       }
     },
     handlePlanningChange(msg: Stomp.Message) {
@@ -177,6 +172,16 @@ export default defineComponent({
       if (this.uuid == content.uuid && this.username && this.username != content.user) {
         if (content.method === "toast") {
           toast({ html: content.payload });
+        } else if (content.method === "join") {
+          this.coeditors.add(content.user);
+          toast({ html: `L'utilisateur ${content.user} s'est connecter.`, displayLength: 20000 });
+        } else if (content.method === "leave") {
+          this.coeditors.delete(content.user);
+          toast({
+            html: `L'utilisateur ${content.user} s'est déconnecter.`,
+            displayLength: 20000,
+            classes: "warn",
+          });
         } else {
           this.$store.dispatch(ActionTypes.commitRemote, content);
         }
@@ -184,18 +189,23 @@ export default defineComponent({
     },
     handleStompQuery(msg: Stomp.Message) {
       var content = JSON.parse(msg.body) as StompQueryMessage;
-      if (content.type == "planningRequest" && content.uuid == this.uuid) {
-        const response: StompQueryMessage = {
-          type: "planningData",
-          uuid: this.uuid,
-          destination: content.destination,
-          payload: zipEncode(JSON.stringify(this.$store.getters.getJSONEvenementState)),
-        };
-        this.stompClient?.send("/app/response", {}, JSON.stringify(response));
-      }
-      if (content.type == "planningData" && content.uuid == this.uuid) {
-        const payload = JSON.parse(decodeUnzip(content.payload)) as EvenementStateJSON;
-        this.importState(payload);
+      if (content.uuid === this.uuid) {
+        if (content.type == "planningRequest") {
+          const response: StompQueryMessage = {
+            type: "planningData",
+            uuid: this.uuid,
+            destination: content.destination,
+            payload: zipEncode(JSON.stringify(this.$store.getters.getJSONEvenementState)),
+          };
+          this.stompClient?.send("/app/response", {}, JSON.stringify(response));
+        }
+        if (content.type == "planningData") {
+          const payload = JSON.parse(decodeUnzip(content.payload)) as EvenementStateJSON;
+          this.importState(payload);
+        }
+        if (content.type === "planningCoeditor") {
+          this.coeditors = new Set(JSON.parse(content.payload));
+        }
       }
     },
     localSave() {

+ 1 - 1
src/models/messages/PlanningUpdateMessage.ts

@@ -3,7 +3,7 @@ import { Mutations } from "@/store/Mutations";
 export type PlanningUpdateMessage = {
   uuid: string;
   user: string;
-  method: keyof Mutations | "toast";
+  method: keyof Mutations | "toast" | "join" | "leave";
   payload: string;
 };
 export default PlanningUpdateMessage;

+ 1 - 1
src/models/messages/StompQueryMessage.ts

@@ -1,4 +1,4 @@
-export type StompQuery = "planningRequest" | "planningData";
+export type StompQuery = "planningRequest" | "planningData" | "planningCoeditor";
 
 export type StompQueryMessage = {
   type: StompQuery;

+ 10 - 2
src/store/Actions.ts

@@ -70,11 +70,17 @@ export const actions: ActionTree<State, State> & Actions = {
         const content = payload.payload as { r: Ressource; pos: number };
         body.payload = JSON.stringify({ r: content.r.toJSON(), pos: content.pos });
       }
-      if (body.payload != "") client.send("/app/notify", {}, JSON.stringify(body));
+      if (body.payload != "" || payload.mutation == MutationTypes.clearBenevole2Creneau)
+        client.send("/app/notify", {}, JSON.stringify(body));
     }
   },
   [ActionTypes.commitRemote](context, data) {
-    if (data.method != "toast" && data.uuid == context.state.evenement.uuid) {
+    if (
+      data.method != "toast" &&
+      data.method != "join" &&
+      data.method != "leave" &&
+      data.uuid == context.state.evenement.uuid
+    ) {
       // Handle mutations that have dedicated JSON parser
       if (data.method == MutationTypes.addBenevole)
         context.commit(data.method, Benevole.fromJSON(JSON.parse(data.payload)));
@@ -99,6 +105,8 @@ export const actions: ActionTree<State, State> & Actions = {
         context.commit(data.method, content);
       } else if (RAW_PAYLOAD.includes(data.method)) {
         context.commit(data.method, JSON.parse(data.payload));
+      } else if (data.method == MutationTypes.clearBenevole2Creneau) {
+        context.commit(MutationTypes.clearBenevole2Creneau, undefined);
       }
     }
   },