Mercurial > libervia-backend
comparison src/plugins/plugin_misc_identity.py @ 2463:65a6d2496504
plugin identity: return resource for MUC room occupants' nicks + added avatar and avatar_basename.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 03 Jan 2018 00:20:21 +0100 |
parents | 07478106a10d |
children | 908be289eb49 |
comparison
equal
deleted
inserted
replaced
2462:2cad04f38bac | 2463:65a6d2496504 |
---|---|
18 # You should have received a copy of the GNU Affero General Public License | 18 # You should have received a copy of the GNU Affero General Public License |
19 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 19 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | 20 |
21 from sat.core.i18n import _ | 21 from sat.core.i18n import _ |
22 from sat.core.constants import Const as C | 22 from sat.core.constants import Const as C |
23 from sat.core import exceptions | |
23 from sat.core.log import getLogger | 24 from sat.core.log import getLogger |
24 log = getLogger(__name__) | 25 log = getLogger(__name__) |
25 from twisted.internet import defer | 26 from twisted.internet import defer |
26 from twisted.words.protocols.jabber import jid | 27 from twisted.words.protocols.jabber import jid |
28 import os.path | |
27 | 29 |
28 | 30 |
29 PLUGIN_INFO = { | 31 PLUGIN_INFO = { |
30 C.PI_NAME: "Identity Plugin", | 32 C.PI_NAME: "Identity Plugin", |
31 C.PI_IMPORT_NAME: "IDENTITY", | 33 C.PI_IMPORT_NAME: "IDENTITY", |
67 id_data = {} | 69 id_data = {} |
68 # we first check roster | 70 # we first check roster |
69 roster_item = yield client.roster.getItem(jid_.userhostJID()) | 71 roster_item = yield client.roster.getItem(jid_.userhostJID()) |
70 if roster_item is not None and roster_item.name: | 72 if roster_item is not None and roster_item.name: |
71 id_data[u'nick'] = roster_item.name | 73 id_data[u'nick'] = roster_item.name |
74 elif jid_.resource and self._v.isRoom(client, jid_): | |
75 id_data[u'nick'] = jid_.resource | |
72 else: | 76 else: |
73 # then vcard | 77 # and finally then vcard |
74 nick = yield self._v.getNick(client, jid_) | 78 nick = yield self._v.getNick(client, jid_) |
75 id_data[u'nick'] = nick if nick else jid_.user.capitalize() | 79 id_data[u'nick'] = nick if nick else jid_.user.capitalize() |
80 | |
81 try: | |
82 avatar_path = id_data[u'avatar'] = yield self._v.getAvatar(client, jid_, cache_only=False) | |
83 except exceptions.NotFound: | |
84 pass | |
85 else: | |
86 id_data[u'avatar_basename'] = os.path.basename(avatar_path) | |
76 | 87 |
77 defer.returnValue(id_data) | 88 defer.returnValue(id_data) |
78 | 89 |
79 def _setIdentity(self, id_data, profile): | 90 def _setIdentity(self, id_data, profile): |
80 client = self.host.getClient(profile) | 91 client = self.host.getClient(profile) |