This repository was archived by the owner on Mar 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUserClassesPlugin.js
More file actions
111 lines (99 loc) · 3.22 KB
/
Copy pathUserClassesPlugin.js
File metadata and controls
111 lines (99 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import $ from 'jquery';
import { defer } from 'underscore';
import { after } from 'meld';
import Events from 'plug/core/Events';
import currentUser from 'plug/models/currentUser';
import UserRowView from 'plug/views/rooms/users/RoomUserRowView';
import WaitListRowView from 'plug/views/rooms/users/WaitListRowView';
import userRolloverView from 'plug/views/users/userRolloverView';
import Plugin from '../Plugin';
import getUserClasses from '../util/getUserClasses';
const r = API.ROLE;
const { roleClasses } = getUserClasses;
const UserClasses = Plugin.extend({
name: 'User Classes',
description: 'Adds some CSS classes for roles and IDs to various places.',
enable() {
this.listenTo(Events, 'chat:beforereceive', this.onChat);
// common advice for user lists
const rowAdvice = function afterUpdateRow() {
// `this` is the row view
const id = this.model.get('id');
if (id) {
this.$el.addClass(getUserClasses(id).join(' '));
}
};
this.rowClasses = after(UserRowView.prototype, 'draw', rowAdvice);
this.waitListClasses = after(WaitListRowView.prototype, 'render', rowAdvice);
this.rolloverClasses = after(userRolloverView, 'showSimple', function afterShowSimple() {
// `this` is the rollover view
const id = this.user.get('id');
if (id) {
this.$el.addClass(getUserClasses(id).join(' '));
}
});
this.onUserChange();
// guest change, mostly
this.listenTo(currentUser, 'change:id change:role change:gRole', this.onUserChange);
},
disable() {
this.rowClasses.remove();
this.waitListClasses.remove();
this.rolloverClasses.remove();
},
onChat(msg) {
const classes = msg.classes ? [msg.classes] : [];
if (msg.uid) {
classes.push(...getUserClasses(msg.uid));
// additional plugCubed chat-only classes
// PlugCubed's classes start with `from-` instead of `role-` so we can't
// just use getUserClasses()
classes.push(`fromID-${msg.uid}`);
const user = API.getUser(msg.uid);
if (msg.uid === API.getUser().id) {
classes.push('from-you');
}
if (user) {
if (user.gRole === r.HOST) {
classes.push('from-admin');
} else if (user.gRole >= r.BOUNCER) {
classes.push('from-ambassador');
}
if (user.friend) {
classes.push('from-friend');
}
// normal user & staff roles
classes.push(`from-${roleClasses[user.role]}`);
}
}
if (msg.sub) {
classes.push('from-subscriber');
}
msg.classes = classes.join(' ');
},
onUserChange() {
this.setUserViewClass();
this.setUserFooterClass();
},
setUserViewClass() {
defer(() => {
$('#user-view')
.removeClass()
.addClass('app-left')
.addClass(getUserClasses(API.getUser().id).join(' '));
});
},
setUserFooterClass() {
defer(() => {
const footer = $('#footer-user');
const online = footer.hasClass('online');
const showing = footer.hasClass('showing');
footer
.removeClass()
.toggleClass('online', online)
.toggleClass('showing', showing)
.addClass(getUserClasses(API.getUser().id).join(' '));
});
},
});
export default UserClasses;