Browse Source

implement user muting/deafening and displaying their avatars in the channel viewer user edit thingy

Natenom/support-murmur-13-1446181288462
Michael Ziegler 15 years ago
parent
commit
24f454d9ea
  1. 42
      pyweb/mumble/media/js/channelviewerplugins.js
  2. 20
      pyweb/mumble/mmobjects.py
  3. 28
      pyweb/mumble/models.py
  4. 32
      pyweb/mumble/views.py

42
pyweb/mumble/media/js/channelviewerplugins.js

@ -37,14 +37,30 @@ Ext.ux.MumbleUserEditor = Ext.extend( Ext.Component, {
}], }],
}, { }, {
title: gettext("Avatar"), title: gettext("Avatar"),
html: '<img src="http://www.gravatar.com/avatar/6a11052bfa1ae52aa63fc0001417158d.jpg?d=monsterid&s=80" />',
scope: this,
listeners: {
afterrender: function( panel ){
Mumble.hasTexture( this.scope.serverid, this.scope.userdata.userid, function(provider, response){
if( response.result.has ){
panel.el.dom.children[0].children[0].innerHTML = String.format(
'<img src="{0}" alt="avatar" />', response.result.url
);
}
else{
panel.el.dom.children[0].children[0].innerHTML =
gettext("This user does not have an Avatar.");
}
} );
}
},
html: gettext("Loading..."),
}, { }, {
title: gettext("Infos"), title: gettext("Infos"),
html: "<ul><li>admin: yes</li><li>registered: maybe</li></ul>", html: "<ul><li>admin: yes</li><li>registered: maybe</li></ul>",
}, { }, {
xtype: "form", xtype: "form",
border: false, border: false,
title: gettext("Kick/Ban"),
title: gettext("Administration"),
items: [{ items: [{
xtype: "checkbox", xtype: "checkbox",
fieldLabel: gettext("Ban"), fieldLabel: gettext("Ban"),
@ -72,6 +88,28 @@ Ext.ux.MumbleUserEditor = Ext.extend( Ext.Component, {
this.serverid, this.userdata.session, f.reason, (f.ban || false), parseInt(f.duration) this.serverid, this.userdata.session, f.reason, (f.ban || false), parseInt(f.duration)
); );
} }
}, {
text: gettext("Mute"),
enableToggle: true,
scope: this,
ref: '../mutebutton',
pressed: this.userdata.mute,
disabled: this.userdata.deaf,
toggleHandler: function(btn, state){
Mumble.muteUser(this.serverid, this.userdata.session, state);
}
}, {
text: gettext("Deafen"),
enableToggle: true,
scope: this,
ref: '../deafenbutton',
pressed: this.userdata.deaf,
toggleHandler: function(btn, state){
Mumble.deafenUser(this.serverid, this.userdata.session, state);
if( state )
btn.refOwner.mutebutton.toggle(true, true);
btn.refOwner.mutebutton.setDisabled(state);
}
}], }],
}], }],
}], }],

20
pyweb/mumble/mmobjects.py

@ -310,8 +310,14 @@ class mmPlayer( object ):
else: else:
del pldata["address"] del pldata["address"]
if self.mumbleuser and self.mumbleuser.hasTexture():
pldata['x_texture'] = "http://" + Site.objects.get_current().domain + self.mumbleuser.textureUrl
if self.channel.server.hasUserTexture(self.userid):
from views import showTexture
from django.core.urlresolvers import reverse
textureurl = reverse( showTexture, kwargs={ 'server': self.channel.server.id, 'userid': self.userid } )
pldata['x_texture'] = "http://" + Site.objects.get_current().domain + textureUrl
if self.mumbleuser and self.mumbleuser.gravatar:
pldata['x_gravatar'] = self.mumbleuser.gravatar
return pldata return pldata
@ -325,8 +331,14 @@ class mmPlayer( object ):
else: else:
me.set( "address", "" ) me.set( "address", "" )
if self.mumbleuser and self.mumbleuser.hasTexture():
me.set( 'x_texture', "http://" + Site.objects.get_current().domain + self.mumbleuser.textureUrl )
if self.channel.server.hasUserTexture(self.userid):
from views import showTexture
from django.core.urlresolvers import reverse
textureurl = reverse( showTexture, kwargs={ 'server': self.channel.server.id, 'userid': self.userid } )
me.set( 'x_texture', "http://" + Site.objects.get_current().domain + textureUrl )
if self.mumbleuser and self.mumbleuser.gravatar:
me.set( 'x_gravatar', self.mumbleuser.gravatar )
def asMvXml( self, parentnode ): def asMvXml( self, parentnode ):
""" Return an XML node for this player suitable for MumbleViewer-ng. """ """ Return an XML node for this player suitable for MumbleViewer-ng. """

28
pyweb/mumble/models.py

