Mercurial > libervia-backend
annotate frontends/src/jp/cmd_message.py @ 2020:f67da1cab6d3
quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
- occupants can be clicked again
- QuickChat.Occupant now keep room jid and real jid if available
- history messages are filtered correctly when requesting history for MUC room or private conversation
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 24 Jul 2016 18:07:45 +0200 |
parents | a2bc5089c2eb |
children | 2265d9df4cfb |
rev | line source |
---|---|
1960 | 1 #!/usr/bin/env python2 |
815 | 2 # -*- coding: utf-8 -*- |
3 | |
4 # jp: a SAT command line tool | |
1766 | 5 # Copyright (C) 2009-2016 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 | |
817 | 20 from sat_frontends.jp import base |
814 | 21 import sys |
771 | 22 from sat.core.i18n import _ |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
23 from sat.core.constants import Const as C |
817 | 24 from sat.tools.utils import clean_ustr |
0 | 25 |
817 | 26 __commands__ = ["Message"] |
393 | 27 |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
28 |
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
|
29 class Send(base.CommandBase): |
817 | 30 |
31 def __init__(self, host): | |
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 super(Send, self).__init__(host, 'send', help=_('send a message to a contact')) |
817 | 33 |
34 def add_parser_options(self): | |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
35 self.parser.add_argument("-l", "--lang", type=str, default='', help=_("language of the message")) |
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
|
36 self.parser.add_argument("-s", "--separate", action="store_true", help=_("separate xmpp messages: send one message per line instead of one message alone.")) |
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
|
37 self.parser.add_argument("-n", "--new-line", action="store_true", help=_("add a new line at the beginning of the input (usefull for ascii art ;))")) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
38 self.parser.add_argument("-S", "--subject", type=base.unicode_decoder, help=_("subject of the message")) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
39 self.parser.add_argument("-L", "--subject_lang", type=str, default='', help=_("language of subject")) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
40 self.parser.add_argument("-t", "--type", choices=C.MESS_TYPE_STANDARD + (C.MESS_TYPE_AUTO,), default=C.MESS_TYPE_AUTO, help=_("type of the message")) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
41 self.parser.add_argument("jid", type=base.unicode_decoder, help=_("the destination jid")) |
401
b2caa2615c4c
jp roster name manegement + Pipe transfer
Goffi <goffi@goffi.org>
parents:
393
diff
changeset
|
42 |
1864
96ba685162f6
jp: all commands now use the new start method and set need_loop in __init__ when needed
Goffi <goffi@goffi.org>
parents:
1828
diff
changeset
|
43 def start(self): |
817 | 44 jids = self.host.check_jids([self.args.jid]) |
45 jid = jids[0] | |
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
|
46 self.sendStdin(jid) |
817 | 47 |
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
|
48 def sendStdin(self, dest_jid): |
817 | 49 """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
|
50 |
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
|
51 @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
|
52 """ |
817 | 53 header = "\n" if self.args.new_line else "" |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
54 if self.args.subject is None: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
55 subject = {} |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
56 else: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
57 subject = {self.args.subject_lang: self.args.subject} |
817 | 58 |
59 if self.args.separate: #we send stdin in several messages | |
60 | |
0 | 61 if header: |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
62 self.host.bridge.messageSend(dest_jid, {self.args.lang: header}, subject, self.args.type, profile_key=self.profile, callback=lambda: None, errback=lambda ignore: ignore) |
817 | 63 |
0 | 64 while (True): |
817 | 65 line = clean_ustr(sys.stdin.readline().decode('utf-8','ignore')) |
0 | 66 if not line: |
67 break | |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
68 self.host.bridge.messageSend(dest_jid, {self.args.lang: line.replace("\n","")}, subject, self.args.type, profile_key=self.host.profile, callback=lambda: None, errback=lambda ignore: ignore) |
0 | 69 |
817 | 70 else: |
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
|
71 msg = header + clean_ustr(u"".join([stream.decode('utf-8','ignore') for stream in sys.stdin.readlines()])) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
72 self.host.bridge.messageSend(dest_jid, {self.args.lang: msg}, subject, self.args.type, profile_key=self.host.profile, callback=lambda: None, errback=lambda ignore: ignore) |
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
|
73 |
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
|
74 |
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
|
75 class Message(base.CommandBase): |
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
|
76 subcommands = (Send, ) |
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
|
77 |
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
|
78 def __init__(self, host): |
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
|
79 super(Message, self).__init__(host, 'message', use_profile=False, help=_('messages handling')) |