@kaikybrofc/omnizap-system 2.1.8
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/.env.example +534 -0
- package/LICENSE +21 -0
- package/README.md +431 -0
- package/RELEASE-v2.1.2.md +83 -0
- package/app/config/adminIdentity.js +87 -0
- package/app/config/baileysConfig.js +693 -0
- package/app/config/groupUtils.js +388 -0
- package/app/connection/socketController.js +992 -0
- package/app/controllers/messageController.js +354 -0
- package/app/modules/adminModule/groupCommandHandlers.js +1294 -0
- package/app/modules/adminModule/groupEventHandlers.js +355 -0
- package/app/modules/aiModule/catCommand.js +1006 -0
- package/app/modules/broadcastModule/noticeCommand.js +416 -0
- package/app/modules/gameModule/diceCommand.js +67 -0
- package/app/modules/menuModule/common.js +311 -0
- package/app/modules/menuModule/menus.js +59 -0
- package/app/modules/playModule/playCommand.js +1615 -0
- package/app/modules/quoteModule/quoteCommand.js +851 -0
- package/app/modules/rpgPokemonModule/rpgBattleCanvasRenderer.js +786 -0
- package/app/modules/rpgPokemonModule/rpgBattleService.js +2082 -0
- package/app/modules/rpgPokemonModule/rpgBattleService.test.js +760 -0
- package/app/modules/rpgPokemonModule/rpgEvolutionUtils.js +22 -0
- package/app/modules/rpgPokemonModule/rpgPokemonCommand.js +172 -0
- package/app/modules/rpgPokemonModule/rpgPokemonDomain.js +192 -0
- package/app/modules/rpgPokemonModule/rpgPokemonDomain.test.js +93 -0
- package/app/modules/rpgPokemonModule/rpgPokemonEvolution.test.js +46 -0
- package/app/modules/rpgPokemonModule/rpgPokemonMessages.js +746 -0
- package/app/modules/rpgPokemonModule/rpgPokemonRepository.js +1859 -0
- package/app/modules/rpgPokemonModule/rpgPokemonService.js +6738 -0
- package/app/modules/rpgPokemonModule/rpgProfileCanvasRenderer.js +354 -0
- package/app/modules/statsModule/globalRankingCommand.js +65 -0
- package/app/modules/statsModule/noMessageCommand.js +288 -0
- package/app/modules/statsModule/rankingCommand.js +60 -0
- package/app/modules/statsModule/rankingCommon.js +889 -0
- package/app/modules/stickerModule/addStickerMetadata.js +239 -0
- package/app/modules/stickerModule/convertToWebp.js +390 -0
- package/app/modules/stickerModule/stickerCommand.js +454 -0
- package/app/modules/stickerModule/stickerConvertCommand.js +156 -0
- package/app/modules/stickerModule/stickerTextCommand.js +657 -0
- package/app/modules/stickerPackModule/autoPackCollectorRuntime.js +20 -0
- package/app/modules/stickerPackModule/autoPackCollectorService.js +284 -0
- package/app/modules/stickerPackModule/semanticReclassificationEngine.js +466 -0
- package/app/modules/stickerPackModule/semanticReclassificationEngine.test.js +88 -0
- package/app/modules/stickerPackModule/semanticThemeClusterService.js +571 -0
- package/app/modules/stickerPackModule/stickerAssetClassificationRepository.js +449 -0
- package/app/modules/stickerPackModule/stickerAssetRepository.js +400 -0
- package/app/modules/stickerPackModule/stickerAssetReprocessQueueRepository.js +180 -0
- package/app/modules/stickerPackModule/stickerAutoPackByTagsRuntime.js +4078 -0
- package/app/modules/stickerPackModule/stickerClassificationBackgroundRuntime.js +598 -0
- package/app/modules/stickerPackModule/stickerClassificationService.js +588 -0
- package/app/modules/stickerPackModule/stickerMarketplaceDriftService.js +102 -0
- package/app/modules/stickerPackModule/stickerPackCatalogHttp.js +7506 -0
- package/app/modules/stickerPackModule/stickerPackCommandHandlers.js +1095 -0
- package/app/modules/stickerPackModule/stickerPackEngagementRepository.js +108 -0
- package/app/modules/stickerPackModule/stickerPackErrors.js +30 -0
- package/app/modules/stickerPackModule/stickerPackInteractionEventRepository.js +110 -0
- package/app/modules/stickerPackModule/stickerPackItemRepository.js +440 -0
- package/app/modules/stickerPackModule/stickerPackMarketplaceService.js +337 -0
- package/app/modules/stickerPackModule/stickerPackMessageService.js +296 -0
- package/app/modules/stickerPackModule/stickerPackRepository.js +442 -0
- package/app/modules/stickerPackModule/stickerPackService.js +788 -0
- package/app/modules/stickerPackModule/stickerPackServiceRuntime.js +51 -0
- package/app/modules/stickerPackModule/stickerPackUtils.js +97 -0
- package/app/modules/stickerPackModule/stickerStorageService.js +507 -0
- package/app/modules/stickerPackModule/stickerWorkerPipelineRuntime.js +233 -0
- package/app/modules/stickerPackModule/stickerWorkerTaskQueueRepository.js +205 -0
- package/app/modules/systemMetricsModule/pingCommand.js +421 -0
- package/app/modules/tiktokModule/tiktokCommand.js +798 -0
- package/app/modules/userModule/userCommand.js +1217 -0
- package/app/modules/waifuPicsModule/waifuPicsCommand.js +177 -0
- package/app/observability/metrics.js +734 -0
- package/app/services/captchaService.js +492 -0
- package/app/services/dbWriteQueue.js +572 -0
- package/app/services/groupMetadataService.js +279 -0
- package/app/services/lidMapService.js +663 -0
- package/app/services/messagePersistenceService.js +56 -0
- package/app/services/newsBroadcastService.js +351 -0
- package/app/services/pokeApiService.js +398 -0
- package/app/services/queueUtils.js +57 -0
- package/app/services/socketState.js +7 -0
- package/app/store/aiPromptStore.js +38 -0
- package/app/store/groupConfigStore.js +58 -0
- package/app/store/premiumUserStore.js +36 -0
- package/app/utils/antiLink/antiLinkModule.js +804 -0
- package/app/utils/http/getImageBufferModule.js +18 -0
- package/app/utils/json/jsonSanitizer.js +113 -0
- package/app/utils/json/jsonSanitizer.test.js +40 -0
- package/app/utils/logger/loggerModule.js +262 -0
- package/app/utils/systemMetrics/systemMetricsModule.js +91 -0
- package/database/index.js +2052 -0
- package/database/init.js +516 -0
- package/database/migrations/20260203_0001_sticker_packs.sql +54 -0
- package/database/migrations/20260210_0003_rpg_pokemon.sql +58 -0
- package/database/migrations/20260210_0004_rpg_shiny_biome.sql +9 -0
- package/database/migrations/20260210_0005_rpg_missions.sql +14 -0
- package/database/migrations/20260210_0006_rpg_world_pokedex_traits.sql +27 -0
- package/database/migrations/20260210_0007_rpg_raid_pvp.sql +56 -0
- package/database/migrations/20260210_0008_rpg_social_system.sql +195 -0
- package/database/migrations/20260211_0009_rpg_social_xp.sql +36 -0
- package/database/migrations/20260222_0010_remove_message_xp.sql +2 -0
- package/database/migrations/20260226_0011_sticker_asset_classification.sql +17 -0
- package/database/migrations/20260226_0012_sticker_pack_engagement.sql +16 -0
- package/database/migrations/20260226_0013_sticker_marketplace_intelligence.sql +19 -0
- package/database/migrations/20260226_0014_sticker_pack_publish_flow.sql +30 -0
- package/database/migrations/20260226_0014_sticker_worker_queues.sql +42 -0
- package/database/migrations/20260226_0015_sticker_auto_pack_curation_integrity.sql +18 -0
- package/database/migrations/20260226_0016_sticker_web_google_auth_persistence.sql +34 -0
- package/database/migrations/20260226_0017_sticker_web_admin_ban.sql +22 -0
- package/database/migrations/20260226_0018_sticker_web_admin_moderator.sql +18 -0
- package/database/migrations/20260227_0019_sticker_classification_v2_signals.sql +12 -0
- package/database/migrations/20260227_0020_semantic_theme_clusters.sql +35 -0
- package/docker-compose.yml +103 -0
- package/ecosystem.prod.config.cjs +35 -0
- package/eslint.config.js +61 -0
- package/index.js +437 -0
- package/ml/clip_classifier/Dockerfile +16 -0
- package/ml/clip_classifier/README.md +120 -0
- package/ml/clip_classifier/adaptive_scoring.py +40 -0
- package/ml/clip_classifier/classifier.py +654 -0
- package/ml/clip_classifier/embedding_store.py +481 -0
- package/ml/clip_classifier/env_loader.py +15 -0
- package/ml/clip_classifier/llm_label_expander.py +144 -0
- package/ml/clip_classifier/main.py +213 -0
- package/ml/clip_classifier/requirements.txt +10 -0
- package/ml/clip_classifier/similarity_engine.py +74 -0
- package/observability/alert-rules.yml +60 -0
- package/observability/grafana/dashboards/omnizap-mysql.json +136 -0
- package/observability/grafana/dashboards/omnizap-overview.json +170 -0
- package/observability/grafana/provisioning/dashboards/dashboards.yml +11 -0
- package/observability/grafana/provisioning/datasources/datasources.yml +15 -0
- package/observability/loki-config.yml +38 -0
- package/observability/mysql-exporter.cnf +5 -0
- package/observability/mysql-setup.sql +46 -0
- package/observability/prometheus.yml +32 -0
- package/observability/promtail-config.yml +84 -0
- package/package.json +109 -0
- package/public/api-docs/index.html +144 -0
- package/public/css/github-project-panel.css +297 -0
- package/public/css/stickers-admin.css +1272 -0
- package/public/css/styles.css +671 -0
- package/public/index.html +1311 -0
- package/public/js/apps/apiDocsApp.js +310 -0
- package/public/js/apps/createPackApp.js +2069 -0
- package/public/js/apps/homeApp.js +396 -0
- package/public/js/apps/stickersAdminApp.js +1744 -0
- package/public/js/apps/stickersApp.js +4830 -0
- package/public/js/catalog.js +1019 -0
- package/public/js/github-panel/components/CommitList.js +34 -0
- package/public/js/github-panel/components/ErrorState.js +16 -0
- package/public/js/github-panel/components/GithubProjectPanel.js +106 -0
- package/public/js/github-panel/components/ReleaseList.js +38 -0
- package/public/js/github-panel/components/SkeletonPanel.js +22 -0
- package/public/js/github-panel/components/StatCard.js +15 -0
- package/public/js/github-panel/index.js +15 -0
- package/public/js/github-panel/useGithubRepoData.js +154 -0
- package/public/js/github-panel/vendor/react.js +11 -0
- package/public/js/runtime/react-runtime.js +19 -0
- package/public/licenca/index.html +106 -0
- package/public/stickers/admin/index.html +23 -0
- package/public/stickers/create/index.html +47 -0
- package/public/stickers/index.html +48 -0
- package/public/termos-de-uso/index.html +125 -0
- package/scripts/cache-bust.mjs +107 -0
- package/scripts/deploy.sh +458 -0
- package/scripts/github-deploy-notify.mjs +174 -0
- package/scripts/release.sh +129 -0
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import logger from '../utils/logger/loggerModule.js';
|
|
2
|
+
import { findById, upsert } from '../../database/index.js';
|
|
3
|
+
import { extractUserIdInfo, resolveUserIdCached, isLidUserId, isWhatsAppUserId } from './lidMapService.js';
|
|
4
|
+
|
|
5
|
+
const GROUP_METADATA_FIELDS = ['id', 'subject', 'description', 'owner_jid', 'creation', 'participants'];
|
|
6
|
+
|
|
7
|
+
const PARTICIPANT_ACTIONS = new Set(['add', 'remove', 'promote', 'demote']);
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Normaliza o campo `participants` para o formato persistido no banco.
|
|
11
|
+
* @param {unknown} value - Valor bruto de participantes.
|
|
12
|
+
* @returns {string | null | undefined} JSON string, null ou undefined.
|
|
13
|
+
*/
|
|
14
|
+
const normalizeParticipantsValue = (value) => {
|
|
15
|
+
if (value === undefined) return undefined;
|
|
16
|
+
if (value === null) return null;
|
|
17
|
+
if (Array.isArray(value)) return JSON.stringify(value);
|
|
18
|
+
if (typeof value === 'string') return value;
|
|
19
|
+
try {
|
|
20
|
+
return JSON.stringify(value);
|
|
21
|
+
} catch (error) {
|
|
22
|
+
logger.warn('Erro ao serializar participantes para persistência.', { error: error.message });
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Faz parse do campo `participants` armazenado no banco.
|
|
29
|
+
* @param {string | Array<Object> | null | undefined} participants - Valor armazenado.
|
|
30
|
+
* @returns {Array<Object>} Lista de participantes normalizada.
|
|
31
|
+
*/
|
|
32
|
+
export const parseParticipantsFromDb = (participants) => {
|
|
33
|
+
if (!participants) return [];
|
|
34
|
+
try {
|
|
35
|
+
if (typeof participants === 'string') return JSON.parse(participants);
|
|
36
|
+
if (Array.isArray(participants)) return participants;
|
|
37
|
+
} catch (error) {
|
|
38
|
+
const preview = typeof participants === 'string' ? participants.slice(0, 200) : null;
|
|
39
|
+
logger.warn('Erro ao fazer parse dos participantes salvos no banco.', {
|
|
40
|
+
error: error.message,
|
|
41
|
+
preview,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return [];
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Normaliza um participante para o formato padrão (id/jid/lid/admin).
|
|
49
|
+
* @param {string | Object | null | undefined} participant - Participante bruto.
|
|
50
|
+
* @returns {Object | null} Participante normalizado ou null.
|
|
51
|
+
*/
|
|
52
|
+
export const normalizeParticipant = (participant) => {
|
|
53
|
+
if (!participant) return null;
|
|
54
|
+
const raw = typeof participant === 'string' ? { id: participant } : participant;
|
|
55
|
+
const rawId = raw.id || raw.jid || raw.participant || raw.participantAlt || null;
|
|
56
|
+
const info = extractUserIdInfo({
|
|
57
|
+
jid: raw.jid || raw.id || null,
|
|
58
|
+
lid: raw.lid || null,
|
|
59
|
+
participantAlt: raw.participantAlt || raw.participant || null,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const canonical = resolveUserIdCached(info) || info.jid || info.lid || rawId || null;
|
|
63
|
+
const canonicalIsJid = canonical && isWhatsAppUserId(canonical);
|
|
64
|
+
const canonicalIsLid = canonical && isLidUserId(canonical);
|
|
65
|
+
|
|
66
|
+
const jid = info.jid || (canonicalIsJid ? canonical : null);
|
|
67
|
+
const lid = info.lid || (canonicalIsLid ? canonical : null);
|
|
68
|
+
const id = canonical || jid || lid || rawId;
|
|
69
|
+
|
|
70
|
+
if (!id && !jid && !lid) return null;
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
id,
|
|
74
|
+
jid,
|
|
75
|
+
lid,
|
|
76
|
+
admin: raw.admin || null,
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Gera chave canônica para dedupe.
|
|
82
|
+
* @param {Object | null} participant - Participante normalizado.
|
|
83
|
+
* @returns {string | null} Chave canônica ou null.
|
|
84
|
+
*/
|
|
85
|
+
export const getParticipantKey = (participant) => {
|
|
86
|
+
if (!participant) return null;
|
|
87
|
+
return participant.id || participant.jid || null;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Normaliza a lista de participantes.
|
|
92
|
+
* @param {Array<Object | string>} [participants=[]] - Lista de participantes.
|
|
93
|
+
* @returns {Array<Object>} Lista normalizada e filtrada.
|
|
94
|
+
*/
|
|
95
|
+
export const normalizeParticipantsList = (participants = []) => {
|
|
96
|
+
if (!Array.isArray(participants)) return [];
|
|
97
|
+
return participants.map(normalizeParticipant).filter((participant) => participant && (participant.jid || participant.id));
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Monta payload com os campos suportados para persistência.
|
|
102
|
+
* @param {Object} data - Dados de grupo.
|
|
103
|
+
* @returns {Object} Payload filtrado e normalizado.
|
|
104
|
+
*/
|
|
105
|
+
const buildGroupMetadataPayload = (data) => {
|
|
106
|
+
const payload = {};
|
|
107
|
+
for (const field of GROUP_METADATA_FIELDS) {
|
|
108
|
+
if (data[field] !== undefined) payload[field] = data[field];
|
|
109
|
+
}
|
|
110
|
+
if (payload.participants !== undefined) {
|
|
111
|
+
payload.participants = normalizeParticipantsValue(payload.participants);
|
|
112
|
+
}
|
|
113
|
+
return payload;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Mescla dados existentes com atualizações, normalizando participantes.
|
|
118
|
+
* @param {Object | null} existing - Dados atuais do banco.
|
|
119
|
+
* @param {Object} updates - Atualizações recebidas.
|
|
120
|
+
* @returns {Object} Payload final pronto para persistência.
|
|
121
|
+
*/
|
|
122
|
+
export const mergeGroupMetadata = (existing, updates) => {
|
|
123
|
+
const safeExisting = existing || {};
|
|
124
|
+
const merged = {
|
|
125
|
+
...safeExisting,
|
|
126
|
+
...updates,
|
|
127
|
+
id: updates.id ?? safeExisting.id,
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
if (merged.participants !== undefined) {
|
|
131
|
+
merged.participants = normalizeParticipantsValue(merged.participants);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return buildGroupMetadataPayload(merged);
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Faz upsert de metadados do grupo no banco.
|
|
139
|
+
* @async
|
|
140
|
+
* @param {string} groupId - ID do grupo.
|
|
141
|
+
* @param {Object} updates - Dados a persistir.
|
|
142
|
+
* @param {Object} [options] - Opções de merge.
|
|
143
|
+
* @param {boolean} [options.mergeExisting=true] - Mescla com dados existentes.
|
|
144
|
+
* @returns {Promise<any | null>} Resultado do upsert ou null quando inválido.
|
|
145
|
+
*/
|
|
146
|
+
export const upsertGroupMetadata = async (groupId, updates, options = {}) => {
|
|
147
|
+
const { mergeExisting = true } = options;
|
|
148
|
+
const safeUpdates = {
|
|
149
|
+
...updates,
|
|
150
|
+
id: groupId,
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const payload = mergeExisting ? mergeGroupMetadata(await findById('groups_metadata', groupId), safeUpdates) : buildGroupMetadataPayload(safeUpdates);
|
|
154
|
+
|
|
155
|
+
if (!payload.id) {
|
|
156
|
+
logger.warn('Ignorando upsert de grupo sem ID.', { groupId, updates });
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return upsert('groups_metadata', payload);
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Aplica ação de participantes (add/remove/promote/demote) sobre a lista atual.
|
|
165
|
+
* @param {Array<Object>} currentParticipants - Participantes atuais.
|
|
166
|
+
* @param {Array<Object | string>} participants - Participantes do evento.
|
|
167
|
+
* @param {string} action - Ação do evento.
|
|
168
|
+
* @returns {Array<Object>} Lista atualizada.
|
|
169
|
+
*/
|
|
170
|
+
export const applyParticipantAction = (currentParticipants, participants, action) => {
|
|
171
|
+
if (!PARTICIPANT_ACTIONS.has(action)) {
|
|
172
|
+
logger.warn('Ação de participante inválida.', { action });
|
|
173
|
+
return currentParticipants || [];
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const currentMap = new Map(
|
|
177
|
+
(currentParticipants || [])
|
|
178
|
+
.map(normalizeParticipant)
|
|
179
|
+
.filter(Boolean)
|
|
180
|
+
.map((participant) => [getParticipantKey(participant), participant])
|
|
181
|
+
.filter(([key]) => !!key),
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
const incoming = Array.isArray(participants) ? participants : [];
|
|
185
|
+
|
|
186
|
+
for (const participant of incoming) {
|
|
187
|
+
const normalized = normalizeParticipant(participant);
|
|
188
|
+
const key = getParticipantKey(normalized);
|
|
189
|
+
if (!normalized || !key) continue;
|
|
190
|
+
|
|
191
|
+
if (action === 'add') {
|
|
192
|
+
if (!currentMap.has(key)) currentMap.set(key, normalized);
|
|
193
|
+
} else if (action === 'remove') {
|
|
194
|
+
currentMap.delete(key);
|
|
195
|
+
} else if (action === 'promote') {
|
|
196
|
+
const entry = currentMap.get(key) || normalized;
|
|
197
|
+
if (entry.admin !== 'superadmin') {
|
|
198
|
+
entry.admin = 'admin';
|
|
199
|
+
}
|
|
200
|
+
currentMap.set(key, entry);
|
|
201
|
+
} else if (action === 'demote') {
|
|
202
|
+
const entry = currentMap.get(key);
|
|
203
|
+
if (entry) {
|
|
204
|
+
entry.admin = null;
|
|
205
|
+
currentMap.set(key, entry);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return Array.from(currentMap.values());
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Atualiza participantes do grupo no banco com base em uma ação.
|
|
215
|
+
* @async
|
|
216
|
+
* @param {string} groupId - ID do grupo.
|
|
217
|
+
* @param {Array<Object | string>} participants - Participantes do evento.
|
|
218
|
+
* @param {string} action - Ação do evento.
|
|
219
|
+
* @returns {Promise<Array<Object> | null>} Lista atualizada ou null.
|
|
220
|
+
*/
|
|
221
|
+
export const updateGroupParticipantsFromAction = async (groupId, participants, action) => {
|
|
222
|
+
if (!groupId || !Array.isArray(participants) || participants.length === 0) return null;
|
|
223
|
+
|
|
224
|
+
const currentGroup = await findById('groups_metadata', groupId);
|
|
225
|
+
const currentParticipants = parseParticipantsFromDb(currentGroup?.participants);
|
|
226
|
+
const updatedParticipants = applyParticipantAction(currentParticipants, participants, action);
|
|
227
|
+
|
|
228
|
+
await upsertGroupMetadata(
|
|
229
|
+
groupId,
|
|
230
|
+
{
|
|
231
|
+
participants: updatedParticipants,
|
|
232
|
+
},
|
|
233
|
+
{ mergeExisting: true },
|
|
234
|
+
);
|
|
235
|
+
|
|
236
|
+
logger.debug('Participantes do grupo atualizados no banco.', {
|
|
237
|
+
groupId,
|
|
238
|
+
action,
|
|
239
|
+
participantsUpdated: participants.length,
|
|
240
|
+
totalParticipants: updatedParticipants.length,
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
return updatedParticipants;
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Constrói metadados de grupo a partir de um evento de update.
|
|
248
|
+
* @param {Object} event - Evento do Baileys.
|
|
249
|
+
* @param {Object | null} existing - Dados atuais do banco.
|
|
250
|
+
* @returns {Object} Metadados prontos para persistência.
|
|
251
|
+
*/
|
|
252
|
+
export const buildGroupMetadataFromUpdate = (event, existing) => {
|
|
253
|
+
const currentParticipants = parseParticipantsFromDb(existing?.participants);
|
|
254
|
+
const participants = event.participants || currentParticipants;
|
|
255
|
+
const normalizedParticipants = normalizeParticipantsList(participants);
|
|
256
|
+
|
|
257
|
+
return {
|
|
258
|
+
id: event.id,
|
|
259
|
+
subject: event.subject ?? existing?.subject,
|
|
260
|
+
description: event.desc ?? existing?.description,
|
|
261
|
+
owner_jid: event.owner ?? existing?.owner_jid,
|
|
262
|
+
creation: event.creation ?? existing?.creation,
|
|
263
|
+
participants: normalizedParticipants,
|
|
264
|
+
};
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Constrói metadados de grupo a partir do snapshot completo do Baileys.
|
|
269
|
+
* @param {Object} group - Grupo do Baileys.
|
|
270
|
+
* @returns {Object} Metadados prontos para persistência.
|
|
271
|
+
*/
|
|
272
|
+
export const buildGroupMetadataFromGroup = (group) => ({
|
|
273
|
+
id: group.id,
|
|
274
|
+
subject: group.subject,
|
|
275
|
+
description: group.desc,
|
|
276
|
+
owner_jid: group.owner,
|
|
277
|
+
creation: group.creation,
|
|
278
|
+
participants: normalizeParticipantsList(group.participants || []),
|
|
279
|
+
});
|