Skip to content

Commit

Permalink
VENOM-302: Generify Contacts and Conversation
Browse files Browse the repository at this point in the history
* Remove Unsafe GenericListModel
  • Loading branch information
naxuroqa committed Apr 8, 2018
1 parent 9337ce5 commit 342090b
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 376 deletions.
78 changes: 0 additions & 78 deletions src/core/Contacts.vala

This file was deleted.

79 changes: 0 additions & 79 deletions src/core/Conversation.vala

This file was deleted.

45 changes: 0 additions & 45 deletions src/core/GenericListModel.vala

This file was deleted.

3 changes: 0 additions & 3 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ venom_source = files(
'Main.vala',
'core/Application.vala',
'core/Contact.vala',
'core/Contacts.vala',
'core/Conversation.vala',
'core/FileTransfer.vala',
'core/GenericListModel.vala',
'core/Interfaces.vala',
'core/Logger.vala',
'core/Message.vala',
Expand Down
18 changes: 10 additions & 8 deletions src/tox/ToxAdapterConferenceListener.vala
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ namespace Venom {
public class ToxAdapterConferenceListenerImpl : ToxAdapterConferenceListener, ConferenceWidgetListener, ConferenceInfoWidgetListener, CreateGroupchatWidgetListener, GLib.Object {
private unowned ToxSession session;
private ILogger logger;
private Contacts contacts;
private ObservableList<IContact> contacts;
private NotificationListener notification_listener;
private GLib.HashTable<IContact, Conversation> conversations;
private GLib.HashTable<IContact, ObservableList<IMessage>> conversations;

private GLib.HashTable<uint32, IContact> conferences;

public ToxAdapterConferenceListenerImpl(ILogger logger, Contacts contacts, GLib.HashTable<IContact, Conversation> conversations, NotificationListener notification_listener) {
public ToxAdapterConferenceListenerImpl(ILogger logger, ObservableList<IContact> contacts, GLib.HashTable<IContact, ObservableList<IMessage>> conversations, NotificationListener notification_listener) {
logger.d("ToxAdapterConferenceListenerImpl created.");
this.logger = logger;
this.contacts = contacts;
Expand Down Expand Up @@ -70,15 +70,17 @@ namespace Venom {
public virtual void on_conference_new(uint32 conference_number, string title) {
logger.d("on_conference_new");
var contact = new GroupchatContact(conference_number, title);
contacts.add_contact(this, contact);
contacts.append(contact);
conferences.@set(conference_number, contact);
conversations.@set(contact, new ConversationImpl(contact));
var conversation = new ObservableList<IMessage>();
conversation.set_list(new GLib.List<IMessage>());
conversations.@set(contact, conversation);
}

public virtual void on_conference_deleted(uint32 conference_number) {
logger.d("on_conference_deleted");
var contact = conferences.@get(conference_number);
contacts.remove_contact(this, contact);
contacts.remove(contact);
conversations.remove(contact);
conferences.remove(conference_number);
}
Expand Down Expand Up @@ -119,7 +121,7 @@ namespace Venom {
var conversation = conversations.@get(contact);
var msg = new GroupMessage.incoming(contact, peer_number, message);
notification_listener.on_unread_message(msg);
conversation.add_message(this, msg);
conversation.append(msg);
}

public virtual void on_conference_message_sent(uint32 conference_number, string message) {
Expand All @@ -128,7 +130,7 @@ namespace Venom {
var conversation = conversations.@get(contact);
var msg = new GroupMessage.outgoing(contact, message);
msg.received = true;
conversation.add_message(this, msg);
conversation.append(msg);
}
}
}
24 changes: 13 additions & 11 deletions src/tox/ToxAdapterFriendListener.vala
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ namespace Venom {
public class ToxAdapterFriendListenerImpl : ToxAdapterFriendListener, AddContactWidgetListener, ConversationWidgetListener, FriendInfoWidgetListener, FriendRequestWidgetListener, GLib.Object {
private unowned ToxSession session;
private ILogger logger;
private Contacts contacts;
private ObservableList<IContact> contacts;
private NotificationListener notification_listener;
private GLib.HashTable<IContact, Conversation> conversations;
private GLib.HashTable<IContact, ObservableList<IMessage>> conversations;
private GLib.HashTable<uint32, Message> messages_waiting_for_rr;

private unowned GLib.HashTable<uint32, IContact> friends;
private GLib.HashTable<string, IContact> friend_requests;

public bool show_typing { get; set; }

public ToxAdapterFriendListenerImpl(ILogger logger, Contacts contacts, GLib.HashTable<IContact, Conversation> conversations, NotificationListener notification_listener) {
public ToxAdapterFriendListenerImpl(ILogger logger, ObservableList<IContact> contacts, GLib.HashTable<IContact, ObservableList<IMessage>> conversations, NotificationListener notification_listener) {
logger.d("ToxAdapterFriendListenerImpl created.");
this.logger = logger;
this.contacts = contacts;
Expand Down Expand Up @@ -79,13 +79,13 @@ namespace Venom {
var public_key = Tools.hexstring_to_bin(id);
session.friend_add_norequest(public_key);
friend_requests.remove(id);
contacts.remove_contact(this, friend_request);
contacts.remove(friend_request);
}

public virtual void on_reject_friend_request(string id) throws Error {
var friend_request = friend_requests.@get(id);
friend_requests.remove(id);
contacts.remove_contact(this, friend_request);
contacts.remove(friend_request);
}

public virtual void on_send_message(IContact c, string message) throws Error {
Expand All @@ -107,7 +107,7 @@ namespace Venom {
var conversation = conversations.@get(contact);
var message = new Message.incoming(contact, message_str);
notification_listener.on_unread_message(message);
conversation.add_message(this, message);
conversation.append(message);
}

public virtual void on_friend_read_receipt(uint32 friend_number, uint32 message_id) {
Expand Down Expand Up @@ -148,7 +148,7 @@ namespace Venom {
logger.d("on_friend_request");
var str_id = Tools.bin_to_hexstring(public_key);
var contact = new FriendRequest(str_id, message);
contacts.add_contact(this, contact);
contacts.append(contact);
friend_requests.@set(str_id, contact);
}

Expand All @@ -172,18 +172,20 @@ namespace Venom {
}

if (!conversations.contains(contact)) {
conversations.@set(contact, new ConversationImpl(contact));
var conversation = new ObservableList<IMessage>();
conversation.set_list(new GLib.List<IMessage>());
conversations.@set(contact, conversation);
}
friends.@set(friend_number, contact);
contacts.add_contact(this, contact);
contacts.append(contact);
}

public virtual void on_friend_deleted(uint32 friend_number) {
logger.d("on_friend_deleted");
var contact = friends.@get(friend_number);
conversations.remove(contact);
friends.remove(friend_number);
contacts.remove_contact(this, contact);
contacts.remove(contact);
}

public virtual void on_friend_message_sent(uint32 friend_number, uint32 message_id, string message) {
Expand All @@ -192,7 +194,7 @@ namespace Venom {
var conversation = conversations.@get(contact);
var msg = new Message.outgoing(contact, message);
msg.message_id = message_id;
conversation.add_message(this, msg);
conversation.append(msg);
messages_waiting_for_rr.@set(message_id, msg);
}
}
Expand Down

0 comments on commit 342090b

Please sign in to comment.