@ -567,7 +567,22 @@ class Mumble( models.Model ):
return self.ctl.muteUser( self.srvid, sessionid, mute ) return self.ctl.muteUser( self.srvid, sessionid, mute )
def deafenUser( self, sessionid, deafen=True ): def deafenUser( self, sessionid, deafen=True ):
return self.ctl.moveUser( self.srvid, sessionid, deafen )
return self.ctl.deafenUser( self.srvid, sessionid, deafen )
def hasUserTexture( self, userid ):
""" Check if this user has a texture set. """
try:
self.getUserTexture( userid )
except ValueError:
return False
else:
return True
def getUserTexture( self, userid ):
return self.ctl.getTexture( self.srvid, userid )
def setUserTexture( self, userid, image ):
return self.ctl.setTexture( self.srvid, userid, image )
def moveChannel( self, channelid, parentid ): def moveChannel( self, channelid, parentid ):
return self.ctl.moveChannel( self.srvid, channelid, parentid ) return self.ctl.moveChannel( self.srvid, channelid, parentid )
@ -713,11 +728,11 @@ class MumbleUser( models.Model ):
# Texture handlers # Texture handlers
def getTexture( self ): def getTexture( self ):
""" Get the user texture as a PIL Image. """ """ Get the user texture as a PIL Image. """
return self.server.ctl.getTexture(self.server.srvid, self.mumbleid)
return self.server.getUserTexture( self.mumbleid )
def setTexture( self, image ): def setTexture( self, image ):
""" Install the given image as the user's texture. """ """ Install the given image as the user's texture. """
self.server.ctl.setTexture(self.server.srvid, self.mumbleid, image)
self.server.setTexture( self.mumbleid, image )
def setTextureFromUrl( self, url, transparency=None ): def setTextureFromUrl( self, url, transparency=None ):
""" Retrieve the image at the given URL and set it as my texture. """ """ Retrieve the image at the given URL and set it as my texture. """
@ -730,12 +745,7 @@ class MumbleUser( models.Model ):
def hasTexture( self ): def hasTexture( self ):
""" Check if this user has a texture set. """ """ Check if this user has a texture set. """
try:
self.getTexture()
except ValueError:
return False
else:
return True
return self.server.hasUserTexture( self.mumbleid )
def gravatarUrl( self, size=80 ): def gravatarUrl( self, size=80 ):
""" Get a Gravatar URL for my owner's email adress (if any), or using the User's cert hash. """ Get a Gravatar URL for my owner's email adress (if any), or using the User's cert hash.

32
pyweb/mumble/views.py

@ -204,18 +204,24 @@ def mobile_show( request, server ):
'MumbleAccount':user, 'MumbleAccount':user,
}, context_instance = RequestContext(request) ) }, context_instance = RequestContext(request) )
@EXT_DIRECT_PROVIDER.register_method( "Mumble" )
def hasTexture( request, server, userid ):
srv = get_object_or_404( Mumble, id=int(server) )
if srv.hasUserTexture(int(userid)):
return {
'has': True,
'url': reverse( showTexture, kwargs={ 'server': server, 'userid': userid } )
}
else:
return { 'has': False, 'url': None }
def showTexture( request, server, userid ): def showTexture( request, server, userid ):
""" Pack the given user's texture into an HttpResponse.
If userid is none, use the currently logged in User.
"""
""" Pack the given user's texture into an HttpResponse. """
srv = get_object_or_404( Mumble, id=int(server) ) srv = get_object_or_404( Mumble, id=int(server) )
user = get_object_or_404( MumbleUser, server=srv, id=int(userid) )
try: try:
img = user.getTexture()
img = srv.getUserTexture(int(userid))
except ValueError: except ValueError:
raise Http404() raise Http404()
else: else:
@ -280,6 +286,20 @@ def kickUser( request, server, sessionid, reason, ban, duration ):
srv.banUser( sessionid, reason, duration ) srv.banUser( sessionid, reason, duration )
srv.kickUser( sessionid, reason ) srv.kickUser( sessionid, reason )
@EXT_DIRECT_PROVIDER.register_method( "Mumble" )
def muteUser( request, server, sessionid, mute ):
srv = get_object_or_404( Mumble, id=int(server) )
if not srv.isUserAdmin( request.user ):
raise Exception( 'Access denied' )
srv.muteUser(sessionid, mute)
@EXT_DIRECT_PROVIDER.register_method( "Mumble" )
def deafenUser( request, server, sessionid, deaf ):
srv = get_object_or_404( Mumble, id=int(server) )
if not srv.isUserAdmin( request.user ):
raise Exception( 'Access denied' )
srv.deafenUser(sessionid, deaf)
@EXT_DIRECT_PROVIDER.register_method( "MumbleUserAdmin" ) @EXT_DIRECT_PROVIDER.register_method( "MumbleUserAdmin" )
def users( request, server ): def users( request, server ):
""" Create a list of MumbleUsers for a given server serialized as a JSON object. """ Create a list of MumbleUsers for a given server serialized as a JSON object.

Loading…
Cancel
Save