Mercurial > libervia-backend
annotate sat_frontends/jp/cmd_message.py @ 3888:aa7197b67c26
component AP gateway: AP <=> XMPP reactions conversions:
- Pubsub Attachments plugin has been renamed to XEP-0470 following publication
- XEP-0470 has been updated to follow 0.2 changes
- AP reactions (as implemented in Pleroma) are converted to XEP-0470
- XEP-0470 events are converted to AP reactions (again, using "EmojiReact" from Pleroma)
- AP activities related to attachments (like/reactions) are cached in Libervia because
it's not possible to retrieve them from Pleroma instances once they have been emitted
(doing an HTTP get on their ID returns a 404). For now those cache are not flushed, this
should be improved in the future.
- `sharedInbox` is used when available. Pleroma returns a 500 HTTP error when ``to`` or
``cc`` are used in a direct inbox.
- reactions and like are not currently used for direct messages, because they can't be
emitted from Pleroma in this case, thus there is no point in implementing them for the
moment.
rel 371
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 31 Aug 2022 17:07:03 +0200 |
parents | 6090141b1b70 |
children | 900bf04d87c8 |
rev | line source |
---|---|
3137 | 1 #!/usr/bin/env python3 |
2 | |
815 | 3 |
4 # jp: a SAT command line tool | |
3479 | 5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
815 | 6 |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
17 # You should have received a copy of the GNU Affero General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
2708 | 20 import sys |
817 | 21 from sat_frontends.jp import base |
2663
32b5f68a23b4
jp (message): new encryption/algorithms command to retrieve available encryptions algorithms.
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
22 from sat_frontends.jp.constants import Const as C |
2708 | 23 from sat_frontends.tools import jid |
771 | 24 from sat.core.i18n import _ |
817 | 25 from sat.tools.utils import clean_ustr |
2708 | 26 from sat.tools.common import data_format |
2719
45189c8bd165
jp (message/mam): display metadata when verbose
Goffi <goffi@goffi.org>
parents:
2708
diff
changeset
|
27 from sat.tools.common.ansi import ANSI as A |
0 | 28 |
817 | 29 __commands__ = ["Message"] |
393 | 30 |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
31 |
1828
cb4be663a4a7
jp (message): message is now a subcommand, and the sending command is moved to message/send
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
32 class Send(base.CommandBase): |
817 | 33 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
34 super(Send, self).__init__(host, "send", help=_("send a message to a contact")) |
817 | 35 |
36 def add_parser_options(self): | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
37 self.parser.add_argument( |
3028 | 38 "-l", "--lang", type=str, default="", help=_("language of the message") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
39 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
40 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
41 "-s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
42 "--separate", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
43 action="store_true", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
44 help=_( |
3028 | 45 "separate xmpp messages: send one message per line instead of one " |
46 "message alone." | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
47 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
48 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
49 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
50 "-n", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
51 "--new-line", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
52 action="store_true", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
53 help=_( |
3028 | 54 "add a new line at the beginning of the input (usefull for ascii art ;))" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
55 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
56 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
57 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
58 "-S", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
59 "--subject", |
3028 | 60 help=_("subject of the message"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
61 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
62 self.parser.add_argument( |
3411
f30b238d9c45
jp: follow best practices and use a dash (`-`) instead of underscore (`_`) for long options.
Goffi <goffi@goffi.org>
parents:
3356
diff
changeset
|
63 "-L", "--subject-lang", type=str, default="", help=_("language of subject") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
64 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
65 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
66 "-t", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
67 "--type", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
68 choices=C.MESS_TYPE_STANDARD + (C.MESS_TYPE_AUTO,), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
69 default=C.MESS_TYPE_AUTO, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
70 help=_("type of the message"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
71 ) |
2740
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
2719
diff
changeset
|
72 self.parser.add_argument("-e", "--encrypt", metavar="ALGORITHM", |
3028 | 73 help=_("encrypt message using given algorithm")) |
2740
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
2719
diff
changeset
|
74 self.parser.add_argument( |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
2719
diff
changeset
|
75 "--encrypt-noreplace", |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
2719
diff
changeset
|
76 action="store_true", |
3028 | 77 help=_("don't replace encryption algorithm if an other one is already used")) |
2081
2265d9df4cfb
jp (message/send): message/send can now send XHTML (-x) or rich (-r) messages
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
78 syntax = self.parser.add_mutually_exclusive_group() |
3028 | 79 syntax.add_argument("-x", "--xhtml", action="store_true", help=_("XHTML body")) |
80 syntax.add_argument("-r", "--rich", action="store_true", help=_("rich body")) | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
81 self.parser.add_argument( |
3028 | 82 "jid", help=_("the destination jid") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
83 ) |
401
b2caa2615c4c
jp roster name manegement + Pipe transfer
Goffi <goffi@goffi.org>
parents:
393
diff
changeset
|
84 |
3040 | 85 async def sendStdin(self, dest_jid): |
817 | 86 """Send incomming data on stdin to jabber contact |
1828
cb4be663a4a7
jp (message): message is now a subcommand, and the sending command is moved to message/send
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
87 |
cb4be663a4a7
jp (message): message is now a subcommand, and the sending command is moved to message/send
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
88 @param dest_jid: destination jid |
cb4be663a4a7
jp (message): message is now a subcommand, and the sending command is moved to message/send
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
89 """ |
817 | 90 header = "\n" if self.args.new_line else "" |
3040 | 91 # FIXME: stdin is not read asynchronously at the moment |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
92 stdin_lines = [ |
3040 | 93 stream for stream in sys.stdin.readlines() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
94 ] |
2081
2265d9df4cfb
jp (message/send): message/send can now send XHTML (-x) or rich (-r) messages
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
95 extra = {} |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
96 if self.args.subject is None: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
97 subject = {} |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
98 else: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
99 subject = {self.args.subject_lang: self.args.subject} |
817 | 100 |
2081
2265d9df4cfb
jp (message/send): message/send can now send XHTML (-x) or rich (-r) messages
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
101 if self.args.xhtml or self.args.rich: |
3028 | 102 key = "xhtml" if self.args.xhtml else "rich" |
2081
2265d9df4cfb
jp (message/send): message/send can now send XHTML (-x) or rich (-r) messages
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
103 if self.args.lang: |
3040 | 104 key = f"{key}_{self.args.lang}" |
3028 | 105 extra[key] = clean_ustr("".join(stdin_lines)) |
2081
2265d9df4cfb
jp (message/send): message/send can now send XHTML (-x) or rich (-r) messages
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
106 stdin_lines = [] |
2265d9df4cfb
jp (message/send): message/send can now send XHTML (-x) or rich (-r) messages
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
107 |
3040 | 108 to_send = [] |
109 | |
110 error = False | |
2740
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
2719
diff
changeset
|
111 |
3040 | 112 if self.args.separate: |
113 # we send stdin in several messages | |
0 | 114 if header: |
3040 | 115 # first we sent the header |
116 try: | |
117 await self.host.bridge.messageSend( | |
118 dest_jid, | |
119 {self.args.lang: header}, | |
120 subject, | |
121 self.args.type, | |
122 profile_key=self.profile, | |
123 ) | |
124 except Exception as e: | |
125 self.disp(f"can't send header: {e}", error=True) | |
126 error = True | |
127 | |
128 to_send.extend({self.args.lang: clean_ustr(l.replace("\n", ""))} | |
129 for l in stdin_lines) | |
130 else: | |
131 # we sent all in a single message | |
132 if not (self.args.xhtml or self.args.rich): | |
133 msg = {self.args.lang: header + clean_ustr("".join(stdin_lines))} | |
134 else: | |
135 msg = {} | |
136 to_send.append(msg) | |
137 | |
138 for msg in to_send: | |
139 try: | |
140 await self.host.bridge.messageSend( | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
141 dest_jid, |
3040 | 142 msg, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
143 subject, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
144 self.args.type, |
3179
84a94b385760
bridge: messageSend's extra is now serialised
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
145 data_format.serialise(extra), |
3040 | 146 profile_key=self.host.profile) |
147 except Exception as e: | |
148 self.disp(f"can't send message {msg!r}: {e}", error=True) | |
149 error = True | |
0 | 150 |
3040 | 151 if error: |
152 # at least one message sending failed | |
153 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
2740
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
2719
diff
changeset
|
154 |
3040 | 155 self.host.quit() |
2740
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
2719
diff
changeset
|
156 |
3040 | 157 async def start(self): |
2740
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
2719
diff
changeset
|
158 if self.args.xhtml and self.args.separate: |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
2719
diff
changeset
|
159 self.disp( |
3028 | 160 "argument -s/--separate is not compatible yet with argument -x/--xhtml", |
2740
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
2719
diff
changeset
|
161 error=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
162 ) |
3040 | 163 self.host.quit(C.EXIT_BAD_ARG) |
2740
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
2719
diff
changeset
|
164 |
3040 | 165 jids = await self.host.check_jids([self.args.jid]) |
2740
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
2719
diff
changeset
|
166 jid_ = jids[0] |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
2719
diff
changeset
|
167 |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
2719
diff
changeset
|
168 if self.args.encrypt_noreplace and self.args.encrypt is None: |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
2719
diff
changeset
|
169 self.parser.error("You need to use --encrypt if you use --encrypt-noreplace") |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
2719
diff
changeset
|
170 |
8fd8ce5a5855
jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents:
2719
diff
changeset
|
171 if self.args.encrypt is not None: |
3040 | 172 try: |
173 namespace = await self.host.bridge.encryptionNamespaceGet( | |
174 self.args.encrypt) | |
175 except Exception as e: | |
176 self.disp(f"can't get encryption namespace: {e}", error=True) | |
177 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
178 | |
179 try: | |
180 await self.host.bridge.messageEncryptionStart( | |
181 jid_, namespace, not self.args.encrypt_noreplace, self.profile | |
182 ) | |
183 except Exception as e: | |
184 self.disp(f"can't start encryption session: {e}", error=True) | |
185 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
186 | |
187 await self.sendStdin(jid_) | |
1828
cb4be663a4a7
jp (message): message is now a subcommand, and the sending command is moved to message/send
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
188 |
cb4be663a4a7
jp (message): message is now a subcommand, and the sending command is moved to message/send
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
189 |
3805
33ab258df0de
cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
190 class Retract(base.CommandBase): |
33ab258df0de
cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
191 |
33ab258df0de
cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
192 def __init__(self, host): |
33ab258df0de
cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
193 super().__init__(host, "retract", help=_("retract a message")) |
33ab258df0de
cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
194 |
33ab258df0de
cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
195 def add_parser_options(self): |
33ab258df0de
cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
196 self.parser.add_argument( |
33ab258df0de
cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
197 "message_id", |
33ab258df0de
cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
198 help=_("ID of the message (internal ID)") |
33ab258df0de
cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
199 ) |
33ab258df0de
cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
200 |
33ab258df0de
cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
201 async def start(self): |
33ab258df0de
cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
202 try: |
3887
6090141b1b70
plugin XEP-0424: rename bridge method:
Goffi <goffi@goffi.org>
parents:
3805
diff
changeset
|
203 await self.host.bridge.messageRetract( |
3805
33ab258df0de
cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
204 self.args.message_id, |
33ab258df0de
cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
205 self.profile |
33ab258df0de
cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
206 ) |
33ab258df0de
cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
207 except Exception as e: |
33ab258df0de
cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
208 self.disp(f"can't retract message: {e}", error=True) |
33ab258df0de
cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
209 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
33ab258df0de
cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
210 else: |
33ab258df0de
cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
211 self.disp( |
33ab258df0de
cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
212 "message retraction has been requested, please note that this is a " |
33ab258df0de
cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
213 "request which can't be enforced (see documentation for details).") |
33ab258df0de
cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
214 self.host.quit(C.EXIT_OK) |
33ab258df0de
cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
215 |
33ab258df0de
cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
216 |
2708 | 217 class MAM(base.CommandBase): |
218 | |
219 def __init__(self, host): | |
220 super(MAM, self).__init__( | |
3040 | 221 host, "mam", use_output=C.OUTPUT_MESS, use_verbose=True, |
222 help=_("query archives using MAM")) | |
2708 | 223 |
224 def add_parser_options(self): | |
225 self.parser.add_argument( | |
3028 | 226 "-s", "--service", default="", |
227 help=_("jid of the service (default: profile's server")) | |
2708 | 228 self.parser.add_argument( |
229 "-S", "--start", dest="mam_start", type=base.date_decoder, | |
2824
0ae25883e223
jp (message/mam): --start doesn't defaut anymore to "1 day ago", it is now unset by default
Goffi <goffi@goffi.org>
parents:
2819
diff
changeset
|
230 help=_( |
3028 | 231 "start fetching archive from this date (default: from the beginning)")) |
2708 | 232 self.parser.add_argument( |
233 "-E", "--end", dest="mam_end", type=base.date_decoder, | |
3028 | 234 help=_("end fetching archive after this date (default: no limit)")) |
2708 | 235 self.parser.add_argument( |
3028 | 236 "-W", "--with", dest="mam_with", |
237 help=_("retrieve only archives with this jid")) | |
2708 | 238 self.parser.add_argument( |
2764
92af49cde255
jp (base): MAM and RSM arguments can now be used for pubsub commands:
Goffi <goffi@goffi.org>
parents:
2740
diff
changeset
|
239 "-m", "--max", dest="rsm_max", type=int, default=20, |
3028 | 240 help=_("maximum number of items to retrieve, using RSM (default: 20))")) |
2819
fd45089b3a92
jp (message/mam): added missing RSM options
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
241 rsm_page_group = self.parser.add_mutually_exclusive_group() |
fd45089b3a92
jp (message/mam): added missing RSM options
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
242 rsm_page_group.add_argument( |
3028 | 243 "-a", "--after", dest="rsm_after", |
244 help=_("find page after this item"), metavar='ITEM_ID') | |
2819
fd45089b3a92
jp (message/mam): added missing RSM options
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
245 rsm_page_group.add_argument( |
3028 | 246 "-b", "--before", dest="rsm_before", |
247 help=_("find page before this item"), metavar='ITEM_ID') | |
2819
fd45089b3a92
jp (message/mam): added missing RSM options
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
248 rsm_page_group.add_argument( |
fd45089b3a92
jp (message/mam): added missing RSM options
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
249 "--index", dest="rsm_index", type=int, |
3028 | 250 help=_("index of the page to retrieve")) |
2708 | 251 |
3040 | 252 async def start(self): |
253 extra = {} | |
254 if self.args.mam_start is not None: | |
255 extra["mam_start"] = float(self.args.mam_start) | |
256 if self.args.mam_end is not None: | |
257 extra["mam_end"] = float(self.args.mam_end) | |
258 if self.args.mam_with is not None: | |
259 extra["mam_with"] = self.args.mam_with | |
260 for suff in ('max', 'after', 'before', 'index'): | |
261 key = 'rsm_' + suff | |
262 value = getattr(self.args,key) | |
263 if value is not None: | |
264 extra[key] = str(value) | |
265 try: | |
3356
569f4cf7183b
plugin XEP-0313: fixed `MAMGet` signature
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
266 data, metadata_s, profile = await self.host.bridge.MAMGet( |
3040 | 267 self.args.service, data_format.serialise(extra), self.profile) |
268 except Exception as e: | |
269 self.disp(f"can't retrieve MAM archives: {e}", error=True) | |
270 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
271 | |
3356
569f4cf7183b
plugin XEP-0313: fixed `MAMGet` signature
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
272 metadata = data_format.deserialise(metadata_s) |
569f4cf7183b
plugin XEP-0313: fixed `MAMGet` signature
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
273 |
3040 | 274 try: |
275 session_info = await self.host.bridge.sessionInfosGet(self.profile) | |
276 except Exception as e: | |
277 self.disp(f"can't get session infos: {e}", error=True) | |
278 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
279 | |
280 # we need to fill own_jid for message output | |
3028 | 281 self.host.own_jid = jid.JID(session_info["jid"]) |
3040 | 282 |
283 await self.output(data) | |
284 | |
2719
45189c8bd165
jp (message/mam): display metadata when verbose
Goffi <goffi@goffi.org>
parents:
2708
diff
changeset
|
285 # FIXME: metadata are not displayed correctly and don't play nice with output |
45189c8bd165
jp (message/mam): display metadata when verbose
Goffi <goffi@goffi.org>
parents:
2708
diff
changeset
|
286 # they should be added to output data somehow |
45189c8bd165
jp (message/mam): display metadata when verbose
Goffi <goffi@goffi.org>
parents:
2708
diff
changeset
|
287 if self.verbosity: |
3028 | 288 for value in ("rsm_first", "rsm_last", "rsm_index", "rsm_count", |
289 "mam_complete", "mam_stable"): | |
2719
45189c8bd165
jp (message/mam): display metadata when verbose
Goffi <goffi@goffi.org>
parents:
2708
diff
changeset
|
290 if value in metadata: |
3028 | 291 label = value.split("_")[1] |
2719
45189c8bd165
jp (message/mam): display metadata when verbose
Goffi <goffi@goffi.org>
parents:
2708
diff
changeset
|
292 self.disp(A.color( |
3028 | 293 C.A_HEADER, label, ': ' , A.RESET, metadata[value])) |
2719
45189c8bd165
jp (message/mam): display metadata when verbose
Goffi <goffi@goffi.org>
parents:
2708
diff
changeset
|
294 |
2708 | 295 self.host.quit() |
296 | |
297 | |
1828
cb4be663a4a7
jp (message): message is now a subcommand, and the sending command is moved to message/send
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
298 class Message(base.CommandBase): |
3805
33ab258df0de
cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
299 subcommands = (Send, Retract, MAM) |
1828
cb4be663a4a7
jp (message): message is now a subcommand, and the sending command is moved to message/send
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
300 |
cb4be663a4a7
jp (message): message is now a subcommand, and the sending command is moved to message/send
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
301 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
302 super(Message, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
303 host, "message", use_profile=False, help=_("messages handling") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
304 ) |