@@ -111,8 +111,6 @@ void MetaGroupWrapper::Init(Napi::Env env, Napi::Object exports) {
111
111
InstanceMethod (
112
112
" membersMarkPendingRemoval" ,
113
113
&MetaGroupWrapper::membersMarkPendingRemoval),
114
- InstanceMethod (
115
- " memberSetNameTruncated" , &MetaGroupWrapper::memberSetNameTruncated),
116
114
InstanceMethod (" memberSetSupplement" , &MetaGroupWrapper::memberSetSupplement),
117
115
InstanceMethod (" memberSetInviteSent" , &MetaGroupWrapper::memberSetInviteSent),
118
116
InstanceMethod (
@@ -131,10 +129,7 @@ void MetaGroupWrapper::Init(Napi::Env env, Napi::Object exports) {
131
129
" memberSetPromotionAccepted" ,
132
130
&MetaGroupWrapper::memberSetPromotionAccepted),
133
131
InstanceMethod (
134
- " memberSetProfilePicture" , &MetaGroupWrapper::memberSetProfilePicture),
135
- InstanceMethod (
136
- " memberSetProfileUpdatedSeconds" ,
137
- &MetaGroupWrapper::memberSetProfileUpdatedSeconds),
132
+ " memberSetProfileDetails" , &MetaGroupWrapper::memberSetProfileDetails),
138
133
InstanceMethod (
139
134
" memberResetAllSendingState" ,
140
135
&MetaGroupWrapper::memberResetAllSendingState),
@@ -523,21 +518,6 @@ Napi::Value MetaGroupWrapper::memberConstructAndSet(const Napi::CallbackInfo& in
523
518
});
524
519
}
525
520
526
- void MetaGroupWrapper::memberSetNameTruncated (const Napi::CallbackInfo& info) {
527
- wrapExceptions (info, [&] {
528
- assertIsString (info[0 ]);
529
- assertIsString (info[1 ]);
530
-
531
- auto pubkeyHex = toCppString (info[0 ], " memberSetNameTruncated pubkeyHex" );
532
- auto newName = toCppString (info[1 ], " memberSetNameTruncated newName" );
533
- auto m = this ->meta_group ->members ->get (pubkeyHex);
534
- if (m) {
535
- m->set_name (newName);
536
- this ->meta_group ->members ->set (*m);
537
- }
538
- });
539
- }
540
-
541
521
void MetaGroupWrapper::memberSetSupplement (const Napi::CallbackInfo& info) {
542
522
wrapExceptions (info, [&] {
543
523
assertIsString (info[0 ]);
@@ -656,35 +636,30 @@ void MetaGroupWrapper::memberSetPromotionAccepted(const Napi::CallbackInfo& info
656
636
});
657
637
}
658
638
659
- void MetaGroupWrapper::memberSetProfilePicture (const Napi::CallbackInfo& info) {
639
+ void MetaGroupWrapper::memberSetProfileDetails (const Napi::CallbackInfo& info) {
660
640
wrapExceptions (info, [&] {
661
641
assertInfoLength (info, 2 );
662
642
assertIsString (info[0 ]);
663
643
assertIsObject (info[1 ]);
664
644
665
- auto pubkeyHex = toCppString (info[0 ], " memberSetProfilePicture" );
666
- auto profilePicture = profile_pic_from_object (info[1 ]);
645
+ auto pubkeyHex = toCppString (info[0 ], " memberSetProfileDetails" );
667
646
668
647
auto m = this ->meta_group ->members ->get (pubkeyHex);
669
- if (m) {
670
- m->profile_picture = profilePicture;
671
- this ->meta_group ->members ->set (*m);
672
- }
673
- });
674
- }
648
+ auto argsAsObj = info[1 ].As <Napi::Object>();
649
+ auto updatedAtSeconds =
650
+ toCppSysSeconds (argsAsObj.Get (" profileUpdatedSeconds" ), " memberSetProfileDetails" );
675
651
676
- void MetaGroupWrapper::memberSetProfileUpdatedSeconds (const Napi::CallbackInfo& info) {
677
- wrapExceptions (info, [&] {
678
- assertInfoLength (info, 2 );
679
- assertIsString (info[0 ]);
680
- assertIsObject (info[1 ]);
652
+ // if the profile details provided are more recent that the ones saved, update them
653
+ if (m && updatedAtSeconds > m->profile_updated ) {
654
+ m->profile_updated = updatedAtSeconds;
655
+
656
+ auto profilePicture = profile_pic_from_object (argsAsObj.Get (" profilePicture" ));
657
+ m->profile_picture = profilePicture;
681
658
682
- auto pubkeyHex = toCppString (info[0 ], " memberSetProfiUpdatedSeconds" );
683
- auto updatedAtSeconds = maybeNonemptySysSeconds (info[1 ], " memberSetProfiUpdatedSeconds" );
659
+ // this will truncate silently if the name is too long
660
+ auto newName = toCppString (argsAsObj.Get (" name" ), " memberSetProfileDetails newName" );
661
+ m->set_name_truncated (newName);
684
662
685
- auto m = this ->meta_group ->members ->get (pubkeyHex);
686
- if (m) {
687
- m->profile_updated = updatedAtSeconds.value ();
688
663
this ->meta_group ->members ->set (*m);
689
664
}
690
665
});
0 commit comments