Skip to content

Commit

Permalink
Handle new achievements on FE
Browse files Browse the repository at this point in the history
  • Loading branch information
megrogan committed Jul 16, 2024
1 parent 59e8f4e commit b951db7
Show file tree
Hide file tree
Showing 47 changed files with 1,179 additions and 159 deletions.
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
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/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
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": "加入了你的第一个群组",
"own_group_with_10_diamond_members": "拥有第一个群组/社区,其中有 10 名经过验证的成员",
"own_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",
"own_group_with_10_diamond_members": "Besitzen Sie Ihre erste Gruppe/Community mit 10 verifizierten Mitgliedern.",
"own_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
55 changes: 53 additions & 2 deletions frontend/app/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -519,21 +519,72 @@
"joinGroupFailed": "Unable to join {level}",
"lastOnline": "Last online {duration} ago",
"learnToEarn": {
"accepted_swap_offer": "Accepted your first swap offer",
"appointed_as_group_admin": "Been appointed an administrator of your first group/channel",
"appointed_as_group_mod": "Been appointed a moderator of your first group/channel",
"appointed_as_group_owner": "Been appointed an owner of your first group/channel",
"appointed_group_admin": "Appointed your first group/channel administrator",
"appointed_group_mod": "Appointed your first group/channel moderator",
"appointed_group_owner": "Appointed your first group/channel owner",
"changed_theme": "First time changing the theme",
"deleted_message": "Deleted first message",
"direct_chat_5": "Have 5 direct chats",
"direct_chats_10": "Have 10 direct chats",
"direct_chats_20": "Have 20 direct chats",
"edited_message": "Edited first message",
"enabled_disappearing_messages": "First time enabling disappearing messages",
"favourited_chat": "Marked your first chat as a favourite",
"followed_thread": "First time following a thread",
"forwarded_message": "Forwarded first message",
"had_message_tipped": "Had your first message tipped",
"joined_call": "Joined your first call",
"joined_community": "Joined your first community",
"joined_gated_group_or_community": "Joined your first gated group/channel",
"joined_group": "Joined your first group",
"own_group_with_10_diamond_members": "Owned your first group/community with 10 verified members",
"own_group_with_100_diamond_members": "Owned your first group/community with 100 verified members",
"owned_group_with_1_diamond_member": "Owned your first group/community with 1 verified member",
"owned_group_with_1000_diamond_members": "Owned your first group/community with 1000 verified members",
"percentageComplete": "{perc}% Complete",
"pinned_message": "Pinned your first message",
"proved_unique_personhood": "Proved your unique humanity",
"quote_replied": "Quote replied to first message",
"reacted_to_message": "Reacted to first message",
"received_crypto": "Received your first crypto message",
"received_direct_message": "Received your first direct message",
"received_reaction": "Received your first reaction on a message",
"replied_in_thread": "Started first reply in thread",
"sent_audio": "Sent your first audio",
"sent_crypto": "Sent your first crypto message",
"sent_direct_message": "Sent your first direct message",
"sent_file": "Sent your first file",
"sent_giphy": "Sent your first giphy",
"sent_image": "Sent your first image",
"sent_meme": "Sent your first meme message",
"sent_poll": "Sent your first poll",
"sent_prize": "Sent your first prize",
"sent_swap_offer": "Sent first P2P swap offer",
"sent_text": "Sent your first text message",
"sent_video": "Sent your first video",
"set_avatar": "Uploaded your profile avatar",
"set_bio": "Updated your profile bio",
"set_community_access_gate": "Set your first community access gate",
"set_community_display_name": "Set your first community display name",
"set_display_name": "Updated your display name",
"set_group_access_gate": "Set your first group/channel access gate",
"showChitPopup": "Notify me of my achievements",
"started_call": "Started first call",
"streak_14": "Achieved a 14 day streak",
"streak_3": "Achieved a 3 day streak",
"streak_30": "Achieved a 30 day streak",
"streak_7": "Achieved a 7 day streak",
"suggested_translation": "Suggested your fiurst translation",
"swapped_from_wallet": "Swapped your first token from the wallet",
"tipped_message": "Tipped first message",
"translation_accepted": "Had your first translation accepted",
"upgrade_to_gold_diamond": "Upgrade to Lifetime Diamond membership",
"upgraded_to_diamond": "Upgraded to Diamond membership"
"upgraded_to_diamond": "Upgraded to Diamond membership",
"voted_on_poll": "Voted on your first poll"
},
"leave": "Leave",
"leaveGroup": "Leave {level}",
Expand Down Expand Up @@ -1110,8 +1161,8 @@
"send": "Send",
"sendGif": "Send gif",
"sendMessage": "Send message",
"sendTextDisabled": "Text messages are disabled",
"sendMessageDisabledAnon": "Please sign-in to send a message",
"sendTextDisabled": "Text messages are disabled",
"sendTo": "Send to...",
"sessionExpired": "Session Expired",
"sessionExpiredBlurb": "Please sign in again",
Expand Down
Loading

0 comments on commit b951db7

Please sign in to comment.