Merge lp:~knitzsche/telegram-app/recent-keyword-aggreagation into lp:telegram-app/app

Proposed by Kyle Nitzsche
Status: Merged
Approved by: Roberto Mier Escandon
Approved revision: 110
Merged at revision: 108
Proposed branch: lp:~knitzsche/telegram-app/recent-keyword-aggreagation
Merge into: lp:telegram-app/app
Diff against target: 459 lines (+82/-218)
8 files modified
.bzrignore (+4/-1)
po/com.ubuntu.telegram.pot (+1/-1)
scope/data/com.ubuntu.telegram_sctelegram.ini (+1/-0)
scope/data/scope.ini.in (+1/-0)
scope/po/Makefile (+0/-167)
scope/po/cmake_install.cmake (+0/-46)
scope/src/query.cpp (+72/-3)
scope/src/query.h (+3/-0)
To merge this branch: bzr merge lp:~knitzsche/telegram-app/recent-keyword-aggreagation
Reviewer Review Type Date Requested Status
Roberto Mier Escandon (community) Approve
Michał Karnicki (community) Needs Fixing
Review via email: mp+260871@code.launchpad.net

Description of the change

this vivid branch supports keyword aggregation (introduced in vivid) of telegram scope by "recent" keyword using the components and result fields expected by "recent"" aggregation. The one most recent result is returned when being aggregated by "recent" keyword.

To post a comment you must log in.
Revision history for this message
Kyle Nitzsche (knitzsche) wrote :

by the way, generated (c)make files are not ignored in bzr and thus (unexpectedly to me) they show up here in the diff. The only files that really matter to this MR's functionality are scope.ini.in, query.cpp and query.h. cheers

Revision history for this message
Roberto Mier Escandon (rmescandon) wrote :

Why scope/po/Makefile and scope/po/cmake_install.cmake are in the repository. Should they be ignored instead?
In any case, they have abs path to your local folders :S

review: Needs Fixing
Revision history for this message
Michał Karnicki (karni) wrote :

I am aware that current scope source may not be super clean, but let's try to make it better.

I would have the following suggestions:
0) what Roberto said - it's less about the local paths present, more about some noise in this MP's diff
1) rename md_ to mMetaData (to follow rest of member fields, like mScopeDir)
2) stick to one convention - camel case, I see recentMessages, agged_by_recent and totalunread:
+ auto recentMessages = reply->register_category("telegram_recent", "Telegram", "", catRecentRendr);
[...]
+ if (!agged_by_recent && totalunread > 0 && search_query.isEmpty()) {
Yes I'm aware two of these where already there in this form, let's just focus on making it better. Feel free to also s/totalunread/totalUnread
3) please open blocks of code with brace on same line, and feel free to put lone 'break;'s on same line as if conditions, if you want - if not, please wrap in { }
4) instead of:
    for (unsigned int i = 0; i < results.size(); i++)
    {
        if (agged_by_recent)
        {
        // huge block here
        break;
        reply->push(results[i]);
    }
I would suggest the following, which should improve readability:
    if (agged_by_recent) {
        // do stuff here
        return;
    }
    for (...) {
        reply->push(results[i]);
    }

I think this would be solid. The new logic looks sane.

review: Needs Fixing
Revision history for this message
Roberto Mier Escandon (rmescandon) wrote :

Just a comment for Karni:
C++ 11 uses this_annotation and Qt uses thisOther ... so... it's not easy agree on one of them since everybody is right regardless of what his opinion is.

In fw we have the next "convention" for everybody to be happy:

- all c++ 11 related code uses underscore annotation
- all Qt related code uses camel case

so that you can have instructions like:

const std::atype& a_var = "a value";
const QVariant &another = QVariant("another");
QString myString = QString::fromStdString(one_object.calling_any_c_eleven_method(a_var, another));

besides, in scopes world the usual way you find code is in c++ 11 way, so that annotation can't be skipped

Revision history for this message
Michał Karnicki (karni) wrote :

Thank you for your feedback, Roberto. To be clear, I'm not in favor of one of those. I'm simply in favor of consistency :) I don't mind if the rest is converted to use underscore notation, as long as we try to be consistent. (Regardless, for instance, the md_ is neither descriptive nor consistent with any other member in that source. Perhaps meta_data would be better, if all other variables/members weren't camel case.)

Revision history for this message
Kyle Nitzsche (knitzsche) wrote :

Thanks guys.
New branch about to be posted. Responses to comments above:
0) I have bzr ignored the po/ cmake/make files. (seems odd that I should need to do this since I have not modified any build scripts or introduced new terms for l10n... but c'est la vie :)
1) have changed md_ to mMetadata (not mMetaData since the api uses a lower case 'd'.
2) have changed agged_by_recent to aggedByRecent
3) & 4) I open blocks on the same line
cheers - Kyle

109. By Kyle Nitzsche

modified code conventions to fit this project per MR request

Revision history for this message
Kyle Nitzsche (knitzsche) wrote :

hang on, the Makefile and cmake files are still present

110. By Kyle Nitzsche

bzr ignore scope/po/Makefile & scope/po/cmake_install.cmake

Revision history for this message
Kyle Nitzsche (knitzsche) wrote :

OK, I removed and ignored the scope/po/ make files

Revision history for this message
Roberto Mier Escandon (rmescandon) wrote :

lgtm (though not tested)

review: Approve
Revision history for this message
Kyle Nitzsche (knitzsche) wrote :

Roberto, can you top approve pls? Looks like karni is on holiday.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file '.bzrignore'
--- .bzrignore 2015-05-11 08:49:51 +0000
+++ .bzrignore 2015-06-03 13:43:06 +0000
@@ -13,8 +13,9 @@
13third_party13third_party
14telegram14telegram
15telegram_automoc.cpp15telegram_automoc.cpp
16
17Makefile16Makefile
17po/Makefile
18po/cmake_install.cmake
18CMakeLists.txt.user19CMakeLists.txt.user
19CMakeFiles20CMakeFiles
20CMakeCache.txt21CMakeCache.txt
@@ -34,3 +35,5 @@
34scope/src/com.ubuntu.telegram_sctelegram_automoc.cpp35scope/src/com.ubuntu.telegram_sctelegram_automoc.cpp
35.ycm_extra_conf.py36.ycm_extra_conf.py
36scope/po/built_mos37scope/po/built_mos
38scope/po/Makefile
39scope/po/cmake_install.cmake
3740
=== modified file 'po/com.ubuntu.telegram.pot'
--- po/com.ubuntu.telegram.pot 2015-06-01 15:01:21 +0000
+++ po/com.ubuntu.telegram.pot 2015-06-03 13:43:06 +0000
@@ -8,7 +8,7 @@
8msgstr ""8msgstr ""
9"Project-Id-Version: \n"9"Project-Id-Version: \n"
10"Report-Msgid-Bugs-To: \n"10"Report-Msgid-Bugs-To: \n"
11"POT-Creation-Date: 2015-06-01 17:00+0200\n"11"POT-Creation-Date: 2015-06-03 09:40-0400\n"
12"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"12"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"13"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14"Language-Team: LANGUAGE <LL@li.org>\n"14"Language-Team: LANGUAGE <LL@li.org>\n"
1515
=== modified file 'scope/data/com.ubuntu.telegram_sctelegram.ini'
--- scope/data/com.ubuntu.telegram_sctelegram.ini 2015-06-01 15:01:21 +0000
+++ scope/data/com.ubuntu.telegram_sctelegram.ini 2015-06-03 13:43:06 +0000
@@ -68,6 +68,7 @@
68SearchHint[uk]=Шукати повідомлення68SearchHint[uk]=Шукати повідомлення
69SearchHint[zh_TW]=搜尋訊息69SearchHint[zh_TW]=搜尋訊息
70HotKey=tasks.HotKey70HotKey=tasks.HotKey
71Keywords=recent
71[Appearance]72[Appearance]
72background=color:///#49749573background=color:///#497495
73PageHeader.Logo=./images/logo.png74PageHeader.Logo=./images/logo.png
7475
=== modified file 'scope/data/scope.ini.in'
--- scope/data/scope.ini.in 2014-12-02 12:35:48 +0000
+++ scope/data/scope.ini.in 2015-06-03 13:43:06 +0000
@@ -6,6 +6,7 @@
6Icon=./images/telegram.png6Icon=./images/telegram.png
7_SearchHint=Search for a message7_SearchHint=Search for a message
8HotKey=tasks.HotKey8HotKey=tasks.HotKey
9Keywords=recent
9[Appearance]10[Appearance]
10background=color:///#49749511background=color:///#497495
11PageHeader.Logo=./images/logo.png12PageHeader.Logo=./images/logo.png
1213
=== removed file 'scope/po/Makefile'
--- scope/po/Makefile 2015-04-15 08:59:54 +0000
+++ scope/po/Makefile 1970-01-01 00:00:00 +0000
@@ -1,167 +0,0 @@
1# CMAKE generated file: DO NOT EDIT!
2# Generated by "Unix Makefiles" Generator, CMake Version 2.8
3
4# Default target executed when no arguments are given to make.
5default_target: all
6.PHONY : default_target
7
8#=============================================================================
9# Special targets provided by cmake.
10
11# Disable implicit rules so canonical targets will work.
12.SUFFIXES:
13
14# Remove some rules from gmake that .SUFFIXES does not remove.
15SUFFIXES =
16
17.SUFFIXES: .hpux_make_needs_suffix_list
18
19# Suppress display of executed commands.
20$(VERBOSE).SILENT:
21
22# A target that is always out of date.
23cmake_force:
24.PHONY : cmake_force
25
26#=============================================================================
27# Set environment variables for the build.
28
29# The shell in which to execute make rules.
30SHELL = /bin/sh
31
32# The CMake executable.
33CMAKE_COMMAND = /usr/bin/cmake
34
35# The command to remove a file.
36RM = /usr/bin/cmake -E remove -f
37
38# Escaping for special characters.
39EQUALS = =
40
41# The top-level source directory on which CMake was run.
42CMAKE_SOURCE_DIR = /home/karni/src/canonical/telegram/app
43
44# The top-level build directory on which CMake was run.
45CMAKE_BINARY_DIR = /home/karni/src/canonical/telegram/app
46
47#=============================================================================
48# Targets provided globally by CMake.
49
50# Special rule for the target edit_cache
51edit_cache:
52 @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running interactive CMake command-line interface..."
53 /usr/bin/cmake -i .
54.PHONY : edit_cache
55
56# Special rule for the target edit_cache
57edit_cache/fast: edit_cache
58.PHONY : edit_cache/fast
59
60# Special rule for the target install
61install: preinstall
62 @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..."
63 /usr/bin/cmake -P cmake_install.cmake
64.PHONY : install
65
66# Special rule for the target install
67install/fast: preinstall/fast
68 @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..."
69 /usr/bin/cmake -P cmake_install.cmake
70.PHONY : install/fast
71
72# Special rule for the target install/local
73install/local: preinstall
74 @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing only the local directory..."
75 /usr/bin/cmake -DCMAKE_INSTALL_LOCAL_ONLY=1 -P cmake_install.cmake
76.PHONY : install/local
77
78# Special rule for the target install/local
79install/local/fast: install/local
80.PHONY : install/local/fast
81
82# Special rule for the target install/strip
83install/strip: preinstall
84 @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing the project stripped..."
85 /usr/bin/cmake -DCMAKE_INSTALL_DO_STRIP=1 -P cmake_install.cmake
86.PHONY : install/strip
87
88# Special rule for the target install/strip
89install/strip/fast: install/strip
90.PHONY : install/strip/fast
91
92# Special rule for the target list_install_components
93list_install_components:
94 @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Available install components are: \"Unspecified\""
95.PHONY : list_install_components
96
97# Special rule for the target list_install_components
98list_install_components/fast: list_install_components
99.PHONY : list_install_components/fast
100
101# Special rule for the target rebuild_cache
102rebuild_cache:
103 @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
104 /usr/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
105.PHONY : rebuild_cache
106
107# Special rule for the target rebuild_cache
108rebuild_cache/fast: rebuild_cache
109.PHONY : rebuild_cache/fast
110
111# The main all target
112all: cmake_check_build_system
113 cd /home/karni/src/canonical/telegram/app && $(CMAKE_COMMAND) -E cmake_progress_start /home/karni/src/canonical/telegram/app/CMakeFiles /home/karni/src/canonical/telegram/app/scope/po/CMakeFiles/progress.marks
114 cd /home/karni/src/canonical/telegram/app && $(MAKE) -f CMakeFiles/Makefile2 scope/po/all
115 $(CMAKE_COMMAND) -E cmake_progress_start /home/karni/src/canonical/telegram/app/CMakeFiles 0
116.PHONY : all
117
118# The main clean target
119clean:
120 cd /home/karni/src/canonical/telegram/app && $(MAKE) -f CMakeFiles/Makefile2 scope/po/clean
121.PHONY : clean
122
123# The main clean target
124clean/fast: clean
125.PHONY : clean/fast
126
127# Prepare targets for installation.
128preinstall: all
129 cd /home/karni/src/canonical/telegram/app && $(MAKE) -f CMakeFiles/Makefile2 scope/po/preinstall
130.PHONY : preinstall
131
132# Prepare targets for installation.
133preinstall/fast:
134 cd /home/karni/src/canonical/telegram/app && $(MAKE) -f CMakeFiles/Makefile2 scope/po/preinstall
135.PHONY : preinstall/fast
136
137# clear depends
138depend:
139 cd /home/karni/src/canonical/telegram/app && $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
140.PHONY : depend
141
142# Help Target
143help:
144 @echo "The following are some of the valid targets for this Makefile:"
145 @echo "... all (the default if no target is provided)"
146 @echo "... clean"
147 @echo "... depend"
148 @echo "... edit_cache"
149 @echo "... install"
150 @echo "... install/local"
151 @echo "... install/strip"
152 @echo "... list_install_components"
153 @echo "... rebuild_cache"
154.PHONY : help
155
156
157
158#=============================================================================
159# Special targets to cleanup operation of make.
160
161# Special rule to run CMake to check the build system integrity.
162# No rule that depends on this can have commands that come from listfiles
163# because they might be regenerated.
164cmake_check_build_system:
165 cd /home/karni/src/canonical/telegram/app && $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
166.PHONY : cmake_check_build_system
167
1680
=== removed file 'scope/po/cmake_install.cmake'
--- scope/po/cmake_install.cmake 2015-04-15 08:59:54 +0000
+++ scope/po/cmake_install.cmake 1970-01-01 00:00:00 +0000
@@ -1,46 +0,0 @@
1# Install script for directory: /home/karni/src/canonical/telegram/app/scope/po
2
3# Set the install prefix
4IF(NOT DEFINED CMAKE_INSTALL_PREFIX)
5 SET(CMAKE_INSTALL_PREFIX "/")
6ENDIF(NOT DEFINED CMAKE_INSTALL_PREFIX)
7STRING(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
8
9# Set the install configuration name.
10IF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
11 IF(BUILD_TYPE)
12 STRING(REGEX REPLACE "^[^A-Za-z0-9_]+" ""
13 CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}")
14 ELSE(BUILD_TYPE)
15 SET(CMAKE_INSTALL_CONFIG_NAME "")
16 ENDIF(BUILD_TYPE)
17 MESSAGE(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"")
18ENDIF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
19
20# Set the component getting installed.
21IF(NOT CMAKE_INSTALL_COMPONENT)
22 IF(COMPONENT)
23 MESSAGE(STATUS "Install component: \"${COMPONENT}\"")
24 SET(CMAKE_INSTALL_COMPONENT "${COMPONENT}")
25 ELSE(COMPONENT)
26 SET(CMAKE_INSTALL_COMPONENT)
27 ENDIF(COMPONENT)
28ENDIF(NOT CMAKE_INSTALL_COMPONENT)
29
30# Install shared libraries without execute permission?
31IF(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)
32 SET(CMAKE_INSTALL_SO_NO_EXE "1")
33ENDIF(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)
34
35IF(NOT CMAKE_INSTALL_COMPONENT OR "${CMAKE_INSTALL_COMPONENT}" STREQUAL "Unspecified")
36 list(APPEND CMAKE_ABSOLUTE_DESTINATION_FILES
37 "/sctelegram/locale")
38 IF (CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION)
39 message(WARNING "ABSOLUTE path INSTALL DESTINATION : ${CMAKE_ABSOLUTE_DESTINATION_FILES}")
40 ENDIF (CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION)
41 IF (CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION)
42 message(FATAL_ERROR "ABSOLUTE path INSTALL DESTINATION forbidden (by caller): ${CMAKE_ABSOLUTE_DESTINATION_FILES}")
43 ENDIF (CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION)
44FILE(INSTALL DESTINATION "/sctelegram" TYPE DIRECTORY FILES "/home/karni/src/canonical/telegram/app/scope/po/built_mos/locale")
45ENDIF(NOT CMAKE_INSTALL_COMPONENT OR "${CMAKE_INSTALL_COMPONENT}" STREQUAL "Unspecified")
46
470
=== modified file 'scope/src/query.cpp'
--- scope/src/query.cpp 2015-02-11 12:38:39 +0000
+++ scope/src/query.cpp 2015-06-03 13:43:06 +0000
@@ -3,6 +3,7 @@
3#include <unity/scopes/CategoryRenderer.h>3#include <unity/scopes/CategoryRenderer.h>
4#include <unity/scopes/QueryBase.h>4#include <unity/scopes/QueryBase.h>
5#include <unity/scopes/SearchReply.h>5#include <unity/scopes/SearchReply.h>
6#include <unity/scopes/VariantBuilder.h>
67
7#include <QDebug>8#include <QDebug>
8#include <QUrl>9#include <QUrl>
@@ -21,6 +22,25 @@
2122
22namespace23namespace
23{24{
25
26static const std::string RECENT = R"(
27{
28 "schema-version": 1,
29 "template":
30 {
31 "category-layout": "grid",
32 "card-layout": "horizontal",
33 "card-size": "large"
34 },
35 "components":
36 {
37 "title": "title",
38 "attributes": {"field": "attributes", "max-count": 4},
39 "mascot": "mascot"
40 }
41}
42)";
43
24const static std::string UNREAD_TEMPLATE =44const static std::string UNREAD_TEMPLATE =
25 R"(45 R"(
26{46{
@@ -154,7 +174,7 @@
154}174}
155175
156TelegramQuery::TelegramQuery(CannedQuery const& query, SearchMetadata const& metadata, QString const& scopeDir) :176TelegramQuery::TelegramQuery(CannedQuery const& query, SearchMetadata const& metadata, QString const& scopeDir) :
157 SearchQueryBase(query, metadata), mScopeDir(scopeDir)177 SearchQueryBase(query, metadata), mMetadata(metadata), mScopeDir(scopeDir)
158{178{
159 setlocale(LC_ALL, "");179 setlocale(LC_ALL, "");
160 textdomain(GETTEXT_DOMAIN.toStdString().c_str());180 textdomain(GETTEXT_DOMAIN.toStdString().c_str());
@@ -452,17 +472,26 @@
452472
453void TelegramQuery::run(unity::scopes::SearchReplyProxy const& reply)473void TelegramQuery::run(unity::scopes::SearchReplyProxy const& reply)
454{474{
475 bool aggedByRecent = false;
455 unsigned int recentMax = 10;476 unsigned int recentMax = 10;
477 if (mMetadata.is_aggregated()){
478 auto keywords = mMetadata.aggregated_keywords();
479 if (keywords.find("recent") != keywords.end()){
480 aggedByRecent = true;
481 }
482 }
456 //Tell gettext where to look for textdomain files483 //Tell gettext where to look for textdomain files
457 QString tdir = QString("%1/locale/").arg(mScopeDir);484 QString tdir = QString("%1/locale/").arg(mScopeDir);
458 QString basedir = QString(bindtextdomain(GETTEXT_DOMAIN.toStdString().c_str(), tdir.toStdString().c_str()));485 QString basedir = QString(bindtextdomain(GETTEXT_DOMAIN.toStdString().c_str(), tdir.toStdString().c_str()));
459 QString search_query = QString::fromStdString(query().query_string());486 QString search_query = QString::fromStdString(query().query_string());
460487
461 CategoryRenderer catReadRendr(search_query.isEmpty()?READ_TEMPLATE:SEARCH_MESS_TEMPLATE);488 CategoryRenderer catReadRendr(search_query.isEmpty()?READ_TEMPLATE:SEARCH_MESS_TEMPLATE);
489 CategoryRenderer catRecentRendr(RECENT);
462 CategoryRenderer catUnreadRendr(UNREAD_TEMPLATE);490 CategoryRenderer catUnreadRendr(UNREAD_TEMPLATE);
463 CategoryRenderer carrRendr(search_query.isEmpty()?CARR_TEMPLATE:CONTACTS_SEARCH_TEMPLATE);491 CategoryRenderer carrRendr(search_query.isEmpty()?CARR_TEMPLATE:CONTACTS_SEARCH_TEMPLATE);
464 CategoryRenderer photoRendr(PHOTO_TEMPLATE);492 CategoryRenderer photoRendr(PHOTO_TEMPLATE);
465493
494 auto recentMessages = reply->register_category("telegram_recent", "Telegram", "", catRecentRendr);
466 auto readMessages = reply->register_category("read", _("Recent Messages"), "", catReadRendr);495 auto readMessages = reply->register_category("read", _("Recent Messages"), "", catReadRendr);
467 auto buddiesCat = reply->register_category("buddies", _("People You Talk To"), "", carrRendr);496 auto buddiesCat = reply->register_category("buddies", _("People You Talk To"), "", carrRendr);
468 auto photoCat = reply->register_category("photos", _("Received Images"), "", photoRendr);;497 auto photoCat = reply->register_category("photos", _("Received Images"), "", photoRendr);;
@@ -485,7 +514,7 @@
485514
486 auto totalunread = getUnreadMessages(myTelegram);515 auto totalunread = getUnreadMessages(myTelegram);
487516
488 if (totalunread > 0 && search_query.isEmpty()) {517 if (!aggedByRecent && totalunread > 0 && search_query.isEmpty()) {
489 QString title_unread = _("Unread Messages: %1");518 QString title_unread = _("Unread Messages: %1");
490 title_unread = title_unread.arg(totalunread);519 title_unread = title_unread.arg(totalunread);
491 auto unReadMessages = reply->register_category("unread",title_unread.toStdString(), "", catUnreadRendr);520 auto unReadMessages = reply->register_category("unread",title_unread.toStdString(), "", catUnreadRendr);
@@ -503,24 +532,37 @@
503 for (unsigned int i = 0 ; i < myTelegram.size(); i++){532 for (unsigned int i = 0 ; i < myTelegram.size(); i++){
504 if (myTelegram[i].out || unReadIds.find(myTelegram[i].id) != unReadIds.end())533 if (myTelegram[i].out || unReadIds.find(myTelegram[i].id) != unReadIds.end())
505 continue;534 continue;
535 if (aggedByRecent && results.size() > 0)
536 break;// recent keyword aggregation only wants one message
506 recieveMsgs++;537 recieveMsgs++;
507 myBuddies[myTelegram[i].from.id] = myTelegram[i].from;538 myBuddies[myTelegram[i].from.id] = myTelegram[i].from;
508 if (recieveMsgs <= recentMax && search_query.isEmpty()){539 if (recieveMsgs <= recentMax && search_query.isEmpty()){
509 auto res = messageToResult(readMessages,myTelegram[i],false);540 auto res = messageToResult(readMessages,myTelegram[i],false);
510 results.push_back(res);541 results.push_back(res);
542 if (aggedByRecent){
543 results.clear();// we want only the last item in the vector
544 results.push_back(res);
545 break;// recent keyword aggregation only wants one message
546 }
511 }547 }
512 if (!search_query.isEmpty() && myTelegram[i].text.contains(search_query,Qt::CaseInsensitive)){548 if (!search_query.isEmpty() && myTelegram[i].text.contains(search_query,Qt::CaseInsensitive)){
513 auto res = messageToResult(searchReadMessages,myTelegram[i],false);549 auto res = messageToResult(searchReadMessages,myTelegram[i],false);
514 results.push_back(res);550 results.push_back(res);
551 if (aggedByRecent)
552 break;// recent keyword aggregation only wants one message
515 }553 }
516 if (search_query.isEmpty() &&554 if (search_query.isEmpty() &&
517 (myTelegram[i].mediaType == MessageMediaType::typeMessageMediaPhoto ||555 (myTelegram[i].mediaType == MessageMediaType::typeMessageMediaPhoto ||
518 myTelegram[i].mediaType == MessageMediaType::typeMessageMediaVideo)) {556 myTelegram[i].mediaType == MessageMediaType::typeMessageMediaVideo)) {
519 auto res = messageToResult(photoCat,myTelegram[i],true);557 auto res = messageToResult(photoCat,myTelegram[i],true);
520 results.push_back(res);558 results.push_back(res);
559 if (aggedByRecent)
560 break;// recent keyword aggregation only wants one message
521 }561 }
522 }562 }
523 for (auto& mycontact: myBuddies) {563 for (auto& mycontact: myBuddies) {
564 if (aggedByRecent)
565 break;// recent keyword aggregation only wants one message
524 if ((mycontact.second.firstName.isEmpty() && mycontact.second.lastName.isEmpty()) ||566 if ((mycontact.second.firstName.isEmpty() && mycontact.second.lastName.isEmpty()) ||
525 mycontact.second.id == mOurId) {567 mycontact.second.id == mOurId) {
526 continue;568 continue;
@@ -536,6 +578,33 @@
536 results.insert(results.begin(),res);578 results.insert(results.begin(),res);
537 }579 }
538 }580 }
539 for (unsigned int i = 0; i < results.size(); i++)581 if (aggedByRecent){
582 auto res = results[0];
583 // open telegram scope instead of preview:
584 res.set_uri("scope://com.ubuntu.telegram_sctelegram");
585 // set up result as recent aggregation expects it
586 std::string title = res["title"].get_string();
587 res["title"] = res["from"];
588 unity::scopes::VariantBuilder attrs;
589 attrs.add_tuple({
590 {"value", unity::scopes::Variant(title)}
591 });
592 attrs.add_tuple({
593 {"value", unity::scopes::Variant("")}
594 });
595 attrs.add_tuple({
596 {"value", unity::scopes::Variant(res["date"])}
597 });
598 attrs.add_tuple({
599 {"value", unity::scopes::Variant("")}
600 });
601 res["attributes"] = attrs.end();
602 std::string icon = QString("file://%1/images/telegram.png").arg(mScopeDir).toStdString();
603 res["mascot"] = icon;
604 reply->push(res);
605 return;
606 }
607 for (unsigned int i = 0; i < results.size(); i++){
540 reply->push(results[i]);608 reply->push(results[i]);
609 }
541}610}
542611
=== modified file 'scope/src/query.h'
--- scope/src/query.h 2014-12-05 14:52:19 +0000
+++ scope/src/query.h 2015-06-03 13:43:06 +0000
@@ -2,8 +2,10 @@
2#define DEMOQUERY_H2#define DEMOQUERY_H
33
4#include <unity/scopes/SearchQueryBase.h>4#include <unity/scopes/SearchQueryBase.h>
5#include <unity/scopes/SearchMetadata.h>
5#include <unity/scopes/ReplyProxyFwd.h>6#include <unity/scopes/ReplyProxyFwd.h>
6#include <unity/scopes/CategorisedResult.h>7#include <unity/scopes/CategorisedResult.h>
8#include <unity/scopes/CategorisedResult.h>
7#include <QtSql>9#include <QtSql>
8#include <QSqlDatabase>10#include <QSqlDatabase>
9#include <QFileInfo>11#include <QFileInfo>
@@ -55,6 +57,7 @@
55 unity::scopes::CategorisedResult messageToResult(unity::scopes::Category::SCPtr category, TelegramMessage message,bool useAttachment);57 unity::scopes::CategorisedResult messageToResult(unity::scopes::Category::SCPtr category, TelegramMessage message,bool useAttachment);
56 unity::scopes::CategorisedResult contactToResult(unity::scopes::Category::SCPtr category, TelegramContact contact);58 unity::scopes::CategorisedResult contactToResult(unity::scopes::Category::SCPtr category, TelegramContact contact);
57 int getUnreadMessages(std::vector<TelegramMessage> & unreadMessages);59 int getUnreadMessages(std::vector<TelegramMessage> & unreadMessages);
60 unity::scopes::SearchMetadata mMetadata;
58};61};
5962
60#endif63#endif

Subscribers

People subscribed via source and target branches