Skip to content
This repository was archived by the owner on Jul 17, 2020. It is now read-only.

Commit 93836e6

Browse files
author
Zirak
committed
Muting and unmuting now bring a room in and out of gallery mode when appropriate.
1 parent 85dc83d commit 93836e6

File tree

3 files changed

+148
-265
lines changed

3 files changed

+148
-265
lines changed

master.js

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5899,6 +5899,8 @@ function checkMuted () {
58995899
}
59005900
});
59015901

5902+
galleryMode.unlockIfNeeded();
5903+
59025904
setTimeout( checkMuted, 60 * 1000 );
59035905
}
59045906
setTimeout( checkMuted, 60 * 1000 );
@@ -5978,6 +5980,73 @@ function takeVoice ( params, cb ) {
59785980
}
59795981
}
59805982

5983+
var galleryMode = {
5984+
lockIfNeeded : function () {
5985+
if ( this.roomInGallery() ) {
5986+
bot.log('room already in gallery');
5987+
return;
5988+
}
5989+
5990+
bot.log('locking room');
5991+
this.lockRoom();
5992+
},
5993+
5994+
lockRoom : function () {
5995+
IO.xhr({
5996+
method : 'POST',
5997+
url : '/rooms/save',
5998+
data : fkey({
5999+
defaultAccess : 'read-only',
6000+
roomId : ownerRoom // implied state. change to variable?
6001+
}),
6002+
6003+
complete : finish
6004+
});
6005+
6006+
// Not much to do here, tbh...we'd probably get a refresh by the time
6007+
//this fires. Should probably do error checking.
6008+
function finish () {}
6009+
},
6010+
6011+
// Room should get locked if it's not already in gallery mode.
6012+
roomInGallery : function () {
6013+
var lockButtonClass = 'sprite-sec-gallery';
6014+
return document.getElementsByClassName( lockButtonClass ).length;
6015+
},
6016+
6017+
unlockIfNeeded : function () {
6018+
if ( !this.shouldUnlockRoom() ) {
6019+
bot.log('not unlocking room');
6020+
return;
6021+
}
6022+
6023+
bot.log( 'unlocking room' );
6024+
this.unlockRoom();
6025+
},
6026+
6027+
unlockRoom : function () {
6028+
IO.xhr({
6029+
method : 'POST',
6030+
url : '/rooms/save',
6031+
data : fkey({
6032+
defaultAccess : 'read-write',
6033+
roomId : ownerRoom // Again implied state.
6034+
}),
6035+
6036+
complete : finish
6037+
});
6038+
6039+
// Again, not much to do.
6040+
function finish () {}
6041+
},
6042+
6043+
// Room should be unlocked if there aren't any more muted users and we're
6044+
//locked.
6045+
shouldUnlockRoom : function () {
6046+
return this.roomInGallery() && !( Object.keys(muted).length );
6047+
}
6048+
};
6049+
59816050
IO.register( 'userregister', function permissionCb ( user, room ) {
59826051
bot.log( user, room, 'permissionCb' );
59836052
var id = user.id;
@@ -6081,7 +6150,7 @@ bot.addCommand({
60816150
return userInfo.error;
60826151
}
60836152
else if ( userInfo.id === bot.adapter.user_id ) {
6084-
return 'Never try and mute a bot who can own your ass.';
6153+
return 'Never try and mute a bot which can own your ass.';
60856154
}
60866155
else if ( bot.isOwner(userInfo.id) ) {
60876156
return 'You probably didn\'t want to mute a room owner.';
@@ -6101,6 +6170,7 @@ bot.addCommand({
61016170
function finish () {
61026171
args.reply(
61036172
'Muted user {0} for {1}'.supplant(userInfo.id, duration) );
6173+
galleryMode.lockIfNeeded();
61046174
}
61056175
},
61066176

@@ -6133,6 +6203,7 @@ bot.addCommand({
61336203

61346204
function finish () {
61356205
args.reply( 'Unmuted user ' + userID.id );
6206+
galleryMode.unlockIfNeeded();
61366207
}
61376208
},
61386209

0 commit comments

Comments
 (0)