Skip to content

Commit ffd2f5e

Browse files
TheFallen058codex
authored andcommitted
notifications: group conversation title prefixes
Use the text before a title's sender separator as a fallback conversation key when the Android companion does not provide sender metadata. Co-authored-by: GPT-5.6 Sol <noreply@openai.com> Signed-off-by: Aliaksandr Karnilovich <thefallen058@gmail.com>
1 parent 9c52486 commit ffd2f5e

2 files changed

Lines changed: 42 additions & 3 deletions

File tree

src/fw/apps/system/notifications_history.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,25 @@ static StringRange prv_trimmed_string_range(const char *string) {
6666
};
6767
}
6868

69+
static StringRange prv_conversation_range_from_title(const char *title) {
70+
StringRange range = prv_trimmed_string_range(title);
71+
if (!range.start) {
72+
return range;
73+
}
74+
75+
const char *separator = strstr(range.start, ": ");
76+
const char *end = range.start + range.length;
77+
if (!separator || separator == range.start || separator + 2 >= end) {
78+
return range;
79+
}
80+
81+
range.length = (size_t)(separator - range.start);
82+
while (range.length > 0 && isspace((unsigned char)range.start[range.length - 1])) {
83+
range.length--;
84+
}
85+
return range;
86+
}
87+
6988
static bool prv_group_sender_for_item(const TimelineItem *item, StringRange *sender_out) {
7089
static const Uuid s_android_notifications_source = UUID_NOTIFICATIONS_DATA_SOURCE;
7190

@@ -75,11 +94,13 @@ static bool prv_group_sender_for_item(const TimelineItem *item, StringRange *sen
7594
}
7695

7796
const char *sender = attribute_get_string(&item->attr_list, AttributeIdSender, NULL);
78-
if (!sender) {
79-
sender = attribute_get_string(&item->attr_list, AttributeIdTitle, NULL);
97+
if (sender) {
98+
*sender_out = prv_trimmed_string_range(sender);
99+
} else {
100+
const char *title = attribute_get_string(&item->attr_list, AttributeIdTitle, NULL);
101+
*sender_out = prv_conversation_range_from_title(title);
80102
}
81103

82-
*sender_out = prv_trimmed_string_range(sender);
83104
return sender_out->length > 0;
84105
}
85106

tests/fw/apps/system_apps/notifications/test_notifications_history.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,24 @@ void test_notifications_history__title_is_used_when_sender_is_missing(void) {
134134
cl_assert_equal_i(prv_row(0)->group.count, 2);
135135
}
136136

137+
void test_notifications_history__title_conversation_prefix_groups_messages(void) {
138+
prv_add_attribute(1, 100, AttributeIdTitle, "PG | Elite: Aloha");
139+
prv_add_attribute(2, 200, AttributeIdTitle, "PG | Elite: Yeuhen");
140+
141+
cl_assert_equal_i(notifications_history_get_row_count(&s_history), 1);
142+
cl_assert_equal_s(prv_row(0)->group.sender, "PG | Elite");
143+
cl_assert_equal_i(prv_row(0)->group.count, 2);
144+
}
145+
146+
void test_notifications_history__sender_attribute_is_not_split(void) {
147+
prv_add(1, 100, "PG | Elite: Aloha");
148+
prv_add(2, 200, "PG | Elite: Yeuhen");
149+
150+
cl_assert_equal_i(notifications_history_get_row_count(&s_history), 2);
151+
cl_assert_equal_s(prv_row(0)->group.sender, "PG | Elite: Yeuhen");
152+
cl_assert_equal_s(prv_row(1)->group.sender, "PG | Elite: Aloha");
153+
}
154+
137155
void test_notifications_history__body_is_not_used_as_group_key(void) {
138156
prv_add_attribute(1, 100, AttributeIdBody, "Same body");
139157
prv_add_attribute(2, 200, AttributeIdBody, "Same body");

0 commit comments

Comments
 (0)