Skip to content

Commit

Permalink
test(messages): revive messaging test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
andyholmes committed Oct 22, 2024
1 parent 571e71c commit dc28fa4
Show file tree
Hide file tree
Showing 38 changed files with 1,251 additions and 840 deletions.
2 changes: 1 addition & 1 deletion REUSE.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ SPDX-FileCopyrightText = "Andy Holmes <[email protected]>"
SPDX-License-Identifier = "GPL-3.0-or-later"

[[annotations]]
path = [".github/**", ".gitignore", ".gitmodules", "build-aux/**", "CHANGELOG.md", "CONTRIBUTING.md", "README.md", "**.ontology", "**.png", "**.svg", "**.vcf", "**.wrap"]
path = [".github/**", ".gitignore", ".gitmodules", "build-aux/**", "CHANGELOG.md", "CONTRIBUTING.md", "README.md", "**.jpg", "**.ontology", "**.png", "**.svg", "**.vcf", "**.wrap"]
precedence = "aggregate"
SPDX-FileCopyrightText = "No rights reserved"
SPDX-License-Identifier = "CC0-1.0"
Expand Down
26 changes: 23 additions & 3 deletions src/libvalent/contacts/valent-contact-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ G_DEFINE_FINAL_TYPE_WITH_CODE (ValentContactList, valent_contact_list, VALENT_TY

typedef enum {
PROP_CONNECTION = 1,
PROP_NOTIFIER,
} ValentContactListProperty;

static GParamSpec *properties[PROP_CONNECTION + 1] = { NULL, };
static GParamSpec *properties[PROP_NOTIFIER + 1] = { NULL, };

static inline int
valent_contact_list_lookup_func (gconstpointer a,
Expand Down Expand Up @@ -468,11 +469,14 @@ valent_contact_list_constructed (GObject *object)

self->cancellable = valent_object_ref_cancellable (VALENT_OBJECT (self));
g_object_get (VALENT_OBJECT (self), "iri", &self->iri, NULL);
if (self->connection != NULL)

if (self->connection != NULL && self->notifier == NULL)
self->notifier = tracker_sparql_connection_create_notifier (self->connection);

if (self->notifier != NULL)
{
g_autofree char *iri_pattern = NULL;

self->notifier = tracker_sparql_connection_create_notifier (self->connection);
g_signal_connect_object (self->notifier,
"events",
G_CALLBACK (on_notifier_event),
Expand Down Expand Up @@ -531,6 +535,10 @@ valent_contact_list_get_property (GObject *object,
g_value_set_object (value, self->connection);
break;

case PROP_NOTIFIER:
g_value_set_object (value, self->notifier);
break;

default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
Expand All @@ -550,6 +558,10 @@ valent_contact_list_set_property (GObject *object,
self->connection = g_value_dup_object (value);
break;

case PROP_NOTIFIER:
self->notifier = g_value_dup_object (value);
break;

default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
Expand All @@ -576,6 +588,14 @@ valent_contact_list_class_init (ValentContactListClass *klass)
G_PARAM_EXPLICIT_NOTIFY |
G_PARAM_STATIC_STRINGS));

properties [PROP_NOTIFIER] =
g_param_spec_object ("notifier", NULL, NULL,
TRACKER_TYPE_NOTIFIER,
(G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_EXPLICIT_NOTIFY |
G_PARAM_STATIC_STRINGS));

g_object_class_install_properties (object_class, G_N_ELEMENTS (properties), properties);
}

Expand Down
8 changes: 6 additions & 2 deletions src/libvalent/contacts/valent-contacts-adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@ on_notifier_event (TrackerNotifier *notifier,
}

static ValentContactList *
valent_contact_list_from_sparql_cursor (TrackerSparqlCursor *cursor)
valent_contact_list_from_sparql_cursor (ValentContactsAdapter *self,
TrackerSparqlCursor *cursor)
{
ValentContactsAdapterPrivate *priv = valent_contacts_adapter_get_instance_private (self);
const char *iri = NULL;

if (!tracker_sparql_cursor_is_bound (cursor, 0))
Expand All @@ -135,6 +137,7 @@ valent_contact_list_from_sparql_cursor (TrackerSparqlCursor *cursor)
iri = tracker_sparql_cursor_get_string (cursor, 0, NULL);
return g_object_new (VALENT_TYPE_CONTACT_LIST,
"connection", tracker_sparql_cursor_get_connection (cursor),
"notifier", priv->notifier,
"iri", iri,
NULL);
}
Expand All @@ -152,7 +155,7 @@ cursor_get_contact_lists_cb (TrackerSparqlCursor *cursor,
{
ValentContactList *contacts = NULL;

contacts = valent_contact_list_from_sparql_cursor (cursor);
contacts = valent_contact_list_from_sparql_cursor (self, cursor);
if (contacts != NULL)
{
unsigned int position;
Expand Down Expand Up @@ -249,6 +252,7 @@ valent_contacts_adapter_add_contact_list (ValentContactsAdapter *self,

list = g_object_new (VALENT_TYPE_CONTACT_LIST,
"connection", priv->connection,
"notifier", priv->notifier,
"iri", iri,
NULL);

Expand Down
35 changes: 23 additions & 12 deletions src/libvalent/contacts/valent-contacts.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ struct _ValentContacts
{
ValentComponent parent_instance;

GPtrArray *adapters;
/* list model */
GPtrArray *items;
};

static void g_list_model_iface_init (GListModelInterface *iface);
static void valent_contacts_unbind_extension (ValentComponent *component,
GObject *extension);
static void g_list_model_iface_init (GListModelInterface *iface);

G_DEFINE_FINAL_TYPE_WITH_CODE (ValentContacts, valent_contacts, VALENT_TYPE_COMPONENT,
G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL, g_list_model_iface_init))
Expand All @@ -53,10 +56,10 @@ valent_contacts_get_item (GListModel *list,

g_assert (VALENT_IS_CONTACTS (self));

if G_UNLIKELY (position >= self->adapters->len)
if G_UNLIKELY (position >= self->items->len)
return NULL;

return g_object_ref (g_ptr_array_index (self->adapters, position));
return g_object_ref (g_ptr_array_index (self->items, position));
}

static GType
Expand All @@ -72,7 +75,7 @@ valent_contacts_get_n_items (GListModel *list)

g_assert (VALENT_IS_CONTACTS (self));

return self->adapters->len;
return self->items->len;
}

static void
Expand All @@ -98,16 +101,22 @@ valent_contacts_bind_extension (ValentComponent *component,
g_assert (VALENT_IS_CONTACTS (self));
g_assert (VALENT_IS_CONTACTS_ADAPTER (extension));

if (g_ptr_array_find (self->adapters, extension, &position))
if (g_ptr_array_find (self->items, extension, &position))
{
g_warning ("Adapter \"%s\" already exported in \"%s\"",
G_OBJECT_TYPE_NAME (extension),
G_OBJECT_TYPE_NAME (component));
return;
}

position = self->adapters->len;
g_ptr_array_add (self->adapters, g_object_ref (extension));
g_signal_connect_object (extension,
"destroy",
G_CALLBACK (valent_contacts_unbind_extension),
self,
G_CONNECT_SWAPPED);

position = self->items->len;
g_ptr_array_add (self->items, g_object_ref (extension));
g_list_model_items_changed (G_LIST_MODEL (self), position, 0, 1);

VALENT_EXIT;
Expand All @@ -118,22 +127,24 @@ valent_contacts_unbind_extension (ValentComponent *component,
GObject *extension)
{
ValentContacts *self = VALENT_CONTACTS (component);
g_autoptr (ValentExtension) item = NULL;
unsigned int position = 0;

VALENT_ENTRY;

g_assert (VALENT_IS_CONTACTS (self));
g_assert (VALENT_IS_CONTACTS_ADAPTER (extension));

if (!g_ptr_array_find (self->adapters, extension, &position))
if (!g_ptr_array_find (self->items, extension, &position))
{
g_warning ("Adapter \"%s\" not found in \"%s\"",
G_OBJECT_TYPE_NAME (extension),
G_OBJECT_TYPE_NAME (component));
return;
}

g_ptr_array_remove (self->adapters, extension);
g_signal_handlers_disconnect_by_func (extension, valent_contacts_unbind_extension, self);
item = g_ptr_array_steal_index (self->items, position);
g_list_model_items_changed (G_LIST_MODEL (self), position, 1, 0);

VALENT_EXIT;
Expand All @@ -147,7 +158,7 @@ valent_contacts_finalize (GObject *object)
{
ValentContacts *self = VALENT_CONTACTS (object);

g_clear_pointer (&self->adapters, g_ptr_array_unref);
g_clear_pointer (&self->items, g_ptr_array_unref);

G_OBJECT_CLASS (valent_contacts_parent_class)->finalize (object);
}
Expand All @@ -167,7 +178,7 @@ valent_contacts_class_init (ValentContactsClass *klass)
static void
valent_contacts_init (ValentContacts *self)
{
self->adapters = g_ptr_array_new_with_free_func (g_object_unref);
self->items = g_ptr_array_new_with_free_func (g_object_unref);
}

/**
Expand Down
14 changes: 8 additions & 6 deletions src/libvalent/messages/data/sparql/get-message-attachments.rq
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ SELECT
?encodedThumbnail
?fileUri
WHERE {
BIND(IRI(xsd:string(~iri)) AS ?message)

?message nmo:hasAttachment ?attachment .
OPTIONAL { ?attachment rdf:type nfo:Attachment }
OPTIONAL { ?attachment vmo:encoded_thumbnail ?encodedThumbnail }
OPTIONAL { ?attachment nie:url ?fileUri }
GRAPH <valent:messages> {
BIND(IRI(xsd:string(~iri)) AS ?message)
?message rdf:type vmo:PhoneMessage ;
nmo:hasAttachment ?attachment .
OPTIONAL { ?attachment rdf:type nfo:Attachment }
OPTIONAL { ?attachment vmo:encoded_thumbnail ?encodedThumbnail }
OPTIONAL { ?attachment nie:url ?fileUri }
}
}

15 changes: 7 additions & 8 deletions src/libvalent/messages/data/sparql/get-message.rq
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,29 @@ SELECT
WHERE {
BIND(IRI(xsd:string(~iri)) AS ?message)
?message rdf:type vmo:PhoneMessage ;
vmo:phoneMessageBox ?phoneMessageBoxId ;
dc:date ?date ;
vmo:phoneMessageBox ?phoneMessageBox ;
vmo:phoneMessageId ?messageId ;
nmo:isRead ?read ;
vmo:communicationChannel ?communicationChannel ;
vmo:subscriptionId ?subscriptionId .
?communicationChannel vmo:communicationChannelId ?threadId .
vmo:subscriptionId ?subscriptionId ;
vmo:communicationChannel ?communicationChannel .
?phoneMessageBox vmo:phoneMessageBoxId ?box .
?communicationChannel vmo:communicationChannelId ?threadId .
OPTIONAL {
?message nmo:hasAttachment ?attachment .
OPTIONAL { ?attachment rdf:type nfo:Attachment }
OPTIONAL { ?attachment vmo:encoded_thumbnail ?encoded_thumbnail }
OPTIONAL { ?attachment nie:url ?fileUri }
}
OPTIONAL {
?message nmo:messageSender ?contactMedium .
OPTIONAL { ?contactMedium (nco:phoneNumber|nco:emailAddress) ?sender }
?message nmo:primaryMessageRecipient/(nco:phoneNumber|nco:emailAddress) ?recipient
}
OPTIONAL {
?message nmo:primaryMessageRecipient ?contactMedium .
OPTIONAL { ?contactMedium (nco:phoneNumber|nco:emailAddress) ?recipient }
?message nmo:messageSender/(nco:phoneNumber|nco:emailAddress) ?sender
}
OPTIONAL {
?message nmo:plainTextMessageContent ?text
}
}
GROUP BY ?message ?attachment

18 changes: 10 additions & 8 deletions src/libvalent/messages/data/sparql/get-thread-attachments.rq
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ SELECT
?encodedThumbnail
?fileUri
WHERE {
BIND(IRI(xsd:string(~iri)) AS ?thread)

?message vmo:communicationChannel ?thread ;
nmo:hasAttachment ?attachment .

OPTIONAL { ?attachment rdf:type nfo:Attachment }
OPTIONAL { ?attachment vmo:encoded_thumbnail ?encodedThumbnail }
OPTIONAL { ?attachment nie:url ?fileUri }
GRAPH <valent:messages> {
BIND(IRI(xsd:string(~iri)) AS ?communicationChannel)
?message rdf:type vmo:PhoneMessage ;
vmo:communicationChannel ?communicationChannel ;
nmo:hasAttachment ?attachment .
OPTIONAL { ?attachment rdf:type nfo:Attachment }
OPTIONAL { ?attachment vmo:encoded_thumbnail ?encodedThumbnail }
OPTIONAL { ?attachment nie:url ?fileUri }
}
}

1 change: 1 addition & 0 deletions src/libvalent/messages/data/sparql/get-thread-messages.rq
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ WHERE {
}
GROUP BY ?message ?attachment
ORDER BY ASC(?date)

17 changes: 8 additions & 9 deletions src/libvalent/messages/data/sparql/get-thread.rq
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# Inputs: iri
# Outputs: message, box, date, messageId, read, recipients, sender, subscriptionId, text, threadId
# communicationChannel,
# communicationChannel, participants
SELECT
?message
?box
Expand All @@ -27,26 +27,25 @@ WHERE {
}
GROUP BY ?communicationChannel
}
FILTER(?date = ?latestDate)
?message rdf:type vmo:PhoneMessage ;
vmo:phoneMessageBox/vmo:phoneMessageBoxId ?box ;
dc:date ?date ;
vmo:phoneMessageBox ?phoneMessageBox ;
vmo:phoneMessageId ?messageId ;
nmo:isRead ?read ;
vmo:communicationChannel ?communicationChannel ;
vmo:subscriptionId ?subscriptionId .
vmo:subscriptionId ?subscriptionId ;
vmo:communicationChannel ?communicationChannel .
?communicationChannel rdf:type vmo:CommunicationChannel ;
vmo:communicationChannelId ?threadId ;
vmo:hasParticipant ?participant .
?phoneMessageBox vmo:phoneMessageBoxId ?box .
OPTIONAL {
?message nmo:messageSender ?contactMedium .
OPTIONAL { ?contactMedium (nco:phoneNumber|nco:emailAddress) ?sender }
?message nmo:primaryMessageRecipient/(nco:phoneNumber|nco:emailAddress) ?recipient
}
OPTIONAL {
?message nmo:primaryMessageRecipient ?contactMedium .
OPTIONAL { ?contactMedium (nco:phoneNumber|nco:emailAddress) ?recipient }
?message nmo:messageSender/(nco:phoneNumber|nco:emailAddress) ?sender
}
OPTIONAL {
?message nmo:plainTextMessageContent ?text
}
}

10 changes: 6 additions & 4 deletions src/libvalent/messages/data/sparql/get-timestamp.rq
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
# Outputs: date
SELECT (MAX(?date) AS ?latestDate)
WHERE {
?message rdf:type vmo:PhoneMessage ;
vmo:communicationChannel/vmo:communicationChannelId ?threadId ;
dc:date ?date .
FILTER(?threadId = ~threadId^^xsd:integer)
GRAPH <valent:messages> {
?message rdf:type vmo:PhoneMessage ;
vmo:communicationChannel/vmo:communicationChannelId ?threadId ;
dc:date ?date .
FILTER(?threadId = ~threadId^^xsd:integer)
}
}

10 changes: 5 additions & 5 deletions src/libvalent/messages/data/sparql/remove-thread.rq
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
# Outputs: None
DELETE
WHERE {
BIND(IRI(xsd:string(~iri)) AS ?channel)
?channel rdf:type vmo:CommunicationChannel ;
?channelProperty ?channelValue .
BIND(IRI(xsd:string(~iri)) AS ?communicationChannel)
?communicationChannel rdf:type vmo:CommunicationChannel ;
?channelProperty ?channelValue .
OPTIONAL { ?channel ?channelProperty ?channelValue . }
?message rdf:type vmo:PhoneMessage ;
vmo:communicationChannel ?channel ;
vmo:communicationChannel ?communicationChannel ;
?messageProperty ?messageValue .
OPTIONAL { ?message ?messageProperty ?messageValue . }
OPTIONAL { ?channel ?channelProperty ?channelValue . }
}

2 changes: 1 addition & 1 deletion src/libvalent/messages/data/sparql/search-messages.rq
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ WHERE {
?message nmo:plainTextMessageContent ?text
}
}
GROUP BY ?message
GROUP BY ?message ?attachment
ORDER BY DESC(fts:rank(?message))
LIMIT 5

Loading

0 comments on commit dc28fa4

Please sign in to comment.