Fix displaying MUC subjects with delay tag

Dont print it as "old" conversation, instead add the delay timestamp
at the end of the subject
This commit is contained in:
Philipp Hörist 2018-08-30 19:19:14 +02:00 committed by Philipp Hörist
parent a8534800b0
commit 41a7196620
4 changed files with 20 additions and 34 deletions

View File

@ -25,7 +25,6 @@ from calendar import timegm
import hashlib import hashlib
import hmac import hmac
import logging import logging
import sys
from time import time as time_time from time import time as time_time
import OpenSSL.crypto import OpenSSL.crypto
@ -499,13 +498,13 @@ class GcMessageReceivedEvent(nec.NetworkIncomingEvent):
# message from server # message from server
self.nick = '' self.nick = ''
self.has_timestamp = bool(self.stanza.timestamp)
self.subject = self.stanza.getSubject() self.subject = self.stanza.getSubject()
if self.subject is not None: if self.subject is not None:
app.nec.push_incoming_event(GcSubjectReceivedEvent(None, app.nec.push_incoming_event(
conn=self.conn, msg_event=self)) nec.NetworkEvent('gc-subject-received',
nickname=self.msg_obj.resource,
**vars(self.msg_obj)))
return return
conditions = self.stanza.getStatusConditions() conditions = self.stanza.getStatusConditions()
@ -566,21 +565,6 @@ class GcMessageReceivedEvent(nec.NetworkIncomingEvent):
return True return True
class GcSubjectReceivedEvent(nec.NetworkIncomingEvent):
name = 'gc-subject-received'
base_network_events = []
def generate(self):
self.conn = self.msg_event.conn
self.stanza = self.msg_event.stanza
self.room_jid = self.msg_event.room_jid
self.nickname = self.msg_event.nickname
self.fjid = self.msg_event.fjid
self.subject = self.msg_event.subject
self.msgtxt = self.msg_event.msgtxt
self.has_timestamp = self.msg_event.has_timestamp
return True
class GcConfigChangedReceivedEvent(nec.NetworkIncomingEvent): class GcConfigChangedReceivedEvent(nec.NetworkIncomingEvent):
name = 'gc-config-changed-received' name = 'gc-config-changed-received'
base_network_events = [] base_network_events = []

View File

@ -1239,7 +1239,7 @@ class GroupchatControl(ChatControlBase):
additional_data=obj.additional_data) additional_data=obj.additional_data)
else: else:
# message from someone # message from someone
if obj.has_timestamp: if obj.delayed:
# don't print xhtml if it's an old message. # don't print xhtml if it's an old message.
# Like that xhtml messages are grayed too. # Like that xhtml messages are grayed too.
self.print_old_conversation( self.print_old_conversation(
@ -1492,20 +1492,22 @@ class GroupchatControl(ChatControlBase):
self.subject = subject self.subject = subject
self.draw_banner_text() self.draw_banner_text()
def _nec_gc_subject_received(self, obj): def _nec_gc_subject_received(self, event):
if obj.conn.name != self.account: if event.conn.name != self.account:
return return
if obj.room_jid != self.room_jid: if event.jid != self.room_jid:
return return
self.set_subject(obj.subject) self.set_subject(event.subject)
text = _('%(nick)s has set the subject to %(subject)s') % { text = _('%(nick)s has set the subject to %(subject)s') % {
'nick': obj.nickname, 'subject': obj.subject} 'nick': event.nickname, 'subject': event.subject}
if obj.has_timestamp:
self.print_old_conversation(text)
else:
self.print_conversation(text)
if obj.subject == '': if event.delayed:
date = time.strftime('%d-%m-%Y %H:%M:%S',
time.localtime(event.timestamp))
text = '%s - %s' % (text, date)
self.print_conversation(text)
if event.subject == '':
self.subject_button.hide() self.subject_button.hide()
else: else:
self.subject_button.show() self.subject_button.show()

View File

@ -383,7 +383,7 @@ class GajimRemote(Server):
# event has not been handled at GUI level # event has not been handled at GUI level
return return
self.raise_signal('GCMessage', (obj.conn.name, [obj.fjid, obj.msgtxt, self.raise_signal('GCMessage', (obj.conn.name, [obj.fjid, obj.msgtxt,
obj.timestamp, obj.has_timestamp, obj.xhtml_msgtxt, obj.status_code, obj.timestamp, obj.delayed, obj.xhtml_msgtxt, obj.status_code,
obj.displaymarking, obj.captcha_form, obj.needs_highlight])) obj.displaymarking, obj.captcha_form, obj.needs_highlight]))
def on_our_status(self, obj): def on_our_status(self, obj):

View File

@ -2694,10 +2694,10 @@ class RosterWindow:
def _nec_gc_subject_received(self, obj): def _nec_gc_subject_received(self, obj):
contact = app.contacts.get_contact_with_highest_priority( contact = app.contacts.get_contact_with_highest_priority(
obj.conn.name, obj.room_jid) obj.conn.name, obj.jid)
if contact: if contact:
contact.status = obj.subject contact.status = obj.subject
self.draw_contact(obj.room_jid, obj.conn.name) self.draw_contact(obj.jid, obj.conn.name)
def _nec_metacontacts_received(self, obj): def _nec_metacontacts_received(self, obj):
self.redraw_metacontacts(obj.conn.name) self.redraw_metacontacts(obj.conn.name)