Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski 2019-09-18 09:27:43 +01:00
parent 54ea85f235
commit e502558f7d
8 changed files with 46 additions and 52 deletions

View file

@ -15,8 +15,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
const MatrixClientPeg = require("./MatrixClientPeg");
const dis = require("./dispatcher");
import MatrixClientPeg from "./MatrixClientPeg";
import dis from "./dispatcher";
import Timer from './utils/Timer';
// Time in ms after that a user is considered as unavailable/away
@ -24,7 +24,6 @@ const UNAVAILABLE_TIME_MS = 3 * 60 * 1000; // 3 mins
const PRESENCE_STATES = ["online", "offline", "unavailable"];
class Presence {
constructor() {
this._activitySignal = null;
this._unavailableTimer = null;
@ -43,7 +42,7 @@ class Presence {
try {
await this._unavailableTimer.finished();
this.setState("unavailable");
} catch(e) { /* aborted, stop got called */ }
} catch (e) { /* aborted, stop got called */ }
}
}
@ -88,7 +87,7 @@ class Presence {
if (PRESENCE_STATES.indexOf(newState) === -1) {
throw new Error("Bad presence state: " + newState);
}
const old_state = this.state;
const oldState = this.state;
this.state = newState;
if (MatrixClientPeg.get().isGuest()) {
@ -98,9 +97,9 @@ class Presence {
try {
await MatrixClientPeg.get().setPresence(this.state);
console.log("Presence: %s", newState);
} catch(err) {
} catch (err) {
console.error("Failed to set presence: %s", err);
this.state = old_state;
this.state = oldState;
}
}
}