xmppjs-chat-bot
Version:
Server-side XMPP chat bot
46 lines • 1.48 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RoomUser = void 0;
class RoomUser {
constructor(room, presence) {
this.currentState = 'offline';
this.room = room;
if (!presence.from) {
throw new Error('Can\'t instanciate a RoomUser from a presence stanza without from.');
}
this.jid = presence.from;
this.userIsMe = presence.isMe();
this.role = 'none';
this.affiliation = 'none';
this.update(presence);
}
update(presence) {
if (presence.from?.toString() !== this.jid.toString()) {
this.room.logger.error('This presence stanza is not for the same user.');
return false;
}
const isPresent = presence.type !== 'unavailable';
const previousState = this.currentState;
this.currentState = isPresent ? 'online' : 'offline';
this.role = presence.role() ?? this.role;
this.affiliation = presence.affiliation() ?? this.affiliation;
return this.currentState !== previousState;
}
updateNick(nickname) {
this.jid.setResource(nickname);
}
get nick() {
return this.jid.getResource();
}
isOnline() {
return this.currentState === 'online';
}
isMe() {
return this.userIsMe;
}
isModerator() {
return this.role === 'moderator';
}
}
exports.RoomUser = RoomUser;
//# sourceMappingURL=user.js.map