Skip to content

Commit

Permalink
Watching Focus (#338)
Browse files Browse the repository at this point in the history
* Watching Focus

* Fix for new event messages

* Add bootstrap tooltip

* Swap bootstrap with tippy
  • Loading branch information
Mitchdev authored Dec 5, 2023
1 parent d5ce32b commit 052e4f1
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 5 deletions.
31 changes: 30 additions & 1 deletion assets/chat/css/style.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
@import '../../common';
@import '../../icons/icons';
@import '~normalize.css';
@import '~tippy.js/dist/tippy.css';
@import '~tippy.js/dist/svg-arrow.css';
@import url('https://fonts.googleapis.com/css?family=Roboto:400,500,600,700');

*,
Expand Down Expand Up @@ -200,6 +202,11 @@ hr {
center;
background-size: contain;
}
#chat-watching-focus-btn .btn-icon {
background: transparent url('../img/icon-watching.svg') no-repeat center
center;
background-size: contain;
}
#chat-settings-btn .btn-icon {
background: transparent url('../img/icon-settings.svg') no-repeat center
center;
Expand Down Expand Up @@ -836,8 +843,20 @@ hr {
}
}

.watching-focus {
.msg-emote,
.msg-user {
opacity: 0.3;

&.watching-same,
&.msg-highlight {
opacity: 1;
}
}
}

