groups initial commit
This commit is contained in:
parent
88786b0398
commit
acf75a6818
8 changed files with 81 additions and 17 deletions
|
@ -19,6 +19,7 @@ from contacts.profile import Profile
|
|||
from file_transfers.file_transfers_handler import FileTransfersHandler
|
||||
from contacts.contact_provider import ContactProvider
|
||||
from contacts.friend_factory import FriendFactory
|
||||
from contacts.group_factory import GroupFactory
|
||||
from contacts.contacts_manager import ContactsManager
|
||||
from av.calls_manager import CallsManager
|
||||
from history.database import Database
|
||||
|
@ -40,6 +41,7 @@ class App:
|
|||
self._tox = self._ms = self._init = self._main_loop = self._av_loop = None
|
||||
self._uri = self._toxes = self._tray = self._file_transfer_handler = self._contacts_provider = None
|
||||
self._friend_factory = self._calls_manager = self._contacts_manager = self._smiley_loader = self._tox_dns = None
|
||||
self._group_factory = None
|
||||
if uri is not None and uri.startswith('tox:'):
|
||||
self._uri = uri[4:]
|
||||
self._path = path_to_profile
|
||||
|
@ -300,7 +302,8 @@ class App:
|
|||
|
||||
friend_items_factory = FriendItemsFactory(self._settings, self._ms)
|
||||
self._friend_factory = FriendFactory(self._profile_manager, self._settings, self._tox, db, friend_items_factory)
|
||||
self._contacts_provider = ContactProvider(self._tox, self._friend_factory)
|
||||
self._group_factory = GroupFactory()
|
||||
self._contacts_provider = ContactProvider(self._tox, self._friend_factory, self._group_factory)
|
||||
profile = Profile(self._profile_manager, self._tox, self._ms, self._contacts_provider, self._reset)
|
||||
self._plugin_loader = PluginLoader(self._tox, self._toxes, profile, self._settings)
|
||||
history = None
|
||||
|
|
|
@ -3,9 +3,10 @@ import common.tox_save as tox_save
|
|||
|
||||
class ContactProvider(tox_save.ToxSave):
|
||||
|
||||
def __init__(self, tox, friend_factory):
|
||||
def __init__(self, tox, friend_factory, group_factory):
|
||||
super().__init__(tox)
|
||||
self._friend_factory = friend_factory
|
||||
self._group_factory = group_factory
|
||||
self._cache = {} # key - contact's public key, value - contact instance
|
||||
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
|
@ -37,13 +38,24 @@ class ContactProvider(tox_save.ToxSave):
|
|||
# -----------------------------------------------------------------------------------------------------------------
|
||||
|
||||
def get_all_groups(self):
|
||||
return []
|
||||
group_numbers = range(self._tox.group_get_number_groups)
|
||||
groups = map(lambda n: self.get_group_by_number(n), group_numbers)
|
||||
|
||||
def get_group_by_number(self):
|
||||
pass
|
||||
return list(groups)
|
||||
|
||||
def get_group_by_public_key(self):
|
||||
pass
|
||||
def get_group_by_number(self, group_number):
|
||||
public_key = self._tox.group_get_chat_id(group_number)
|
||||
|
||||
return self.get_group_by_public_key(public_key)
|
||||
|
||||
def get_group_by_public_key(self, public_key):
|
||||
group = self._get_contact_from_cache(public_key)
|
||||
if group is not None:
|
||||
return group
|
||||
group = self._group_factory.create_group_by_public_key(public_key)
|
||||
self._add_to_cache(public_key, group)
|
||||
|
||||
return group
|
||||
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
# All contacts
|
||||
|
@ -59,9 +71,9 @@ class ContactProvider(tox_save.ToxSave):
|
|||
def clear_cache(self):
|
||||
self._cache.clear()
|
||||
|
||||
def remove_friend_from_cache(self, friend_public_key):
|
||||
if friend_public_key in self._cache:
|
||||
del self._cache[friend_public_key]
|
||||
def remove_contact_from_cache(self, contact_public_key):
|
||||
if contact_public_key in self._cache:
|
||||
del self._cache[contact_public_key]
|
||||
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
# Private methods
|
||||
|
|
|
@ -298,6 +298,11 @@ class ContactsManager:
|
|||
self._contacts.append(friend)
|
||||
friend.reset_avatar()
|
||||
|
||||
def add_group(self, group_number):
|
||||
group = self._contact_provider.get_group_by_numner(group_number)
|
||||
self._contacts.append(group)
|
||||
group.reset_avatar()
|
||||
|
||||
def block_user(self, tox_id):
|
||||
"""
|
||||
Block user with specified tox id (or public key) - delete from friends list and ignore friend requests
|
||||
|
|
|
@ -24,8 +24,8 @@ class GroupChat(contact.Contact):
|
|||
super().set_name(title)
|
||||
|
||||
@staticmethod
|
||||
def get_default_avatar_name():
|
||||
return 'group.png'
|
||||
def _get_default_avatar_path():
|
||||
return util.join_path(util.get_images_directory(), 'group.png')
|
||||
|
||||
def remove_invalid_unsent_files(self):
|
||||
pass
|
||||
|
|
6
toxygen/contacts/group_factory.py
Normal file
6
toxygen/contacts/group_factory.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
|
||||
|
||||
class GroupFactory:
|
||||
|
||||
def create_group_by_public_key(self, public_key):
|
||||
pass
|
0
toxygen/groups/__init__.py
Normal file
0
toxygen/groups/__init__.py
Normal file
32
toxygen/groups/groups_service.py
Normal file
32
toxygen/groups/groups_service.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
import common.tox_save as tox_save
|
||||
|
||||
|
||||
class GroupsService(tox_save.ToxSave):
|
||||
|
||||
def __init__(self, tox, contacts_manager, contacts_provider):
|
||||
super().__init__(tox)
|
||||
self._contacts_manager = contacts_manager
|
||||
self._contacts_provider = contacts_provider
|
||||
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
# Groups creation
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
|
||||
def create_new_gc(self, name, privacy_state):
|
||||
group_number = self._tox.group_new(privacy_state, name)
|
||||
self._add_new_group_by_number(group_number)
|
||||
|
||||
def join_gc_by_id(self, chat_id, password):
|
||||
group_number = self._tox.group_join(chat_id, password)
|
||||
self._add_new_group_by_number(group_number)
|
||||
|
||||
def join_gc_via_invite(self, invite_data, friend_number, password):
|
||||
group_number = self._tox.group_invite_accept(invite_data, friend_number, password)
|
||||
self._add_new_group_by_number(group_number)
|
||||
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
# Private methods
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
|
||||
def _add_new_group_by_number(self, group_number):
|
||||
self._contacts_manager.add_group(group_number)
|
|
@ -1,4 +1,3 @@
|
|||
from contacts.profile import *
|
||||
from ui.contact_items import *
|
||||
from ui.widgets import MultilineEdit, ComboBox
|
||||
from ui.main_screen_widgets import *
|
||||
|
@ -50,6 +49,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||
|
||||
self.menuProfile = QtWidgets.QMenu(self.menubar)
|
||||
self.menuProfile.setObjectName("menuProfile")
|
||||
self.menuGC = QtWidgets.QMenu(self.menubar)
|
||||
self.menuSettings = QtWidgets.QMenu(self.menubar)
|
||||
self.menuSettings.setObjectName("menuSettings")
|
||||
self.menuPlugins = QtWidgets.QMenu(self.menubar)
|
||||
|
@ -58,7 +58,6 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||
self.menuAbout.setObjectName("menuAbout")
|
||||
|
||||
self.actionAdd_friend = QtWidgets.QAction(window)
|
||||
self.actionAdd_gc = QtWidgets.QAction(window)
|
||||
self.actionAdd_friend.setObjectName("actionAdd_friend")
|
||||
self.actionprofilesettings = QtWidgets.QAction(window)
|
||||
self.actionprofilesettings.setObjectName("actionprofilesettings")
|
||||
|
@ -81,10 +80,14 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||
self.importPlugin = QtWidgets.QAction(window)
|
||||
self.reloadPlugins = QtWidgets.QAction(window)
|
||||
self.lockApp = QtWidgets.QAction(window)
|
||||
self.createGC = QtWidgets.QAction(window)
|
||||
self.joinGC = QtWidgets.QAction(window)
|
||||
|
||||
self.menuProfile.addAction(self.actionAdd_friend)
|
||||
self.menuProfile.addAction(self.actionAdd_gc)
|
||||
self.menuProfile.addAction(self.actionSettings)
|
||||
self.menuProfile.addAction(self.lockApp)
|
||||
self.menuGC.addAction(self.createGC)
|
||||
self.menuGC.addAction(self.joinGC)
|
||||
self.menuSettings.addAction(self.actionPrivacy_settings)
|
||||
self.menuSettings.addAction(self.actionInterface_settings)
|
||||
self.menuSettings.addAction(self.actionNotifications)
|
||||
|
@ -98,6 +101,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||
self.menuAbout.addAction(self.actionAbout_program)
|
||||
|
||||
self.menubar.addAction(self.menuProfile.menuAction())
|
||||
self.menubar.addAction(self.menuGC.menuAction())
|
||||
self.menubar.addAction(self.menuSettings.menuAction())
|
||||
self.menubar.addAction(self.menuPlugins.menuAction())
|
||||
self.menubar.addAction(self.menuAbout.menuAction())
|
||||
|
@ -105,7 +109,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||
self.actionAbout_program.triggered.connect(self.about_program)
|
||||
self.actionNetwork.triggered.connect(self.network_settings)
|
||||
self.actionAdd_friend.triggered.connect(self.add_contact_triggered)
|
||||
self.actionAdd_gc.triggered.connect(self.create_gc)
|
||||
self.createGC.triggered.connect(self.create_gc)
|
||||
self.actionSettings.triggered.connect(self.profile_settings)
|
||||
self.actionPrivacy_settings.triggered.connect(self.privacy_settings)
|
||||
self.actionInterface_settings.triggered.connect(self.interface_settings)
|
||||
|
@ -130,12 +134,14 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||
def retranslateUi(self):
|
||||
self.lockApp.setText(util_ui.tr("Lock"))
|
||||
self.menuPlugins.setTitle(util_ui.tr("Plugins"))
|
||||
self.menuGC.setTitle(util_ui.tr("Group chats"))
|
||||
self.pluginData.setText(util_ui.tr("List of plugins"))
|
||||
self.menuProfile.setTitle(util_ui.tr("Profile"))
|
||||
self.menuSettings.setTitle(util_ui.tr("Settings"))
|
||||
self.menuAbout.setTitle(util_ui.tr("About"))
|
||||
self.actionAdd_friend.setText(util_ui.tr("Add contact"))
|
||||
self.actionAdd_gc.setText(util_ui.tr("Create group chat"))
|
||||
self.createGC.setText(util_ui.tr("Create group chat"))
|
||||
self.joinGC.setText(util_ui.tr("Join group chat"))
|
||||
self.actionprofilesettings.setText(util_ui.tr("Profile"))
|
||||
self.actionPrivacy_settings.setText(util_ui.tr("Privacy"))
|
||||
self.actionInterface_settings.setText(util_ui.tr("Interface"))
|
||||
|
|
Loading…
Reference in a new issue