Skip to content

Commit 873c63b

Browse files
committed
fix: add enum for removedStatus too
1 parent c2793b5 commit 873c63b

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

src/groups/meta_group_wrapper.hpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@
77
#include "../utilities.hpp"
88
#include "./meta_group.hpp"
99
#include "oxenc/bt_producer.h"
10+
#include "session/config/user_groups.hpp"
1011

1112
namespace session::nodeapi {
1213
using config::groups::Members;
14+
using session::config::GROUP_DESTROYED;
15+
using session::config::KICKED_FROM_GROUP;
16+
using session::config::NOT_REMOVED;
1317
using session::config::groups::member;
1418
using session::nodeapi::MetaGroup;
1519

@@ -27,10 +31,10 @@ struct toJs_impl<member> {
2731
// Note: this should be part of `libsession-util`, not `libsession-util-nodejs`
2832
if (info.promoted() && !info.promotion_pending()) {
2933
obj["memberStatus"] = toJs(env, "PROMOTION_ACCEPTED");
30-
} else if (info.promotion_pending()) {
31-
obj["memberStatus"] = toJs(env, "PROMOTION_SENT");
3234
} else if (info.promotion_failed()) {
3335
obj["memberStatus"] = toJs(env, "PROMOTION_FAILED");
36+
} else if (info.promotion_pending()) {
37+
obj["memberStatus"] = toJs(env, "PROMOTION_SENT");
3438
} else if (info.admin) {
3539
obj["memberStatus"] = toJs(env, "PROMOTION_NOT_SENT");
3640
} else if (info.invite_status == 0) {
@@ -39,19 +43,25 @@ struct toJs_impl<member> {
3943
obj["memberStatus"] = toJs(env, "INVITE_NOT_SENT");
4044
} else if (info.invite_failed()) {
4145
obj["memberStatus"] = toJs(env, "INVITE_FAILED");
42-
} else {
46+
} else if (info.invite_pending()) {
4347
// Note: INVITE_NOT_SENT is 3, which makes invite_pending() return true, so be sure to
44-
// check for invite_not_sent() above. this is probably a bad idea to have a catch-all
45-
// else, but we have to when we consider upgrades of libsession-util
48+
// check for invite_not_sent() above.
4649
obj["memberStatus"] = toJs(env, "INVITE_SENT");
50+
} else {
51+
obj["memberStatus"] = toJs(env, "UNKNOWN");
4752
}
4853

4954
obj["nominatedAdmin"] = toJs(env, info.admin);
5055

51-
// removed status
52-
obj["isRemoved"] = toJs(env, info.is_removed());
53-
obj["shouldRemoveMessages"] = toJs(env, info.should_remove_messages());
54-
56+
if (!info.is_removed()) {
57+
obj["removedStatus"] = toJs(env, "NOT_REMOVED");
58+
} else {
59+
if (info.should_remove_messages()) {
60+
obj["removedStatus"] = toJs(env, "REMOVED_MEMBER_AND_MESSAGES");
61+
} else {
62+
obj["removedStatus"] = toJs(env, "REMOVED_MEMBER");
63+
}
64+
}
5565
return obj;
5666
}
5767
};

types/groups/groupmembers.d.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ declare module 'libsession_util_nodejs' {
2020
| 'PROMOTION_NOT_SENT' // as soon as we've scheduled that guy to be an admin, but before we've tried sending the promotion message
2121
| 'PROMOTION_FAILED'
2222
| 'PROMOTION_SENT'
23-
| 'PROMOTION_ACCEPTED'; // regular admin
23+
| 'PROMOTION_ACCEPTED' // regular admin
24+
| 'UNKNOWN';
2425

2526
export type GroupMemberGet = GroupMemberShared & {
2627
memberStatus: MemberStateGroupV2;
@@ -30,7 +31,7 @@ declare module 'libsession_util_nodejs' {
3031
* REMOVED_MEMBER = 1,
3132
* REMOVED_MEMBER_AND_MESSAGES = 2;
3233
*/
33-
removedStatus: number;
34+
removedStatus: 'NOT_REMOVED' | 'REMOVED_MEMBER' | 'REMOVED_MEMBER_AND_MESSAGES' | 'UNKNOWN';
3435
/**
3536
* True if the member is scheduled to get the keys (.admin field of libsession).
3637
* This is equivalent of memberStatus being one of:
@@ -40,10 +41,6 @@ declare module 'libsession_util_nodejs' {
4041
* - PROMOTION_ACCEPTED
4142
*/
4243
nominatedAdmin: boolean;
43-
/** True if the user should be removed from the group */
44-
isRemoved: boolean;
45-
/** True if the user and his messages should be removed from the group */
46-
shouldRemoveMessages: boolean;
4744
};
4845

4946
type GroupMemberWrapper = {

0 commit comments

Comments
 (0)