history improvements, ui for creation finished, some updates
This commit is contained in:
parent
3aba7dffd2
commit
3ad7d20827
@ -1,11 +1,12 @@
|
||||
import contact
|
||||
|
||||
|
||||
class Groupchat(contact.Contact):
|
||||
class GroupChat(contact.Contact):
|
||||
|
||||
def __init__(self, group_id, *args):
|
||||
def __init__(self, group_id, tox, *args):
|
||||
super().__init__(*args)
|
||||
self._id = group_id
|
||||
self._tox = tox
|
||||
|
||||
def load_avatar(self, default_path='group.png'):
|
||||
super().load_avatar(default_path)
|
||||
|
@ -87,9 +87,18 @@ class Contact(basecontact.BaseContact):
|
||||
if hasattr(self, '_message_getter'):
|
||||
del self._message_getter
|
||||
# don't delete data about active file transfer
|
||||
self._corr = list(filter(lambda x: x.get_type() in (2, 3) and x.get_status() >= 2, self._corr))
|
||||
self._corr = list(filter(lambda x: x.get_type() in (2, 3) and (x.get_status() >= 2 or x.get_status() is None),
|
||||
self._corr))
|
||||
self._unsaved_messages = 0
|
||||
|
||||
def delete_old_messages(self):
|
||||
old = filter(lambda x: x.get_type() in (2, 3) and (x.get_status() >= 2 or x.get_status() is None),
|
||||
self._corr[:-SAVE_MESSAGES])
|
||||
old = list(old)
|
||||
l = max(len(self._corr) - SAVE_MESSAGES, 0) - len(old)
|
||||
self._unsaved_messages -= l
|
||||
self._corr = old + self._corr[-SAVE_MESSAGES:]
|
||||
|
||||
def get_curr_text(self):
|
||||
return self._curr_text
|
||||
|
||||
|
@ -8,6 +8,8 @@ from toxencryptsave import ToxEncryptSave
|
||||
|
||||
PAGE_SIZE = 42
|
||||
|
||||
SAVE_MESSAGES = 150
|
||||
|
||||
MESSAGE_OWNER = {
|
||||
'ME': 0,
|
||||
'FRIEND': 1,
|
||||
|
@ -11,36 +11,54 @@ import toxencryptsave
|
||||
import plugin_support
|
||||
|
||||
|
||||
class AddGroupchat(QtGui.QWidget):
|
||||
class AddGroupchat(CenteredWidget):
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.initUI()
|
||||
self.retranslateUi()
|
||||
self.center()
|
||||
|
||||
def initUI(self):
|
||||
self.setObjectName('AddGC')
|
||||
self.resize(570, 320)
|
||||
self.resize(570, 240)
|
||||
self.setMaximumSize(QtCore.QSize(570, 240))
|
||||
self.setMinimumSize(QtCore.QSize(570, 240))
|
||||
self.label = QtGui.QLabel(self)
|
||||
self.label.setGeometry(QtCore.QRect(50, 20, 470, 20))
|
||||
self.createGCButton = QtGui.QPushButton(self)
|
||||
self.createGCButton.setGeometry(QtCore.QRect(50, 280, 470, 30))
|
||||
self.createGCButton.setGeometry(QtCore.QRect(50, 190, 470, 30))
|
||||
self.name = LineEdit(self)
|
||||
self.name.setGeometry(QtCore.QRect(50, 40, 470, 27))
|
||||
self.privacy_type = QtGui.QLabel(self)
|
||||
self.privacy_type.setGeometry(QtCore.QRect(50, 70, 470, 20))
|
||||
self.privacy_combobox = QtGui.QComboBox(self)
|
||||
self.privacy_combobox.setGeometry(QtCore.QRect(50, 100, 470, 30))
|
||||
self.privacy_combobox.setGeometry(QtCore.QRect(50, 90, 470, 30))
|
||||
self.pass_label = QtGui.QLabel(self)
|
||||
self.pass_label.setGeometry(QtCore.QRect(50, 130, 470, 20))
|
||||
self.password = LineEdit(self)
|
||||
self.password.setGeometry(QtCore.QRect(50, 150, 470, 27))
|
||||
|
||||
self.createGCButton.clicked.connect(self.button_click)
|
||||
QtCore.QMetaObject.connectSlotsByName(self)
|
||||
|
||||
def retranslateUi(self):
|
||||
self.setWindowTitle(QtGui.QApplication.translate('AddGC', "Create groupchat", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.setWindowTitle(QtGui.QApplication.translate('AddGC', "Create group chat", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.createGCButton.setText(QtGui.QApplication.translate("AddGC", "Create", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.label.setText(QtGui.QApplication.translate('AddGC', "Name:", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.privacy_type.setText(QtGui.QApplication.translate('AddGC', "Privacy type:", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.privacy_combobox.addItem(QtGui.QApplication.translate('AddGC', "Public", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.privacy_combobox.addItem(QtGui.QApplication.translate('AddGC', "Private", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.name.setPlaceholderText(QtGui.QApplication.translate('AddGC', "Not empty group name", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.password.setPlaceholderText(QtGui.QApplication.translate('AddGC', "Optional password", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.pass_label.setText(QtGui.QApplication.translate('AddGC', "Password:", None, QtGui.QApplication.UnicodeUTF8))
|
||||
|
||||
def button_click(self):
|
||||
if self.name.text():
|
||||
Profile.get_instance().create_gc(self.name.text(),
|
||||
self.privacy_combobox.currentIndex() == 0,
|
||||
self.password.text())
|
||||
self.close()
|
||||
|
||||
|
||||
class AddContact(CenteredWidget):
|
||||
|
@ -83,6 +83,7 @@ class TransferMessage(Message):
|
||||
|
||||
|
||||
class UnsentFile(Message):
|
||||
|
||||
def __init__(self, path, data, time):
|
||||
super(UnsentFile, self).__init__(MESSAGE_TYPE['FILE_TRANSFER'], 0, time)
|
||||
self._data, self._path = data, path
|
||||
|
@ -16,6 +16,7 @@ import calls
|
||||
import avwidgets
|
||||
import plugin_support
|
||||
import basecontact
|
||||
from groupchat import *
|
||||
|
||||
|
||||
class Profile(basecontact.BaseContact, Singleton):
|
||||
@ -175,7 +176,8 @@ class Profile(basecontact.BaseContact, Singleton):
|
||||
pass
|
||||
self._active_friend_or_gc = value
|
||||
friend_or_gc = self._friends_and_gc[value]
|
||||
self._friends_and_gc[value].reset_messages()
|
||||
friend_or_gc.reset_messages()
|
||||
friend_or_gc.delete_old_messages()
|
||||
self._screen.messageEdit.setPlainText(friend_or_gc.curr_text)
|
||||
self._messages.clear()
|
||||
friend.load_corr()
|
||||
@ -1195,6 +1197,17 @@ class Profile(basecontact.BaseContact, Singleton):
|
||||
self.create_message_item(text, time.time(), '', MESSAGE_TYPE['INFO_MESSAGE'])
|
||||
self._messages.scrollToBottom()
|
||||
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
# Group chats support
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
|
||||
def create_gc(self, name, is_public, password):
|
||||
privacy_state = TOX_GROUP_PRIVACY_STATE['TOX_GROUP_PRIVACY_STATE_PUBLIC'] if is_public else TOX_GROUP_PRIVACY_STATE['TOX_GROUP_PRIVACY_STATE_PRIVATE']
|
||||
num = self._tox.group_new(privacy_state, bytes(name, 'utf-8'))
|
||||
if password:
|
||||
self._tox.group_founder_set_password(num, password)
|
||||
# self._friends_and_gc.append(Groupchat(num, self._tox, ))
|
||||
|
||||
|
||||
def tox_factory(data=None, settings=None):
|
||||
"""
|
||||
|
@ -1545,12 +1545,14 @@ class Tox:
|
||||
Otherwise a friend invite will be required to join the group.
|
||||
:param group_name: The name of the group. The name must be non-NULL.
|
||||
|
||||
:return groupnumber on success, UINT32_MAX on failure.
|
||||
:return group number on success, UINT32_MAX on failure.
|
||||
"""
|
||||
|
||||
error = c_int()
|
||||
result = Tox.libtoxcore.tox_group_new(self._tox_pointer, privacy_state, group_name,
|
||||
len(group_name), byref(error))
|
||||
func = Tox.libtoxcore.tox_group_new
|
||||
func.restype = c_uint32
|
||||
result = func(self._tox_pointer, privacy_state, group_name,
|
||||
len(group_name), byref(error))
|
||||
return result
|
||||
|
||||
def group_join(self, chat_id, password):
|
||||
|
Loading…
Reference in New Issue
Block a user