@xuda.io/account_module 1.2.2057 → 1.2.2058
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/get_user_info.mjs +126 -0
- package/package.json +1 -1
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
export const get_contact_info = async function (uid, contact_doc, _id) {
|
|
2
|
+
let doc = contact_doc;
|
|
3
|
+
if (_id) {
|
|
4
|
+
doc = await get_contact(uid, _id);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
delete doc.metadata;
|
|
8
|
+
delete doc.profile_avatar_obj;
|
|
9
|
+
delete doc.profile_picture_obj;
|
|
10
|
+
delete doc.bio;
|
|
11
|
+
|
|
12
|
+
const chat_conversation_count = async function () {
|
|
13
|
+
const account_profile_info = await get_active_account_profile_info(uid);
|
|
14
|
+
|
|
15
|
+
const counts_ret = await db_module.get_app_couch_view(account_profile_info.app_id, 'chat_conversation_item_counts', {
|
|
16
|
+
reduce: true,
|
|
17
|
+
group_level: 1,
|
|
18
|
+
|
|
19
|
+
startkey: [doc._id, ''],
|
|
20
|
+
endkey: [doc._id, 'zzzzzz'],
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
return counts_ret?.rows?.[0]?.value || 0;
|
|
24
|
+
};
|
|
25
|
+
const chat_conversation_read = async function () {
|
|
26
|
+
const account_profile_info = await get_active_account_profile_info(uid);
|
|
27
|
+
|
|
28
|
+
const counts_ret = await db_module.get_app_couch_view(account_profile_info.app_id, 'chat_conversation_item_read', {
|
|
29
|
+
reduce: true,
|
|
30
|
+
group_level: 2,
|
|
31
|
+
|
|
32
|
+
startkey: [uid, doc._id, ''],
|
|
33
|
+
endkey: [uid, doc._id, 'zzzzzz'],
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
return counts_ret?.rows?.[0]?.value || 0;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
doc.notifications = 0;
|
|
40
|
+
if (doc.contact_uid) {
|
|
41
|
+
const account_info_ret = await get_account_name({ uid_query: doc.contact_uid });
|
|
42
|
+
if (account_info_ret.code < 0) {
|
|
43
|
+
return; // throw new Error(`account ${contact_uid} not found`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
doc.profile_avatar = account_info_ret.data.profile_avatar;
|
|
47
|
+
|
|
48
|
+
//membership_plan
|
|
49
|
+
// doc.name = `${account_info_ret.data.first_name} ${account_info_ret.data.last_name}`;
|
|
50
|
+
doc.name = account_info_ret.data?.account_type === 'business' ? account_info_ret.data.business_name : `${account_info_ret.data.first_name} ${account_info_ret.data.last_name}`;
|
|
51
|
+
|
|
52
|
+
if (account_info_ret.data.phone_number) {
|
|
53
|
+
try {
|
|
54
|
+
doc.phone_number = formatPhoneWithFlag(account_info_ret.data.phone_number, account_info_ret.data.country);
|
|
55
|
+
} catch (err) {
|
|
56
|
+
// console.error(err);
|
|
57
|
+
doc.phone_number = account_info_ret.data.phone_number;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (doc.team_req_id) {
|
|
62
|
+
try {
|
|
63
|
+
const req_doc = await db_module.get_couch_doc_native('xuda_team', doc.team_req_id);
|
|
64
|
+
doc.connection_stat = req_doc.team_req_stat;
|
|
65
|
+
doc.connection_type = req_doc.access_type;
|
|
66
|
+
doc.connection_uid = req_doc.team_req_from_uid === uid ? req_doc.team_req_to_uid : req_doc.team_req_from_uid;
|
|
67
|
+
doc.connection_contact_id = req_doc.team_req_from_contact_id === doc._id ? req_doc.team_req_to_contact_id : req_doc.team_req_from_contact_id;
|
|
68
|
+
if (doc.connection_type === 'contact_connection') {
|
|
69
|
+
doc.friend_since = req_doc.team_req_date;
|
|
70
|
+
}
|
|
71
|
+
if (doc.connection_type === 'account_profile') {
|
|
72
|
+
try {
|
|
73
|
+
const app_id = await get_account_default_project_id(uid);
|
|
74
|
+
const account_profile_doc = await db_module.get_app_couch_doc_native(app_id, req_doc.share_item_id);
|
|
75
|
+
doc.account_profile = account_profile_doc;
|
|
76
|
+
} catch (error) {}
|
|
77
|
+
}
|
|
78
|
+
} catch (err) {
|
|
79
|
+
if (err.message === 'deleted') {
|
|
80
|
+
try {
|
|
81
|
+
let contact_doc = await get_contact(uid, doc._id);
|
|
82
|
+
contact_doc.team_req_id = '';
|
|
83
|
+
await save_contact(uid, contact_doc);
|
|
84
|
+
} catch (error) {}
|
|
85
|
+
}
|
|
86
|
+
doc.connection_stat = 0;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
doc.avatar_source = account_info_ret.data.avatar_source;
|
|
91
|
+
// doc.icon_pattern = await get_contact_pattern(doc);
|
|
92
|
+
doc.username = account_info_ret.data.username;
|
|
93
|
+
doc.business_name = account_info_ret.data.business_name;
|
|
94
|
+
doc.address = account_info_ret.data.address;
|
|
95
|
+
doc.city = account_info_ret.data.city;
|
|
96
|
+
doc.state = account_info_ret.data.state;
|
|
97
|
+
doc.zip = account_info_ret.data.zip;
|
|
98
|
+
doc.account_type = account_info_ret.data.account_type;
|
|
99
|
+
doc.email = doc.email;
|
|
100
|
+
if (doc.connection_stat === 3) {
|
|
101
|
+
doc.online = account_info_ret.data.online;
|
|
102
|
+
}
|
|
103
|
+
} else {
|
|
104
|
+
doc.email = doc.email;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
doc.business_has_person = doc?.business_has_person && doc?.person_info?.person_full_name !== 'Not available';
|
|
108
|
+
doc.icon_pattern = await get_contact_pattern(doc);
|
|
109
|
+
|
|
110
|
+
delete doc.account_type_info;
|
|
111
|
+
delete doc.person_info;
|
|
112
|
+
delete doc.business_info;
|
|
113
|
+
|
|
114
|
+
const contact_chat_conversation_count_ret = await chat_conversation_count();
|
|
115
|
+
const contact_chat_conversation_read_ret = await chat_conversation_read();
|
|
116
|
+
|
|
117
|
+
doc.interactions = contact_chat_conversation_count_ret;
|
|
118
|
+
doc.notifications = contact_chat_conversation_count_ret - contact_chat_conversation_read_ret;
|
|
119
|
+
doc.chats = doc.interactions;
|
|
120
|
+
|
|
121
|
+
doc.card_background = get_contact_background(doc);
|
|
122
|
+
|
|
123
|
+
doc.border = get_contact_border(doc);
|
|
124
|
+
|
|
125
|
+
return doc;
|
|
126
|
+
};
|