Support for displaying XEP-0184 receipts.
This commit is contained in:
parent
8b1abeba54
commit
f704701ba4
Binary file not shown.
After Width: | Height: | Size: 194 B |
|
@ -45,7 +45,7 @@ from common.contacts import GC_Contact
|
|||
from common.logger import Constants
|
||||
constants = Constants()
|
||||
from common.rst_xhtml_generator import create_xhtml
|
||||
from common.xmpp.protocol import NS_XHTML, NS_FILE, NS_MUC, NS_ESESSION
|
||||
from common.xmpp.protocol import NS_XHTML, NS_FILE, NS_MUC, NS_RECEIPTS, NS_ESESSION
|
||||
|
||||
try:
|
||||
import gtkspell
|
||||
|
@ -660,7 +660,7 @@ class ChatControlBase(MessageControl):
|
|||
|
||||
def print_conversation_line(self, text, kind, name, tim,
|
||||
other_tags_for_name=[], other_tags_for_time=[], other_tags_for_text=[],
|
||||
count_as_new=True, subject=None, old_kind=None, xhtml=None, simple=False):
|
||||
count_as_new=True, subject=None, old_kind=None, xhtml=None, simple=False, xep0184_id = None):
|
||||
'''prints 'chat' type messages'''
|
||||
jid = self.contact.jid
|
||||
full_jid = self.get_full_jid()
|
||||
|
@ -672,6 +672,9 @@ class ChatControlBase(MessageControl):
|
|||
other_tags_for_name, other_tags_for_time, other_tags_for_text,
|
||||
subject, old_kind, xhtml, simple=simple)
|
||||
|
||||
if xep0184_id is not None:
|
||||
textview.show_xep0184_warning(xep0184_id)
|
||||
|
||||
if not count_as_new:
|
||||
return
|
||||
if kind == 'incoming':
|
||||
|
@ -1538,12 +1541,23 @@ class ChatControl(ChatControlBase):
|
|||
gobject.source_remove(self.possible_inactive_timeout_id)
|
||||
self._schedule_activity_timers()
|
||||
|
||||
if ChatControlBase.send_message(self, message, keyID,
|
||||
type = 'chat', chatstate = chatstate_to_send,
|
||||
composing_xep = composing_xep,
|
||||
process_command = process_command):
|
||||
id = ChatControlBase.send_message(self, message, keyID,
|
||||
type = 'chat', chatstate = chatstate_to_send,
|
||||
composing_xep = composing_xep,
|
||||
process_command = process_command)
|
||||
if id:
|
||||
# XXX: Once we have fallback to disco, remove
|
||||
# notexistant check
|
||||
if gajim.capscache.is_supported(contact, NS_RECEIPTS) \
|
||||
and not gajim.capscache.is_supported(contact,
|
||||
'notexistant') and gajim.config.get_per('accounts',
|
||||
self.account, 'request_receipt'):
|
||||
xep0184_id = id
|
||||
else:
|
||||
xep0184_id = None
|
||||
|
||||
self.print_conversation(message, self.contact.jid,
|
||||
encrypted = encrypted)
|
||||
encrypted = encrypted, xep0184_id = xep0184_id)
|
||||
|
||||
def check_for_possible_paused_chatstate(self, arg):
|
||||
''' did we move mouse of that window or write something in message
|
||||
|
@ -1629,7 +1643,7 @@ class ChatControl(ChatControlBase):
|
|||
self.session.is_loggable(), self.session and self.session.verified_identity)
|
||||
|
||||
def print_conversation(self, text, frm='', tim=None, encrypted=False,
|
||||
subject=None, xhtml=None, simple=False):
|
||||
subject=None, xhtml=None, simple=False, xep0184_id=None):
|
||||
# TODO: contact? ITYM frm.
|
||||
'''Print a line in the conversation:
|
||||
if contact is set to status: it's a status message
|
||||
|
@ -1683,7 +1697,7 @@ class ChatControl(ChatControlBase):
|
|||
xhtml = '<body xmlns="%s">%s</body>' % (NS_XHTML, xhtml)
|
||||
ChatControlBase.print_conversation_line(self, text, kind, name, tim,
|
||||
subject=subject, old_kind=self.old_msg_kind, xhtml=xhtml,
|
||||
simple=simple)
|
||||
simple=simple, xep0184_id=xep0184_id)
|
||||
if text.startswith('/me ') or text.startswith('/me\n'):
|
||||
self.old_msg_kind = None
|
||||
else:
|
||||
|
|
|
@ -1729,6 +1729,13 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
|
|||
receipt.setThread(thread_id)
|
||||
con.send(receipt)
|
||||
|
||||
# We got our message's receipt
|
||||
if msg.getTag('received', namespace=common.xmpp.NS_RECEIPTS) \
|
||||
and session.control and gajim.config.get_per('accounts',
|
||||
self.name, 'request_receipt'):
|
||||
session.control.conv_textview.hide_xep0184_warning(
|
||||
msg.getID())
|
||||
|
||||
addressTag = msg.getTag('addresses', namespace = common.xmpp.NS_ADDRESS)
|
||||
|
||||
# Be sure it comes from one of our resource, else ignore address element
|
||||
|
|
|
@ -148,8 +148,10 @@ class ConversationTextview:
|
|||
'''Class for the conversation textview (where user reads already said messages)
|
||||
for chat/groupchat windows'''
|
||||
|
||||
path_to_file = os.path.join(gajim.DATA_DIR, 'pixmaps', 'muc_separator.png')
|
||||
FOCUS_OUT_LINE_PIXBUF = gtk.gdk.pixbuf_new_from_file(path_to_file)
|
||||
FOCUS_OUT_LINE_PIXBUF = gtk.gdk.pixbuf_new_from_file(os.path.join(
|
||||
gajim.DATA_DIR, 'pixmaps', 'muc_separator.png'))
|
||||
XEP0184_WARNING_PIXBUF = gtk.gdk.pixbuf_new_from_file(os.path.join(
|
||||
gajim.DATA_DIR, 'pixmaps', 'xep0184.png'))
|
||||
|
||||
# smooth scroll constants
|
||||
MAX_SCROLL_TIME = 0.4 # seconds
|
||||
|
@ -175,6 +177,7 @@ class ConversationTextview:
|
|||
self.handlers = {}
|
||||
self.images = []
|
||||
self.image_cache = {}
|
||||
self.xep0184_marks = {}
|
||||
|
||||
# It's True when we scroll in the code, so we can detect scroll from user
|
||||
self.auto_scrolling = False
|
||||
|
@ -389,6 +392,58 @@ class ConversationTextview:
|
|||
self.smooth_id = None
|
||||
self.smooth_scroll_timer.cancel()
|
||||
|
||||
def show_xep0184_warning(self, id):
|
||||
try:
|
||||
if self.xep0184_marks[id] is not None:
|
||||
return
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
buffer = self.tv.get_buffer()
|
||||
|
||||
buffer.begin_user_action()
|
||||
|
||||
end_iter = buffer.get_end_iter()
|
||||
buffer.insert(end_iter, ' ')
|
||||
buffer.insert_pixbuf(end_iter,
|
||||
ConversationTextview.XEP0184_WARNING_PIXBUF)
|
||||
|
||||
end_iter = buffer.get_end_iter();
|
||||
before_img_iter = end_iter.copy()
|
||||
# XXX: Is there a nicer way?
|
||||
before_img_iter.backward_char();
|
||||
before_img_iter.backward_char();
|
||||
|
||||
self.xep0184_marks[id] = buffer.create_mark(None,
|
||||
buffer.get_end_iter(), left_gravity=True)
|
||||
|
||||
buffer.end_user_action()
|
||||
|
||||
def hide_xep0184_warning(self, id):
|
||||
try:
|
||||
if self.xep0184_marks[id] is None:
|
||||
return
|
||||
except KeyError:
|
||||
return
|
||||
|
||||
buffer = self.tv.get_buffer()
|
||||
|
||||
buffer.begin_user_action()
|
||||
|
||||
end_iter = buffer.get_iter_at_mark(self.xep0184_marks[id])
|
||||
|
||||
begin_iter = end_iter.copy()
|
||||
# XXX: Is there a nicer way?
|
||||
begin_iter.backward_char();
|
||||
begin_iter.backward_char();
|
||||
|
||||
buffer.delete(begin_iter, end_iter)
|
||||
buffer.delete_mark(self.xep0184_marks[id])
|
||||
|
||||
buffer.end_user_action()
|
||||
|
||||
self.xep0184_marks[id] = None
|
||||
|
||||
def show_focus_out_line(self):
|
||||
if not self.allow_focus_out_line:
|
||||
# if room did not receive focus-in from the last time we added
|
||||
|
|
|
@ -167,6 +167,8 @@ class MessageControl:
|
|||
|
||||
# Send and update history
|
||||
return conn.send_message(jid, message, keyID, type = type,
|
||||
chatstate = chatstate, msg_id = msg_id, composing_xep = composing_xep,
|
||||
chatstate = chatstate, msg_id = msg_id,
|
||||
composing_xep = composing_xep,
|
||||
resource = self.resource, user_nick = user_nick,
|
||||
session = self.session, original_message = original_message)
|
||||
session = self.session,
|
||||
original_message = original_message)
|
||||
|
|
Loading…
Reference in New Issue