Philipp Hörist pushed to branch mainwindow at gajim / gajim
Commits:
-
16488c20
by lovetox at 2021-04-27T13:11:48+02:00
8 changed files:
- gajim/chat_control.py
- gajim/chat_control_base.py
- gajim/groupchat_control.py
- gajim/gtk/conversation/rows/base.py
- gajim/gtk/conversation/rows/info.py
- + gajim/gtk/conversation/rows/muc_subject.py
- gajim/gtk/conversation/view.py
- gajim/privatechat_control.py
Changes:
| ... | ... | @@ -478,7 +478,7 @@ def _on_mam_message_received(self, event): |
| 478 | 478 |
if not event.properties.jid.bare_match(self.contact.jid):
|
| 479 | 479 |
return
|
| 480 | 480 |
|
| 481 |
- kind = '' # incoming
|
|
| 481 |
+ kind = 'incoming'
|
|
| 482 | 482 |
if event.kind == KindConstant.CHAT_MSG_SENT:
|
| 483 | 483 |
kind = 'outgoing'
|
| 484 | 484 |
|
| ... | ... | @@ -493,12 +493,12 @@ def _on_message_received(self, event): |
| 493 | 493 |
if not event.msgtxt:
|
| 494 | 494 |
return
|
| 495 | 495 |
|
| 496 |
- typ = ''
|
|
| 496 |
+ kind = 'incoming'
|
|
| 497 | 497 |
if event.properties.is_sent_carbon:
|
| 498 |
- typ = 'out'
|
|
| 498 |
+ kind = 'outgoing'
|
|
| 499 | 499 |
|
| 500 | 500 |
self.add_message(event.msgtxt,
|
| 501 |
- typ,
|
|
| 501 |
+ kind,
|
|
| 502 | 502 |
tim=event.properties.timestamp,
|
| 503 | 503 |
subject=event.properties.subject,
|
| 504 | 504 |
displaymarking=event.displaymarking,
|
| ... | ... | @@ -529,7 +529,7 @@ def _on_message_sent(self, event): |
| 529 | 529 |
self.msg_textview, 'gajim-msg-correcting')
|
| 530 | 530 |
|
| 531 | 531 |
self.add_message(event.message,
|
| 532 |
- self.contact.jid,
|
|
| 532 |
+ 'outgoing',
|
|
| 533 | 533 |
tim=event.timestamp,
|
| 534 | 534 |
displaymarking=displaymarking,
|
| 535 | 535 |
message_id=message_id,
|
| ... | ... | @@ -928,7 +928,7 @@ def get_our_nick(self): |
| 928 | 928 |
|
| 929 | 929 |
def add_message(self,
|
| 930 | 930 |
text,
|
| 931 |
- frm='',
|
|
| 931 |
+ kind,
|
|
| 932 | 932 |
tim=None,
|
| 933 | 933 |
subject=None,
|
| 934 | 934 |
displaymarking=None,
|
| ... | ... | @@ -936,36 +936,14 @@ def add_message(self, |
| 936 | 936 |
correct_id=None,
|
| 937 | 937 |
message_id=None,
|
| 938 | 938 |
additional_data=None):
|
| 939 |
- """
|
|
| 940 |
- Print a line in the conversation
|
|
| 941 |
- |
|
| 942 |
- If frm is set to status: it's a status message.
|
|
| 943 |
- if frm is set to error: it's an error message. The difference between
|
|
| 944 |
- status and error is mainly that with error, msg count as a new
|
|
| 945 |
- message (in systray and in control).
|
|
| 946 |
- If frm is set to info: it's a information message.
|
|
| 947 |
- If frm is set to print_queue: it is incoming from queue.
|
|
| 948 |
- If frm is set to another value: it's an outgoing message.
|
|
| 949 |
- If frm is not set: it's an incoming message.
|
|
| 950 |
- """
|
|
| 951 |
- contact = self.contact
|
|
| 952 | 939 |
|
| 953 | 940 |
if additional_data is None:
|
| 954 | 941 |
additional_data = AdditionalDataDict()
|
| 955 | 942 |
|
| 956 |
- if frm == 'error':
|
|
| 957 |
- kind = 'error'
|
|
| 958 |
- name = ''
|
|
| 943 |
+ if kind == 'incoming':
|
|
| 944 |
+ name = self.contact.name
|
|
| 959 | 945 |
else:
|
| 960 |
- if not frm:
|
|
| 961 |
- kind = 'incoming'
|
|
| 962 |
- name = contact.name
|
|
| 963 |
- elif frm == 'print_queue':
|
|
| 964 |
- kind = 'incoming_queue'
|
|
| 965 |
- name = contact.name
|
|
| 966 |
- else:
|
|
| 967 |
- kind = 'outgoing'
|
|
| 968 |
- name = self.get_our_nick()
|
|
| 946 |
+ name = self.get_our_nick()
|
|
| 969 | 947 |
|
| 970 | 948 |
ChatControlBase.add_message(self,
|
| 971 | 949 |
text,
|
| ... | ... | @@ -978,11 +956,6 @@ def add_message(self, |
| 978 | 956 |
correct_id=correct_id,
|
| 979 | 957 |
additional_data=additional_data)
|
| 980 | 958 |
|
| 981 |
- if text.startswith('/me ') or text.startswith('/me\n'):
|
|
| 982 |
- self.old_msg_kind = None
|
|
| 983 |
- else:
|
|
| 984 |
- self.old_msg_kind = kind
|
|
| 985 |
- |
|
| 986 | 959 |
def prepare_context_menu(self, hide_buttonbar_items=False):
|
| 987 | 960 |
"""
|
| 988 | 961 |
Set compact view menuitem active state sets active and sensitivity state
|
| ... | ... | @@ -1117,7 +1090,7 @@ def _on_presence_received(self, event): |
| 1117 | 1090 |
status = '- %s' % event.status if event.status else ''
|
| 1118 | 1091 |
status_line = _('%(name)s is now %(show)s %(status)s') % {
|
| 1119 | 1092 |
'name': name, 'show': uf_show, 'status': status}
|
| 1120 |
- self.add_status_message(status_line)
|
|
| 1093 |
+ self.add_info_message(status_line)
|
|
| 1121 | 1094 |
|
| 1122 | 1095 |
def _info_bar_show_message(self):
|
| 1123 | 1096 |
if self.info_bar.get_visible():
|
| ... | ... | @@ -1073,13 +1073,8 @@ def save_message(self, message, msg_type): |
| 1073 | 1073 |
else:
|
| 1074 | 1074 |
self.received_history_pos = pos
|
| 1075 | 1075 |
|
| 1076 |
- def add_info_message(self, text, message_id=None):
|
|
| 1077 |
- self.conversation_view.add_message(
|
|
| 1078 |
- text, 'info', '', None, message_id=message_id)
|
|
| 1079 |
- |
|
| 1080 |
- def add_status_message(self, text):
|
|
| 1081 |
- self.conversation_view.add_message(
|
|
| 1082 |
- text, 'status', '', None)
|
|
| 1076 |
+ def add_info_message(self, text):
|
|
| 1077 |
+ self.conversation_view.add_info_message(text)
|
|
| 1083 | 1078 |
|
| 1084 | 1079 |
def add_message(self,
|
| 1085 | 1080 |
text,
|
| ... | ... | @@ -1108,16 +1103,13 @@ def add_message(self, |
| 1108 | 1103 |
log_line_id=msg_log_id,
|
| 1109 | 1104 |
additional_data=additional_data)
|
| 1110 | 1105 |
|
| 1111 |
- if restored:
|
|
| 1112 |
- return
|
|
| 1113 |
- |
|
| 1114 | 1106 |
if message_id:
|
| 1115 | 1107 |
if self._type.is_groupchat:
|
| 1116 | 1108 |
self.last_msg_id = stanza_id or message_id
|
| 1117 | 1109 |
else:
|
| 1118 | 1110 |
self.last_msg_id = message_id
|
| 1119 | 1111 |
|
| 1120 |
- if kind in ('incoming', 'incoming_queue'):
|
|
| 1112 |
+ if kind == 'incoming':
|
|
| 1121 | 1113 |
# Record the history of received messages
|
| 1122 | 1114 |
self.save_message(text, 'received')
|
| 1123 | 1115 |
|
| ... | ... | @@ -1334,7 +1326,7 @@ def add_messages(self, messages): |
| 1334 | 1326 |
for msg in messages:
|
| 1335 | 1327 |
if not msg:
|
| 1336 | 1328 |
continue
|
| 1337 |
- kind = 'status'
|
|
| 1329 |
+ |
|
| 1338 | 1330 |
contact_name = msg.contact_name
|
| 1339 | 1331 |
if msg.kind in (
|
| 1340 | 1332 |
KindConstant.SINGLE_MSG_RECV, KindConstant.CHAT_MSG_RECV):
|
| ... | ... | @@ -1346,6 +1338,9 @@ def add_messages(self, messages): |
| 1346 | 1338 |
KindConstant.SINGLE_MSG_SENT, KindConstant.CHAT_MSG_SENT):
|
| 1347 | 1339 |
kind = 'outgoing'
|
| 1348 | 1340 |
contact_name = self.get_our_nick()
|
| 1341 |
+ else:
|
|
| 1342 |
+ raise ValueError('no kind attribute')
|
|
| 1343 |
+ |
|
| 1349 | 1344 |
if not msg.message:
|
| 1350 | 1345 |
continue
|
| 1351 | 1346 |
self.conversation_view.add_message(
|
| ... | ... | @@ -691,26 +691,23 @@ def _on_gc_message_received(self, event): |
| 691 | 691 |
additional_data=event.additional_data)
|
| 692 | 692 |
event.needs_highlight = self.needs_visual_notification(event.msgtxt)
|
| 693 | 693 |
|
| 694 |
- def add_message(self, text, contact='', tim=None,
|
|
| 695 |
- displaymarking=None, correct_id=None, message_id=None,
|
|
| 696 |
- stanza_id=None, additional_data=None):
|
|
| 697 |
- """
|
|
| 698 |
- Add message to the ConversationsTextview
|
|
| 699 |
- |
|
| 700 |
- If contact is set: it's a message from someone
|
|
| 701 |
- If contact is not set: it's a message from the server or help.
|
|
| 702 |
- """
|
|
| 703 |
- |
|
| 704 |
- if not contact:
|
|
| 705 |
- # Message from the server
|
|
| 706 |
- kind = 'status'
|
|
| 707 |
- elif contact == self.contact.nickname: # it's us
|
|
| 694 |
+ def add_message(self,
|
|
| 695 |
+ text,
|
|
| 696 |
+ contact='',
|
|
| 697 |
+ tim=None,
|
|
| 698 |
+ displaymarking=None,
|
|
| 699 |
+ correct_id=None,
|
|
| 700 |
+ message_id=None,
|
|
| 701 |
+ stanza_id=None,
|
|
| 702 |
+ additional_data=None):
|
|
| 703 |
+ |
|
| 704 |
+ if contact == self.contact.nickname:
|
|
| 708 | 705 |
kind = 'outgoing'
|
| 709 | 706 |
else:
|
| 710 | 707 |
kind = 'incoming'
|
| 711 | 708 |
# muc-specific chatstate
|
| 712 | 709 |
|
| 713 |
- if kind == 'incoming': # it's a message NOT from us
|
|
| 710 |
+ if kind == 'incoming':
|
|
| 714 | 711 |
# highlighting and sounds
|
| 715 | 712 |
highlight, _sound = self.highlighting_for_message(text, tim)
|
| 716 | 713 |
# other_tags_for_name.append('muc_nickname_color_%s' % contact)
|
| ... | ... | @@ -820,7 +817,7 @@ def _on_room_subject(self, _contact, _signal_name, properties): |
| 820 | 817 |
|
| 821 | 818 |
if (app.settings.get('show_subject_on_join') or
|
| 822 | 819 |
not self.contact.is_joining):
|
| 823 |
- self.add_info_message(text)
|
|
| 820 |
+ self.conversation_view.add_muc_subject(text)
|
|
| 824 | 821 |
|
| 825 | 822 |
def _on_room_config_changed(self, _contact, _signal_name, properties):
|
| 826 | 823 |
# http://www.xmpp.org/extensions/xep-0045.html#roomconfig-notify
|
| ... | ... | @@ -996,7 +993,7 @@ def _on_user_status_show_changed(self, |
| 996 | 993 |
message = _('{nick} is now {show}{status}').format(nick=nick,
|
| 997 | 994 |
show=show,
|
| 998 | 995 |
status=status)
|
| 999 |
- self.add_status_message(message)
|
|
| 996 |
+ self.add_info_message(message)
|
|
| 1000 | 997 |
|
| 1001 | 998 |
def _on_user_affiliation_changed(self,
|
| 1002 | 999 |
_contact,
|
| ... | ... | @@ -23,7 +23,6 @@ |
| 23 | 23 |
from gajim.common.i18n import _
|
| 24 | 24 |
from gajim.common.helpers import from_one_line
|
| 25 | 25 |
|
| 26 |
-from ...conversation_textview import ConversationTextview
|
|
| 27 | 26 |
from ...util import convert_rgba_to_hex
|
| 28 | 27 |
from ...util import text_to_color
|
| 29 | 28 |
from ...util import wrap_with_event_box
|
| ... | ... | @@ -12,40 +12,30 @@ |
| 12 | 12 |
# You should have received a copy of the GNU General Public License
|
| 13 | 13 |
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
| 14 | 14 |
|
| 15 |
+import time
|
|
| 15 | 16 |
from datetime import datetime
|
| 16 | 17 |
|
| 17 | 18 |
from gi.repository import GLib
|
| 18 | 19 |
from gi.repository import Gtk
|
| 19 | 20 |
|
| 20 | 21 |
from gajim.common.const import AvatarSize
|
| 21 |
-from gajim.common.i18n import _
|
|
| 22 | 22 |
from gajim.common.styling import process
|
| 23 | 23 |
|
| 24 | 24 |
from .base import BaseRow
|
| 25 | 25 |
from ..message_widget import MessageWidget
|
| 26 | 26 |
|
| 27 | 27 |
|
| 28 |
-class InfoMessageRow(BaseRow):
|
|
| 29 |
- def __init__(self,
|
|
| 30 |
- account,
|
|
| 31 |
- timestamp,
|
|
| 32 |
- text,
|
|
| 33 |
- kind,
|
|
| 34 |
- subject,
|
|
| 35 |
- history_mode=False):
|
|
| 36 |
- BaseRow.__init__(self, account, history_mode=history_mode)
|
|
| 28 |
+class InfoMessage(BaseRow):
|
|
| 29 |
+ def __init__(self, account, text):
|
|
| 30 |
+ BaseRow.__init__(self, account)
|
|
| 31 |
+ |
|
| 37 | 32 |
self.type = 'info'
|
| 33 |
+ timestamp = time.time()
|
|
| 38 | 34 |
self.timestamp = datetime.fromtimestamp(timestamp)
|
| 39 | 35 |
self.db_timestamp = timestamp
|
| 40 |
- self.kind = kind
|
|
| 41 |
- |
|
| 42 |
- if subject:
|
|
| 43 |
- subject_title = _('Subject:')
|
|
| 44 |
- text = (f'{subject_title}\n'
|
|
| 45 |
- f'{GLib.markup_escape_text(subject)}\n'
|
|
| 46 |
- f'{GLib.markup_escape_text(text)}')
|
|
| 47 |
- else:
|
|
| 48 |
- text = GLib.markup_escape_text(text)
|
|
| 36 |
+ self.kind = 'info'
|
|
| 37 |
+ |
|
| 38 |
+ text = GLib.markup_escape_text(text)
|
|
| 49 | 39 |
|
| 50 | 40 |
avatar_placeholder = Gtk.Box()
|
| 51 | 41 |
avatar_placeholder.set_size_request(AvatarSize.ROSTER, -1)
|
| 1 |
+# This file is part of Gajim.
|
|
| 2 |
+#
|
|
| 3 |
+# Gajim is free software; you can redistribute it and/or modify
|
|
| 4 |
+# it under the terms of the GNU General Public License as published
|
|
| 5 |
+# by the Free Software Foundation; version 3 only.
|
|
| 6 |
+#
|
|
| 7 |
+# Gajim is distributed in the hope that it will be useful,
|
|
| 8 |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 9 |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 10 |
+# GNU General Public License for more details.
|
|
| 11 |
+#
|
|
| 12 |
+# You should have received a copy of the GNU General Public License
|
|
| 13 |
+# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
|
| 14 |
+ |
|
| 15 |
+import time
|
|
| 16 |
+from datetime import datetime
|
|
| 17 |
+ |
|
| 18 |
+from gi.repository import GLib
|
|
| 19 |
+from gi.repository import Gtk
|
|
| 20 |
+ |
|
| 21 |
+from gajim.common.styling import process
|
|
| 22 |
+ |
|
| 23 |
+from .base import BaseRow
|
|
| 24 |
+from ..message_widget import MessageWidget
|
|
| 25 |
+ |
|
| 26 |
+ |
|
| 27 |
+class MUCSubject(BaseRow):
|
|
| 28 |
+ |
|
| 29 |
+ type = 'muc-subject'
|
|
| 30 |
+ |
|
| 31 |
+ def __init__(self, account, text):
|
|
| 32 |
+ BaseRow.__init__(self, account)
|
|
| 33 |
+ |
|
| 34 |
+ timestamp = time.time()
|
|
| 35 |
+ self.timestamp = datetime.fromtimestamp(timestamp)
|
|
| 36 |
+ self.db_timestamp = timestamp
|
|
| 37 |
+ |
|
| 38 |
+ text = GLib.markup_escape_text(text)
|
|
| 39 |
+ |
|
| 40 |
+ # avatar_placeholder = Gtk.Box()
|
|
| 41 |
+ # avatar_placeholder.set_size_request(AvatarSize.ROSTER, -1)
|
|
| 42 |
+ # self.grid.attach(avatar_placeholder, 0, 0, 1, 2)
|
|
| 43 |
+ timestamp_widget = self.create_timestamp_widget(self.timestamp)
|
|
| 44 |
+ timestamp_widget.set_valign(Gtk.Align.START)
|
|
| 45 |
+ self.grid.attach(timestamp_widget, 2, 0, 1, 1)
|
|
| 46 |
+ |
|
| 47 |
+ result = process(text)
|
|
| 48 |
+ message_widget = MessageWidget(account)
|
|
| 49 |
+ message_widget.add_content(result)
|
|
| 50 |
+ |
|
| 51 |
+ self.grid.attach(message_widget, 1, 0, 1, 1)
|
|
| 52 |
+ self.show_all()
|
| ... | ... | @@ -30,8 +30,9 @@ |
| 30 | 30 |
from .conversation.rows.read_marker import ReadMarkerRow
|
| 31 | 31 |
from .conversation.rows.scroll_hint import ScrollHintRow
|
| 32 | 32 |
from .conversation.rows.message import MessageRow
|
| 33 |
-from .conversation.rows.info import InfoMessageRow
|
|
| 33 |
+from .conversation.rows.info import InfoMessage
|
|
| 34 | 34 |
from .conversation.rows.date import DateRow
|
| 35 |
+from .conversation.rows.muc_subject import MUCSubject
|
|
| 35 | 36 |
|
| 36 | 37 |
|
| 37 | 38 |
log = logging.getLogger('gajim.gui.conversation_view')
|
| ... | ... | @@ -105,6 +106,14 @@ def _sort_func(self, row1, row2): |
| 105 | 106 |
return 0
|
| 106 | 107 |
return -1 if row1.timestamp < row2.timestamp else 1
|
| 107 | 108 |
|
| 109 |
+ def add_muc_subject(self, text):
|
|
| 110 |
+ subject = MUCSubject(self._account, text)
|
|
| 111 |
+ self._insert_message(subject)
|
|
| 112 |
+ |
|
| 113 |
+ def add_info_message(self, text):
|
|
| 114 |
+ message = InfoMessage(self._account, text)
|
|
| 115 |
+ self._insert_message(message)
|
|
| 116 |
+ |
|
| 108 | 117 |
def add_message(self,
|
| 109 | 118 |
text,
|
| 110 | 119 |
kind,
|
| ... | ... | @@ -122,43 +131,32 @@ def add_message(self, |
| 122 | 131 |
if not timestamp:
|
| 123 | 132 |
timestamp = time.time()
|
| 124 | 133 |
|
| 125 |
- muc_subject = bool(subject and self._contact is not None and
|
|
| 126 |
- self._contact.is_groupchat)
|
|
| 127 |
- if kind in ('status', 'info') or muc_subject:
|
|
| 128 |
- message = InfoMessageRow(
|
|
| 129 |
- self._account,
|
|
| 130 |
- timestamp,
|
|
| 131 |
- text,
|
|
| 132 |
- kind,
|
|
| 133 |
- subject,
|
|
| 134 |
- history_mode=self._history_mode)
|
|
| 135 |
- else:
|
|
| 136 |
- if correct_id:
|
|
| 137 |
- self.correct_message(correct_id, message_id, text)
|
|
| 138 |
- return
|
|
| 134 |
+ if correct_id:
|
|
| 135 |
+ self.correct_message(correct_id, message_id, text)
|
|
| 136 |
+ return
|
|
| 139 | 137 |
|
| 140 |
- avatar = self._get_avatar(kind, name)
|
|
| 141 |
- |
|
| 142 |
- is_groupchat = False
|
|
| 143 |
- if self._contact is not None:
|
|
| 144 |
- is_groupchat = self._contact.is_groupchat
|
|
| 145 |
- |
|
| 146 |
- message = MessageRow(
|
|
| 147 |
- self._account,
|
|
| 148 |
- message_id,
|
|
| 149 |
- timestamp,
|
|
| 150 |
- kind,
|
|
| 151 |
- name,
|
|
| 152 |
- text,
|
|
| 153 |
- avatar,
|
|
| 154 |
- is_groupchat,
|
|
| 155 |
- additional_data=additional_data,
|
|
| 156 |
- display_marking=display_marking,
|
|
| 157 |
- marker=marker,
|
|
| 158 |
- error=error,
|
|
| 159 |
- encryption_enabled=self.encryption_enabled,
|
|
| 160 |
- history_mode=self._history_mode,
|
|
| 161 |
- log_line_id=log_line_id)
|
|
| 138 |
+ avatar = self._get_avatar(kind, name)
|
|
| 139 |
+ |
|
| 140 |
+ is_groupchat = False
|
|
| 141 |
+ if self._contact is not None:
|
|
| 142 |
+ is_groupchat = self._contact.is_groupchat
|
|
| 143 |
+ |
|
| 144 |
+ message = MessageRow(
|
|
| 145 |
+ self._account,
|
|
| 146 |
+ message_id,
|
|
| 147 |
+ timestamp,
|
|
| 148 |
+ kind,
|
|
| 149 |
+ name,
|
|
| 150 |
+ text,
|
|
| 151 |
+ avatar,
|
|
| 152 |
+ is_groupchat,
|
|
| 153 |
+ additional_data=additional_data,
|
|
| 154 |
+ display_marking=display_marking,
|
|
| 155 |
+ marker=marker,
|
|
| 156 |
+ error=error,
|
|
| 157 |
+ encryption_enabled=self.encryption_enabled,
|
|
| 158 |
+ history_mode=self._history_mode,
|
|
| 159 |
+ log_line_id=log_line_id)
|
|
| 162 | 160 |
|
| 163 | 161 |
if message.type == 'chat':
|
| 164 | 162 |
self._message_id_row_map[message.message_id] = message
|
| ... | ... | @@ -116,7 +116,7 @@ def _on_user_status_show_changed(self, |
| 116 | 116 |
message = _('{nick} is now {show}{status}').format(nick=nick,
|
| 117 | 117 |
show=show,
|
| 118 | 118 |
status=status)
|
| 119 |
- self.add_status_message(message)
|
|
| 119 |
+ self.add_info_message(message)
|
|
| 120 | 120 |
self.update_ui()
|
| 121 | 121 |
|
| 122 | 122 |
# def _on_disconnected(self, event):
|