Skip to content

Instantly share code, notes, and snippets.

@sm00th
Created September 23, 2017 17:07
Show Gist options
  • Save sm00th/824a9ac46e2dabac1489f9d756e56b2c to your computer and use it in GitHub Desktop.
Save sm00th/824a9ac46e2dabac1489f9d756e56b2c to your computer and use it in GitHub Desktop.
proposed friendship changes
diff --git a/src/discord-handlers.c b/src/discord-handlers.c
index b38f807..72b9571 100644
--- a/src/discord-handlers.c
+++ b/src/discord-handlers.c
@@ -84,7 +84,6 @@ static void discord_handle_presence(struct im_connection *ic,
}
const char *status = json_o_str(pinfo, "status");
- int flags = 0;
if (uinfo->user->ic != ic ||
g_strcmp0(uinfo->user->handle, dd->uname) == 0) {
@@ -92,10 +91,12 @@ static void discord_handle_presence(struct im_connection *ic,
}
if (g_strcmp0(status, "online") == 0) {
- flags = BEE_USER_ONLINE;
+ uinfo->flags = BEE_USER_ONLINE;
} else if (g_strcmp0(status, "idle") == 0 ||
set_getbool(&ic->acc->set, "never_offline") == TRUE) {
- flags = BEE_USER_ONLINE | BEE_USER_AWAY;
+ uinfo->flags = BEE_USER_ONLINE | BEE_USER_AWAY;
+ } else {
+ uinfo->flags = 0;
}
for (GSList *cl = sinfo->channels; cl; cl = g_slist_next(cl)) {
@@ -103,7 +104,7 @@ static void discord_handle_presence(struct im_connection *ic,
if (cinfo->type == CHANNEL_TEXT) {
if (cinfo->to.channel.gc != NULL) {
- if (flags) {
+ if (uinfo->flags) {
imcb_chat_add_buddy(cinfo->to.channel.gc, uinfo->user->handle);
} else {
imcb_chat_remove_buddy(cinfo->to.channel.gc, uinfo->user->handle,
@@ -113,7 +114,13 @@ static void discord_handle_presence(struct im_connection *ic,
}
}
- imcb_buddy_status(ic, uinfo->name, flags, NULL, NULL);
+ bee_user_t *bu = bee_user_by_handle(ic->bee, ic, uinfo->name);
+ if (bu) {
+ if (set_getbool(&ic->acc->set, "friendship_mode") != TRUE ||
+ GPOINTER_TO_INT(bu->data) == TRUE) {
+ imcb_buddy_status(ic, uinfo->name, uinfo->flags, NULL, NULL);
+ }
+ }
}
static void discord_handle_user(struct im_connection *ic, json_value *uinfo,
@@ -192,14 +199,9 @@ static void discord_handle_relationship(struct im_connection *ic, json_value *ri
discord_handle_user(ic, uinfo, GLOBAL_SERVER_ID, ACTION_CREATE);
bu = bee_user_by_handle(ic->bee, ic, name);
}
-
if (bu) {
bu->data = GINT_TO_POINTER(TRUE);
- if (set_getbool(&ic->acc->set, "friendship_mode") == TRUE) {
- imcb_buddy_status(ic, name, BEE_USER_ONLINE, NULL, NULL);
- }
}
-
} else if (rtype == RELATIONSHIP_REQUEST_RECEIVED) {
// call imcb_ask() here
}
@@ -406,8 +408,7 @@ static void discord_handle_server(struct im_connection *ic, json_value *sinfo,
}
json_value *presences = json_o_get(sinfo, "presences");
- if (presences != NULL && presences->type == json_array &&
- set_getbool(&ic->acc->set, "friendship_mode") == FALSE) {
+ if (presences != NULL && presences->type == json_array) {
for (int pidx = 0; pidx < presences->u.array.length; pidx++) {
json_value *pinfo = presences->u.array.values[pidx];
discord_handle_presence(ic, pinfo, sdata->id);
@@ -784,8 +785,7 @@ void discord_parse_message(struct im_connection *ic, gchar *buf, guint64 size)
}
json_value *presences = json_o_get(data, "presences");
- if (presences != NULL && presences->type == json_array &&
- set_getbool(&ic->acc->set, "friendship_mode") == FALSE) {
+ if (presences != NULL && presences->type == json_array) {
for (int pidx = 0; pidx < presences->u.array.length; pidx++) {
json_value *pinfo = presences->u.array.values[pidx];
discord_handle_presence(ic, pinfo, id);
@@ -800,8 +800,7 @@ void discord_parse_message(struct im_connection *ic, gchar *buf, guint64 size)
} else if (g_strcmp0(event, "VOICE_STATE_UPDATE") == 0) {
json_value *vsinfo = json_o_get(js, "d");
discord_handle_voice_state(ic, vsinfo, json_o_str(vsinfo, "guild_id"));
- } else if (g_strcmp0(event, "PRESENCE_UPDATE") == 0 &&
- set_getbool(&ic->acc->set, "friendship_mode") == FALSE) {
+ } else if (g_strcmp0(event, "PRESENCE_UPDATE") == 0) {
json_value *pinfo = json_o_get(js, "d");
discord_handle_presence(ic, pinfo, json_o_str(pinfo, "guild_id"));
} else if (g_strcmp0(event, "CHANNEL_CREATE") == 0) {
diff --git a/src/discord.c b/src/discord.c
index 1eada10..ae21156 100644
--- a/src/discord.c
+++ b/src/discord.c
@@ -161,7 +161,6 @@ static struct groupchat *discord_chat_join(struct im_connection *ic,
struct groupchat *gc = NULL;
server_info *sinfo = NULL;
channel_info *cinfo = get_channel(dd, room, NULL, SEARCH_FNAME);
- gboolean friendship_mode = set_getbool(&ic->acc->set, "friendship_mode");
if (cinfo == NULL || cinfo->type != CHANNEL_TEXT) {
return NULL;
@@ -175,7 +174,7 @@ static struct groupchat *discord_chat_join(struct im_connection *ic,
for (GSList *ul = sinfo->users; ul; ul = g_slist_next(ul)) {
user_info *uinfo = ul->data;
- if (uinfo->user->flags & BEE_USER_ONLINE || friendship_mode == TRUE) {
+ if (uinfo->flags & BEE_USER_ONLINE) {
imcb_chat_add_buddy(gc, uinfo->user->handle);
}
}
diff --git a/src/discord.h b/src/discord.h
index 817bbe9..f158061 100644
--- a/src/discord.h
+++ b/src/discord.h
@@ -108,6 +108,7 @@ typedef struct _user_info {
char *name;
channel_info *voice_channel;
bee_user_t *user;
+ guint32 flags;
} user_info;
gboolean discord_is_self(struct im_connection *ic, const char *who);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment