Skip to content

Commit 2c91203

Browse files
committed
[MIG] mail_gategay_telegram: Migration to v17
WIP for test workflows of mail_gateway migration in #1614
1 parent 180c577 commit 2c91203

File tree

6 files changed

+25
-21
lines changed

6 files changed

+25
-21
lines changed

mail_gateway_telegram/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"name": "Mail Telegram Gateway",
66
"summary": """
77
Set a gateway for telegram""",
8-
"version": "16.0.1.0.1",
8+
"version": "17.0.1.0.1",
99
"license": "AGPL-3",
1010
"author": "Creu Blanca,Dixmit,Odoo Community Association (OCA)",
1111
"website": "https://github.com/OCA/social",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
from . import mail_gateway_channel
1+
from . import discuss_channel
22
from . import mail_gateway
33
from . import mail_gateway_telegram

mail_gateway_telegram/models/mail_gateway_channel.py renamed to mail_gateway_telegram/models/discuss_channel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
from odoo.addons.base.models.avatar_mixin import get_hsl_from_seed
88

99

10-
class MailChannel(models.Model):
11-
_inherit = "mail.channel"
10+
class DiscussChannel(models.Model):
11+
_inherit = "discuss.channel"
1212

1313
def _generate_avatar_gateway(self):
1414
if self.gateway_id.gateway_type == "telegram":

mail_gateway_telegram/models/mail_gateway_telegram.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,16 @@ def _get_telegram_attachment_name(self, attachment):
130130
async def _process_telegram_attachment(self, attachment):
131131
if isinstance(attachment, tuple):
132132
attachment = attachment[-1]
133-
# That might happen with images, we will get the last one as it is the bigger one.
133+
# That might happen with images, we will get the last one as it is the
134+
# bigger one.
134135
if isinstance(
135136
attachment,
136137
(
137-
telegram.Game,
138-
telegram.Invoice,
139-
telegram.Location,
140-
telegram.SuccessfulPayment,
141-
telegram.Venue,
138+
telegram.Game
139+
| telegram.Invoice
140+
| telegram.Location
141+
| telegram.SuccessfulPayment
142+
| telegram.Venue
142143
),
143144
):
144145
return
@@ -190,12 +191,9 @@ def _process_update(self, chat, update):
190191
effective_attachment = current_attachment
191192
if isinstance(effective_attachment, telegram.Location):
192193
body += (
193-
'<a target="_blank" href="https://www.google.com/'
194-
'maps/search/?api=1&query=%s,%s">Location</a>'
195-
% (
196-
effective_attachment.latitude,
197-
effective_attachment.longitude,
198-
)
194+
f'<a target="_blank" href="https://www.google.com/'
195+
f"maps/search/?api=1&query={effective_attachment.latitude},"
196+
f'{effective_attachment.longitude}">Location</a>'
199197
)
200198
attachment_data = asyncio.run(
201199
self._process_telegram_attachment(effective_attachment)
@@ -204,7 +202,12 @@ def _process_update(self, chat, update):
204202
attachments.append(attachment_data)
205203
if len(body) > 0 or attachments:
206204
author = self._get_author(chat.gateway_id, update)
207-
new_message = chat.message_post(
205+
if author._name == "mail.guest":
206+
chat = chat.with_user(self.env.ref("base.public_user").id).with_context(
207+
guest=author
208+
)
209+
# TODO: Check the sudo...
210+
new_message = chat.sudo().message_post(
208211
body=body,
209212
author_id=author._name == "res.partner" and author.id,
210213
gateway_type="telegram",

mail_gateway_telegram/static/src/components/message/message.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22
<templates xml:space="preserve">
3-
<t t-inherit="mail.MessageViewNotification" t-inherit-mode="extension">
3+
<t t-inherit="mail.Message.notification" t-inherit-mode="extension">
44
<xpath expr="//div" position="after">
55
<i
66
class="fa fa-paper-plane text-info"
7-
t-if="messageView.message.gateway_type == 'telegram' and messageView.message.notifications.length == 0"
7+
t-if="message.gateway_type == 'telegram' and message.notifications.length == 0"
88
/>
99
</xpath>
1010
</t>

mail_gateway_telegram/views/mail_gateway.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
<field name="has_new_channel_security" position="after">
1313
<field
1414
name="telegram_security_key"
15-
attrs="{'invisible': ['|', ('gateway_type', '!=', 'telegram'), ('has_new_channel_security', '=', False)], 'required': [('gateway_type', '=', 'telegram'), ('has_new_channel_security', '=', True)]}"
15+
invisible="gateway_type != 'telegram' or not has_new_channel_security"
16+
required="gateway_type == 'telegram' and has_new_channel_security"
1617
/>
1718
</field>
1819
<notebook position="inside">
1920
<page
2021
name="telegram"
2122
string="Telegram configuration"
22-
attrs="{'invisible': [('gateway_type', '!=', 'telegram')]}"
23+
invisible="gateway_type != 'telegram'"
2324
>
2425
<div>
2526
<ol>

0 commit comments

Comments
 (0)