mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-08-06 06:10:54 +00:00
* Fixed: When unloading an emote set, also unload its CSS block. * API Added: `badges.removeBadge()` method for removing a badge from the system. * API Added: `chat.iterateUsers()` method to iterate all User instances. * API Added: `getUser().removeAllBadges()` method to remove all badges from a provider. * API Added: `getRoom().iterateUsers()` method to iterate all User instances on a Room instance. * API Added: `tooltips.define()` method to add a tool-tip handler to the system. * API Changed: All core modules now use the add-on proxies to track which add-ons are responsible for injecting content, and to make it easier to unload (and reload) add-ons. * API Changed: Many core module methods now display warning messages in the console when used improperly. For now, this mainly checks that IDs are correct, but there may be more warnings in the future. * API Fixed: Calling `resolve()` will now properly use add-on proxies. * Experiment Changed: Improved handling for server disconnects with the MQTT experiment, as well as handling for topic mapping changes.
238 lines
No EOL
5 KiB
JavaScript
238 lines
No EOL
5 KiB
JavaScript
'use strict';
|
|
|
|
// ============================================================================
|
|
// User
|
|
// ============================================================================
|
|
|
|
import {SourcedSet} from 'utilities/object';
|
|
|
|
export default class User {
|
|
constructor(manager, room, id, login) {
|
|
this.manager = manager;
|
|
this.room = room;
|
|
|
|
this.emote_sets = null; //new SourcedSet;
|
|
this.badges = null; // new SourcedSet;
|
|
|
|
this._id = id;
|
|
this.login = login;
|
|
|
|
if ( id )
|
|
(room || manager).user_ids[id] = this;
|
|
}
|
|
|
|
destroy() {
|
|
this.destroyed = true;
|
|
|
|
if ( this.emote_sets ) {
|
|
for(const set_id of this.emote_sets._cache)
|
|
this.manager.emotes.unrefSet(set_id);
|
|
|
|
this.emote_sets = null;
|
|
}
|
|
|
|
if ( this.badges )
|
|
this.badges = null;
|
|
|
|
const parent = this.room || this.manager;
|
|
|
|
if ( parent ) {
|
|
if ( this._login && parent.users && parent.users[this._login] === this )
|
|
parent.users[this._login] = null;
|
|
|
|
if ( parent.user_ids && parent.user_ids[this._id] === this )
|
|
parent.user_ids[this._id] = null;
|
|
}
|
|
}
|
|
|
|
merge(other) {
|
|
if ( ! this.login && other.login )
|
|
this.login = other.login;
|
|
|
|
if ( other.emote_sets && other.emote_sets._sources ) {
|
|
for(const [provider, sets] of other.emote_sets._sources.entries()) {
|
|
for(const set_id of sets)
|
|
this.addSet(provider, set_id);
|
|
}
|
|
}
|
|
|
|
if ( other.badges && other.badges._sources ) {
|
|
for(const [provider, badges] of other.badges._sources.entries()) {
|
|
for(const badge of badges)
|
|
this.addBadge(provider, badge.id, badge);
|
|
}
|
|
}
|
|
}
|
|
|
|
_unloadAddon(addon_id) {
|
|
// TODO: This
|
|
return 0;
|
|
}
|
|
|
|
get id() {
|
|
return this._id;
|
|
}
|
|
|
|
get login() {
|
|
return this._login;
|
|
}
|
|
|
|
set login(val) {
|
|
if ( this._login === val )
|
|
return;
|
|
|
|
const obj = this.room || this.manager;
|
|
|
|
if ( this._login ) {
|
|
const old_user = obj.users[this._login];
|
|
if ( old_user === this )
|
|
obj.users[this._login] = null;
|
|
}
|
|
|
|
this._login = val;
|
|
if ( ! val )
|
|
return;
|
|
|
|
const old_user = obj.users[val];
|
|
if ( old_user && old_user !== this )
|
|
old_user.login = null;
|
|
|
|
// Make sure we didn't have a funky loop thing happen.
|
|
this._login = val;
|
|
obj.users[val] = this;
|
|
}
|
|
|
|
|
|
// ========================================================================
|
|
// Add Badges
|
|
// ========================================================================
|
|
|
|
addBadge(provider, badge_id, data) {
|
|
if ( this.destroyed )
|
|
return;
|
|
|
|
if ( typeof badge_id === 'number' )
|
|
badge_id = `${badge_id}`;
|
|
|
|
if ( data )
|
|
data.id = badge_id;
|
|
else
|
|
data = {id: badge_id};
|
|
|
|
if ( ! this.badges )
|
|
this.badges = new SourcedSet;
|
|
|
|
if ( this.badges.has(provider) )
|
|
for(const old_b of this.badges.get(provider))
|
|
if ( old_b.id == badge_id ) {
|
|
Object.assign(old_b, data);
|
|
return false;
|
|
}
|
|
|
|
this.badges.push(provider, data);
|
|
//this.manager.badges.refBadge(badge_id);
|
|
return true;
|
|
}
|
|
|
|
|
|
getBadge(badge_id) {
|
|
if ( ! this.badges )
|
|
return null;
|
|
|
|
for(const badge of this.badges._cache)
|
|
if ( badge.id == badge_id )
|
|
return badge;
|
|
}
|
|
|
|
|
|
removeBadge(provider, badge_id) {
|
|
if ( ! this.badges || ! this.badges.has(provider) )
|
|
return false;
|
|
|
|
for(const old_b of this.badges.get(provider))
|
|
if ( old_b.id == badge_id ) {
|
|
this.badges.remove(provider, old_b);
|
|
//this.manager.badges.unrefBadge(badge_id);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
removeAllBadges(provider) {
|
|
if ( this.destroyed || ! this.badges )
|
|
return false;
|
|
|
|
if ( ! this.badges.has(provider) )
|
|
return false;
|
|
|
|
// Just yeet them all since we don't ref badges.
|
|
this.badges.delete(provider);
|
|
return true;
|
|
}
|
|
|
|
|
|
// ========================================================================
|
|
// Emote Sets
|
|
// ========================================================================
|
|
|
|
addSet(provider, set_id, data) {
|
|
if ( this.destroyed )
|
|
return;
|
|
|
|
if ( ! this.emote_sets )
|
|
this.emote_sets = new SourcedSet;
|
|
|
|
if ( typeof set_id === 'number' )
|
|
set_id = `${set_id}`;
|
|
|
|
let changed = false, added = false;
|
|
if ( ! this.emote_sets.sourceIncludes(provider, set_id) ) {
|
|
changed = ! this.emote_sets.includes(set_id);
|
|
this.emote_sets.push(provider, set_id);
|
|
added = true;
|
|
}
|
|
|
|
if ( data )
|
|
this.manager.emotes.loadSetData(set_id, data);
|
|
|
|
if ( changed ) {
|
|
this.manager.emotes.refSet(set_id);
|
|
this.manager.emotes.emit(':update-user-sets', this, provider, set_id, true);
|
|
}
|
|
|
|
return added;
|
|
}
|
|
|
|
removeAllSets(provider) {
|
|
if ( this.destroyed || ! this.emote_sets )
|
|
return false;
|
|
|
|
const sets = this.emote_sets.get(provider);
|
|
if ( ! Array.isArray(sets) || ! sets.length )
|
|
return false;
|
|
|
|
for(const set_id of sets)
|
|
this.removeSet(provider, set_id);
|
|
|
|
return true;
|
|
}
|
|
|
|
removeSet(provider, set_id) {
|
|
if ( this.destroyed || ! this.emote_sets )
|
|
return;
|
|
|
|
if ( typeof set_id === 'number' )
|
|
set_id = `${set_id}`;
|
|
|
|
if ( this.emote_sets.sourceIncludes(provider, set_id) ) {
|
|
this.emote_sets.remove(provider, set_id);
|
|
if ( ! this.emote_sets.includes(set_id) ) {
|
|
this.manager.emotes.unrefSet(set_id);
|
|
this.manager.emotes.emit(':update-user-sets', this, provider, set_id, false);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
} |