mirror of
https://github.com/cryptpad/cryptpad.git
synced 2026-09-14 11:05:41 +05:00
Fix UX with disabled badge
This commit is contained in:
parent
ff7741c509
commit
e55e2f875b
@ -97,6 +97,26 @@ const Badge: BadgeModule<ModuleObject> = {
|
||||
listBadges(ctx, data, undefined, cb);
|
||||
};
|
||||
|
||||
// On ready, check if our badge is still valid
|
||||
const Store = ctx.Store;
|
||||
Store.onReadyEvt.reg(() => {
|
||||
const md = Store.getMetadata(void 0, 'drive', () => {});
|
||||
const myBadge:string = md?.user?.badge || "";
|
||||
if (!myBadge) { return; }
|
||||
listBadges(ctx, {}, undefined, all => {
|
||||
if (!all.includes(myBadge)) {
|
||||
const profile = ctx?.store?.modules?.profile;
|
||||
profile?.execCommand(void 0, {
|
||||
cmd: 'SET',
|
||||
data: {
|
||||
key: 'badge',
|
||||
value: ''
|
||||
}
|
||||
}, () => {});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
listBadges: _listBadges,
|
||||
removeClient: () => {},
|
||||
|
||||
@ -6,6 +6,8 @@ const factory = (Util, Hash, Constants, Realtime,
|
||||
Messaging, Listmap, Crypto, ChainPad) => {
|
||||
var Profile = {};
|
||||
|
||||
const onReady = Util.mkEvent(true);
|
||||
|
||||
var initializeProfile = function (ctx, cb) {
|
||||
var profile = ctx.profile;
|
||||
if (!profile.edit || !profile.view) {
|
||||
@ -71,6 +73,7 @@ const factory = (Util, Hash, Constants, Realtime,
|
||||
});
|
||||
ctx.onReadyHandlers = [];
|
||||
}
|
||||
onReady.fire();
|
||||
}).on('change', [], function () {
|
||||
ctx.emit('UPDATE', lm.proxy, ctx.clients);
|
||||
});
|
||||
@ -99,24 +102,26 @@ const factory = (Util, Hash, Constants, Realtime,
|
||||
};
|
||||
|
||||
var setValue = function (ctx, data, cId, cb) {
|
||||
var key = data.key;
|
||||
var value = data.value;
|
||||
if (!key) { return; }
|
||||
ctx.listmap.proxy[key] = value;
|
||||
Realtime.whenRealtimeSyncs(ctx.listmap.realtime, function () {
|
||||
ctx.emit('UPDATE', ctx.listmap.proxy, ctx.clients.filter(function (clientId) {
|
||||
return clientId !== cId;
|
||||
}));
|
||||
if (key === 'badge') {
|
||||
ctx.Store.set(null, {
|
||||
key: ['profile', 'badge'],
|
||||
value: value || undefined
|
||||
}, () => {
|
||||
Messaging.updateMyData(ctx.store);
|
||||
ctx.updateMetadata();
|
||||
});
|
||||
}
|
||||
cb(ctx.listmap.proxy);
|
||||
onReady.reg(() => {
|
||||
var key = data.key;
|
||||
var value = data.value;
|
||||
if (!key) { return; }
|
||||
ctx.listmap.proxy[key] = value;
|
||||
Realtime.whenRealtimeSyncs(ctx.listmap.realtime, function () {
|
||||
ctx.emit('UPDATE', ctx.listmap.proxy, ctx.clients.filter(function (clientId) {
|
||||
return clientId !== cId;
|
||||
}));
|
||||
if (key === 'badge') {
|
||||
ctx.Store.set(null, {
|
||||
key: ['profile', 'badge'],
|
||||
value: value || undefined
|
||||
}, () => {
|
||||
Messaging.updateMyData(ctx.store);
|
||||
ctx.updateMetadata();
|
||||
});
|
||||
}
|
||||
cb(ctx.listmap.proxy);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@ -15,6 +15,10 @@ define([
|
||||
error: 'fa-exclamation-circle'
|
||||
};
|
||||
|
||||
// safeBadges won't show an error when they aren't active anymore
|
||||
// --> we just hide them
|
||||
Badges.safeBadges = ["premium"];
|
||||
|
||||
Badges.render = id => {
|
||||
let icon = badges[id];
|
||||
if (!icon) { return; }
|
||||
|
||||
@ -441,7 +441,9 @@ MessengerUI, Messages, Pages, PadTypes) {
|
||||
if (typeof (v) === "string") {
|
||||
addBadge(v);
|
||||
} else if (v === false) {
|
||||
addBadge('error');
|
||||
if (!Badges.safeBadges.includes(data.badge)) {
|
||||
addBadge('error');
|
||||
}
|
||||
} else {
|
||||
let ev = validatedBadges[key] ||= Util.mkEvent(true);
|
||||
ev.reg(badge => { addBadge(badge); });
|
||||
@ -454,6 +456,7 @@ MessengerUI, Messages, Pages, PadTypes) {
|
||||
}, res => {
|
||||
if (!res?.verified) {
|
||||
validatedBadges[key] = false;
|
||||
if (Badges.safeBadges.includes(data.badge)) { return; }
|
||||
return void addBadge('error');
|
||||
}
|
||||
validatedBadges[key] = res.badge;
|
||||
|
||||
2
www/common/worker.bundle.min.js
vendored
2
www/common/worker.bundle.min.js
vendored
File diff suppressed because one or more lines are too long
@ -347,7 +347,11 @@ define([
|
||||
nid: privateData.channel
|
||||
}, res => {
|
||||
if (!res?.verified) {
|
||||
data.badge = 'error';
|
||||
if (Badges.safeBadges.includes(data.badge)) {
|
||||
delete data.badge;
|
||||
} else {
|
||||
data.badge = 'error';
|
||||
}
|
||||
displayAvatar(val, data, true);
|
||||
return;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user