2024-01-17 15:36:28 +01:00
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
NOTE
|
|
|
|
|
|
|
|
|
|
The VCard XML fields that can be set are as follows:
|
|
|
|
|
‘FN’, ‘NICKNAME’, ‘URL’, ‘BDAY’, ‘ROLE’, ‘NOTE’, ‘MAILER’,
|
|
|
|
|
‘TZ’, ‘REV’, ‘UID’, ‘DESC’, ‘TITLE’, ‘PRODID’, ‘SORT-STRING’,
|
|
|
|
|
‘N’, ‘ADR’, ‘TEL’, ‘EMAIL’, ‘JABBERID’, ‘ORG’, ‘CATEGORIES’,
|
|
|
|
|
‘NOTE’, ‘PRODID’, ‘REV’, ‘SORT-STRING’, ‘SOUND’, ‘UID’, ‘URL’,
|
|
|
|
|
‘CLASS’, ‘KEY’, ‘MAILER’, ‘GEO’, ‘TITLE’, ‘ROLE’,
|
|
|
|
|
‘LOGO’, ‘AGENT’
|
|
|
|
|
|
|
|
|
|
TODO
|
|
|
|
|
|
|
|
|
|
1) Test XEP-0084.
|
|
|
|
|
|
|
|
|
|
2) Make sure to support all type of servers.
|
|
|
|
|
|
|
|
|
|
3) Catch IqError
|
|
|
|
|
ERROR:slixmpp.basexmpp:internal-server-error: Database failure
|
|
|
|
|
WARNING:slixmpp.basexmpp:You should catch IqError exceptions
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
import glob
|
2024-03-12 18:13:01 +01:00
|
|
|
|
from slixfeed.config import Config
|
|
|
|
|
import slixfeed.config as config
|
2024-06-13 17:53:53 +02:00
|
|
|
|
from slixfeed.log import Logger
|
2024-05-14 21:39:58 +02:00
|
|
|
|
from slixmpp.exceptions import IqTimeout, IqError
|
2024-01-17 15:36:28 +01:00
|
|
|
|
import os
|
|
|
|
|
|
2024-06-13 17:53:53 +02:00
|
|
|
|
logger = Logger(__name__)
|
|
|
|
|
|
2024-02-06 04:04:43 +01:00
|
|
|
|
# class XmppProfile:
|
2024-01-17 15:36:28 +01:00
|
|
|
|
|
|
|
|
|
async def update(self):
|
2024-05-14 21:39:58 +02:00
|
|
|
|
""" Update profile """
|
|
|
|
|
try:
|
|
|
|
|
await set_vcard(self)
|
|
|
|
|
except IqTimeout as e:
|
2024-06-13 17:53:53 +02:00
|
|
|
|
logger.error('Profile vCard: Error Timeout')
|
|
|
|
|
logger.error(str(e))
|
2024-05-14 21:39:58 +02:00
|
|
|
|
except IqError as e:
|
2024-06-13 17:53:53 +02:00
|
|
|
|
logger.error('Profile vCard: Error XmppIQ')
|
|
|
|
|
logger.error(str(e))
|
2024-05-14 21:39:58 +02:00
|
|
|
|
try:
|
|
|
|
|
await set_avatar(self)
|
|
|
|
|
except IqTimeout as e:
|
2024-06-13 17:53:53 +02:00
|
|
|
|
logger.error('Profile Photo: Error Timeout')
|
|
|
|
|
logger.error(str(e))
|
2024-05-14 21:39:58 +02:00
|
|
|
|
except IqError as e:
|
2024-06-13 17:53:53 +02:00
|
|
|
|
logger.error('Profile Photo: Error XmppIQ')
|
|
|
|
|
logger.error(str(e))
|
2024-01-17 15:36:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def set_avatar(self):
|
2024-11-19 14:55:29 +01:00
|
|
|
|
config_dir = self.dir_config
|
2024-02-04 19:19:56 +01:00
|
|
|
|
filename = glob.glob(config_dir + '/image.*')
|
2024-01-22 13:48:00 +01:00
|
|
|
|
if not filename and os.path.isdir('/usr/share/slixfeed/'):
|
|
|
|
|
# filename = '/usr/share/slixfeed/image.svg'
|
2024-02-04 19:19:56 +01:00
|
|
|
|
filename = glob.glob('/usr/share/slixfeed/image.*')
|
2024-01-27 20:19:41 +01:00
|
|
|
|
if not filename:
|
2024-01-22 13:48:00 +01:00
|
|
|
|
config_dir = os.path.dirname(__file__)
|
2024-02-04 19:19:56 +01:00
|
|
|
|
config_dir = config_dir.split('/')
|
2024-01-22 13:48:00 +01:00
|
|
|
|
config_dir.pop()
|
2024-02-04 19:19:56 +01:00
|
|
|
|
config_dir = '/'.join(config_dir)
|
|
|
|
|
filename = glob.glob(config_dir + '/assets/image.*')
|
2024-02-25 02:52:24 +01:00
|
|
|
|
if len(filename):
|
|
|
|
|
filename = filename[0]
|
|
|
|
|
image_file = os.path.join(config_dir, filename)
|
|
|
|
|
with open(image_file, 'rb') as avatar_file:
|
|
|
|
|
avatar = avatar_file.read()
|
|
|
|
|
# await self.plugin['xep_0084'].publish_avatar(avatar)
|
2024-06-13 17:53:53 +02:00
|
|
|
|
try:
|
|
|
|
|
await self.plugin['xep_0153'].set_avatar(avatar=avatar)
|
|
|
|
|
except IqTimeout as e:
|
|
|
|
|
logger.error('Profile Photo: Error Timeout 222')
|
|
|
|
|
logger.error(str(e))
|
|
|
|
|
except IqError as e:
|
|
|
|
|
logger.error('Profile Photo: Error XmppIQ 222')
|
|
|
|
|
logger.error(str(e))
|
2024-01-17 15:36:28 +01:00
|
|
|
|
|
|
|
|
|
|
2024-02-04 18:08:12 +01:00
|
|
|
|
def set_identity(self, category):
|
|
|
|
|
"""
|
|
|
|
|
Identify for Service Descovery.
|
|
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
|
----------
|
|
|
|
|
category : str
|
|
|
|
|
"client" or "service".
|
|
|
|
|
|
|
|
|
|
Returns
|
|
|
|
|
-------
|
|
|
|
|
None.
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
self['xep_0030'].add_identity(
|
|
|
|
|
category=category,
|
|
|
|
|
itype='news',
|
|
|
|
|
name='slixfeed',
|
|
|
|
|
node=None,
|
|
|
|
|
jid=self.boundjid.full,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2024-01-17 15:36:28 +01:00
|
|
|
|
async def set_vcard(self):
|
2024-02-04 19:19:56 +01:00
|
|
|
|
vcard = self.plugin['xep_0054'].make_vcard()
|
2024-03-12 18:13:01 +01:00
|
|
|
|
profile = config.get_values('accounts.toml', 'xmpp')['profile']
|
|
|
|
|
for key in profile:
|
|
|
|
|
vcard[key] = profile[key]
|
2024-02-04 19:19:56 +01:00
|
|
|
|
await self.plugin['xep_0054'].publish_vcard(vcard)
|
2024-01-17 15:36:28 +01:00
|
|
|
|
|