minimal working ngc version - sending messages, invites, char creation

This commit is contained in:
ingvar1995 2018-05-19 19:27:27 +03:00
parent ef4a1b18fd
commit a935d602f8
6 changed files with 43 additions and 17 deletions

File diff suppressed because one or more lines are too long

View File

@ -50,6 +50,9 @@ class ContactsManager:
return self.get_curr_contact().number == group_number
def is_contact_active(self, contact):
return self._contacts[self._active_contact].tox_id == contact.tox_id
# -----------------------------------------------------------------------------------------------------------------
# Work with active friend
# -----------------------------------------------------------------------------------------------------------------

View File

@ -39,7 +39,7 @@ class GroupChat(contact.Contact):
self._tox.group_peer_get_public_key(self._number, peer_id))
self._peers.append(peer)
def get_peer(self, peer_id):
def get_peer_by_id(self, peer_id):
peers = list(filter(lambda p: p.id == peer_id, self._peers))
return peers[0]

View File

@ -14,7 +14,7 @@ class GroupsService(tox_save.ToxSave):
# -----------------------------------------------------------------------------------------------------------------
def create_new_gc(self, name, privacy_state):
group_number = self._tox.group_new(privacy_state, name)
group_number = self._tox.group_new(privacy_state, name.encode('utf-8'))
self._add_new_group_by_number(group_number)
def join_gc_by_id(self, chat_id, password):
@ -48,6 +48,14 @@ class GroupsService(tox_save.ToxSave):
if util_ui.question(text.format(friend.name), util_ui.tr('Group invite')):
self.join_gc_via_invite(invite_data, friend_number, None)
# -----------------------------------------------------------------------------------------------------------------
# Group info methods
# -----------------------------------------------------------------------------------------------------------------
def update_group_info(self, group):
group.name = self._tox.group_get_name(group.number).encode('utf-8')
group.status_message = self._tox.group_get_topic(group.number).encode('utf-8')
# -----------------------------------------------------------------------------------------------------------------
# Private methods
# -----------------------------------------------------------------------------------------------------------------

View File

@ -41,16 +41,7 @@ class Messenger(tox_save.ToxSave):
t = util.get_unix_time()
friend = self._get_friend_by_number(friend_number)
text_message = TextMessage(message, MessageAuthor(friend.name, MESSAGE_AUTHOR['FRIEND']), t, message_type)
if self._contacts_manager.is_friend_active(friend_number): # add message to list
self._create_message_item(text_message)
self._screen.messages.scrollToBottom()
self._contacts_manager.get_curr_contact().append_message(text_message)
else:
friend.inc_messages()
friend.append_message(text_message)
if not friend.visibility:
self._contacts_manager.update_filtration()
self._add_message(text_message, friend)
def send_message(self):
text = self._screen.messageEdit.toPlainText()
@ -135,6 +126,18 @@ class Messenger(tox_save.ToxSave):
self._screen.messageEdit.clear()
self._screen.messages.scrollToBottom()
def new_group_message(self, group_number, message_type, message, peer_id):
"""
Current user gets new message
:param message_type: message type - plain text or action message (/me)
:param message: text of message
"""
t = util.get_unix_time()
group = self._get_group_by_number(group_number)
peer = group.get_peer_by_id(peer_id)
text_message = TextMessage(message, MessageAuthor(peer.name, MESSAGE_AUTHOR['GC_PEER']), t, message_type)
self._add_message(text_message, group)
# -----------------------------------------------------------------------------------------------------------------
# Message receipts
# -----------------------------------------------------------------------------------------------------------------
@ -229,3 +232,14 @@ class Messenger(tox_save.ToxSave):
def _create_info_message_item(self, message):
self._items_factory.create_message_item(message)
self._screen.messages.scrollToBottom()
def _add_message(self, text_message, contact):
if self._contacts_manager.is_contact_active(contact): # add message to list
self._create_message_item(text_message)
self._screen.messages.scrollToBottom()
self._contacts_manager.get_curr_contact().append_message(text_message)
else:
contact.inc_messages()
contact.append_message(text_message)
if not contact.visibility:
self._contacts_manager.update_filtration()

View File

@ -388,10 +388,11 @@ def group_invite(groups_service):
return wrapped
def group_self_join(contacts_provider):
def group_self_join(contacts_provider, groups_service):
def wrapped(tox, group_number, user_data):
group = contacts_provider.get_group_by_number(group_number)
invoke_in_main_thread(group.set_status, TOX_USER_STATUS['NONE'])
invoke_in_main_thread(groups_service.update_group_info, group)
return wrapped
@ -407,7 +408,7 @@ def group_peer_join(contacts_provider):
def group_peer_name(contacts_provider):
def wrapped(tox, group_number, peer_id, name, length, user_data):
group = contacts_provider.get_group_by_number(group_number)
peer = group.get_peer(peer_id)
peer = group.get_peer_by_id(peer_id)
peer.name = str(name[:length])
return wrapped
@ -416,7 +417,7 @@ def group_peer_name(contacts_provider):
def group_peer_status(contacts_provider):
def wrapped(tox, group_number, peer_id, peer_status, user_data):
group = contacts_provider.get_group_by_number(group_number)
peer = group.get_peer(peer_id)
peer = group.get_peer_by_id(peer_id)
peer.status = peer_status
return wrapped
@ -479,7 +480,7 @@ def init_callbacks(tox, profile, settings, plugin_loader, contacts_manager,
# gc callbacks
tox.callback_group_message(group_message(main_window, tray, tox, messenger, settings, profile), 0)
tox.callback_group_invite(group_invite(groups_service), 0)
tox.callback_group_self_join(group_self_join(contacts_provider), 0)
tox.callback_group_self_join(group_self_join(contacts_provider, groups_service), 0)
tox.callback_group_peer_join(group_peer_join(contacts_provider), 0)
tox.callback_group_peer_name(group_peer_name(contacts_provider), 0)
tox.callback_group_peer_status(group_peer_status(contacts_provider), 0)