/* Focus or highlight a line */
.focus .msg-chat {
.focus:not(.watching-focus) .msg-chat {
opacity: 0.3;

&.msg-pinned {
Expand Down Expand Up @@ -2162,3 +2181,13 @@ body.pref-fontscale[data-fontscale='10'] {
font-family: 'Among Us';
src: url('../../../fonts/AmongUs-Regular.ttf') format('truetype');
}

.tippy-box[data-theme~='dgg'] {
text-align: center;
background-color: white;
color: #000;
}

.tippy-box[data-theme~='dgg'] > .tippy-svg-arrow {
fill: white;
}
1 change: 1 addition & 0 deletions assets/chat/img/icon-watching.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 39 additions & 1 deletion assets/chat/js/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { fetch } from 'whatwg-fetch';
import $ from 'jquery';
import { debounce } from 'throttle-debounce';
import moment from 'moment';
import tippy, { roundArrow } from 'tippy.js';
import {
KEYCODES,
DATE_FORMATS,
Expand Down Expand Up @@ -102,6 +103,7 @@ class Chat {
this.regexhighlightnicks = null;
this.regexhighlightself = null;
this.replyusername = null;
this.watchingfocus = false;

// An interface to tell the chat to do things via chat commands, or via emit
// e.g. control.emit('CONNECT', 'ws://localhost:9001') is essentially chat.cmdCONNECT('ws://localhost:9001')
Expand Down Expand Up @@ -265,6 +267,16 @@ class Chat {
return link.sheet;
})();

// Tooltips
tippy('[data-tippy-content]', {
arrow: roundArrow,
delay: 0,
duration: 0,
maxWidth: 250,
hideOnClick: false,
theme: 'dgg',
});

this.ishidden = (document.visibilityState || 'visible') !== 'visible';
this.output = this.ui.find('#chat-output-frame');
this.input = this.ui.find('#chat-input-control');
Expand Down Expand Up @@ -352,6 +364,12 @@ class Chat {
}
});

// Watching focus
this.ui.on('click touch', '#chat-watching-focus-btn', () => {
this.watchingfocus = !this.watchingfocus;
this.ui.toggleClass('watching-focus', this.watchingfocus);
});

// Chat focus / menu close when clicking on some areas
let downinoutput = false;
this.output.on('mousedown', () => {
Expand Down Expand Up @@ -687,6 +705,12 @@ class Chat {
) {
user.createdDate = data.createdDate;
}
if (
Object.hasOwn(data, 'watching') &&
!user.equalWatching(data.watching)
) {
user.watching = data.watching;
}
}
return user;
}
Expand Down Expand Up @@ -1057,10 +1081,21 @@ class Chat {
) {
if (win.lastmessage.type === MessageTypes.EMOTE) {
win.lastmessage.incEmoteCount();

if (this.user.equalWatching(usr.watching)) {
win.lastmessage.ui.classList.toggle('watching-same', true);
}

this.mainwindow.update();
} else {
win.removeLastMessage();
MessageBuilder.emote(textonly, data.timestamp, 2).into(this);
const msg = MessageBuilder.emote(textonly, data.timestamp, 2).into(
this,
);

if (this.user.equalWatching(usr.watching)) {
msg.ui.classList.add('watching-same');
}
}
} else if (!this.resolveMessage(data.nick, data.data)) {
MessageBuilder.message(data.data, usr, data.timestamp).into(this);
Expand Down Expand Up @@ -1394,6 +1429,9 @@ class Chat {
onUPDATEUSER(data) {
if (this.user?.id === data.id) {
this.setUser(data);
for (const window of this.windows.values()) {
window.updateMessages(this);
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions assets/chat/js/messages/ChatMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default class ChatMessage extends ChatUIMessage {
this.unformatted = unformatted;
this.ignored = false;
this.censorType = null;
this.watching = null;
}

html(chat = null) {
Expand Down Expand Up @@ -146,4 +147,11 @@ export default class ChatMessage extends ChatUIMessage {
this.ui.classList.toggle('msg-own', isOwn);
this.isown = isOwn;
}

setWatching(user) {
this.ui.classList.toggle(
'watching-same',
user.equalWatching(this.watching),
);
}
}
7 changes: 7 additions & 0 deletions assets/chat/js/messages/ChatUserMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ export default class ChatUserMessage extends ChatMessage {
if (this.user && this.user.username) {
classes.push(...this.user.features);
attr['data-username'] = this.user.username;

if (this.user.watching) {
this.watching = this.user.watching;
if (chat.user.equalWatching(this.user.watching)) {
classes.push('watching-same');
}
}
}
if (this.mentioned && this.mentioned.length > 0)
attr['data-mentioned'] = this.mentioned.join(' ').toLowerCase();
Expand Down
14 changes: 14 additions & 0 deletions assets/chat/js/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ class ChatUser {
*/
features = [];

/**
* User's watching embed.
* @type {?Object}
*/
watching = null;

/**
* @param {string|User} user
*/
Expand All @@ -52,6 +58,7 @@ class ChatUser {
this.username = this.displayName.toLowerCase();
this.createdDate = user.createdDate || '';
this.features = user.features || [];
this.watching = user.watching || null;
}
}

Expand Down Expand Up @@ -111,6 +118,13 @@ class ChatUser {
}
return 0;
}

equalWatching(embed) {
return (
this.watching?.platform === embed?.platform &&
this.watching?.id === embed?.id
);
}
}

export default ChatUser;
1 change: 1 addition & 0 deletions assets/chat/js/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class ChatWindow extends EventEmitter {
message.highlight(chat.shouldHighlightMessage(message));
message.setTag(chat.taggednicks.get(username));
message.setTagTitle(chat.taggednotes.get(username));
message.setWatching(chat.user);

if (message.moderated) {
message.censor(parseInt(chat.settings.get('showremoved') || '1', 10));
Expand Down
7 changes: 7 additions & 0 deletions assets/views/embed.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@
</a>
</div>
<div class="chat-tools-group">
<a
id="chat-watching-focus-btn"
class="chat-tool-btn"
data-tippy-content="Highlights messages from users watching the same stream"
>
<i class="btn-icon"></i>
</a>
<a id="chat-settings-btn" class="chat-tool-btn" title="Settings">
<i class="btn-icon"></i>
</a>
Expand Down
34 changes: 32 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"overlayscrollbars": "^2.0.3",
"sass-loader": "^13.2.0",
"throttle-debounce": "~5.0.0",
"tippy.js": "^6.3.7",
"whatwg-fetch": "^3.6.2"
},
"devDependencies": {
Expand Down Expand Up @@ -87,4 +88,4 @@
"prettier -cwu --loglevel silent ."
]
}
}
}

0 comments on commit 052e4f1

Please sign in to comment.