mirror of
https://github.com/cryptpad/cryptpad.git
synced 2026-09-12 19:49:59 +05:00
List first badges
This commit is contained in:
parent
0d11e86a06
commit
3caec4e521
@ -309,3 +309,9 @@ Pinning.getDeletedPads = function (Env, channels, cb) {
|
||||
Pinning.isChannelPinned = function (Env, channel, cb) {
|
||||
return void cb(void 0, true);
|
||||
};
|
||||
|
||||
Pinning.isPremium = function (Env, userKey, cb) {
|
||||
const limit = Env.limits[userKey];
|
||||
return void cb(void 0, !!limit?.plan);
|
||||
//return void cb(void 0, (limit?.plan && limit.plan !== "custom"));
|
||||
};
|
||||
|
||||
@ -24,6 +24,7 @@ const UNAUTHENTICATED_CALLS = {
|
||||
WRITE_PRIVATE_MESSAGE: Channel.writePrivateMessage,
|
||||
DELETE_MAILBOX_MESSAGE: Channel.deleteMailboxMessage,
|
||||
GET_METADATA: Metadata.getMetadata,
|
||||
IS_PREMIUM: Pinning.isPremium,
|
||||
ADD_FIRST_ADMIN: Admin.addFirstAdmin
|
||||
};
|
||||
|
||||
|
||||
@ -9,12 +9,13 @@ const factory = (ApiConfig = {}, Sortify, UserObject, ProxyManager,
|
||||
SF, AccountTS, DriveTS, Cursor,
|
||||
Support, Integration, OnlyOffice,
|
||||
Mailbox, Profile, Team, Messenger, History,
|
||||
Calendar, Block, NetConfig, AppConfig = {},
|
||||
Calendar, BadgeTS, Block, NetConfig, AppConfig = {},
|
||||
Crypto, ChainPad, CpNetflux, Listmap,
|
||||
Netflux, nThen) => {
|
||||
|
||||
const Account = AccountTS.Account;
|
||||
const Drive = DriveTS.Drive;
|
||||
const Badge = BadgeTS.Badge;
|
||||
const window = globalThis;
|
||||
globalThis.nacl = globalThis.nacl || Crypto.Nacl;
|
||||
|
||||
@ -2808,6 +2809,7 @@ const factory = (ApiConfig = {}, Sortify, UserObject, ProxyManager,
|
||||
loadUniversal(Integration, 'integration', waitFor);
|
||||
loadUniversal(Messenger, 'messenger', waitFor);
|
||||
loadUniversal(History, 'history', waitFor);
|
||||
loadUniversal(Badge, 'badge', waitFor);
|
||||
loadOnlyOffice();
|
||||
if (store) {
|
||||
store.messenger = store.modules['messenger'];
|
||||
@ -3472,6 +3474,7 @@ if (typeof(module) !== 'undefined' && module.exports) {
|
||||
require('./modules/messenger'),
|
||||
require('./modules/history'),
|
||||
require('./modules/calendar'),
|
||||
require('./modules/badge'),
|
||||
require('../common/login-block'),
|
||||
require('../common/network-config'),
|
||||
undefined,
|
||||
|
||||
80
src/worker/modules/badge.ts
Normal file
80
src/worker/modules/badge.ts
Normal file
@ -0,0 +1,80 @@
|
||||
import nacl from 'tweetnacl/nacl-fast';
|
||||
import nThen from 'nthen';
|
||||
import { Module, ModuleObject, Callback } from '../types'
|
||||
import * as Util from '../../common/common-util.js';
|
||||
|
||||
export interface BadgeModule<T> extends Module<T> {
|
||||
setCustomize: (data: any) => void
|
||||
}
|
||||
|
||||
let ApiConfig:any = {};
|
||||
|
||||
const checkApi = (ctx, ed, cb) => {
|
||||
const badges = [];
|
||||
const origin:string = ApiConfig?.httpUnsafeOrigin;
|
||||
Util.fetchApi(origin, 'config', true, Config => {
|
||||
const isAdmin = Config?.adminKeys?.includes(ed);
|
||||
if (isAdmin) { badges.push('admin'); }
|
||||
const isModerator = Config?.moderatorKeys?.includes(ed);
|
||||
if (isModerator) { badges.push('moderator'); }
|
||||
cb(badges);
|
||||
});
|
||||
};
|
||||
const checkPremium = (ctx, ed, cb) => {
|
||||
ctx.Store.anonRpcMsg('', {
|
||||
msg: 'IS_PREMIUM',
|
||||
data: ed
|
||||
}, obj => {
|
||||
let premium = Array.isArray(obj) && obj[0];
|
||||
cb(premium);
|
||||
});
|
||||
};
|
||||
|
||||
const listBadges:Callback = (ctx, data, clientId, cb) => {
|
||||
const badges = [];
|
||||
const origin:string = ApiConfig?.httpUnsafeOrigin;
|
||||
const ed = ctx.store?.proxy?.edPublic;
|
||||
nThen(waitFor => {
|
||||
checkApi(ctx, ed, waitFor(list => {
|
||||
Array.prototype.push.apply(badges, list);
|
||||
}));
|
||||
}).nThen(waitFor => {
|
||||
checkPremium(ctx, ed, waitFor(isPremium => {
|
||||
if (isPremium) { badges.push('premium'); }
|
||||
}));
|
||||
}).nThen(() => {
|
||||
cb(badges);
|
||||
});
|
||||
};
|
||||
|
||||
const Badge: BadgeModule<ModuleObject> = {
|
||||
|
||||
init: (config, cb, emit) => {
|
||||
|
||||
const ctx:any = {
|
||||
store: config.store,
|
||||
Store: config.Store,
|
||||
updateMetadata: config.updateMetadata
|
||||
};
|
||||
|
||||
return {
|
||||
removeClient: () => {},
|
||||
execCommand: (clientId, obj, cb) => {
|
||||
console.log('Exex command', clientId, obj);
|
||||
const cmd = obj.cmd;
|
||||
const data = obj.data;
|
||||
if (cmd === 'LIST_BADGES') {
|
||||
return void listBadges(ctx, data, clientId, cb);
|
||||
}
|
||||
cb();
|
||||
},
|
||||
}
|
||||
},
|
||||
setCustomize: data => {
|
||||
console.error('PAICONFIG', data);
|
||||
ApiConfig = data?.ApiConfig;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
export { Badge }
|
||||
@ -7,7 +7,7 @@ export interface TestModuleObject extends ModuleObject {
|
||||
|
||||
const TestModule: Module<TestModuleObject> = {
|
||||
|
||||
init: (config, cb) => {
|
||||
init: (config, cb, emit) => {
|
||||
let myTest = {};
|
||||
|
||||
cb();
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import nacl from 'tweetnacl/nacl-fast';
|
||||
import { Module } from './types';
|
||||
import { TestModule, TestModuleObject } from './modules/test';
|
||||
//import { TestModule, TestModuleObject } from './modules/test';
|
||||
import { Badge } from './modules/badge';
|
||||
|
||||
import { Account } from './components/account';
|
||||
|
||||
@ -72,7 +73,8 @@ let start = (cfg: StoreConfig):void => {
|
||||
Calendar,
|
||||
Store,
|
||||
Account,
|
||||
Mailbox
|
||||
Mailbox,
|
||||
Badge
|
||||
].forEach(dep => {
|
||||
if (typeof(dep.setCustomize) === "function") {
|
||||
dep.setCustomize(cfg);
|
||||
@ -84,10 +86,9 @@ let start = (cfg: StoreConfig):void => {
|
||||
const ApiConfig = cfg.ApiConfig;
|
||||
|
||||
let test = TestModule.init({
|
||||
emit: () => {}
|
||||
}, () => {
|
||||
console.log('Test initialized');
|
||||
});
|
||||
}, () => {});
|
||||
let b64 = test.toBase64('pewpewPEZPEZ');
|
||||
console.error(b64);
|
||||
console.error(AppConfig.minimumPasswordLength, AppConfig.degradedLimit);
|
||||
|
||||
@ -3,7 +3,11 @@
|
||||
export type Callback = (...args: any[]) => void
|
||||
|
||||
export type ModuleConfig = {
|
||||
emit: Function
|
||||
store: any,
|
||||
Store: any,
|
||||
updateMetadata: Callback,
|
||||
pinPads: Callback,
|
||||
unpinPads: Callback
|
||||
}
|
||||
|
||||
export type CommandData = {
|
||||
@ -17,7 +21,7 @@ export interface ModuleObject {
|
||||
}
|
||||
|
||||
export interface Module<T> {
|
||||
init: (config: ModuleConfig, cb: Callback) => T
|
||||
init: (config: ModuleConfig, cb: Callback, emit: Callback) => T
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -92,6 +92,7 @@ define([
|
||||
var LINK_ID = "cp-app-profile-link";
|
||||
var AVATAR_ID = "cp-app-profile-avatar";
|
||||
var DESCRIPTION_ID = "cp-app-profile-description";
|
||||
var BADGES_ID = "cp-app-profile-badges";
|
||||
var CREATE_ID = "cp-app-profile-create";
|
||||
var HEADER_ID = "cp-app-profile-header";
|
||||
var HEADER_RIGHT_ID = "cp-app-profile-rightside";
|
||||
@ -435,6 +436,18 @@ define([
|
||||
displayAvatar(data.avatar);
|
||||
};
|
||||
|
||||
const addBadges = $container => {
|
||||
if (APP.readOnly) { return; }
|
||||
var $block = $('<div>', {id: BADGES_ID, class:'cp-sidebarlayout-element'}).appendTo($container);
|
||||
APP.$badges = $(h('span')).appendTo($block);
|
||||
};
|
||||
const refreshBadges = () => {
|
||||
if (!APP.$badges) { return; }
|
||||
APP.badge.execCommand('LIST_BADGES', {}, data => {
|
||||
console.error(data);
|
||||
});
|
||||
};
|
||||
|
||||
var addDescription = function ($container) {
|
||||
var $block = $('<div>', {id: DESCRIPTION_ID, class:'cp-sidebarlayout-element'}).appendTo($container);
|
||||
|
||||
@ -582,6 +595,7 @@ define([
|
||||
addFriendRequest($rightside);
|
||||
addMuteButton($rightside);
|
||||
addDescription(APP.$rightside);
|
||||
addBadges(APP.$rightside);
|
||||
addPublicKey($rightside);
|
||||
addCopyData($rightside);
|
||||
addViewButton($rightside);
|
||||
@ -595,6 +609,7 @@ define([
|
||||
refreshName(data);
|
||||
refreshLink(data);
|
||||
refreshDescription(data);
|
||||
refreshBadges(data);
|
||||
refreshFriendRequest(data);
|
||||
refreshMute(data);
|
||||
setPublicKeyButton(data);
|
||||
@ -671,6 +686,9 @@ define([
|
||||
APP.module = common.makeUniversal('profile', {
|
||||
onEvent: onEvent
|
||||
});
|
||||
APP.badge = common.makeUniversal('badge', {
|
||||
onEvent: onEvent
|
||||
});
|
||||
var execCommand = APP.module.execCommand;
|
||||
|
||||
init();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user