Philipp Hörist pushed to branch mainwindow at gajim / gajim
Commits:
-
70ade17b
by lovetox at 2021-02-02T22:56:57+01:00
-
7373b349
by lovetox at 2021-02-02T22:56:57+01:00
-
0bcf9951
by lovetox at 2021-02-02T22:58:47+01:00
13 changed files:
- gajim/chat_control.py
- gajim/chat_control_base.py
- gajim/common/connection_handlers_events.py
- gajim/common/modules/mam.py
- gajim/common/modules/message.py
- gajim/common/storage/archive.py
- gajim/common/storage/cache.py
- gajim/groupchat_control.py
- gajim/gtk/chat_list.py
- gajim/gtk/chat_list_stack.py
- gajim/gtk/chat_stack.py
- gajim/gtk/main.py
- gajim/gui_interface.py
Changes:
| ... | ... | @@ -227,7 +227,7 @@ def __init__(self, parent_win, contact, acct, session, resource=None): |
| 227 | 227 |
('caps-update', ged.GUI1, self._on_caps_update),
|
| 228 | 228 |
('message-sent', ged.OUT_POSTCORE, self._on_message_sent),
|
| 229 | 229 |
('mam-decrypted-message-received', ged.GUI1, self._on_mam_decrypted_message_received),
|
| 230 |
- ('decrypted-message-received', ged.GUI1, self._on_decrypted_message_received),
|
|
| 230 |
+ # ('decrypted-message-received', ged.GUI1, self._on_decrypted_message_received),
|
|
| 231 | 231 |
('receipt-received', ged.GUI1, self._receipt_received),
|
| 232 | 232 |
('displayed-received', ged.GUI1, self._displayed_received),
|
| 233 | 233 |
('message-error', ged.GUI1, self._on_message_error),
|
| ... | ... | @@ -604,34 +604,6 @@ def _on_mam_decrypted_message_received(self, event): |
| 604 | 604 |
message_id=event.properties.id,
|
| 605 | 605 |
additional_data=event.additional_data)
|
| 606 | 606 |
|
| 607 |
- @event_filter(['account'])
|
|
| 608 |
- def _on_decrypted_message_received(self, event):
|
|
| 609 |
- if not event.msgtxt:
|
|
| 610 |
- return True
|
|
| 611 |
- |
|
| 612 |
- if event.session.control != self:
|
|
| 613 |
- return
|
|
| 614 |
- |
|
| 615 |
- typ = ''
|
|
| 616 |
- if event.properties.is_sent_carbon:
|
|
| 617 |
- typ = 'out'
|
|
| 618 |
- |
|
| 619 |
- self.add_message(event.msgtxt,
|
|
| 620 |
- typ,
|
|
| 621 |
- tim=event.properties.timestamp,
|
|
| 622 |
- subject=event.properties.subject,
|
|
| 623 |
- displaymarking=event.displaymarking,
|
|
| 624 |
- msg_log_id=event.msg_log_id,
|
|
| 625 |
- message_id=event.properties.id,
|
|
| 626 |
- correct_id=event.correct_id,
|
|
| 627 |
- additional_data=event.additional_data)
|
|
| 628 |
- if event.msg_log_id:
|
|
| 629 |
- pw = self.parent_win
|
|
| 630 |
- end = self.conv_textview.autoscroll
|
|
| 631 |
- if not pw or (pw.get_active_control() and self \
|
|
| 632 |
- == pw.get_active_control() and pw.is_active() and end):
|
|
| 633 |
- app.storage.archive.set_read_messages([event.msg_log_id])
|
|
| 634 |
- |
|
| 635 | 607 |
@event_filter(['account', 'jid'])
|
| 636 | 608 |
def _on_message_error(self, event):
|
| 637 | 609 |
self.conv_textview.show_error(event.message_id, event.error)
|
| ... | ... | @@ -1229,17 +1201,6 @@ def shutdown(self): |
| 1229 | 1201 |
self.get_full_jid(),
|
| 1230 | 1202 |
types=['printed_%s' % self._type, str(self._type)])
|
| 1231 | 1203 |
# Remove contact instance if contact has been removed
|
| 1232 |
- key = (self.contact.jid, self.account)
|
|
| 1233 |
- roster = app.interface.roster
|
|
| 1234 |
- has_pending = roster.contact_has_pending_roster_events(self.contact,
|
|
| 1235 |
- self.account)
|
|
| 1236 |
- if key in roster.contacts_to_be_removed.keys() and not has_pending:
|
|
| 1237 |
- backend = roster.contacts_to_be_removed[key]['backend']
|
|
| 1238 |
- del roster.contacts_to_be_removed[key]
|
|
| 1239 |
- roster.remove_contact(self.contact.jid,
|
|
| 1240 |
- self.account,
|
|
| 1241 |
- force=True,
|
|
| 1242 |
- backend=backend)
|
|
| 1243 | 1204 |
|
| 1244 | 1205 |
super(ChatControl, self).shutdown()
|
| 1245 | 1206 |
|
| ... | ... | @@ -1180,15 +1180,15 @@ def add_message(self, |
| 1180 | 1180 |
self.save_message(text, 'received')
|
| 1181 | 1181 |
|
| 1182 | 1182 |
# Send chat marker if we’re actively following the chat
|
| 1183 |
- if self.parent_win and self.contact.settings.get('send_marker'):
|
|
| 1184 |
- if (self.parent_win.get_active_control() == self and
|
|
| 1185 |
- self.parent_win.is_active() and
|
|
| 1186 |
- self.has_focus() and end):
|
|
| 1187 |
- con = app.connections[self.account]
|
|
| 1188 |
- con.get_module('ChatMarkers').send_displayed_marker(
|
|
| 1189 |
- self.contact,
|
|
| 1190 |
- self.last_msg_id,
|
|
| 1191 |
- self._type)
|
|
| 1183 |
+ # if self.parent_win and self.contact.settings.get('send_marker'):
|
|
| 1184 |
+ # if (self.parent_win.get_active_control() == self and
|
|
| 1185 |
+ # self.parent_win.is_active() and
|
|
| 1186 |
+ # self.has_focus() and end):
|
|
| 1187 |
+ # con = app.connections[self.account]
|
|
| 1188 |
+ # con.get_module('ChatMarkers').send_displayed_marker(
|
|
| 1189 |
+ # self.contact,
|
|
| 1190 |
+ # self.last_msg_id,
|
|
| 1191 |
+ # self._type)
|
|
| 1192 | 1192 |
|
| 1193 | 1193 |
# TODO old event Code
|
| 1194 | 1194 |
# if kind in ('incoming', 'incoming_queue', 'error'):
|
| ... | ... | @@ -132,8 +132,7 @@ def generate(self): |
| 132 | 132 |
|
| 133 | 133 |
class NotificationEvent(nec.NetworkIncomingEvent):
|
| 134 | 134 |
name = 'notification'
|
| 135 |
- base_network_events = ['decrypted-message-received',
|
|
| 136 |
- 'gc-message-received',
|
|
| 135 |
+ base_network_events = ['gc-message-received',
|
|
| 137 | 136 |
'presence-received']
|
| 138 | 137 |
|
| 139 | 138 |
def generate(self):
|
| ... | ... | @@ -238,7 +238,6 @@ def _mam_message_received(self, _con, stanza, properties): |
| 238 | 238 |
with_,
|
| 239 | 239 |
properties.mam.timestamp,
|
| 240 | 240 |
kind,
|
| 241 |
- unread=False,
|
|
| 242 | 241 |
message=msgtxt,
|
| 243 | 242 |
contact_name=properties.muc_nickname,
|
| 244 | 243 |
additional_data=additional_data,
|
| ... | ... | @@ -134,22 +134,22 @@ def _message_received(self, _con, stanza, properties): |
| 134 | 134 |
msgtxt = properties.body
|
| 135 | 135 |
|
| 136 | 136 |
session = None
|
| 137 |
- if not properties.type.is_groupchat:
|
|
| 138 |
- if properties.is_muc_pm and properties.type.is_error:
|
|
| 139 |
- session = self._con.find_session(fjid, properties.thread)
|
|
| 140 |
- if not session:
|
|
| 141 |
- session = self._con.get_latest_session(fjid)
|
|
| 142 |
- if not session:
|
|
| 143 |
- session = self._con.make_new_session(
|
|
| 144 |
- fjid, properties.thread, type_='pm')
|
|
| 145 |
- else:
|
|
| 146 |
- session = self._con.get_or_create_session(
|
|
| 147 |
- fjid, properties.thread)
|
|
| 148 |
- |
|
| 149 |
- if properties.thread and not session.received_thread_id:
|
|
| 150 |
- session.received_thread_id = True
|
|
| 151 |
- |
|
| 152 |
- session.last_receive = time.time()
|
|
| 137 |
+ # if not properties.type.is_groupchat:
|
|
| 138 |
+ # if properties.is_muc_pm and properties.type.is_error:
|
|
| 139 |
+ # session = self._con.find_session(fjid, properties.thread)
|
|
| 140 |
+ # if not session:
|
|
| 141 |
+ # session = self._con.get_latest_session(fjid)
|
|
| 142 |
+ # if not session:
|
|
| 143 |
+ # session = self._con.make_new_session(
|
|
| 144 |
+ # fjid, properties.thread, type_='pm')
|
|
| 145 |
+ # else:
|
|
| 146 |
+ # session = self._con.get_or_create_session(
|
|
| 147 |
+ # fjid, properties.thread)
|
|
| 148 |
+ |
|
| 149 |
+ # if properties.thread and not session.received_thread_id:
|
|
| 150 |
+ # session.received_thread_id = True
|
|
| 151 |
+ |
|
| 152 |
+ # session.last_receive = time.time()
|
|
| 153 | 153 |
|
| 154 | 154 |
additional_data = AdditionalDataDict()
|
| 155 | 155 |
|
| ... | ... | @@ -210,7 +210,7 @@ def _message_received(self, _con, stanza, properties): |
| 210 | 210 |
return
|
| 211 | 211 |
|
| 212 | 212 |
app.nec.push_incoming_event(
|
| 213 |
- NetworkEvent('decrypted-message-received', **event_attr))
|
|
| 213 |
+ NetworkEvent('message-received', **event_attr))
|
|
| 214 | 214 |
|
| 215 | 215 |
def _message_error_received(self, _con, _stanza, properties):
|
| 216 | 216 |
jid = properties.jid
|
| ... | ... | @@ -48,12 +48,6 @@ |
| 48 | 48 |
jid TEXT UNIQUE,
|
| 49 | 49 |
type INTEGER
|
| 50 | 50 |
);
|
| 51 |
- CREATE TABLE unread_messages(
|
|
| 52 |
- message_id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
|
|
| 53 |
- jid_id INTEGER,
|
|
| 54 |
- shown BOOLEAN default 0
|
|
| 55 |
- );
|
|
| 56 |
- CREATE INDEX idx_unread_messages_jid_id ON unread_messages (jid_id);
|
|
| 57 | 51 |
CREATE TABLE logs(
|
| 58 | 52 |
log_line_id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
|
| 59 | 53 |
account_id INTEGER,
|
| ... | ... | @@ -326,78 +320,6 @@ def convert_show_values_to_db_api_values(show): |
| 326 | 320 |
# it's a RFC violation .... but we should not crash
|
| 327 | 321 |
return None
|
| 328 | 322 |
|
| 329 |
- @timeit
|
|
| 330 |
- def insert_unread_events(self, message_id, jid_id):
|
|
| 331 |
- """
|
|
| 332 |
- Add unread message with id: message_id
|
|
| 333 |
- """
|
|
| 334 |
- sql = '''INSERT INTO unread_messages (message_id, jid_id, shown)
|
|
| 335 |
- VALUES (?, ?, 0)'''
|
|
| 336 |
- self._con.execute(sql, (message_id, jid_id))
|
|
| 337 |
- self._delayed_commit()
|
|
| 338 |
- |
|
| 339 |
- @timeit
|
|
| 340 |
- def set_read_messages(self, message_ids):
|
|
| 341 |
- """
|
|
| 342 |
- Mark all messages with ids in message_ids as read
|
|
| 343 |
- """
|
|
| 344 |
- ids = ','.join([str(i) for i in message_ids])
|
|
| 345 |
- sql = 'DELETE FROM unread_messages WHERE message_id IN (%s)' % ids
|
|
| 346 |
- self._con.execute(sql)
|
|
| 347 |
- self._delayed_commit()
|
|
| 348 |
- |
|
| 349 |
- @timeit
|
|
| 350 |
- def set_shown_unread_msgs(self, msg_log_id):
|
|
| 351 |
- """
|
|
| 352 |
- Mark unread message as shown un GUI
|
|
| 353 |
- """
|
|
| 354 |
- sql = 'UPDATE unread_messages SET shown = 1 where message_id = %s' % \
|
|
| 355 |
- msg_log_id
|
|
| 356 |
- self._con.execute(sql)
|
|
| 357 |
- self._delayed_commit()
|
|
| 358 |
- |
|
| 359 |
- @timeit
|
|
| 360 |
- def reset_shown_unread_messages(self):
|
|
| 361 |
- """
|
|
| 362 |
- Set shown field to False in unread_messages table
|
|
| 363 |
- """
|
|
| 364 |
- sql = 'UPDATE unread_messages SET shown = 0'
|
|
| 365 |
- self._con.execute(sql)
|
|
| 366 |
- self._delayed_commit()
|
|
| 367 |
- |
|
| 368 |
- @timeit
|
|
| 369 |
- def get_unread_msgs(self):
|
|
| 370 |
- """
|
|
| 371 |
- Get all unread messages
|
|
| 372 |
- """
|
|
| 373 |
- all_messages = []
|
|
| 374 |
- try:
|
|
| 375 |
- unread_results = self._con.execute(
|
|
| 376 |
- 'SELECT message_id, shown from unread_messages').fetchall()
|
|
| 377 |
- except Exception:
|
|
| 378 |
- unread_results = []
|
|
| 379 |
- for message in unread_results:
|
|
| 380 |
- msg_log_id = message.message_id
|
|
| 381 |
- shown = message.shown
|
|
| 382 |
- # here we get infos for that message, and related jid from jids table
|
|
| 383 |
- # do NOT change order of SELECTed things, unless you change function(s)
|
|
| 384 |
- # that called this function
|
|
| 385 |
- result = self._con.execute('''
|
|
| 386 |
- SELECT logs.log_line_id, logs.message, logs.time, logs.subject,
|
|
| 387 |
- jids.jid, logs.additional_data
|
|
| 388 |
- FROM logs, jids
|
|
| 389 |
- WHERE logs.log_line_id = %d AND logs.jid_id = jids.jid_id
|
|
| 390 |
- ''' % msg_log_id
|
|
| 391 |
- ).fetchone()
|
|
| 392 |
- if result is None:
|
|
| 393 |
- # Log line is no more in logs table.
|
|
| 394 |
- # remove it from unread_messages
|
|
| 395 |
- self.set_read_messages([msg_log_id])
|
|
| 396 |
- continue
|
|
| 397 |
- |
|
| 398 |
- all_messages.append((result, shown))
|
|
| 399 |
- return all_messages
|
|
| 400 |
- |
|
| 401 | 323 |
@timeit
|
| 402 | 324 |
def load_groupchat_messages(self, account, jid):
|
| 403 | 325 |
account_id = self.get_account_id(account, type_=JIDConstant.ROOM_TYPE)
|
| ... | ... | @@ -824,8 +746,7 @@ def insert_jid(self, jid, kind=None, type_=JIDConstant.NORMAL_TYPE): |
| 824 | 746 |
return self.get_jid_id(jid, kind, type_)
|
| 825 | 747 |
|
| 826 | 748 |
@timeit
|
| 827 |
- def insert_into_logs(self, account, jid, time_, kind,
|
|
| 828 |
- unread=True, **kwargs):
|
|
| 749 |
+ def insert_into_logs(self, account, jid, time_, kind, **kwargs):
|
|
| 829 | 750 |
"""
|
| 830 | 751 |
Insert a new message into the `logs` table
|
| 831 | 752 |
|
| ... | ... | @@ -863,11 +784,6 @@ def insert_into_logs(self, account, jid, time_, kind, |
| 863 | 784 |
log.info('Insert into DB: jid: %s, time: %s, kind: %s, stanza_id: %s',
|
| 864 | 785 |
jid, time_, kind, kwargs.get('stanza_id', None))
|
| 865 | 786 |
|
| 866 |
- if unread and kind == KindConstant.CHAT_MSG_RECV:
|
|
| 867 |
- sql = '''INSERT INTO unread_messages (message_id, jid_id)
|
|
| 868 |
- VALUES (?, (SELECT jid_id FROM jids WHERE jid = ?))'''
|
|
| 869 |
- self._con.execute(sql, (lastrowid, jid))
|
|
| 870 |
- |
|
| 871 | 787 |
self._delayed_commit()
|
| 872 | 788 |
|
| 873 | 789 |
return lastrowid
|
| ... | ... | @@ -23,7 +23,7 @@ |
| 23 | 23 |
from gajim.common.storage.base import timeit
|
| 24 | 24 |
|
| 25 | 25 |
|
| 26 |
-CURRENT_USER_VERSION = 6
|
|
| 26 |
+CURRENT_USER_VERSION = 7
|
|
| 27 | 27 |
|
| 28 | 28 |
CACHE_SQL_STATEMENT = '''
|
| 29 | 29 |
CREATE TABLE caps_cache (
|
| ... | ... | @@ -45,6 +45,14 @@ |
| 45 | 45 |
jid TEXT PRIMARY KEY UNIQUE,
|
| 46 | 46 |
avatar_sha TEXT
|
| 47 | 47 |
);
|
| 48 |
+ CREATE TABLE unread(
|
|
| 49 |
+ account TEXT,
|
|
| 50 |
+ jid TEXT,
|
|
| 51 |
+ count INTEGER,
|
|
| 52 |
+ message_id TEXT,
|
|
| 53 |
+ timestamp INTEGER,
|
|
| 54 |
+ PRIMARY KEY (account, jid)
|
|
| 55 |
+ );
|
|
| 48 | 56 |
PRAGMA user_version=%s;
|
| 49 | 57 |
''' % CURRENT_USER_VERSION
|
| 50 | 58 |
|
| ... | ... | @@ -88,6 +96,23 @@ def _migrate(self): |
| 88 | 96 |
|
| 89 | 97 |
if user_version < 6:
|
| 90 | 98 |
self._reinit_storage()
|
| 99 |
+ return
|
|
| 100 |
+ |
|
| 101 |
+ if user_version < 7:
|
|
| 102 |
+ statements = [
|
|
| 103 |
+ '''CREATE TABLE unread(
|
|
| 104 |
+ account TEXT,
|
|
| 105 |
+ jid TEXT,
|
|
| 106 |
+ count INTEGER,
|
|
| 107 |
+ message_id TEXT,
|
|
| 108 |
+ timestamp INTEGER,
|
|
| 109 |
+ PRIMARY KEY (account, jid))''',
|
|
| 110 |
+ |
|
| 111 |
+ 'CREATE INDEX idx_unread ON unread(account, jid)',
|
|
| 112 |
+ 'PRAGMA user_version=7'
|
|
| 113 |
+ ]
|
|
| 114 |
+ |
|
| 115 |
+ self._execute_multiple(statements)
|
|
| 91 | 116 |
|
| 92 | 117 |
@timeit
|
| 93 | 118 |
def _load_caps_data(self):
|
| ... | ... | @@ -262,3 +287,28 @@ def get_muc_avatar_sha(self, jid): |
| 262 | 287 |
"""
|
| 263 | 288 |
|
| 264 | 289 |
return self._muc_avatar_sha_cache.get(jid)
|
| 290 |
+ |
|
| 291 |
+ @timeit
|
|
| 292 |
+ def get_unread_count(self, account, jid):
|
|
| 293 |
+ sql = '''SELECT count, message_id, timestamp FROM unread
|
|
| 294 |
+ WHERE account = ? AND jid = ?'''
|
|
| 295 |
+ return self._con.execute(sql, (account, jid)).fetchone()
|
|
| 296 |
+ |
|
| 297 |
+ @timeit
|
|
| 298 |
+ def set_unread_count(self, account, jid, count, message_id, timestamp):
|
|
| 299 |
+ sql = '''INSERT INTO unread (account, jid, count, message_id, timestamp)
|
|
| 300 |
+ VALUES (?, ?, ?, ?, ?)'''
|
|
| 301 |
+ self._con.execute(sql, (account, jid, count, message_id, timestamp))
|
|
| 302 |
+ self._delayed_commit()
|
|
| 303 |
+ |
|
| 304 |
+ @timeit
|
|
| 305 |
+ def update_unread_count(self, account, jid, count):
|
|
| 306 |
+ sql = 'UPDATE unread SET count = ? WHERE account = ? AND jid = ?'
|
|
| 307 |
+ self._con.execute(sql, (count, account, jid))
|
|
| 308 |
+ self._delayed_commit()
|
|
| 309 |
+ |
|
| 310 |
+ @timeit
|
|
| 311 |
+ def reset_unread_count(self, account, jid):
|
|
| 312 |
+ sql = 'DELETE FROM unread WHERE account = ? AND jid = ?'
|
|
| 313 |
+ self._con.execute(sql, (account, jid))
|
|
| 314 |
+ self._delayed_commit()
|
| ... | ... | @@ -1610,10 +1610,10 @@ def on_cancel(is_checked): |
| 1610 | 1610 |
on_yes(self)
|
| 1611 | 1611 |
|
| 1612 | 1612 |
def _close_control(self, reason=None):
|
| 1613 |
- if self.parent_win is None:
|
|
| 1614 |
- self.shutdown(reason)
|
|
| 1615 |
- else:
|
|
| 1616 |
- self.parent_win.remove_tab(self, None, reason=reason, force=True)
|
|
| 1613 |
+ # if self.parent_win is None:
|
|
| 1614 |
+ self.shutdown(reason)
|
|
| 1615 |
+ # else:
|
|
| 1616 |
+ # self.parent_win.remove_tab(self, None, reason=reason, force=True)
|
|
| 1617 | 1617 |
|
| 1618 | 1618 |
def set_control_active(self, state):
|
| 1619 | 1619 |
self.conv_textview.allow_focus_out_line = True
|
| ... | ... | @@ -33,12 +33,11 @@ def __init__(self, workspace_id): |
| 33 | 33 |
self._timer_id = GLib.timeout_add_seconds(60, self._update_timer)
|
| 34 | 34 |
|
| 35 | 35 |
def _on_destroy(self):
|
| 36 |
- if self._timer_id is not None:
|
|
| 37 |
- GLib.source_remove(self._timer_id)
|
|
| 36 |
+ GLib.source_remove(self._timer_id)
|
|
| 38 | 37 |
|
| 39 | 38 |
def _update_timer(self):
|
| 40 |
- self.update()
|
|
| 41 |
- GLib.timeout_add_seconds(60, self._update_timer)
|
|
| 39 |
+ self.update_time()
|
|
| 40 |
+ return True
|
|
| 42 | 41 |
|
| 43 | 42 |
def _filter_func(self, row):
|
| 44 | 43 |
if not self._current_filter_text:
|
| ... | ... | @@ -87,9 +86,14 @@ def get_open_chats(self): |
| 87 | 86 |
open_chats.append(key + (value.type,))
|
| 88 | 87 |
return open_chats
|
| 89 | 88 |
|
| 90 |
- def update(self):
|
|
| 89 |
+ def update_time(self):
|
|
| 91 | 90 |
for _, row in self._chats.items():
|
| 92 |
- row.update()
|
|
| 91 |
+ row.update_time()
|
|
| 92 |
+ |
|
| 93 |
+ def update(self, event):
|
|
| 94 |
+ row = self._chats.get((event.account, event.jid))
|
|
| 95 |
+ row.add_unread()
|
|
| 96 |
+ row.set_last_message_text('Me', event.msgtext)
|
|
| 93 | 97 |
|
| 94 | 98 |
|
| 95 | 99 |
class ChatRow(Gtk.ListBoxRow):
|
| ... | ... | @@ -150,11 +154,11 @@ def __init__(self, workspace_id, account, jid, type_): |
| 150 | 154 |
chat_name_label.set_ellipsize(Pango.EllipsizeMode.END)
|
| 151 | 155 |
chat_name_label.set_text(name)
|
| 152 | 156 |
|
| 153 |
- last_message_label = Gtk.Label()
|
|
| 154 |
- last_message_label.set_halign(Gtk.Align.START)
|
|
| 155 |
- last_message_label.set_xalign(0)
|
|
| 156 |
- last_message_label.set_ellipsize(Pango.EllipsizeMode.END)
|
|
| 157 |
- last_message_label.get_style_context().add_class('small-label')
|
|
| 157 |
+ self._last_message_label = Gtk.Label()
|
|
| 158 |
+ self._last_message_label.set_halign(Gtk.Align.START)
|
|
| 159 |
+ self._last_message_label.set_xalign(0)
|
|
| 160 |
+ self._last_message_label.set_ellipsize(Pango.EllipsizeMode.END)
|
|
| 161 |
+ self._last_message_label.get_style_context().add_class('small-label')
|
|
| 158 | 162 |
|
| 159 | 163 |
self._timestamp_label = Gtk.Label()
|
| 160 | 164 |
self._timestamp_label.set_halign(Gtk.Align.END)
|
| ... | ... | @@ -167,23 +171,24 @@ def __init__(self, workspace_id, account, jid, type_): |
| 167 | 171 |
last_message_box = Gtk.Box(spacing=3)
|
| 168 | 172 |
if line is not None and line.message is not None:
|
| 169 | 173 |
one_line = ' '.join(line.message.splitlines())
|
| 170 |
- last_message_label.set_text(one_line)
|
|
| 171 |
- nick_label = Gtk.Label()
|
|
| 172 |
- nick_label.set_halign(Gtk.Align.START)
|
|
| 173 |
- nick_label.get_style_context().add_class('small-label')
|
|
| 174 |
- nick_label.get_style_context().add_class('dim-label')
|
|
| 174 |
+ |
|
| 175 |
+ self._last_message_label.set_text(one_line)
|
|
| 176 |
+ self._nick_label = Gtk.Label()
|
|
| 177 |
+ self._nick_label.set_halign(Gtk.Align.START)
|
|
| 178 |
+ self._nick_label.get_style_context().add_class('small-label')
|
|
| 179 |
+ self._nick_label.get_style_context().add_class('dim-label')
|
|
| 175 | 180 |
if line.kind in (KindConstant.CHAT_MSG_SENT,
|
| 176 | 181 |
KindConstant.SINGLE_MSG_SENT):
|
| 177 |
- nick_label.set_text(_('Me:'))
|
|
| 178 |
- last_message_box.add(nick_label)
|
|
| 182 |
+ self._nick_label.set_text(_('Me:'))
|
|
| 183 |
+ last_message_box.add(self._nick_label)
|
|
| 179 | 184 |
if line.kind == KindConstant.GC_MSG:
|
| 180 | 185 |
our_nick = get_group_chat_nick(account, jid)
|
| 181 | 186 |
if line.contact_name == our_nick:
|
| 182 |
- nick_label.set_text(_('Me:'))
|
|
| 187 |
+ self._nick_label.set_text(_('Me:'))
|
|
| 183 | 188 |
else:
|
| 184 |
- nick_label.set_text(_('%(muc_nick)s: ') % {
|
|
| 189 |
+ self._nick_label.set_text(_('%(muc_nick)s: ') % {
|
|
| 185 | 190 |
'muc_nick': line.contact_name})
|
| 186 |
- last_message_box.add(nick_label)
|
|
| 191 |
+ last_message_box.add(self._nick_label)
|
|
| 187 | 192 |
|
| 188 | 193 |
# TODO: file transfers have to be displayed differently
|
| 189 | 194 |
|
| ... | ... | @@ -191,7 +196,7 @@ def __init__(self, workspace_id, account, jid, type_): |
| 191 | 196 |
uf_timestamp = get_uf_relative_time(line.time)
|
| 192 | 197 |
self._timestamp_label.set_text(uf_timestamp)
|
| 193 | 198 |
|
| 194 |
- last_message_box.add(last_message_label)
|
|
| 199 |
+ last_message_box.add(self._last_message_label)
|
|
| 195 | 200 |
|
| 196 | 201 |
self._unread_label = Gtk.Label()
|
| 197 | 202 |
self._unread_label.set_no_show_all(True)
|
| ... | ... | @@ -242,16 +247,16 @@ def _on_state_flags_changed(self, _listboxrow, *args): |
| 242 | 247 |
def _on_close_button_clicked(self, _button):
|
| 243 | 248 |
app.window.remove_chat(self.workspace_id, self.account, self.jid)
|
| 244 | 249 |
|
| 245 |
- def update(self):
|
|
| 250 |
+ def update_time(self):
|
|
| 246 | 251 |
if self._timestamp is not None:
|
| 247 | 252 |
uf_timestamp = get_uf_relative_time(self._timestamp)
|
| 248 | 253 |
self._timestamp_label.set_text(uf_timestamp)
|
| 249 | 254 |
|
| 250 |
- def set_unread(self, count):
|
|
| 251 |
- log.info('Set unread count: %s (%s)', self.jid, count)
|
|
| 252 |
- self._unread_count = count
|
|
| 253 |
- if not count:
|
|
| 254 |
- self._unread_label.hide()
|
|
| 255 |
- else:
|
|
| 256 |
- self._unread_label.set_text(str(count))
|
|
| 257 |
- self._unread_label.show()
|
|
| 255 |
+ def add_unread(self):
|
|
| 256 |
+ self._unread_count += 1
|
|
| 257 |
+ self._unread_label.set_text(str(self._unread_count))
|
|
| 258 |
+ self._unread_label.show()
|
|
| 259 |
+ |
|
| 260 |
+ def set_last_message_text(self, nickname, text):
|
|
| 261 |
+ self._last_message_label.set_text(text)
|
|
| 262 |
+ self._nick_label.set_text(nickname)
|
| ... | ... | @@ -120,3 +120,7 @@ def contains_chat(self, account, jid, workspace_id=None): |
| 120 | 120 |
|
| 121 | 121 |
chat_list = self._chat_lists[workspace_id]
|
| 122 | 122 |
return chat_list.contains_chat(account, jid)
|
| 123 |
+ |
|
| 124 |
+ def update(self, event):
|
|
| 125 |
+ chat_list = self._find_chat(event.account, event.jid)
|
|
| 126 |
+ chat_list.update(event)
|
| ... | ... | @@ -83,3 +83,23 @@ def show_chat(self, account, jid): |
| 83 | 83 |
|
| 84 | 84 |
def clear(self):
|
| 85 | 85 |
self.set_visible_child_name('empty')
|
| 86 |
+ |
|
| 87 |
+ def update(self, event):
|
|
| 88 |
+ if not event.msgtxt:
|
|
| 89 |
+ return
|
|
| 90 |
+ |
|
| 91 |
+ control = self.get_control(event.account, event.jid)
|
|
| 92 |
+ |
|
| 93 |
+ typ = ''
|
|
| 94 |
+ if event.properties.is_sent_carbon:
|
|
| 95 |
+ typ = 'out'
|
|
| 96 |
+ |
|
| 97 |
+ control.add_message(event.msgtxt,
|
|
| 98 |
+ typ,
|
|
| 99 |
+ tim=event.properties.timestamp,
|
|
| 100 |
+ subject=event.properties.subject,
|
|
| 101 |
+ displaymarking=event.displaymarking,
|
|
| 102 |
+ msg_log_id=event.msg_log_id,
|
|
| 103 |
+ message_id=event.properties.id,
|
|
| 104 |
+ correct_id=event.correct_id,
|
|
| 105 |
+ additional_data=event.additional_data)
|
| ... | ... | @@ -4,6 +4,7 @@ |
| 4 | 4 |
from gi.repository import Gio
|
| 5 | 5 |
|
| 6 | 6 |
from gajim.common import app
|
| 7 |
+from gajim.common import ged
|
|
| 7 | 8 |
from gajim.common.i18n import _
|
| 8 | 9 |
from gajim.gui.util import get_builder
|
| 9 | 10 |
from gajim.gui.util import load_icon
|
| ... | ... | @@ -61,6 +62,10 @@ def __init__(self): |
| 61 | 62 |
'clicked', self._on_start_chat_clicked)
|
| 62 | 63 |
self._ui.connect_signals(self)
|
| 63 | 64 |
|
| 65 |
+ app.ged.register_event_handler('message-received',
|
|
| 66 |
+ ged.CORE,
|
|
| 67 |
+ self._on_message_received)
|
|
| 68 |
+ |
|
| 64 | 69 |
self.show_all()
|
| 65 | 70 |
|
| 66 | 71 |
self._load_chats()
|
| ... | ... | @@ -236,6 +241,13 @@ def _on_edit_workspace_clicked(self, _button): |
| 236 | 241 |
open_window('WorkspaceDialog',
|
| 237 | 242 |
workspace_id=self.get_active_workspace())
|
| 238 | 243 |
|
| 244 |
+ def _on_message_received(self, event):
|
|
| 245 |
+ if not self.chat_exists(event.account, event.jid):
|
|
| 246 |
+ self.add_chat(event.account, event.jid, 'contact')
|
|
| 247 |
+ |
|
| 248 |
+ self._chat_stack.update(event)
|
|
| 249 |
+ self._chat_list_stack.update(event)
|
|
| 250 |
+ |
|
| 239 | 251 |
def quit(self):
|
| 240 | 252 |
accounts = list(app.connections.keys())
|
| 241 | 253 |
get_msg = False
|
| ... | ... | @@ -63,7 +63,6 @@ |
| 63 | 63 |
from gajim.chat_control import ChatControl
|
| 64 | 64 |
from gajim.groupchat_control import GroupchatControl
|
| 65 | 65 |
from gajim.privatechat_control import PrivateChatControl
|
| 66 |
-from gajim.message_window import MessageWindowMgr
|
|
| 67 | 66 |
|
| 68 | 67 |
from gajim.session import ChatControlSession
|
| 69 | 68 |
|
| ... | ... | @@ -2124,8 +2123,6 @@ def __init__(self): |
| 2124 | 2123 |
# Load CSS files
|
| 2125 | 2124 |
app.load_css_config()
|
| 2126 | 2125 |
|
| 2127 |
- app.storage.archive.reset_shown_unread_messages()
|
|
| 2128 |
- |
|
| 2129 | 2126 |
for account in app.settings.get_accounts():
|
| 2130 | 2127 |
if app.settings.get_account_setting(account, 'is_zeroconf'):
|
| 2131 | 2128 |
app.ZEROCONF_ACC_NAME = account
|