|
|
@@ -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() {
|