single messages are well handled: they are saved in awaiting_events if needed and are printed when we dubble click a contact row, or systray or popup window
This commit is contained in:
parent
966afbb031
commit
77cb852057
|
@ -56,7 +56,8 @@ newly_added = {} # list of contacts that has just signed in
|
||||||
to_be_removed = {} # list of contacts that has just signed out
|
to_be_removed = {} # list of contacts that has just signed out
|
||||||
awaiting_events = {} # list of messages/FT reveived but not printed
|
awaiting_events = {} # list of messages/FT reveived but not printed
|
||||||
# awaiting_events[jid] = (type, (data1, data2, ...))
|
# awaiting_events[jid] = (type, (data1, data2, ...))
|
||||||
# if type == 'message': data = (message, subject, kind, time, encrypted)
|
# if type in ('chat', 'normal'): data = (message, subject, kind, time,
|
||||||
|
# encrypted)
|
||||||
# kind can be (incoming, error)
|
# kind can be (incoming, error)
|
||||||
nicks = {} # list of our nick names in each account
|
nicks = {} # list of our nick names in each account
|
||||||
allow_notifications = {} # do we allow notifications for each account ?
|
allow_notifications = {} # do we allow notifications for each account ?
|
||||||
|
|
|
@ -907,10 +907,14 @@ class PopupNotificationWindow:
|
||||||
self.account)
|
self.account)
|
||||||
|
|
||||||
if self.msg_type == 'normal': # it's single message
|
if self.msg_type == 'normal': # it's single message
|
||||||
return # FIXME: I think I should not print here but in new_chat?
|
# Get the first single message event
|
||||||
contact = get_contact_instance_with_highest_priority(account, jid)
|
q = gajim.awaiting_events[self.account][self.jid]
|
||||||
SingleMessageWindow(self.plugin, self.account, contact.jid,
|
for ev in q:
|
||||||
action = 'receive', from_whom = jid, subject = subject, message = msg)
|
if ev[0] == 'normal':
|
||||||
|
break
|
||||||
|
# Open the window
|
||||||
|
self.plugin.roster.open_single_message_window_from_event(self.jid,
|
||||||
|
self.account, ev)
|
||||||
|
|
||||||
elif self.msg_type == 'pm': # It's a private message
|
elif self.msg_type == 'pm': # It's a private message
|
||||||
self.plugin.roster.new_chat(contact, self.account)
|
self.plugin.roster.new_chat(contact, self.account)
|
||||||
|
|
|
@ -1377,7 +1377,7 @@ current room topic.') % command, room_jid)
|
||||||
|
|
||||||
if no_queue:
|
if no_queue:
|
||||||
qs[fjid] = []
|
qs[fjid] = []
|
||||||
qs[fjid].append(('message', (msg, '', 'incoming', tim, False)))
|
qs[fjid].append(('chat', (msg, '', 'incoming', tim, False)))
|
||||||
self.nb_unread[room_jid] += 1
|
self.nb_unread[room_jid] += 1
|
||||||
|
|
||||||
autopopup = gajim.config.get('autopopup')
|
autopopup = gajim.config.get('autopopup')
|
||||||
|
|
|
@ -1568,25 +1568,29 @@ _('If "%s" accepts this request you will know his status.') %jid)
|
||||||
path = None
|
path = None
|
||||||
autopopup = gajim.config.get('autopopup')
|
autopopup = gajim.config.get('autopopup')
|
||||||
autopopupaway = gajim.config.get('autopopupaway')
|
autopopupaway = gajim.config.get('autopopupaway')
|
||||||
|
save_in_queue = False
|
||||||
|
|
||||||
if msg_type == 'normal': # it's single message
|
|
||||||
#FIXME: take into account autopopup and autopopupaway
|
|
||||||
# if user doesn't want to be bugged do it as we do the 'chat'
|
|
||||||
contact = gajim.contacts[account][jid][0]
|
|
||||||
dialogs.SingleMessageWindow(self.plugin, account, contact.jid,
|
|
||||||
action = 'receive', from_whom = jid, subject = subject,
|
|
||||||
message = msg)
|
|
||||||
return
|
|
||||||
|
|
||||||
# Do we have a queue?
|
# Do we have a queue?
|
||||||
qs = gajim.awaiting_events[account]
|
qs = gajim.awaiting_events[account]
|
||||||
no_queue = True
|
no_queue = True
|
||||||
if qs.has_key(jid):
|
if qs.has_key(jid):
|
||||||
no_queue = False
|
no_queue = False
|
||||||
|
popup = False
|
||||||
|
if autopopupaway or (autopopup and gajim.connections[account].connected \
|
||||||
|
in (2, 3)):
|
||||||
|
popup = True
|
||||||
|
|
||||||
# We print if window is opened
|
if msg_type == 'normal': # it's single message
|
||||||
if self.plugin.windows[account]['chats'].has_key(jid):
|
if popup:
|
||||||
|
contact = gajim.contacts[account][jid][0]
|
||||||
|
dialogs.SingleMessageWindow(self.plugin, account, contact.jid,
|
||||||
|
action = 'receive', from_whom = jid, subject = subject,
|
||||||
|
message = msg)
|
||||||
|
return
|
||||||
|
|
||||||
|
# We print if window is opened and it's not a single message
|
||||||
|
if self.plugin.windows[account]['chats'].has_key(jid) and \
|
||||||
|
msg_type != 'normal':
|
||||||
typ = ''
|
typ = ''
|
||||||
if msg_type == 'error':
|
if msg_type == 'error':
|
||||||
typ = 'status'
|
typ = 'status'
|
||||||
|
@ -1597,30 +1601,30 @@ _('If "%s" accepts this request you will know his status.') %jid)
|
||||||
# We save it in a queue
|
# We save it in a queue
|
||||||
if no_queue:
|
if no_queue:
|
||||||
qs[jid] = []
|
qs[jid] = []
|
||||||
qs[jid].append(('message', (msg, subject, msg_type, tim, encrypted)))
|
kind = 'chat'
|
||||||
|
if msg_type == 'normal':
|
||||||
|
kind = 'normal'
|
||||||
|
qs[jid].append((kind, (msg, subject, msg_type, tim, encrypted)))
|
||||||
self.nb_unread += 1
|
self.nb_unread += 1
|
||||||
if (not autopopup or ( not autopopupaway and \
|
if popup:
|
||||||
gajim.connections[account].connected > 2)) and not \
|
if not self.plugin.windows[account]['chats'].has_key(jid):
|
||||||
self.plugin.windows[account]['chats'].has_key(jid):
|
c = gajim.get_contact_instance_with_highest_priority(account, jid)
|
||||||
if no_queue: # We didn't have a queue: we change icons
|
self.new_chat(c, account)
|
||||||
model = self.tree.get_model()
|
if path:
|
||||||
self.draw_contact(jid, account)
|
|
||||||
if self.plugin.systray_enabled:
|
|
||||||
self.plugin.systray.add_jid(jid, account, 'chat')
|
|
||||||
self.show_title() # we show the * or [n]
|
|
||||||
if not path:
|
|
||||||
self.add_contact_to_roster(jid, account)
|
|
||||||
iters = self.get_contact_iter(jid, account)
|
|
||||||
path = self.tree.get_model().get_path(iters[0])
|
|
||||||
self.tree.expand_row(path[0:1], False)
|
self.tree.expand_row(path[0:1], False)
|
||||||
self.tree.expand_row(path[0:2], False)
|
self.tree.expand_row(path[0:2], False)
|
||||||
self.tree.scroll_to_cell(path)
|
self.tree.scroll_to_cell(path)
|
||||||
self.tree.set_cursor(path)
|
self.tree.set_cursor(path)
|
||||||
else:
|
else:
|
||||||
if not self.plugin.windows[account]['chats'].has_key(jid):
|
if no_queue: # We didn't have a queue: we change icons
|
||||||
c = gajim.get_contact_instance_with_highest_priority(account, jid)
|
self.draw_contact(jid, account)
|
||||||
self.new_chat(c, account)
|
if self.plugin.systray_enabled:
|
||||||
if path:
|
self.plugin.systray.add_jid(jid, account, kind)
|
||||||
|
self.show_title() # we show the * or [n]
|
||||||
|
if not path:
|
||||||
|
self.add_contact_to_roster(jid, account)
|
||||||
|
iters = self.get_contact_iter(jid, account)
|
||||||
|
path = self.tree.get_model().get_path(iters[0])
|
||||||
self.tree.expand_row(path[0:1], False)
|
self.tree.expand_row(path[0:1], False)
|
||||||
self.tree.expand_row(path[0:2], False)
|
self.tree.expand_row(path[0:2], False)
|
||||||
self.tree.scroll_to_cell(path)
|
self.tree.scroll_to_cell(path)
|
||||||
|
@ -1795,8 +1799,23 @@ _('If "%s" accepts this request you will know his status.') %jid)
|
||||||
self.send_status(acct, 'offline', message, True)
|
self.send_status(acct, 'offline', message, True)
|
||||||
self.quit_gtkgui_plugin()
|
self.quit_gtkgui_plugin()
|
||||||
|
|
||||||
|
def open_single_message_window_from_event(self, jid, account, event):
|
||||||
|
qs = gajim.awaiting_events[account]
|
||||||
|
data = event[1]
|
||||||
|
dialogs.SingleMessageWindow(self.plugin, account, jid, action = 'receive',
|
||||||
|
from_whom = jid, subject = data[1], message = data[0])
|
||||||
|
qs[jid].remove(event)
|
||||||
|
self.nb_unread -= 1
|
||||||
|
self.show_title()
|
||||||
|
# Is it the last event?
|
||||||
|
if not len(qs[jid]):
|
||||||
|
del qs[jid]
|
||||||
|
self.draw_contact(jid, account)
|
||||||
|
if self.plugin.systray_enabled:
|
||||||
|
self.plugin.systray.remove_jid(jid, account, 'normal')
|
||||||
|
|
||||||
def on_roster_treeview_row_activated(self, widget, path, col = 0):
|
def on_roster_treeview_row_activated(self, widget, path, col = 0):
|
||||||
'''When an iter is double clicked: open the chat window'''
|
'''When an iter is double clicked: open the first event window'''
|
||||||
model = self.tree.get_model()
|
model = self.tree.get_model()
|
||||||
iter = model.get_iter(path)
|
iter = model.get_iter(path)
|
||||||
account = model[iter][C_ACCOUNT].decode('utf-8')
|
account = model[iter][C_ACCOUNT].decode('utf-8')
|
||||||
|
@ -1808,6 +1827,14 @@ _('If "%s" accepts this request you will know his status.') %jid)
|
||||||
else:
|
else:
|
||||||
self.tree.expand_row(path, False)
|
self.tree.expand_row(path, False)
|
||||||
else:
|
else:
|
||||||
|
qs = gajim.awaiting_events[account]
|
||||||
|
if qs.has_key(jid):
|
||||||
|
first_ev = qs[jid][0]
|
||||||
|
typ = first_ev[0]
|
||||||
|
if typ == 'normal':
|
||||||
|
self.open_single_message_window_from_event(jid, account, first_ev)
|
||||||
|
return
|
||||||
|
|
||||||
if self.plugin.windows[account]['chats'].has_key(jid):
|
if self.plugin.windows[account]['chats'].has_key(jid):
|
||||||
self.plugin.windows[account]['chats'][jid].set_active_tab(jid)
|
self.plugin.windows[account]['chats'][jid].set_active_tab(jid)
|
||||||
elif gajim.contacts[account].has_key(jid):
|
elif gajim.contacts[account].has_key(jid):
|
||||||
|
|
|
@ -76,7 +76,8 @@ class Systray:
|
||||||
|
|
||||||
def add_jid(self, jid, account, typ):
|
def add_jid(self, jid, account, typ):
|
||||||
l = [account, jid, typ]
|
l = [account, jid, typ]
|
||||||
if not l in self.jids:
|
# We can keep several single message 'cause we open them one by one
|
||||||
|
if not l in self.jids or typ == 'normal':
|
||||||
self.jids.append(l)
|
self.jids.append(l)
|
||||||
self.set_img()
|
self.set_img()
|
||||||
|
|
||||||
|
@ -273,8 +274,15 @@ class Systray:
|
||||||
self.plugin.roster.new_chat(
|
self.plugin.roster.new_chat(
|
||||||
gajim.contacts[account][jid][0], account)
|
gajim.contacts[account][jid][0], account)
|
||||||
w = wins['chats'][jid]
|
w = wins['chats'][jid]
|
||||||
elif typ == 'single_chat':
|
elif typ == 'normal': # single message
|
||||||
pass
|
# Get the first single message event
|
||||||
|
q = gajim.awaiting_events[account][jid]
|
||||||
|
for ev in q:
|
||||||
|
if ev[0] == 'normal':
|
||||||
|
break
|
||||||
|
# Open the window
|
||||||
|
self.plugin.roster.open_single_message_window_from_event(jid,
|
||||||
|
account, ev)
|
||||||
elif typ == 'pm':
|
elif typ == 'pm':
|
||||||
if wins['chats'].has_key(jid):
|
if wins['chats'].has_key(jid):
|
||||||
w = wins['chats'][jid]
|
w = wins['chats'][jid]
|
||||||
|
|
|
@ -770,7 +770,7 @@ class TabbedChatWindow(chat.Chat):
|
||||||
events_to_keep = []
|
events_to_keep = []
|
||||||
for event in l:
|
for event in l:
|
||||||
typ = event[0]
|
typ = event[0]
|
||||||
if typ != 'message':
|
if typ != 'chat':
|
||||||
events_to_keep.append(event)
|
events_to_keep.append(event)
|
||||||
continue
|
continue
|
||||||
data = event[1]
|
data = event[1]
|
||||||
|
@ -868,7 +868,7 @@ class TabbedChatWindow(chat.Chat):
|
||||||
if gajim.awaiting_events[self.account].has_key(jid):
|
if gajim.awaiting_events[self.account].has_key(jid):
|
||||||
l = gajim.awaiting_events[self.account][jid]
|
l = gajim.awaiting_events[self.account][jid]
|
||||||
for event in l:
|
for event in l:
|
||||||
if event[0] == 'message':
|
if event[0] == 'chat':
|
||||||
pos += 1
|
pos += 1
|
||||||
|
|
||||||
now = time.time()
|
now = time.time()
|
||||||
|
|
Loading…
Reference in New Issue