@@ -969,7 +969,7 @@ var Gmail = function(localJQuery) {
969
969
api . check . data . is_thread_id = function ( id ) {
970
970
return id
971
971
&& typeof id === "string"
972
- && / ^ t h r e a d - a : / . test ( id ) ;
972
+ && / ^ t h r e a d - [ a | f ] : / . test ( id ) ;
973
973
} ;
974
974
975
975
api . check . data . is_thread = function ( obj ) {
@@ -982,7 +982,7 @@ var Gmail = function(localJQuery) {
982
982
api . check . data . is_email_id = function ( id ) {
983
983
return id
984
984
&& typeof id === "string"
985
- && / ^ m s g - a : / . test ( id ) ;
985
+ && / ^ m s g - [ a | f ] : / . test ( id ) ;
986
986
} ;
987
987
988
988
api . check . data . is_email = function ( obj ) {
@@ -992,6 +992,14 @@ var Gmail = function(localJQuery) {
992
992
&& api . check . data . is_email_id ( obj [ "1" ] ) ;
993
993
} ;
994
994
995
+ api . check . data . is_action = function ( obj ) {
996
+ return obj
997
+ && obj [ "1" ]
998
+ && Array . isArray ( obj [ "1" ] )
999
+ && obj [ "1" ] . length === 1
1000
+ && typeof obj [ "1" ] [ "0" ] === 'string' ;
1001
+ } ;
1002
+
995
1003
api . check . data . is_smartlabels_array = function ( obj ) {
996
1004
const isNotArray = ! obj || ! Array . isArray ( obj ) || obj . length === 0 ;
997
1005
if ( isNotArray ) {
@@ -1021,7 +1029,32 @@ var Gmail = function(localJQuery) {
1021
1029
1022
1030
let str = obj . trim ( ) ;
1023
1031
return ( ( str . startsWith ( "{" ) && str . endsWith ( "}" ) )
1024
- || ( str . startsWith ( "[" ) && str . endsWith ( "]" ) ) ) ;
1032
+ || ( str . startsWith ( "[" ) && str . endsWith ( "]" ) ) ) ;
1033
+ } ;
1034
+
1035
+ api . tools . get_thread_id = function ( obj ) {
1036
+ return api . check . data . is_thread ( obj )
1037
+ && obj [ "1" ] ;
1038
+ } ;
1039
+
1040
+ api . tools . get_thread_data = function ( obj ) {
1041
+ return obj
1042
+ && obj [ "2" ]
1043
+ && typeof obj [ "2" ] === "object"
1044
+ && obj [ "2" ] [ "7" ]
1045
+ && typeof obj [ "2" ] [ "7" ] === "object"
1046
+ && obj [ "2" ] [ "7" ] ;
1047
+ } ;
1048
+
1049
+ api . tools . get_action_type = function ( obj ) {
1050
+ return obj [ 1 ] [ 0 ] ;
1051
+ } ;
1052
+
1053
+ api . tools . get_message_ids = function ( obj ) {
1054
+ return obj
1055
+ && obj [ "3" ]
1056
+ && Array . isArray ( obj [ "3" ] )
1057
+ && obj [ "3" ] ;
1025
1058
} ;
1026
1059
1027
1060
api . tools . extract_from_graph = function ( obj , predicate ) {
@@ -1067,6 +1100,52 @@ var Gmail = function(localJQuery) {
1067
1100
return result ;
1068
1101
} ;
1069
1102
1103
+ api . tools . check_event_type = function ( threadObj ) {
1104
+ const action_map = {
1105
+ // "" : "add_to_tasks",
1106
+ "^a" : "archive" ,
1107
+ "^k" : "delete" ,
1108
+ // "" : "delete_message_in_thread",
1109
+ // "" : "delete_forever",
1110
+ // "" : "delete_label",
1111
+ // "" : "discard_draft",
1112
+ // "" : "expand_categories",
1113
+ // "" : "filter_messages_like_these",
1114
+ // "" : "label",
1115
+ // "" : "mark_as_important",
1116
+ // "" : "mark_as_not_important",
1117
+ // "" : "mark_as_not_spam",
1118
+ // "" : "mark_as_spam",
1119
+ // "" : "move_label",
1120
+ // "" : "move_to_inbox",
1121
+ // "" : "mute",
1122
+ // "" : "read",
1123
+ // "" : "save_draft",
1124
+ // "" : "send_message",
1125
+ // "" : "show_newly_arrived_message",
1126
+ // "" : "star",
1127
+ // "" : "undo_send",
1128
+ // "" : "unmute",
1129
+ // "" : "unread",
1130
+ // "" : "unstar",
1131
+ // "" : "new_email",
1132
+ // "" : "poll",
1133
+ // "" : "refresh",
1134
+ // "" : "restore_message_in_thread",
1135
+ // "" : "open_email",
1136
+ // "" : "toggle_threads"
1137
+ } ;
1138
+ const threadData = api . tools . get_thread_data ( threadObj ) ;
1139
+
1140
+ if ( threadData && api . check . data . is_action ( threadData ) ) {
1141
+ const action = api . tools . get_action_type ( threadData ) ;
1142
+
1143
+ return action_map [ action ] ;
1144
+ } else {
1145
+ return null ;
1146
+ }
1147
+ } ;
1148
+
1070
1149
api . tools . parse_request_payload = function ( params , events ) {
1071
1150
const threads = api . tools . extract_from_graph ( params , api . check . data . is_thread ) ;
1072
1151
// console.log("Threads:");
@@ -1089,6 +1168,23 @@ var Gmail = function(localJQuery) {
1089
1168
}
1090
1169
}
1091
1170
}
1171
+
1172
+ try {
1173
+ if ( Array . isArray ( threads ) && api . check . data . is_thread ( threads [ 0 ] ) ) {
1174
+ const actionType = api . tools . check_event_type ( threads [ 0 ] ) ;
1175
+
1176
+ if ( actionType ) {
1177
+ // console.log(threads[0]);
1178
+ const threadsData = threads . map ( thread => api . tools . get_thread_data ( thread ) ) ;
1179
+
1180
+ const new_thread_ids = threads . map ( thread => api . tools . get_thread_id ( thread ) ) ;
1181
+ const new_email_ids = threadsData . map ( threadData => api . tools . get_message_ids ( threadData ) ) . reduce ( ( a , b ) => a . concat ( b ) , [ ] ) ;
1182
+ events [ actionType ] = [ null , params . url , params . body , new_email_ids , new_thread_ids ] ;
1183
+ }
1184
+ }
1185
+ } catch ( e ) {
1186
+ console . error ( 'Error: ' , e ) ;
1187
+ }
1092
1188
} ;
1093
1189
1094
1190
api . tools . parse_response = function ( response ) {
@@ -1255,7 +1351,7 @@ var Gmail = function(localJQuery) {
1255
1351
}
1256
1352
1257
1353
// if any matching after events, bind onreadystatechange callback
1258
- if ( api . observe . bound ( events , "after" ) ) {
1354
+ if ( api . observe . bound ( events , "after" ) ) {
1259
1355
var curr_onreadystatechange = this . onreadystatechange ;
1260
1356
var xhr = this ;
1261
1357
this . onreadystatechange = function ( progress ) {
@@ -1943,7 +2039,7 @@ var Gmail = function(localJQuery) {
1943
2039
if ( start ) {
1944
2040
start = parseInt ( start - 1 ) ;
1945
2041
url += "&start=" + start +
1946
- "&sstart=" + start ;
2042
+ "&sstart=" + start ;
1947
2043
} else {
1948
2044
url += "&start=0" ;
1949
2045
}
@@ -2529,8 +2625,8 @@ var Gmail = function(localJQuery) {
2529
2625
var button = $ ( document . createElement ( "div" ) ) ;
2530
2626
var buttonClasses = "T-I J-J5-Ji " ;
2531
2627
if ( styleClass !== undefined &&
2532
- styleClass !== null &&
2533
- styleClass !== "" ) {
2628
+ styleClass !== null &&
2629
+ styleClass !== "" ) {
2534
2630
buttonClasses += basicStyle + styleClass ;
2535
2631
} else {
2536
2632
buttonClasses += basicStyle + defaultStyle ;
0 commit comments