Commit da94f8ab authored by Tijmen de Mes's avatar Tijmen de Mes

Added option to remove messages

parent e320af39
...@@ -376,6 +376,7 @@ class ChatWebPage(QWebPage): ...@@ -376,6 +376,7 @@ class ChatWebPage(QWebPage):
class ChatWebView(QWebView): class ChatWebView(QWebView):
sizeChanged = pyqtSignal() sizeChanged = pyqtSignal()
messageShouldRemove = pyqtSignal(str)
def __init__(self, parent=None): def __init__(self, parent=None):
super(ChatWebView, self).__init__(parent) super(ChatWebView, self).__init__(parent)
...@@ -388,6 +389,25 @@ class ChatWebView(QWebView): ...@@ -388,6 +389,25 @@ class ChatWebView(QWebView):
def contextMenuEvent(self, event): def contextMenuEvent(self, event):
menu = self.page().createStandardContextMenu() menu = self.page().createStandardContextMenu()
hit = self.page().currentFrame().hitTestContent(event.pos())
self.id = None
if hit.element().hasAttribute('id'):
id = hit.element().attribute('id')
else:
id = hit.element().parent().attribute('id')
if not id:
id = hit.element().parent().parent().attribute('id')
if id.startswith('text-'):
self.id = id[5:]
action = menu.addAction('Remove Message')
action.triggered.connect(self._SH_RemoveClicked)
if id.startswith('message-'):
self.id = id[8:]
action = menu.addAction('Remove Message')
action.triggered.connect(self._SH_RemoveClicked)
if any(action.isVisible() and not action.isSeparator() for action in menu.actions()): if any(action.isVisible() and not action.isSeparator() for action in menu.actions()):
menu.exec_(event.globalPos()) menu.exec_(event.globalPos())
...@@ -402,6 +422,9 @@ class ChatWebView(QWebView): ...@@ -402,6 +422,9 @@ class ChatWebView(QWebView):
super(ChatWebView, self).resizeEvent(event) super(ChatWebView, self).resizeEvent(event)
self.sizeChanged.emit() self.sizeChanged.emit()
def _SH_RemoveClicked(self):
self.messageShouldRemove.emit(self.id)
ui_class, base_class = uic.loadUiType(Resources.get('chat_input_lock.ui')) ui_class, base_class = uic.loadUiType(Resources.get('chat_input_lock.ui'))
...@@ -687,6 +710,8 @@ class ChatWidget(base_class, ui_class): ...@@ -687,6 +710,8 @@ class ChatWidget(base_class, ui_class):
self.chat_input.lockReleased.connect(self._SH_ChatInputLockReleased) self.chat_input.lockReleased.connect(self._SH_ChatInputLockReleased)
self.chat_view.sizeChanged.connect(self._SH_ChatViewSizeChanged) self.chat_view.sizeChanged.connect(self._SH_ChatViewSizeChanged)
self.chat_view.page().mainFrame().contentsSizeChanged.connect(self._SH_ChatViewFrameContentsSizeChanged) self.chat_view.page().mainFrame().contentsSizeChanged.connect(self._SH_ChatViewFrameContentsSizeChanged)
self.chat_view.messageShouldRemove.connect(self._SH_MessageShouldRemove)
self.composing_timer.timeout.connect(self._SH_ComposingTimerTimeout) self.composing_timer.timeout.connect(self._SH_ComposingTimerTimeout)
self.otr_timer.timeout.connect(self._SH_OTRTimerTimeout) self.otr_timer.timeout.connect(self._SH_OTRTimerTimeout)
...@@ -907,6 +932,10 @@ class ChatWidget(base_class, ui_class): ...@@ -907,6 +932,10 @@ class ChatWidget(base_class, ui_class):
self.chat_input.keyPressEvent(QKeyEvent(QEvent.KeyPress, Qt.Key_Return, Qt.NoModifier, text='\r')) self.chat_input.keyPressEvent(QKeyEvent(QEvent.KeyPress, Qt.Key_Return, Qt.NoModifier, text='\r'))
self.chat_input.setHtml(user_text) self.chat_input.setHtml(user_text)
def _SH_MessageShouldRemove(self, id):
blink_session = self.session.blink_session
MessageManager().send_remove_message(blink_session, id)
def _SH_ChatViewSizeChanged(self): def _SH_ChatViewSizeChanged(self):
# print("chat view size changed") # print("chat view size changed")
self._align_chat(scroll=True) self._align_chat(scroll=True)
......
...@@ -1271,6 +1271,10 @@ class MessageManager(object, metaclass=Singleton): ...@@ -1271,6 +1271,10 @@ class MessageManager(object, metaclass=Singleton):
outgoing_message = OutgoingMessage(session.account, session.contact, content, IsComposingDocument.content_type, session=session) outgoing_message = OutgoingMessage(session.account, session.contact, content, IsComposingDocument.content_type, session=session)
self._send_message(outgoing_message) self._send_message(outgoing_message)
def send_remove_message(self, session, id, account=None):
outgoing_message = OutgoingMessage(session.account, session.contact, id, 'application/sylk-api-message-remove', session=session)
self._send_message(outgoing_message)
def send_imdn_message(self, session, id, timestamp, state, account=None): def send_imdn_message(self, session, id, timestamp, state, account=None):
if account is None and not session.account.sms.use_cpim or not session.account.sms.enable_imdn: if account is None and not session.account.sms.use_cpim or not session.account.sms.enable_imdn:
return return
......
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