@@ -23,7 +23,6 @@ import {
23
23
Contact ,
24
24
ContactTypeRef ,
25
25
createDefaultAlarmInfo ,
26
- createGroupSettings ,
27
26
GroupSettings ,
28
27
UserSettingsGroupRoot ,
29
28
} from "../../../common/api/entities/tutanota/TypeRefs.js"
@@ -101,7 +100,7 @@ import { CalendarEventPreviewViewModel } from "../gui/eventpopup/CalendarEventPr
101
100
import { client } from "../../../common/misc/ClientDetector.js"
102
101
import { FloatingActionButton } from "../../gui/FloatingActionButton.js"
103
102
import { Icon , IconSize , progressIcon } from "../../../common/gui/base/Icon.js"
104
- import { Group , GroupInfo , User } from "../../../common/api/entities/sys/TypeRefs.js"
103
+ import { Group , User } from "../../../common/api/entities/sys/TypeRefs.js"
105
104
import { formatDate , formatTime } from "../../../common/misc/Formatter.js"
106
105
import { getExternalCalendarName , parseCalendarStringData , SyncStatus } from "../../../common/calendar/gui/ImportExportUtils.js"
107
106
import type { ParsedEvent } from "../../../common/calendar/gui/CalendarImporter.js"
@@ -945,7 +944,7 @@ export class CalendarView extends BaseTopLevelView implements TopLevelView<Calen
945
944
946
945
private showCreateCalendarDialog ( calendarType : CalendarType ) {
947
946
const createNormalCalendar = async ( dialog : Dialog , properties : CalendarProperties , calendarModel : CalendarModel ) => {
948
- await calendarModel . createCalendar ( properties . name , properties . color , properties . alarms , null )
947
+ await calendarModel . createCalendar ( properties . nameData . name , properties . color , properties . alarms , null )
949
948
dialog . close ( )
950
949
}
951
950
const createExternalCalendar = async ( dialog : Dialog , properties : CalendarProperties , calendarModel : CalendarModel ) => {
@@ -979,7 +978,6 @@ export class CalendarView extends BaseTopLevelView implements TopLevelView<Calen
979
978
showCreateEditCalendarDialog ( {
980
979
calendarType,
981
980
titleTextId : "add_action" ,
982
- shared : false ,
983
981
okAction : createNormalCalendar ,
984
982
okTextId : "save_action" ,
985
983
calendarModel : this . viewModel . getCalendarModel ( ) ,
@@ -989,7 +987,6 @@ export class CalendarView extends BaseTopLevelView implements TopLevelView<Calen
989
987
showCreateEditCalendarDialog ( {
990
988
calendarType,
991
989
titleTextId : "newCalendarSubscriptionsDialog_title" ,
992
- shared : false ,
993
990
okAction : createExternalCalendar ,
994
991
okTextId : "subscribe_action" ,
995
992
warningMessage : ( ) => m ( ".smaller.content-fg" , lang . get ( "externalCalendarInfo_msg" ) ) ,
@@ -1032,16 +1029,11 @@ export class CalendarView extends BaseTopLevelView implements TopLevelView<Calen
1032
1029
} )
1033
1030
1034
1031
return filteredCalendarInfos . map ( ( [ _ , calendarInfo ] ) => {
1035
- return this . renderCalendarItem ( calendarInfo , calendarInfo . shared , toggleHidden , this . viewModel . hiddenCalendars . has ( calendarInfo . group . _id ) )
1032
+ return this . renderCalendarItem ( calendarInfo , toggleHidden , this . viewModel . hiddenCalendars . has ( calendarInfo . group . _id ) )
1036
1033
} )
1037
1034
}
1038
1035
1039
- private renderCalendarItem (
1040
- calendarInfo : CalendarInfo ,
1041
- shared : boolean ,
1042
- toggleHidden : ( viewModel : CalendarViewModel , groupRootId : string ) => void ,
1043
- isHidden : boolean ,
1044
- ) {
1036
+ private renderCalendarItem ( calendarInfo : CalendarInfo , toggleHidden : ( viewModel : CalendarViewModel , groupRootId : string ) => void , isHidden : boolean ) {
1045
1037
const { userSettingsGroupRoot } = locator . logins . getUserController ( )
1046
1038
const existingGroupSettings = userSettingsGroupRoot . groupSettings . find ( ( gc ) => gc . group === calendarInfo . groupInfo . group ) ?? null
1047
1039
@@ -1111,7 +1103,7 @@ export class CalendarView extends BaseTopLevelView implements TopLevelView<Calen
1111
1103
} ,
1112
1104
} )
1113
1105
: null ,
1114
- this . createCalendarActionDropdown ( calendarInfo , colorValue ?? defaultCalendarColor , existingGroupSettings , userSettingsGroupRoot , shared ) ,
1106
+ this . createCalendarActionDropdown ( calendarInfo , colorValue ?? defaultCalendarColor , existingGroupSettings , userSettingsGroupRoot ) ,
1115
1107
] )
1116
1108
}
1117
1109
@@ -1120,7 +1112,6 @@ export class CalendarView extends BaseTopLevelView implements TopLevelView<Calen
1120
1112
colorValue : string ,
1121
1113
existingGroupSettings : GroupSettings | null ,
1122
1114
userSettingsGroupRoot : UserSettingsGroupRoot ,
1123
- sharedCalendar : boolean ,
1124
1115
) : Children {
1125
1116
const { group, groupInfo, groupRoot, isExternal } = calendarInfo
1126
1117
const user = locator . logins . getUserController ( ) . user
@@ -1136,7 +1127,7 @@ export class CalendarView extends BaseTopLevelView implements TopLevelView<Calen
1136
1127
label : "edit_action" ,
1137
1128
icon : Icons . Edit ,
1138
1129
size : ButtonSize . Compact ,
1139
- click : ( ) => this . onPressedEditCalendar ( groupInfo , colorValue , existingGroupSettings , userSettingsGroupRoot , sharedCalendar ) ,
1130
+ click : ( ) => this . onPressedEditCalendar ( calendarInfo , colorValue , existingGroupSettings , userSettingsGroupRoot ) ,
1140
1131
} ,
1141
1132
! isExternal && ! isClientOnly
1142
1133
? {
@@ -1146,7 +1137,7 @@ export class CalendarView extends BaseTopLevelView implements TopLevelView<Calen
1146
1137
if ( locator . logins . getUserController ( ) . isFreeAccount ( ) ) {
1147
1138
showNotAvailableForFreeDialog ( )
1148
1139
} else {
1149
- showGroupSharingDialog ( groupInfo , sharedCalendar )
1140
+ showGroupSharingDialog ( groupInfo , calendarInfo . shared )
1150
1141
}
1151
1142
} ,
1152
1143
}
@@ -1166,7 +1157,7 @@ export class CalendarView extends BaseTopLevelView implements TopLevelView<Calen
1166
1157
const alarmInfoList = user . alarmInfoList
1167
1158
if ( alarmInfoList ) {
1168
1159
exportCalendar (
1169
- getSharedGroupName ( groupInfo , locator . logins . getUserController ( ) , sharedCalendar ) ,
1160
+ getSharedGroupName ( groupInfo , locator . logins . getUserController ( ) , calendarInfo . shared ) ,
1170
1161
groupRoot ,
1171
1162
alarmInfoList . alarms ,
1172
1163
new Date ( ) ,
@@ -1234,13 +1225,13 @@ export class CalendarView extends BaseTopLevelView implements TopLevelView<Calen
1234
1225
} )
1235
1226
}
1236
1227
1237
- private onPressedEditCalendar (
1238
- groupInfo : GroupInfo ,
1228
+ private async onPressedEditCalendar (
1229
+ calendarInfo : CalendarInfo ,
1239
1230
colorValue : string ,
1240
1231
existingGroupSettings : GroupSettings | null ,
1241
1232
userSettingsGroupRoot : UserSettingsGroupRoot ,
1242
- shared : boolean ,
1243
1233
) {
1234
+ const { groupInfo } = calendarInfo
1244
1235
if ( isClientOnlyCalendar ( groupInfo . group ) && ! this . viewModel . isNewPaidPlan ) {
1245
1236
showPlanUpgradeRequiredDialog ( NewPaidPlans )
1246
1237
return
@@ -1249,11 +1240,10 @@ export class CalendarView extends BaseTopLevelView implements TopLevelView<Calen
1249
1240
showCreateEditCalendarDialog ( {
1250
1241
calendarType : getCalendarType ( existingGroupSettings , groupInfo ) ,
1251
1242
titleTextId : "edit_action" ,
1252
- shared,
1253
- okAction : ( dialog , properties ) => this . handleModifiedCalendar ( dialog , properties , shared , groupInfo , existingGroupSettings , userSettingsGroupRoot ) ,
1243
+ okAction : ( dialog , properties ) => this . handleModifiedCalendar ( dialog , properties , calendarInfo , existingGroupSettings , userSettingsGroupRoot ) ,
1254
1244
okTextId : "save_action" ,
1255
1245
calendarProperties : {
1256
- name : getSharedGroupName ( groupInfo , locator . logins . getUserController ( ) , shared ) ,
1246
+ nameData : await this . viewModel . getCalendarNameData ( calendarInfo . groupInfo ) ,
1257
1247
color : colorValue . substring ( 1 ) ,
1258
1248
alarms : existingGroupSettings ?. defaultAlarmsList . map ( ( alarm ) => parseAlarmInterval ( alarm . trigger ) ) ?? [ ] ,
1259
1249
sourceUrl : existingGroupSettings ?. sourceUrl ?? null ,
@@ -1266,58 +1256,53 @@ export class CalendarView extends BaseTopLevelView implements TopLevelView<Calen
1266
1256
private handleModifiedCalendar (
1267
1257
dialog : Dialog ,
1268
1258
properties : CalendarProperties ,
1269
- shared : boolean ,
1270
- groupInfo : GroupInfo ,
1259
+ calendarInfo : CalendarInfo ,
1271
1260
existingGroupSettings : GroupSettings | null ,
1272
1261
userSettingsGroupRoot : UserSettingsGroupRoot ,
1273
1262
) {
1263
+ const { groupInfo, shared, userIsOwner } = calendarInfo
1264
+
1274
1265
const clientOnlyCalendar = isClientOnlyCalendar ( groupInfo . group )
1275
- if ( ! shared && ! clientOnlyCalendar ) {
1276
- // User is the owner, so we update the entity instead of groupSettings
1277
- groupInfo . name = properties . name
1278
- locator . entityClient . update ( groupInfo )
1279
- }
1280
1266
1281
- const shouldSyncExternal = ! ! ( existingGroupSettings && hasSourceUrl ( existingGroupSettings ) && existingGroupSettings . sourceUrl !== properties . sourceUrl )
1282
- const alarms = properties . alarms . map ( ( alarm ) => createDefaultAlarmInfo ( { trigger : serializeAlarmInterval ( alarm ) } ) )
1283
- // color always set for existing calendar
1284
- if ( existingGroupSettings ) {
1285
- existingGroupSettings . color = properties . color
1286
- existingGroupSettings . name = shared && properties . name !== groupInfo . name ? properties . name : null
1287
- existingGroupSettings . defaultAlarmsList = alarms
1288
- existingGroupSettings . sourceUrl = properties . sourceUrl
1289
- } else if ( clientOnlyCalendar ) {
1290
- this . viewModel . handleClientOnlyUpdate ( groupInfo , downcast ( { name : properties . name , color : properties . color } ) )
1267
+ if ( clientOnlyCalendar ) {
1268
+ this . viewModel . handleClientOnlyUpdate ( groupInfo , { name : properties . nameData . name , color : properties . color } )
1291
1269
dialog . close ( )
1292
1270
return this . viewModel . redraw ( undefined )
1293
1271
} else {
1294
- const newGroupSettings = createGroupSettings ( {
1295
- group : groupInfo . group ,
1296
- color : properties . color ,
1297
- name : shared && properties . name !== groupInfo . name ? properties . name : null ,
1298
- defaultAlarmsList : alarms ,
1299
- sourceUrl : properties . sourceUrl ,
1300
- } )
1301
-
1302
- userSettingsGroupRoot . groupSettings . push ( newGroupSettings )
1303
- }
1272
+ if ( userIsOwner ) {
1273
+ // if it is a shared calendar and the shared name has been changed the entity needs to be updated
1274
+ // the name on the entity is what is shared with everyone
1275
+ this . viewModel . setCalendarGroupInfoName ( groupInfo , properties . nameData . name )
1276
+ }
1304
1277
1305
- locator . entityClient
1306
- . update ( userSettingsGroupRoot )
1307
- . then ( ( ) => {
1308
- if ( shouldSyncExternal )
1309
- this . viewModel . forceSyncExternal ( existingGroupSettings ) ?. catch ( async ( e ) => {
1310
- showSnackBar ( {
1311
- message : lang . makeTranslation ( "exception_msg" , e . message ) ,
1312
- button : {
1313
- label : "ok_action" ,
1314
- click : noOp ,
1315
- } ,
1316
- waitingTime : 500 ,
1278
+ const shouldSyncExternal = ! ! (
1279
+ existingGroupSettings &&
1280
+ hasSourceUrl ( existingGroupSettings ) &&
1281
+ existingGroupSettings . sourceUrl !== properties . sourceUrl
1282
+ )
1283
+ const alarms = properties . alarms . map ( ( alarm ) => createDefaultAlarmInfo ( { trigger : serializeAlarmInterval ( alarm ) } ) )
1284
+ this . viewModel
1285
+ . setCalendarGroupSettings ( groupInfo , {
1286
+ color : properties . color ,
1287
+ name : properties . nameData . kind === "shared" ? properties . nameData . customName : null ,
1288
+ defaultAlarmsList : alarms ,
1289
+ sourceUrl : properties . sourceUrl ,
1290
+ } )
1291
+ . then ( ( ) => {
1292
+ if ( shouldSyncExternal )
1293
+ this . viewModel . forceSyncExternal ( existingGroupSettings ) ?. catch ( async ( e ) => {
1294
+ showSnackBar ( {
1295
+ message : lang . makeTranslation ( "exception_msg" , e . message ) ,
1296
+ button : {
1297
+ label : "ok_action" ,
1298
+ click : noOp ,
1299
+ } ,
1300
+ waitingTime : 500 ,
1301
+ } )
1317
1302
} )
1318
- } )
1319
- } )
1320
- . catch ( ofClass ( LockedError , noOp ) )
1303
+ } )
1304
+ . catch ( ofClass ( LockedError , noOp ) )
1305
+ }
1321
1306
dialog . close ( )
1322
1307
}
1323
1308
0 commit comments