Update pushed flags without requesting from server

This commit is contained in:
Hadi Nategh 2020-08-05 15:38:14 +02:00
parent 67fa46ce96
commit f776b523ee
7 changed files with 129 additions and 69 deletions

View File

@ -1955,19 +1955,19 @@ $filter['before']= date("d-M-Y", $cutoffdate2);
$css_styles[] = 'forwarded';
}
if ($header['label1']) {
$css_styles[] = 'labelone';
$css_styles[] = 'label1';
}
if ($header['label2']) {
$css_styles[] = 'labeltwo';
$css_styles[] = 'label2';
}
if ($header['label3']) {
$css_styles[] = 'labelthree';
$css_styles[] = 'label3';
}
if ($header['label4']) {
$css_styles[] = 'labelfour';
$css_styles[] = 'label4';
}
if ($header['label5']) {
$css_styles[] = 'labelfive';
$css_styles[] = 'label5';
}
//error_log(__METHOD__.array2string($css_styles));
@ -2087,11 +2087,11 @@ $filter['before']= date("d-M-Y", $cutoffdate2);
foreach ($css_styles as &$flag) {
if ($flag!='mail')
{
if ($flag=='labelone') {$data["flags"]['label1'] = 'label1';}
elseif ($flag=='labeltwo') {$data["flags"]['label2'] = 'label2';}
elseif ($flag=='labelthree') {$data["flags"]['label3'] = 'label3';}
elseif ($flag=='labelfour') {$data["flags"]['label4'] = 'label4';}
elseif ($flag=='labelfive') {$data["flags"]['label5'] = 'label5';}
if ($flag=='label1') {$data["flags"]['label1'] = 'label1';}
elseif ($flag=='label2') {$data["flags"]['label2'] = 'label2';}
elseif ($flag=='label3') {$data["flags"]['label3'] = 'label3';}
elseif ($flag=='label4') {$data["flags"]['label4'] = 'label4';}
elseif ($flag=='label5') {$data["flags"]['label5'] = 'label5';}
elseif ($flag=='unseen') {unset($data["flags"]['read']);}
else $data["flags"][$flag] = $flag;
}

View File

@ -84,6 +84,11 @@ app.classes.mail = AppJS.extend(
*/
image_proxy: 'https://',
/**
* stores push activated acc ids
*/
push_active: {},
/**
* Initialize javascript for this application
*
@ -165,7 +170,7 @@ app.classes.mail = AppJS.extend(
// call parent; somehow this function is called more often. (twice on a display and compose) why?
this._super.apply(this, arguments);
this.et2_obj = et2;
this.push_active = {};
switch (_name)
{
case 'mail.sieve.vacation':
@ -193,7 +198,7 @@ app.classes.mail = AppJS.extend(
{
var self = this;
jQuery(nm).on('refresh',function(_event, _widget, _row_id, _type) {
if (_type !== 'update-in-place')
if (!self.push_active[_widget.settings.foldertree.split("::")[0]])
{
self.mail_refreshFolderStatus.call(self,undefined,undefined,false);
}
@ -398,6 +403,11 @@ app.classes.mail = AppJS.extend(
// don't care about other apps data, reimplement if your app does care eg. calendar
if (pushData.app !== this.appname) return;
let id0 = typeof pushData.id === 'string' ? pushData.id : pushData.id[0];
let acc_id = id0.split('::')[1];
let folder = acc_id+'::'+atob(id0.split('::')[2]);
this.push_active[acc_id] = true;
// only handle delete by default, for simple case of uid === "$app::$id"
if (pushData.type === 'delete')
{
@ -416,17 +426,26 @@ app.classes.mail = AppJS.extend(
// check if we might not see it because we are on a different mail account or folder
let nm = this.et2 ? this.et2.getWidgetById('nm') : null;
let nm_value = nm ? nm.getValue() : null;
let id0 = typeof pushData.id === 'string' ? pushData.id : pushData.id[0];
let folder = id0.split('::')[1]+'::'+atob(id0.split('::')[2]);
// nm_value.selectedFolder is not always set, read it from foldertree, if not
let foldertree = this.et2 ? this.et2.getWidgetById('nm[foldertree]') : null;
let displayed_folder = (nm_value ? nm_value.selectedFolder : null) || (foldertree ? foldertree.getValue() : '');
if (!displayed_folder.match(/::/)) displayed_folder += '::INBOX';
if (folder === displayed_folder)
{
switch(pushData.acl.event)
{
case 'FlagsSet':
this.pushUpdateFlags(pushData);
break;
case 'FlagsClear':
this.pushUpdateFlags(pushData);
break;
default:
// Just update the nm (todo: pushData.message = total number of messages in folder)
nm.refresh(pushData.id, pushData.type === 'update' ? 'update-in-place' : pushData.type, pushData.messages);
}
}
// update unseen counter in folder-tree
if (pushData.acl.folder && typeof pushData.acl.unseen !== 'undefined')
{
@ -454,6 +473,47 @@ app.classes.mail = AppJS.extend(
}
},
/**
* Updates flags on respective rows
*
* @param {type} pushData
*/
pushUpdateFlags: function(pushData)
{
let flag = pushData.acl.flags[0] || pushData.acl.keywords[0];
let unset = (pushData.acl.flags_old && pushData.acl.flags_old.indexOf(pushData.acl.flags[0]) > -1)
|| (pushData.acl.keywords_old && pushData.acl.keywords_old.indexOf(pushData.acl.keywords[0]) > -1) ? true : false;
let rowClass = '';
if (flag[0] == '\\' || flag[0] == '$') flag = flag.slice(1).toLowerCase();
let ids = typeof pushData.id == "string" ? [pushData.id] : pushData.id;
for (let i in ids)
{
let msg = {msg:['mail::'+ids[i]]};
switch(flag)
{
case 'seen':
this.mail_removeRowClass(msg, (unset) ? 'seen' : 'unseen');
rowClass = (unset) ? 'unseen' : 'seen';
break;
case 'label1':
case 'label2':
case 'label3':
case 'label4':
case 'label5':
if (unset)
{
this.mail_removeRowClass(msg, flag);
}
else
{
rowClass = flag;
}
break;
}
this.mail_setRowClass(msg, rowClass);
}
},
/**
* Observer method receives update notifications from all applications
*
@ -2566,19 +2626,19 @@ app.classes.mail = AppJS.extend(
rowClass = 'seen';
break;
case 'label1':
rowClass = 'labelone';
rowClass = 'label1';
break;
case 'label2':
rowClass = 'labeltwo';
rowClass = 'label2';
break;
case 'label3':
rowClass = 'labelthree';
rowClass = 'label3';
break;
case 'label4':
rowClass = 'labelfour';
rowClass = 'label4';
break;
case 'label5':
rowClass = 'labelfive';
rowClass = 'label5';
break;
default:
break;
@ -2590,7 +2650,7 @@ app.classes.mail = AppJS.extend(
//old style, only available for undelete and unlabel (no toggle)
if ( _action.id=='unlabel') // this means all labels should be removed
{
var labels = ['labelone','labeltwo','labelthree','labelfour','labelfive'];
var labels = ['label1','label2','label3','label4','label5'];
for (var i=0; i<labels.length; i++) this.mail_removeRowClass(_elems,labels[i]);
this.mail_flagMessages(_action.id,data);
}

View File

@ -37,19 +37,19 @@ tr.unseen a {
font-weight: bold;
}
tr.mail.labelone td:first-child{
tr.mail.label1 td:first-child{
border-left:6px solid #ff0080 !important;
}
tr.mail.labeltwo td:first-child{
tr.mail.label2 td:first-child{
border-left:6px solid #ff8000 !important;
}
tr.mail.labelthree td:first-child{
tr.mail.label3 td:first-child{
border-left:6px solid #008000 !important;
}
tr.mail.labelfour td:first-child{
tr.mail.label4 td:first-child{
border-left: 6px solid #0000ff !important;
}
tr.mail.labelfive td:first-child{
tr.mail.label5 td:first-child{
border-left: 6px solid #8000ff !important;
}

View File

@ -68,19 +68,19 @@ tr.unseen a {
color: #003075;
font-weight: bold;
}
tr.mail.labelone td:first-child {
tr.mail.label1 td:first-child {
border-left: 6px solid #ff0080 !important;
}
tr.mail.labeltwo td:first-child {
tr.mail.label2 td:first-child {
border-left: 6px solid #ff8000 !important;
}
tr.mail.labelthree td:first-child {
tr.mail.label3 td:first-child {
border-left: 6px solid #008000 !important;
}
tr.mail.labelfour td:first-child {
tr.mail.label4 td:first-child {
border-left: 6px solid #0000ff !important;
}
tr.mail.labelfive td:first-child {
tr.mail.label5 td:first-child {
border-left: 6px solid #8000ff !important;
}
tr.mail.flagged td:first-child {
@ -472,7 +472,7 @@ div#mail-index_mailPreview > div {
border: none;
}
#mail-compose_composeToolbar > button {
padding: 0.2em 0.4em;
padding: .2em .4em;
}
#mail-compose_composeToolbar > img {
width: 16px;
@ -485,7 +485,7 @@ div#mail-index_mailPreview > div {
height: 16px !important;
}
#mail-compose_composeToolbar > button {
padding: 0.2em 0.4em;
padding: .2em .4em;
}
#mail-compose_to div.ms-sel-ctn,
#mail-compose_cc .ms-sel-ctn,
@ -493,7 +493,7 @@ div#mail-index_mailPreview > div {
max-height: 75px;
}
#mail-display_toolbar > button > span {
padding: 0.2em 0.4em;
padding: .2em .4em;
}
#mail-display_toolbar > button > span > img {
width: 16px;
@ -516,7 +516,7 @@ div#mail-index_mailPreview > div {
height: 35px;
}
#mail-index_toolbar > button > span {
padding: 0.2em 0.4em;
padding: .2em .4em;
}
#mail-index_toolbar > button > span > img {
width: 16px;
@ -1625,19 +1625,19 @@ tr.unseen a {
color: #003075;
font-weight: bold;
}
tr.mail.labelone td:first-child {
tr.mail.label1 td:first-child {
border-left: 6px solid #ff0080 !important;
}
tr.mail.labeltwo td:first-child {
tr.mail.label2 td:first-child {
border-left: 6px solid #ff8000 !important;
}
tr.mail.labelthree td:first-child {
tr.mail.label3 td:first-child {
border-left: 6px solid #008000 !important;
}
tr.mail.labelfour td:first-child {
tr.mail.label4 td:first-child {
border-left: 6px solid #0000ff !important;
}
tr.mail.labelfive td:first-child {
tr.mail.label5 td:first-child {
border-left: 6px solid #8000ff !important;
}
tr.mail.flagged td:first-child {
@ -1893,7 +1893,7 @@ input[type=button] {
padding: 0px;
}
#mail-display_toolbar > button > span {
padding: 0.2em 0.4em;
padding: .2em .4em;
}
#mail-display_toolbar > button > span > img {
width: 16px;
@ -2308,19 +2308,19 @@ table#mail-index_previewAttachmentArea::-webkit-scrollbar-thumb:hover {
#mail-index table.egwGridView_outer tbody tr span.mail.mobile_cat_col {
background: #F5F5F5;
}
#mail-index table.egwGridView_outer tbody tr span.mail.labelone.mobile_cat_col {
#mail-index table.egwGridView_outer tbody tr span.mail.label1.mobile_cat_col {
background: #ff0080;
}
#mail-index table.egwGridView_outer tbody tr span.mail.labeltwo.mobile_cat_col {
#mail-index table.egwGridView_outer tbody tr span.mail.label2.mobile_cat_col {
background: #ff8000;
}
#mail-index table.egwGridView_outer tbody tr span.mail.labelthree.mobile_cat_col {
#mail-index table.egwGridView_outer tbody tr span.mail.label3.mobile_cat_col {
background: #008000;
}
#mail-index table.egwGridView_outer tbody tr span.mail.labelfour.mobile_cat_col {
#mail-index table.egwGridView_outer tbody tr span.mail.label4.mobile_cat_col {
background: #0000ff;
}
#mail-index table.egwGridView_outer tbody tr span.mail.labelfive.mobile_cat_col {
#mail-index table.egwGridView_outer tbody tr span.mail.label5.mobile_cat_col {
background: #8000ff;
}
#mail-index table.egwGridView_outer tbody tr span.mail.flagged.mobile_cat_col {

View File

@ -266,19 +266,19 @@
span.mail.mobile_cat_col {
background: #F5F5F5;
}
span.mail.labelone.mobile_cat_col {
span.mail.label1.mobile_cat_col {
background: #ff0080;
}
span.mail.labeltwo.mobile_cat_col{
span.mail.label2.mobile_cat_col{
background: #ff8000;
}
span.mail.labelthree.mobile_cat_col {
span.mail.label3.mobile_cat_col {
background: #008000;
}
span.mail.labelfour.mobile_cat_col {
span.mail.label4.mobile_cat_col {
background: #0000ff;
}
span.mail.labelfive.mobile_cat_col {
span.mail.label5.mobile_cat_col {
background: #8000ff;
}

View File

@ -56,19 +56,19 @@ tr.unseen a {
color: #003075;
font-weight: bold;
}
tr.mail.labelone td:first-child {
tr.mail.label1 td:first-child {
border-left: 6px solid #ff0080 !important;
}
tr.mail.labeltwo td:first-child {
tr.mail.label2 td:first-child {
border-left: 6px solid #ff8000 !important;
}
tr.mail.labelthree td:first-child {
tr.mail.label3 td:first-child {
border-left: 6px solid #008000 !important;
}
tr.mail.labelfour td:first-child {
tr.mail.label4 td:first-child {
border-left: 6px solid #0000ff !important;
}
tr.mail.labelfive td:first-child {
tr.mail.label5 td:first-child {
border-left: 6px solid #8000ff !important;
}
tr.mail.flagged td:first-child {
@ -1613,19 +1613,19 @@ tr.unseen a {
color: #003075;
font-weight: bold;
}
tr.mail.labelone td:first-child {
tr.mail.label1 td:first-child {
border-left: 6px solid #ff0080 !important;
}
tr.mail.labeltwo td:first-child {
tr.mail.label2 td:first-child {
border-left: 6px solid #ff8000 !important;
}
tr.mail.labelthree td:first-child {
tr.mail.label3 td:first-child {
border-left: 6px solid #008000 !important;
}
tr.mail.labelfour td:first-child {
tr.mail.label4 td:first-child {
border-left: 6px solid #0000ff !important;
}
tr.mail.labelfive td:first-child {
tr.mail.label5 td:first-child {
border-left: 6px solid #8000ff !important;
}
tr.mail.flagged td:first-child {

View File

@ -700,19 +700,19 @@ tr.unseen a {
font-weight: bold;
}
tr.mail.labelone td:first-child {
tr.mail.label1 td:first-child {
border-left:6px solid #ff0080 !important;
}
tr.mail.labeltwo td:first-child {
tr.mail.label2 td:first-child {
border-left:6px solid #ff8000 !important;
}
tr.mail.labelthree td:first-child {
tr.mail.label3 td:first-child {
border-left:6px solid #008000 !important;
}
tr.mail.labelfour td:first-child {
tr.mail.label4 td:first-child {
border-left:6px solid #0000ff !important;
}
tr.mail.labelfive td:first-child {
tr.mail.label5 td:first-child {
border-left:6px solid #8000ff !important;
}