Skip to content

Commit

Permalink
Add basic groupchat functionality
Browse files Browse the repository at this point in the history
* Add GroupMessage for groupchats
* Add ConferenceWindow for groupchats
* Add ConferenceInfoWidget to get info on a groupchat (more to come)
* Refactor ToxSessionListener to use uint32 instead of uint8[] as id
* Move person and group to meaningful names, make them symbolic
* Make use of status icons for friends
* Create a convenience functions in the vapi to avoid dealing with uint8[] inside the caller
  • Loading branch information
naxuroqa committed Feb 15, 2018
1 parent 7ed6bcd commit 7afbb17
Show file tree
Hide file tree
Showing 32 changed files with 1,458 additions and 413 deletions.
1 change: 1 addition & 0 deletions src/core/Contact.vala
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace Venom {
public abstract string get_id();
public abstract string get_name_string();
public abstract string get_status_string();
public abstract UserStatus get_status();
public abstract Gdk.Pixbuf get_image();
}
}
1 change: 0 additions & 1 deletion src/core/Message.vala
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ namespace Venom {
public abstract string get_message_plain();
public abstract string get_time_plain();

public abstract string get_notification_header();
public abstract Gdk.Pixbuf get_sender_image();

public abstract bool equals_message(IMessage m);
Expand Down
4 changes: 2 additions & 2 deletions src/core/R.vala
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ namespace Venom {
public string offline { get { return "offline-symbolic"; } }
public string online { get { return "online-symbolic"; } }

public string default_contact { get { return "person"; } }
public string default_groupchat { get { return "group"; } }
public string default_contact { get { return "friend-symbolic"; } }
public string default_groupchat { get { return "conference-symbolic"; } }
}

public sealed class StringResource {
Expand Down
4 changes: 2 additions & 2 deletions src/icons/icons.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<file compressed="true">scalable/status/idle-symbolic.svg</file>
<file compressed="true">scalable/status/offline-symbolic.svg</file>
<file compressed="true">scalable/status/online-symbolic.svg</file>
<file compressed="true">scalable/status/group.svg</file>
<file compressed="true">scalable/status/person.svg</file>
<file compressed="true">scalable/status/conference-symbolic.svg</file>
<file compressed="true">scalable/status/friend-symbolic.svg</file>
</gresource>
</gresources>
4 changes: 4 additions & 0 deletions src/icons/scalable/status/conference-symbolic.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/icons/scalable/status/friend-symbolic.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 0 additions & 4 deletions src/icons/scalable/status/group.svg

This file was deleted.

4 changes: 0 additions & 4 deletions src/icons/scalable/status/person.svg

This file was deleted.

3 changes: 3 additions & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ venom_source = files(
'tox/DhtNode.vala',
'tox/DhtNodeDatabase.vala',
'tox/GroupchatContact.vala',
'tox/GroupMessage.vala',
'tox/JsonWebDhtNodeDatabase.vala',
'tox/MessageDatabase.vala',
'tox/SqliteDhtNodeDatabase.vala',
Expand All @@ -54,6 +55,8 @@ venom_source = files(
'ui/AboutDialog.vala',
'ui/AddContactWidget.vala',
'ui/ApplicationWindow.vala',
'ui/ConferenceInfoWidget.vala',
'ui/ConferenceWindow.vala',
'ui/ContactListEntry.vala',
'ui/ContactListWidget.vala',
'ui/ConversationWindow.vala',
Expand Down
14 changes: 10 additions & 4 deletions src/tox/Contact.vala
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ namespace Venom {
public class Contact : IContact, GLib.Object {
// Saved in toxs savefile
public string tox_id { get; set; }
public uint32 tox_friend_number {get; set;}
public string name { get; set; default = ""; }
public string status_message { get; set; default = ""; }
public DateTime last_seen { get; set; default = new DateTime.now_local(); }
public uint8 user_status { get; set; default = (uint8) ToxCore.UserStatus.NONE; }
public UserStatus user_status { get; set; default = UserStatus.OFFLINE; }
// Saved in venoms savefile
public string note { get; set; default = ""; }
public string alias { get; set; default = ""; }
Expand All @@ -38,7 +39,8 @@ namespace Venom {
public int unread_messages { get; set; default = 0; }
public bool is_typing { get; set; default = false; }

public Contact(string id) {
public Contact(uint32 friend_number, string id) {
tox_friend_number = friend_number;
tox_id = id;
}

Expand All @@ -47,15 +49,19 @@ namespace Venom {
}

public virtual string get_name_string() {
return name != "" ? name : tox_id;
return alias != "" ? alias : (name != "" ? name : tox_id);
}

public virtual string get_status_string() {
return status_message;
}

public virtual UserStatus get_status() {
return user_status;
}

public virtual Gdk.Pixbuf get_image() {
return tox_image ?? Gtk.IconTheme.get_default().load_icon("person", 48, 0);
return tox_image ?? Gtk.IconTheme.get_default().load_icon("friend-symbolic", 48, 0);
}
}
}
82 changes: 82 additions & 0 deletions src/tox/GroupMessage.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* GroupMessage.vala
*
* Copyright (C) 2018 Venom authors and contributors
*
* This file is part of Venom.
*
* Venom is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Venom is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Venom. If not, see <http://www.gnu.org/licenses/>.
*/

namespace Venom {
public class GroupMessage : IMessage, Object {
public unowned IContact contact { get; protected set; }
public uint32 peer_number { get; protected set; }
public string message { get; protected set; }

public GLib.DateTime timestamp { get; protected set; }
public MessageDirection message_direction { get; protected set; }
public bool important { get; set; }
public bool is_action { get; set; }
public uint32 message_id { get; set; }
public bool received { get; set; }

private GroupMessage(IContact contact, MessageDirection direction, string message, GLib.DateTime timestamp) {
this.contact = contact;
this.message_direction = direction;
this.message = message;
this.timestamp = timestamp;
this.important = false;
this.is_action = false;
}

public GroupMessage.outgoing(IContact contact, string message, GLib.DateTime timestamp = new GLib.DateTime.now_local()) {
this(contact, MessageDirection.OUTGOING, message, timestamp);
}

public GroupMessage.incoming(IContact contact, uint32 peer_number, string message, GLib.DateTime timestamp = new GLib.DateTime.now_local()) {
this(contact, MessageDirection.INCOMING, message, timestamp);
this.peer_number = peer_number;
}

public virtual string get_sender_plain() {
if (message_direction == MessageDirection.OUTGOING) {
return User.instance.name;
} else {
return "peer %u".printf(peer_number);
}
}

public virtual string get_message_plain() {
return message;
}

public virtual string get_time_plain() {
var now = new DateTime.now_local();
if (now.difference(timestamp) > GLib.TimeSpan.DAY) {
return timestamp.format("%c");
} else {
return timestamp.format("%X");
}
}

public Gdk.Pixbuf get_sender_image() {
return UITools.pixbuf_from_resource(R.icons.default_contact);
}

public bool equals_message(IMessage m) {
return false;
}
}
}
16 changes: 10 additions & 6 deletions src/tox/GroupchatContact.vala
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,33 @@
namespace Venom {
public class GroupchatContact : IContact, GLib.Object {
// Saved in toxs savefile
public uint32 groupchat_id { get; set; }
public uint32 tox_conference_number { get; set; }
public string title { get; set; }
public string status_message { get; set; default = ""; }

public GroupchatContact(uint32 id, string title) {
groupchat_id = id;
public GroupchatContact(uint32 conference_number, string title) {
tox_conference_number = conference_number;
this.title = title;
}

public virtual string get_id() {
return groupchat_id.to_string();
return tox_conference_number.to_string();
}

public virtual string get_name_string() {
return title != "" ? title : groupchat_id.to_string();
return title != "" ? title : tox_conference_number.to_string();
}

public virtual string get_status_string() {
return status_message;
}

public virtual UserStatus get_status() {
return UserStatus.ONLINE;
}

public virtual Gdk.Pixbuf get_image() {
return Gtk.IconTheme.get_default().load_icon("group", 48, 0);
return Gtk.IconTheme.get_default().load_icon(R.icons.default_groupchat, 48, 0);
}
}
}

0 comments on commit 7afbb17

Please sign in to comment.