Commit 31fac3e1 authored by Tijmen de Mes's avatar Tijmen de Mes

Added menu option to show last messages/chat

parent 1dfbed51
...@@ -1597,6 +1597,7 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin): ...@@ -1597,6 +1597,7 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin):
notification_center.add_observer(self, name='BlinkMessageDidFail') notification_center.add_observer(self, name='BlinkMessageDidFail')
notification_center.add_observer(self, name='BlinkMessageHistoryLoadDidSucceed') notification_center.add_observer(self, name='BlinkMessageHistoryLoadDidSucceed')
notification_center.add_observer(self, name='BlinkMessageHistoryLoadDidFail') notification_center.add_observer(self, name='BlinkMessageHistoryLoadDidFail')
notification_center.add_observer(self, name='BlinkMessageHistoryLastContactsDidSucceed')
# self.splitter.splitterMoved.connect(self._SH_SplitterMoved) # check this and decide on what size to have in the window (see Notes) -Dan # self.splitter.splitterMoved.connect(self._SH_SplitterMoved) # check this and decide on what size to have in the window (see Notes) -Dan
...@@ -2045,6 +2046,13 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin): ...@@ -2045,6 +2046,13 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin):
self.raise_() self.raise_()
self.activateWindow() self.activateWindow()
def show_with_messages(self):
super(ChatWindow, self).show()
self.raise_()
self.activateWindow()
history = HistoryManager()
history.get_last_contacts()
def closeEvent(self, event): def closeEvent(self, event):
QSettings().setValue("chat_window/geometry", self.saveGeometry()) QSettings().setValue("chat_window/geometry", self.saveGeometry())
super(ChatWindow, self).closeEvent(event) super(ChatWindow, self).closeEvent(event)
...@@ -2453,6 +2461,12 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin): ...@@ -2453,6 +2461,12 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin):
session.chat_widget.history_loaded = True session.chat_widget.history_loaded = True
session.chat_widget.show_loading_screen(False) session.chat_widget.show_loading_screen(False)
def _NH_BlinkMessageHistoryLastContactsDidSucceed(self, notification):
contacts = notification.data.contacts
message_manager = MessageManager()
for contact in contacts[::-1]:
message_manager.create_message_session(contact)
def _NH_ChatStreamGotMessage(self, notification): def _NH_ChatStreamGotMessage(self, notification):
blink_session = notification.sender.blink_session blink_session = notification.sender.blink_session
session = blink_session.items.chat session = blink_session.items.chat
......
...@@ -73,6 +73,9 @@ class HistoryManager(object, metaclass=Singleton): ...@@ -73,6 +73,9 @@ class HistoryManager(object, metaclass=Singleton):
def load(self, uri, session): def load(self, uri, session):
return self.message_history.load(uri, session) return self.message_history.load(uri, session)
def get_last_contacts(self, number=5):
return self.message_history.get_last_contacts(number)
@run_in_gui_thread @run_in_gui_thread
def handle_notification(self, notification): def handle_notification(self, notification):
handler = getattr(self, '_NH_%s' % notification.name, Null) handler = getattr(self, '_NH_%s' % notification.name, Null)
...@@ -362,7 +365,22 @@ class MessageHistory(object, metaclass=Singleton): ...@@ -362,7 +365,22 @@ class MessageHistory(object, metaclass=Singleton):
notification_center.post_notification('BlinkMessageHistoryLoadDidFail', sender=session, data=NotificationData(uri=uri)) notification_center.post_notification('BlinkMessageHistoryLoadDidFail', sender=session, data=NotificationData(uri=uri))
return return
# print(f"-- Messages loaded: {len(list(result))}") # print(f"-- Messages loaded: {len(list(result))}")
notification_center.post_notification('BlinkMessageHistoryLoadDidSucceed', sender=session, data=NotificationData(messages=list(result),uri=uri)) notification_center.post_notification('BlinkMessageHistoryLoadDidSucceed', sender=session, data=NotificationData(messages=list(result), uri=uri))
@run_in_thread('db')
def get_last_contacts(self, number=5):
# print(f'-- Getting last {number} contacts wtih messages')
query = f'select distinct(remote_uri) from messages order by id desc limit {Message.sqlrepr(number)}'
notification_center = NotificationCenter()
try:
result = self.db.queryAll(query)
except Exception as e:
return
# print(f"-- Contacts fetched: {len(list(result))}")
result = [' '.join(item) for item in result]
notification_center.post_notification('BlinkMessageHistoryLastContactsDidSucceed', data=NotificationData(contacts=list(result)))
@run_in_thread('db') @run_in_thread('db')
def remove(self, account): def remove(self, account):
......
...@@ -204,6 +204,7 @@ class MainWindow(base_class, ui_class): ...@@ -204,6 +204,7 @@ class MainWindow(base_class, ui_class):
self.history_on_server_action.triggered.connect(self._AH_HistoryOnServer) self.history_on_server_action.triggered.connect(self._AH_HistoryOnServer)
self.google_contacts_action.triggered.connect(self._AH_GoogleContactsActionTriggered) self.google_contacts_action.triggered.connect(self._AH_GoogleContactsActionTriggered)
self.show_last_messages_action.triggered.connect(self._AH_ShowLastMessagesActionTriggered) # This will load messages from 5 last contacts used in messages/chat
# Window menu actions # Window menu actions
self.chat_window_action.triggered.connect(self._AH_ChatWindowActionTriggered) self.chat_window_action.triggered.connect(self._AH_ChatWindowActionTriggered)
self.transfers_window_action.triggered.connect(self._AH_TransfersWindowActionTriggered) self.transfers_window_action.triggered.connect(self._AH_TransfersWindowActionTriggered)
...@@ -430,6 +431,10 @@ class MainWindow(base_class, ui_class): ...@@ -430,6 +431,10 @@ class MainWindow(base_class, ui_class):
blink = QApplication.instance() blink = QApplication.instance()
blink.chat_window.show() blink.chat_window.show()
def _AH_ShowLastMessagesActionTriggered(self, checked):
blink = QApplication.instance()
blink.chat_window.show_with_messages()
def _AH_TransfersWindowActionTriggered(self, checked): def _AH_TransfersWindowActionTriggered(self, checked):
self.filetransfer_window.show() self.filetransfer_window.show()
......
...@@ -300,3 +300,14 @@ class MessageManager(object, metaclass=Singleton): ...@@ -300,3 +300,14 @@ class MessageManager(object, metaclass=Singleton):
outgoing_message = OutgoingMessage(account, contact, content, content_type, recipients, courtesy_recipients, subject, timestamp, required, additional_headers, id) outgoing_message = OutgoingMessage(account, contact, content, content_type, recipients, courtesy_recipients, subject, timestamp, required, additional_headers, id)
outgoing_message.send(blink_session) outgoing_message.send(blink_session)
def create_message_session(self, uri):
from blink.contacts import URIUtils
contact, contact_uri = URIUtils.find_contact(uri)
session_manager = SessionManager()
account = AccountManager().default_account
try:
next(session for session in self.sessions if session.reusable and session.contact.settings is contact.settings)
except StopIteration:
session_manager.create_session(contact, contact_uri, [StreamDescription('messages')], account=account, connect=False)
...@@ -1131,6 +1131,7 @@ padding: 2px;</string> ...@@ -1131,6 +1131,7 @@ padding: 2px;</string>
<string>&amp;Chat</string> <string>&amp;Chat</string>
</property> </property>
<addaction name="join_conference_action"/> <addaction name="join_conference_action"/>
<addaction name="show_last_messages_action"/>
<addaction name="auto_accept_chat_action"/> <addaction name="auto_accept_chat_action"/>
<addaction name="received_messages_sound_action"/> <addaction name="received_messages_sound_action"/>
</widget> </widget>
...@@ -1444,6 +1445,17 @@ padding: 2px;</string> ...@@ -1444,6 +1445,17 @@ padding: 2px;</string>
<string>&amp;Auto-answer</string> <string>&amp;Auto-answer</string>
</property> </property>
</action> </action>
<action name="show_last_messages_action">
<property name="text">
<string>&amp;Show last messages/chats</string>
</property>
<property name="shortcut">
<string>Ctrl+O</string>
</property>
<property name="shortcutContext">
<enum>Qt::ApplicationShortcut</enum>
</property>
</action>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment