Skip to content

Commit 5211817

Browse files
author
g8g3
committed
Solved conflict merging master into conversation-off.
2 parents 88719be + fa88297 commit 5211817

File tree

2 files changed

+154
-10
lines changed

2 files changed

+154
-10
lines changed

README.md

100644100755
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ gmail.get.user_email();
5656
- [gmail.get **.email_subject()**](#gmailgetemail_subject)
5757
- [gmail.get **.compose_ids()**](#gmailgetcompose_ids)
5858
- [gmail.get **.email_data(email_id=undefined)**](#gmailgetemail_dataemail_idundefined)
59+
- [gmail.get **.displayed_email_data()**](#gmailgetdisplayed_email_data)
5960
- [gmail.get **.search_query()**](#gmailgetsearch_query)
6061
- [gmail.get **.unread_emails()**](#gmailgetunread_emails)
6162
- [gmail.get **.unread_inbox_emails()**](#gmailgetunread_emails)
@@ -84,6 +85,7 @@ gmail.get.user_email();
8485
- [gmail.check **.is_vertical_split()**](#gmailcheckis_vertical_split)
8586
- [gmail.check **.is_tabbed_inbox()**](#gmailcheckis_tabbed_inbox)
8687
- [gmail.check **.is_right_side_chat()**](#gmailcheckis_right_side_chat)
88+
- [gmail.check **.is_conversation_view()**](#gmailcheckis_conversation_view)
8789
- [gmail.check **.is_google_apps_user()**](#gmailcheckis_google_apps_user)
8890
- [gmail.check **.is_priority_inbox()**](#gmailcheckis_priority_inbox)
8991
- [gmail.check **.is_rapportive_installed()**](#gmailcheckis_rapportive_installed)
@@ -156,6 +158,8 @@ These are some helper functions that the rest of the methods use. See source for
156158
- gmail.tools **.deparam()**
157159
- gmail.tools **.parse_view_data()**
158160
- gmail.tools **.parse_email_data()**
161+
- gmail.tools **.extract_email_address(str)**
162+
- gmail.tools **.extract_name(str)**
159163
- gmail.tools **.make_request()**
160164
- gmail.tools **.sleep(ms)**
161165
- gmail.tools **.multitry(ms_delay, tries, func, bool_success_check)**
@@ -231,6 +235,41 @@ the data for the specified id is returned instead of the email currently visible
231235
}
232236
```
233237

238+
#### gmail.get.displayed_email_data()
239+
240+
Returns an object representation of the emails that are being displayed.
241+
242+
```json
243+
{
244+
"first_email": "145881e7a8befff6",
245+
"last_email": "145881e7a8befff6",
246+
"total_emails": 1,
247+
"total_threads": ["145881e7a8befff6"],
248+
"people_involved": [
249+
["Kartik Talwar", "[email protected]"],
250+
["California", "[email protected]"]
251+
],
252+
"subject": "test",
253+
"threads": {
254+
"145881e7a8befff6": {
255+
"reply_to_id": "",
256+
"is_deleted" : false,
257+
"from": "California",
258+
"to" : ["[email protected]"],
259+
"cc" : [],
260+
"bcc" : [],
261+
"from_email": "[email protected]",
262+
"timestamp": 1382246359000,
263+
"datetime": "Sun, Nov 20, 2013 at 1:19 AM",
264+
"content_plain": "another test",
265+
"subject": "test",
266+
"content_html": "<div dir=\"ltr\">another test</div>\n"
267+
}
268+
}
269+
}
270+
271+
```
272+
234273
#### gmail.get.user_email()
235274

236275
Returns the current user's email address
@@ -393,6 +432,10 @@ Returns `True` if tabbed inbox view is enabled `False` otherwise
393432

394433
Returns `True` if chat is on the right sidebar `False` otherwise
395434

435+
#### gmail.check.is_conversation_view()
436+
437+
Returns `True` if emails are displayed as threads, `False` otherwise (i.e. displayed individually)
438+
396439
#### gmail.check.is_google_apps_user()
397440

398441
Returns `True` if the current user is google apps user (email not ending in gmail.com) `False` otherwise

src/gmail.js

Lines changed: 111 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ var Gmail = function() {
8989
var dom = api.dom.inbox_content();
9090
var box = dom.find("[gh=tl]").find('.nn');
9191

92-
return box.length == 0;
92+
return box.length == 0;
9393
}
9494

9595

@@ -126,13 +126,13 @@ var Gmail = function() {
126126

127127
api.dom.email_subject = function () {
128128
var e = $(".hP");
129-
129+
130130
for(var i=0; i<e.length; i++) {
131131
if($(e[i]).is(':visible')) {
132132
return $(e[i]);
133133
}
134134
};
135-
135+
136136
return $();
137137
}
138138

@@ -153,10 +153,10 @@ var Gmail = function() {
153153
if(api.get.current_page() != null && !api.check.is_preview_pane()) {
154154
return false;
155155
}
156-
156+
157157
var items = $('.ii.gt');
158158
var ids = [];
159-
159+
160160
for(var i=0; i<items.length; i++) {
161161
var mail_id = items[i].getAttribute('class').split(' ')[2];
162162
if(mail_id != 'undefined' && mail_id != undefined) {
@@ -165,7 +165,7 @@ var Gmail = function() {
165165
}
166166
}
167167
}
168-
168+
169169
return ids.length > 0;
170170
}
171171

@@ -195,7 +195,7 @@ var Gmail = function() {
195195
}
196196
return [];
197197
}
198-
198+
199199
api.get.compose_ids = function() {
200200
var ret = [];
201201
var dom = $(".AD [name=draft]");
@@ -531,7 +531,7 @@ var Gmail = function() {
531531

532532

533533
api.tools.parse_actions = function(params) {
534-
534+
535535
if(params.url.act == 'fup' || params.url.act == 'fuv' || typeof params.body == "object") {
536536
// a way to stop observers when files are being uploaded. See issue #22
537537
return;
@@ -576,7 +576,7 @@ var Gmail = function() {
576576
'refresh' : 'refresh',
577577
'rtr' : 'restore_message_in_thread',
578578
'open_email' : 'open_email',
579-
'toggle_threads' : 'toggle_threads'
579+
'toggle_threads' : 'toggle_threads'
580580
}
581581

582582
if(typeof params.url.ik == 'string') {
@@ -902,7 +902,7 @@ var Gmail = function() {
902902
top.css('visibility', 'visible').fadeTo(time, 0, function(){
903903
$(this).css("visibility", "hidden");
904904
$(this).css("opacity", "");
905-
});
905+
});
906906
}
907907
else{
908908
top.css('visibility', 'visible');
@@ -974,6 +974,107 @@ var Gmail = function() {
974974
}
975975

976976

977+
api.get.displayed_email_data = function() {
978+
var email_data = api.get.email_data();
979+
var displayed_email_data = {};
980+
981+
if (api.check.is_conversation_view()) {
982+
displayed_email_data = email_data;
983+
984+
var threads = displayed_email_data.threads;
985+
var total_threads = displayed_email_data.total_threads;
986+
987+
var hash = window.location.hash.split('#')[1] || '';
988+
var is_in_trash = (hash.indexOf('trash') === 0);
989+
990+
for (id in threads) {
991+
var email = threads[id];
992+
var keep_email = (is_in_trash) ? email.is_deleted : !email.is_deleted;
993+
994+
if (!keep_email) {
995+
delete threads[id];
996+
total_threads.splice(total_threads.indexOf(id), 1);
997+
displayed_email_data.total_emails--;
998+
// TODO: remove people involved only in this email.
999+
}
1000+
}
1001+
}
1002+
else { // Supposing only one displayed email.
1003+
for (id in email_data.threads) {
1004+
var displayed_email_element = $('.ii.gt[class*="' + id + '"]');
1005+
1006+
if (displayed_email_element.length > 0) {
1007+
var email = email_data.threads[id];
1008+
1009+
displayed_email_data.first_email = id;
1010+
displayed_email_data.last_email = id;
1011+
displayed_email_data.subject = email_data.subject;
1012+
1013+
displayed_email_data.threads = {};
1014+
displayed_email_data.threads[id] = email;
1015+
displayed_email_data.total_emails = 1;
1016+
displayed_email_data.total_threads = [id];
1017+
1018+
displayed_email_data.people_involved = [];
1019+
1020+
displayed_email_data.people_involved.push(
1021+
[email.from, email.from_email]
1022+
);
1023+
1024+
email.to.forEach(function(recipient) {
1025+
var address = api.tools.extract_email_address(recipient);
1026+
var name = api.tools.extract_name(recipient.replace(address, '')) || '';
1027+
1028+
displayed_email_data.people_involved.push(
1029+
[name, address]
1030+
);
1031+
});
1032+
1033+
break;
1034+
}
1035+
}
1036+
}
1037+
1038+
return displayed_email_data;
1039+
}
1040+
1041+
1042+
api.check.is_conversation_view = function() {
1043+
var flag_name = 'bx_vmb';
1044+
var flag_value = undefined;
1045+
1046+
var array_with_flag = api.tracker.globals[17][5][1];
1047+
1048+
for (var i = 0; i < array_with_flag.length; i++) {
1049+
var current = array_with_flag[i];
1050+
1051+
if (current[0] === flag_name) {
1052+
flag_value = current[1];
1053+
1054+
break;
1055+
}
1056+
}
1057+
1058+
return flag_value === '0' || flag_value === undefined;
1059+
}
1060+
1061+
1062+
api.tools.extract_email_address = function(str) {
1063+
var regex = /[\+a-z0-9._-]+@[a-z0-9._-]+\.[a-z0-9._-]+/gi;
1064+
var matches = (str) ? str.match(regex) : undefined;
1065+
1066+
return (matches) ? matches[0] : undefined;
1067+
}
1068+
1069+
1070+
api.tools.extract_name = function(str) {
1071+
var regex = /[a-z'._-\s]+/gi;
1072+
var matches = (str) ? str.match(regex) : undefined;
1073+
1074+
return (matches && matches[0]) ? matches[0].trim() : undefined;
1075+
}
1076+
1077+
9771078
api.tools.i18n = function(label) {
9781079
var locale = api.tracker.globals[17][9][8];
9791080
var dictionary;

0 commit comments

Comments
 (0)