alexlcdee il y a 8 ans
Parent
commit
3a59d8d3db
2 fichiers modifiés avec 15 ajouts et 8 suppressions
  1. 6 0
      src/Client.ts
  2. 9 8
      src/Conversation.ts

+ 6 - 0
src/Client.ts

@@ -202,6 +202,12 @@ export namespace Clients {
             socket.on('chat-run-conversation', this.onRunConversation.bind(this));
             socket.on('chat-send-message', this.onSendMessage.bind(this));
             socket.on('chat-stop-conversation', this.onStopConversation.bind(this));
+            this.logger.debug(`Restart conversations`);
+            for (let id in this.conversations) {
+                if (this.conversations.hasOwnProperty(id)) {
+                    this.conversations[id].state = Interfaces.ConversationState.RUNNING();
+                }
+            }
         }
 
         send(event: string, data: {} = {}) {

+ 9 - 8
src/Conversation.ts

@@ -1,4 +1,5 @@
 import {Interfaces} from "./Interfaces";
+import ConversationStateInterface = Interfaces.ConversationState;
 
 export module Conversations {
 
@@ -103,7 +104,7 @@ export module Conversations {
 
         duration: number = 0;
 
-        private conversationState: (value?: Interfaces.ConversationState) => Interfaces.ConversationState;
+        private conversationState: (value?: Interfaces.ConversationState) => ConversationStateInterface;
 
         private apiConnector: Interfaces.ApiConnectorInterface;
         private initiator: Interfaces.ClientInterface;
@@ -117,13 +118,13 @@ export module Conversations {
             this.logger = logger;
             this._id = id;
             let state = Interfaces.ConversationState.INIT();
-            this.conversationState = (value?: Interfaces.ConversationState) => {
+            this.conversationState = (value?: ConversationStateInterface) => {
                 if (value !== undefined)
                     state = value;
                 return state;
             };
 
-            this.state = Interfaces.ConversationState.INIT();
+            this.state = ConversationStateInterface.INIT();
         }
 
         getInitiator(): Interfaces.ClientInterface {
@@ -144,15 +145,15 @@ export module Conversations {
 
         set state(state: Interfaces.ConversationState) {
             if (!this.state.isEqualsTo(state)) {
-                if (state.isEqualsTo(Interfaces.ConversationState.INIT())) {
+                if (state.isEqualsTo(ConversationStateInterface.INIT())) {
                 }
-                if (state.isEqualsTo(Interfaces.ConversationState.RUNNING())) {
+                if (state.isEqualsTo(ConversationStateInterface.RUNNING())) {
                     this.setRunning();
                 }
-                if (state.isEqualsTo(Interfaces.ConversationState.PAUSED())) {
+                if (state.isEqualsTo(ConversationStateInterface.PAUSED())) {
                     this.setPaused();
                 }
-                if (state.isEqualsTo(Interfaces.ConversationState.STOPPED())) {
+                if (state.isEqualsTo(ConversationStateInterface.STOPPED())) {
                     this.setStopped();
                 }
                 this.conversationState(state);
@@ -174,7 +175,7 @@ export module Conversations {
                     this.recipient.payedTime += Math.round(interval * this.recipient.coefficient);
                     if (this.initiator.payedTime < 0) {
                         this.logger.debug(`User with ID=${this.initiator.id} is ran out of money`);
-                        this.state = Interfaces.ConversationState.STOPPED();
+                        this.state = ConversationStateInterface.STOPPED();
                     }
                 }, 1000);
             }