|
|
@@ -144,7 +144,6 @@ export module Conversations {
|
|
|
|
|
|
set state(state: Interfaces.ConversationState) {
|
|
|
if (!this.state.isEqualsTo(state)) {
|
|
|
- this.conversationState(state);
|
|
|
if (state.isEqualsTo(Interfaces.ConversationState.INIT())) {
|
|
|
}
|
|
|
if (state.isEqualsTo(Interfaces.ConversationState.RUNNING())) {
|
|
|
@@ -156,6 +155,7 @@ export module Conversations {
|
|
|
if (state.isEqualsTo(Interfaces.ConversationState.STOPPED())) {
|
|
|
this.setStopped();
|
|
|
}
|
|
|
+ this.conversationState(state);
|
|
|
} else {
|
|
|
this.logger.debug(`Conversation state already set to "${state.toString()}"`);
|
|
|
}
|
|
|
@@ -170,8 +170,8 @@ export module Conversations {
|
|
|
let interval = (now - lastIntervalTick) / 1000;
|
|
|
this.duration += interval;
|
|
|
lastIntervalTick = now;
|
|
|
- this.initiator.payedTime -= Math.ceil(interval * this.recipient.coefficient);
|
|
|
- this.recipient.payedTime += Math.ceil(interval * this.recipient.coefficient);
|
|
|
+ this.initiator.payedTime -= Math.round(interval * this.recipient.coefficient);
|
|
|
+ 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();
|
|
|
@@ -190,30 +190,30 @@ export module Conversations {
|
|
|
private sync() {
|
|
|
this.initiator.send('chat-sync-timer', {
|
|
|
conversationId: this.id,
|
|
|
- duration: Math.ceil(this.duration)
|
|
|
+ duration: Math.round(this.duration)
|
|
|
});
|
|
|
|
|
|
this.recipient.send('chat-sync-timer', {
|
|
|
conversationId: this.id,
|
|
|
- duration: Math.ceil(this.duration)
|
|
|
+ duration: Math.round(this.duration)
|
|
|
});
|
|
|
|
|
|
this.apiConnector.execute('/conversations', {
|
|
|
id: this.id,
|
|
|
action: 'duration',
|
|
|
- duration: Math.ceil(this.duration)
|
|
|
+ duration: Math.round(this.duration)
|
|
|
});
|
|
|
|
|
|
this.apiConnector.execute('/user', {
|
|
|
action: 'updatetime',
|
|
|
id: this.initiator.id,
|
|
|
- value: Math.ceil(this.initiator.payedTime)
|
|
|
+ value: Math.round(this.initiator.payedTime)
|
|
|
});
|
|
|
|
|
|
this.apiConnector.execute('/user', {
|
|
|
action: 'updatetime',
|
|
|
id: this.recipient.id,
|
|
|
- value: Math.ceil(this.recipient.payedTime)
|
|
|
+ value: Math.round(this.recipient.payedTime)
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -235,7 +235,7 @@ export module Conversations {
|
|
|
this.syncInterval = null;
|
|
|
delete this.initiator.conversations[this.id];
|
|
|
delete this.recipient.conversations[this.id];
|
|
|
- this.apiConnector.execute('/conversations', {id: this.id, action: 'stop', duration: this.duration});
|
|
|
+ this.apiConnector.execute('/conversations', {id: this.id, action: 'stop', duration: Math.round(this.duration)});
|
|
|
this.apiConnector.execute('/user', {
|
|
|
action: 'updatetime',
|
|
|
id: this.initiator.id,
|