tootle-linux-client/src/API/NotificationType.vala

87 lines
3.1 KiB
Vala
Raw Normal View History

2019-03-11 15:14:37 +01:00
public enum Tootle.API.NotificationType {
2018-04-17 14:01:55 +02:00
MENTION,
REBLOG,
REBLOG_REMOTE_USER, // Internal
2020-11-12 11:57:35 +01:00
FAVOURITE,
2018-05-09 17:32:53 +02:00
FOLLOW,
2021-02-12 16:26:37 +01:00
FOLLOW_REQUEST; // Internal
2018-04-17 14:01:55 +02:00
2020-05-29 14:19:35 +02:00
public string to_string () {
2018-04-17 14:01:55 +02:00
switch (this) {
case MENTION:
return "mention";
case REBLOG:
return "reblog";
case REBLOG_REMOTE_USER:
return "reblog_remote";
2020-11-12 11:57:35 +01:00
case FAVOURITE:
2018-04-17 14:01:55 +02:00
return "favourite";
case FOLLOW:
return "follow";
2018-05-09 17:32:53 +02:00
case FOLLOW_REQUEST:
return "follow_request";
2018-04-17 14:01:55 +02:00
default:
2020-05-29 14:19:35 +02:00
warning (@"Unknown notification type: $this");
return "";
2018-04-17 14:01:55 +02:00
}
}
2020-05-29 14:19:35 +02:00
public static NotificationType from_string (string str) throws Oopsie {
2018-04-17 14:01:55 +02:00
switch (str) {
case "mention":
return MENTION;
case "reblog":
return REBLOG;
case "reblog_remote":
return REBLOG_REMOTE_USER;
2018-04-17 14:01:55 +02:00
case "favourite":
2020-11-12 11:57:35 +01:00
return FAVOURITE;
2018-04-17 14:01:55 +02:00
case "follow":
return FOLLOW;
2018-05-09 17:32:53 +02:00
case "follow_request":
return FOLLOW_REQUEST;
2018-04-17 14:01:55 +02:00
default:
2020-05-29 14:19:35 +02:00
throw new Oopsie.INSTANCE (@"Unknown notification type: $str");
2018-04-17 14:01:55 +02:00
}
}
2018-04-17 14:01:55 +02:00
public string get_desc (Account? account) {
switch (this) {
case MENTION:
return _("<span underline=\"none\"><a href=\"%s\">%s</a> mentioned you</span>").printf (account.url, account.display_name);
2018-04-17 14:01:55 +02:00
case REBLOG:
return _("<span underline=\"none\"><a href=\"%s\">%s</a> boosted your status</span>").printf (account.url, account.display_name);
case REBLOG_REMOTE_USER:
return _("<span underline=\"none\"><a href=\"%s\">%s</a> boosted</span>").printf (account.url, account.display_name);
2020-11-12 11:57:35 +01:00
case FAVOURITE:
return _("<span underline=\"none\"><a href=\"%s\">%s</a> favorited your status</span>").printf (account.url, account.display_name);
2018-04-17 14:01:55 +02:00
case FOLLOW:
return _("<span underline=\"none\"><a href=\"%s\">%s</a> now follows you</span>").printf (account.url, account.display_name);
2018-05-09 17:32:53 +02:00
case FOLLOW_REQUEST:
return _("<span underline=\"none\"><a href=\"%s\">%s</a> wants to follow you</span>").printf (account.url, account.display_name);
2018-04-17 14:01:55 +02:00
default:
2020-05-29 14:19:35 +02:00
warning (@"Unknown notification type: $this");
return "";
2018-04-17 14:01:55 +02:00
}
}
2018-04-17 14:01:55 +02:00
public string get_icon () {
switch (this) {
case MENTION:
return "user-available-symbolic";
case REBLOG:
2020-05-29 14:19:35 +02:00
case REBLOG_REMOTE_USER:
2018-06-03 18:44:36 +02:00
return "media-playlist-repeat-symbolic";
2020-11-12 11:57:35 +01:00
case FAVOURITE:
2020-10-24 05:47:15 +02:00
return "starred-symbolic";
2018-04-17 14:01:55 +02:00
case FOLLOW:
2018-05-09 17:32:53 +02:00
case FOLLOW_REQUEST:
2018-04-17 14:01:55 +02:00
return "contact-new-symbolic";
default:
2020-05-29 14:19:35 +02:00
warning (@"Unknown notification type: $this");
return "";
2018-04-17 14:01:55 +02:00
}
}
2018-04-17 14:01:55 +02:00
}