Skip to content

Commit

Permalink
Handle new achievements on FE (#6043)
Browse files Browse the repository at this point in the history
  • Loading branch information
megrogan authored Jul 17, 2024
1 parent f086794 commit 3e8951f
Show file tree
Hide file tree
Showing 51 changed files with 1,146 additions and 167 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn edit_message_impl(args: Args, state: &mut RuntimeState) -> Response {
handle_activity_notification(state);

if args.new_achievement {
state.notify_user_of_achievements(sender, vec![Achievement::ReactedToMessage]);
state.notify_user_of_achievements(sender, vec![Achievement::EditedMessage]);
}

Success
Expand Down
5 changes: 4 additions & 1 deletion backend/canisters/community/impl/src/updates/send_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,10 @@ fn process_send_message_result(
);

if new_achievement {
state.notify_user_of_achievements(sender, Achievement::from_message(false, &result.message_event.event));
state.notify_user_of_achievements(
sender,
Achievement::from_message(false, &result.message_event.event, thread_root_message_index.is_some()),
);
}

Success(SuccessResult {
Expand Down
2 changes: 1 addition & 1 deletion backend/canisters/group/impl/src/updates/edit_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn edit_message_impl(args: Args, state: &mut RuntimeState) -> Response {
handle_activity_notification(state);

if args.new_achievement {
state.notify_user_of_achievements(sender, vec![Achievement::ReactedToMessage]);
state.notify_user_of_achievements(sender, vec![Achievement::EditedMessage]);
}

Success
Expand Down
5 changes: 4 additions & 1 deletion backend/canisters/group/impl/src/updates/send_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@ fn process_send_message_result(
handle_activity_notification(state);

if new_achievement {
state.notify_user_of_achievements(sender, Achievement::from_message(false, &result.message_event.event));
state.notify_user_of_achievements(
sender,
Achievement::from_message(false, &result.message_event.event, thread_root_message_index.is_some()),
);
}

Success(SuccessResult {
Expand Down
2 changes: 1 addition & 1 deletion backend/canisters/user/impl/src/updates/edit_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn edit_message_impl(args: Args, state: &mut RuntimeState) -> Response {
})),
);

state.data.award_achievement_and_notify(Achievement::ReactedToMessage, now);
state.data.award_achievement_and_notify(Achievement::EditedMessage, now);
}
Success
}
Expand Down
2 changes: 1 addition & 1 deletion backend/canisters/user/impl/src/updates/send_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ fn send_message_impl(

state
.data
.award_achievements_and_notify(Achievement::from_message(true, &message_event.event), now)
.award_achievements_and_notify(Achievement::from_message(true, &message_event.event, false), now)
}

register_timer_jobs(
Expand Down
10 changes: 5 additions & 5 deletions backend/libraries/types/src/achievement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ pub enum Achievement {
Streak30,

SentPoll,
VotedOnPoll,
SentText,
SentImage,
SentVideo,
Expand All @@ -29,10 +28,9 @@ pub enum Achievement {
SentGiphy,
SentPrize,
SentMeme,
SentReminder,
StartedCall,
SentCrypto,
SentP2PSwapOffer,
StartedCall,
ReactedToMessage,
EditedMessage,
RepliedInThread,
Expand All @@ -41,6 +39,8 @@ pub enum Achievement {
DeletedMessage,
ForwardedMessage,

SentReminder,
VotedOnPoll,
ReceivedCrypto,
HadMessageReactedTo,
HadMessageTipped,
Expand Down Expand Up @@ -145,7 +145,7 @@ impl Achievement {
}
}

pub fn from_message(direct: bool, message: &Message) -> Vec<Achievement> {
pub fn from_message(direct: bool, message: &Message, is_thread: bool) -> Vec<Achievement> {
let mut achievements = Vec::new();

if let Some(achievement) = message.content.to_achievement() {
Expand All @@ -162,7 +162,7 @@ impl Achievement {

if message.replies_to.is_some() {
achievements.push(Achievement::QuoteReplied);
} else if message.thread_summary.is_some() && message.message_index == MessageIndex::from(0) {
} else if is_thread && message.message_index == MessageIndex::from(0) {
achievements.push(Achievement::RepliedInThread);
}

Expand Down
8 changes: 7 additions & 1 deletion backend/libraries/types/src/message_content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,13 @@ impl MessageContent {
MessageContent::ReportedMessage(_) => None,
MessageContent::P2PSwap(_) => Some(Achievement::SentP2PSwapOffer),
MessageContent::VideoCall(_) => Some(Achievement::StartedCall),
MessageContent::Custom(_) => None,
MessageContent::Custom(c) => {
if c.kind == "meme_fighter" {
Some(Achievement::SentMeme)
} else {
None
}
}
}
}

Expand Down
30 changes: 26 additions & 4 deletions frontend/app/src/components/home/profile/LearnToEarn.svelte
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<script lang="ts">
import CheckCircle from "svelte-material-icons/CheckCircle.svelte";
import CheckCircleOutline from "svelte-material-icons/CheckCircleOutline.svelte";
import { OpenChat, achievements } from "openchat-client";
import { OpenChat, achievements, type Achievement } from "openchat-client";
import ModalContent from "../../ModalContent.svelte";
import Overlay from "../../Overlay.svelte";
import Translatable from "../../Translatable.svelte";
import { i18nKey } from "../../../i18n/i18n";
import { _ } from "svelte-i18n";
import { i18nKey, } from "../../../i18n/i18n";
import Button from "../../Button.svelte";
import { createEventDispatcher, getContext } from "svelte";
import { iconSize } from "../../../stores/iconSize";
Expand All @@ -14,11 +15,32 @@
const dispatch = createEventDispatcher();
const client = getContext<OpenChat>("client");
const enabled = new Set<Achievement>([
"streak_3",
"streak_7",
"streak_14",
"streak_30",
"set_bio",
"set_avatar",
"joined_group",
"joined_community",
"sent_direct_message",
"received_direct_message",
"upgraded_to_diamond",
"set_display_name",
"upgrade_to_gold_diamond",
]);
$: globalState = client.globalStateStore;
$: [achieved, notAchieved] = client.partition([...achievements], (a) =>
$: filtered = [...achievements].filter(filter);
$: [achieved, notAchieved] = client.partition(filtered, (a) =>
$globalState.achievements.has(a),
);
$: percComplete = Math.floor((achieved.length / achievements.length) * 100);
$: percComplete = Math.floor((achieved.length / filtered.length) * 100);
function filter(achievement: Achievement): boolean {
return enabled.has(achievement) || $globalState.achievements.has(achievement);
}
</script>

<Overlay dismissible>
Expand Down
55 changes: 53 additions & 2 deletions frontend/app/src/i18n/cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -519,21 +519,72 @@
"joinGroupFailed": "无法加入{level}",
"lastOnline": "上次在线 {duration} 前",
"learnToEarn": {
"accepted_swap_offer": "接受了您的第一个掉期报价",
"appointed_as_group_admin": "被任命为第一个群组/频道的管理员",
"appointed_as_group_mod": "被任命为第一个群组/频道的版主",
"appointed_as_group_owner": "被任命为第一个群组/频道的所有者",
"appointed_group_admin": "任命了您的第一个群组/频道管理员",
"appointed_group_mod": "任命了您的第一位群组/频道管理员",
"appointed_group_owner": "指定了您的第一个群组/频道所有者",
"changed_theme": "第一次更换主题",
"deleted_message": "删除了第一条消息",
"direct_chat_5": "进行 5 次直接聊天",
"direct_chats_10": "进行 10 次直接聊天",
"direct_chats_20": "进行 20 次直接聊天",
"edited_message": "编辑第一条消息",
"enabled_disappearing_messages": "首次启用“消失的消息”",
"favourited_chat": "将你的第一次聊天标记为收藏",
"followed_thread": "第一次关注帖子",
"forwarded_message": "转发第一条消息",
"had_message_tipped": "你的第一条信息被泄露",
"joined_call": "加入了你的第一次通话",
"joined_community": "加入你的第一个社区",
"joined_gated_group_or_community": "加入你的第一个封闭群组/频道",
"joined_group": "加入了你的第一个群组",
"owned_group_with_10_diamond_members": "拥有第一个群组/社区,其中有 10 名经过验证的成员",
"owned_group_with_100_diamond_members": "拥有第一个拥有 100 名经过验证的成员的群组/社区",
"owned_group_with_1_diamond_member": "拥有第一个群组/社区,其中有 1 名经过验证的成员",
"owned_group_with_1000_diamond_members": "拥有第一个拥有 1000 名经过验证的成员的群组/社区",
"percentageComplete": "{perc}% 完成",
"pinned_message": "已置顶您的第一条消息",
"proved_unique_personhood": "证明了你独特的人性",
"quote_replied": "引用对第一条消息的回复",
"reacted_to_message": "对第一条消息做出回应",
"received_crypto": "收到你的第一个加密消息",
"received_direct_message": "收到你的第一条私信",
"received_reaction": "收到你对消息的第一反应",
"replied_in_thread": "开始在主题中回复第一条消息",
"sent_audio": "发送了你的第一条音频",
"sent_crypto": "发送了第一条加密消息",
"sent_direct_message": "发送了第一条私信",
"sent_file": "发送了你的第一个文件",
"sent_giphy": "发送了你的第一个 giphy",
"sent_image": "发送了你的第一张图片",
"sent_meme": "发送了你的第一条 meme 消息",
"sent_poll": "发送了您的第一个投票",
"sent_prize": "已发送您的一等奖",
"sent_swap_offer": "发送第一个 P2P 交换要约",
"sent_text": "发送了第一条短信",
"sent_video": "发送了你的第一个视频",
"set_avatar": "已上传您的个人资料头像",
"set_bio": "更新了您的个人简介",
"set_community_access_gate": "设置您的第一个社区出入口",
"set_community_display_name": "设置您的第一个社区显示名称",
"set_display_name": "已更新您的显示名称",
"set_group_access_gate": "设置第一个群组/通道访问门",
"showChitPopup": "通知我我的成就",
"started_call": "开始第一次通话",
"streak_14": "已连续 14 天",
"streak_3": "已连续 3 天",
"streak_30": "已连续 30 天",
"streak_7": "已连续 7 天",
"suggested_translation": "建议你的第一个翻译",
"swapped_from_wallet": "从钱包中兑换了第一个代币",
"tipped_message": "已给小费的第一条消息",
"translation_accepted": "你的第一个翻译是否被接受",
"upgrade_to_gold_diamond": "升级为终身钻石会员",
"upgraded_to_diamond": "升级为钻石会员"
"upgraded_to_diamond": "升级为钻石会员",
"voted_on_poll": "首次投票"
},
"leave": "退出",
"leaveGroup": "离开{level}",
Expand Down Expand Up @@ -1110,8 +1161,8 @@
"send": "发送",
"sendGif": "发送动图",
"sendMessage": "发信息",
"sendTextDisabled": "短信已禁用",
"sendMessageDisabledAnon": "请登录以发送消息",
"sendTextDisabled": "短信已禁用",
"sendTo": "发给...",
"sessionExpired": "登录状态已过期",
"sessionExpiredBlurb": "请重新登录",
Expand Down
55 changes: 53 additions & 2 deletions frontend/app/src/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -519,21 +519,72 @@
"joinGroupFailed": "Beitritt zu {level} nicht möglich",
"lastOnline": "Zuletzt online vor {duration}",
"learnToEarn": {
"accepted_swap_offer": "Ihr erstes Tauschangebot angenommen",
"appointed_as_group_admin": "Wurde zum Administrator Ihrer ersten Gruppe/Ihres ersten Kanals ernannt",
"appointed_as_group_mod": "Wurde zum Moderator Ihrer ersten Gruppe/Ihres ersten Kanals ernannt",
"appointed_as_group_owner": "Wurde zum Eigentümer Ihrer ersten Gruppe/Ihres ersten Kanals ernannt",
"appointed_group_admin": "Dein erster Gruppen-/Kanaladministrator wurde ernannt",
"appointed_group_mod": "Ernennung Ihres ersten Gruppen-/Kanalmoderators",
"appointed_group_owner": "Den ersten Gruppen-/Kanalbesitzer ernannt",
"changed_theme": "Zum ersten Mal das Thema ändern",
"deleted_message": "Erste Nachricht gelöscht",
"direct_chat_5": "Führen Sie 5 direkte Chats",
"direct_chats_10": "Führen Sie 10 direkte Chats",
"direct_chats_20": "Führen Sie 20 direkte Chats",
"edited_message": "Erste Nachricht bearbeitet",
"enabled_disappearing_messages": "Zum ersten Mal verschwindende Nachrichten aktivieren",
"favourited_chat": "Den ersten Chat als Favorit markiert",
"followed_thread": "Das erste Mal, dass ich einem Thread folge",
"forwarded_message": "Erste Nachricht weitergeleitet",
"had_message_tipped": "Ihre erste Nachricht wurde getippt",
"joined_call": "Bei Ihrem ersten Anruf dabei",
"joined_community": "Ihrer ersten Community beigetreten",
"joined_gated_group_or_community": "Ihrer ersten geschlossenen Gruppe/Ihrem ersten geschlossenen Kanal beigetreten",
"joined_group": "Ihrer ersten Gruppe beigetreten",
"owned_group_with_10_diamond_members": "Besitzen Sie Ihre erste Gruppe/Community mit 10 verifizierten Mitgliedern.",
"owned_group_with_100_diamond_members": "Besitzen Sie Ihre erste Gruppe/Community mit 100 verifizierten Mitgliedern.",
"owned_group_with_1_diamond_member": "Besitzen Sie Ihre erste Gruppe/Community mit 1 verifiziertem Mitglied.",
"owned_group_with_1000_diamond_members": "Besitzen Sie Ihre erste Gruppe/Community mit 1000 verifizierten Mitgliedern.",
"percentageComplete": "{perc} % abgeschlossen",
"pinned_message": "Deine erste Nachricht angepinnt",
"proved_unique_personhood": "Deine einzigartige Menschlichkeit unter Beweis gestellt",
"quote_replied": "Zitat: Antwort auf erste Nachricht",
"reacted_to_message": "Auf die erste Nachricht reagiert",
"received_crypto": "Ihre erste Kryptonachricht erhalten",
"received_direct_message": "Deine erste Direktnachricht erhalten",
"received_reaction": "Ihre erste Reaktion auf eine Nachricht erhalten",
"replied_in_thread": "Habe mit der ersten Antwort im Thread begonnen",
"sent_audio": "Sende dein erstes Audio",
"sent_crypto": "Ihre erste Kryptonachricht gesendet",
"sent_direct_message": "Deine erste Direktnachricht gesendet",
"sent_file": "Ihre erste Datei gesendet",
"sent_giphy": "Dein erstes Giphy gesendet",
"sent_image": "Ihr erstes Bild gesendet",
"sent_meme": "Deine erste Meme-Nachricht gesendet",
"sent_poll": "Senden Sie Ihre erste Umfrage",
"sent_prize": "Versendet Ihren ersten Preis",
"sent_swap_offer": "Erstes P2P-Tauschangebot gesendet",
"sent_text": "Deine erste Textnachricht gesendet",
"sent_video": "Dein erstes Video gesendet",
"set_avatar": "Dein Profil-Avatar wurde hochgeladen",
"set_bio": "Ihre Profilbiografie wurde aktualisiert",
"set_community_access_gate": "Richten Sie Ihr erstes Gemeinschaftszugangstor ein",
"set_community_display_name": "Legen Sie Ihren ersten Community-Anzeigenamen fest",
"set_display_name": "Deinen Anzeigenamen hast du aktualisiert",
"set_group_access_gate": "Richten Sie Ihr erstes Gruppen-/Kanalzugriffstor ein",
"showChitPopup": "Benachrichtigen Sie mich über meine Erfolge",
"started_call": "Ersten Anruf gestartet",
"streak_14": "Eine 14-tägige Erfolgsserie erreicht",
"streak_3": "3 Tage lang erfolgreich gewesen",
"streak_30": "30 Tage lang erfolgreich gewesen",
"streak_7": "Eine 7-Tage-Serie erreicht",
"suggested_translation": "Ihre erste Übersetzung wurde vorgeschlagen",
"swapped_from_wallet": "Dein erstes Token aus der Wallet getauscht",
"tipped_message": "Erste Nachricht mit Trinkgeld",
"translation_accepted": "Ihre erste Übersetzung wurde akzeptiert",
"upgrade_to_gold_diamond": "Upgrade auf Lifetime Diamond-Mitgliedschaft",
"upgraded_to_diamond": "Upgrade auf Diamond-Mitgliedschaft"
"upgraded_to_diamond": "Upgrade auf Diamond-Mitgliedschaft",
"voted_on_poll": "Bei Ihrer ersten Umfrage abgestimmt"
},
"leave": "Verlassen",
"leaveGroup": "Verlasse {level}",
Expand Down Expand Up @@ -1110,8 +1161,8 @@
"send": "Senden",
"sendGif": "GIFs senden",
"sendMessage": "Nachricht senden",
"sendTextDisabled": "Textnachrichten sind deaktiviert",
"sendMessageDisabledAnon": "Bitte melden Sie sich an, um eine Nachricht zu senden",
"sendTextDisabled": "Textnachrichten sind deaktiviert",
"sendTo": "Senden an...",
"sessionExpired": "Sitzung abgelaufen",
"sessionExpiredBlurb": "Bitte neu anmelden",
Expand Down
Loading

0 comments on commit 3e8951f

Please sign in to comment.