aboutsummaryrefslogtreecommitdiffstats
path: root/protocols
diff options
context:
space:
mode:
Diffstat (limited to 'protocols')
-rw-r--r--protocols/twitter/twitter.c42
-rw-r--r--protocols/twitter/twitter.h1
-rw-r--r--protocols/twitter/twitter_lib.c56
3 files changed, 51 insertions, 48 deletions
diff --git a/protocols/twitter/twitter.c b/protocols/twitter/twitter.c
index ee410abc..25304bbf 100644
--- a/protocols/twitter/twitter.c
+++ b/protocols/twitter/twitter.c
@@ -52,6 +52,10 @@ static void twitter_main_loop_start(struct im_connection *ic)
{
struct twitter_data *td = ic->proto_data;
+ /* Create the room now that we "logged in". */
+ if (td->flags & TWITTER_MODE_CHAT)
+ twitter_groupchat_init(ic);
+
imcb_log(ic, "Getting initial statuses");
// Run this once. After this queue the main loop function (or open the
@@ -75,6 +79,32 @@ static void twitter_main_loop_start(struct im_connection *ic)
}
}
+struct groupchat *twitter_groupchat_init(struct im_connection *ic)
+{
+ char *name_hint;
+ struct groupchat *gc;
+ struct twitter_data *td = ic->proto_data;
+ GSList *l;
+
+ if (td->timeline_gc)
+ return td->timeline_gc;
+
+ td->timeline_gc = gc = imcb_chat_new(ic, "twitter/timeline");
+
+ name_hint = g_strdup_printf("%s_%s", td->prefix, ic->acc->user);
+ imcb_chat_name_hint(gc, name_hint);
+ g_free(name_hint);
+
+ for (l = ic->bee->users; l; l = l->next) {
+ bee_user_t *bu = l->data;
+ if (bu->ic == ic)
+ imcb_chat_add_buddy(td->timeline_gc, bu->handle);
+ }
+ imcb_chat_add_buddy(gc, ic->acc->user);
+
+ return gc;
+}
+
static void twitter_oauth_start(struct im_connection *ic);
void twitter_login_finish(struct im_connection *ic)
@@ -85,8 +115,8 @@ void twitter_login_finish(struct im_connection *ic)
if (set_getbool(&ic->acc->set, "oauth") && !td->oauth_info)
twitter_oauth_start(ic);
- else if (g_strcasecmp(set_getstr(&ic->acc->set, "mode"), "one") != 0 &&
- !(td->flags & TWITTER_HAVE_FRIENDS)) {
+ else if ((td->flags & TWITTER_MODE_ONE) &&
+ !(td->flags & TWITTER_HAVE_FRIENDS)) {
imcb_log(ic, "Getting contact list");
twitter_get_friends_ids(ic, -1);
} else
@@ -353,6 +383,14 @@ static void twitter_login(account_t * acc)
td->log = g_new0(struct twitter_log_data, TWITTER_LOG_LENGTH);
td->log_id = -1;
+
+ s = set_getstr(&ic->acc->set, "mode");
+ if (g_strcasecmp(s, "one") == 0)
+ td->flags |= TWITTER_MODE_ONE;
+ else if (g_strcasecmp(s, "many") == 0)
+ td->flags |= TWITTER_MODE_MANY;
+ else
+ td->flags |= TWITTER_MODE_CHAT;
twitter_login_finish(ic);
}
diff --git a/protocols/twitter/twitter.h b/protocols/twitter/twitter.h
index 108d20b3..ceac4371 100644
--- a/protocols/twitter/twitter.h
+++ b/protocols/twitter/twitter.h
@@ -104,5 +104,6 @@ struct http_request;
char *twitter_parse_error( struct http_request *req );
void twitter_log(struct im_connection *ic, char *format, ... );
+struct groupchat *twitter_groupchat_init(struct im_connection *ic);
#endif //_TWITTER_H
diff --git a/protocols/twitter/twitter_lib.c b/protocols/twitter/twitter_lib.c
index f358b307..ad349c6f 100644
--- a/protocols/twitter/twitter_lib.c
+++ b/protocols/twitter/twitter_lib.c
@@ -69,8 +69,6 @@ struct twitter_xml_status {
guint64 id, reply_to;
};
-static void twitter_groupchat_init(struct im_connection *ic);
-
/**
* Frees a twitter_xml_user struct.
*/
@@ -147,17 +145,15 @@ static void twitter_add_buddy(struct im_connection *ic, char *name, const char *
// Check if the buddy is already in the buddy list.
if (!bee_user_by_handle(ic->bee, ic, name)) {
- char *mode = set_getstr(&ic->acc->set, "mode");
-
// The buddy is not in the list, add the buddy and set the status to logged in.
imcb_add_buddy(ic, name, NULL);
imcb_rename_buddy(ic, name, fullname);
- if (g_strcasecmp(mode, "chat") == 0) {
+ if (td->flags & TWITTER_MODE_CHAT) {
/* Necessary so that nicks always get translated to the
exact Twitter username. */
imcb_buddy_nick_hint(ic, name, name);
imcb_chat_add_buddy(td->timeline_gc, name);
- } else if (g_strcasecmp(mode, "many") == 0)
+ } else if (td->flags & TWITTER_MODE_MANY)
imcb_buddy_status(ic, name, OPT_LOGGED_IN, NULL, NULL);
}
}
@@ -305,10 +301,6 @@ static void twitter_http_get_friends_ids(struct http_request *req)
td = ic->proto_data;
- /* Create the room now that we "logged in". */
- if (!td->timeline_gc && g_strcasecmp(set_getstr(&ic->acc->set, "mode"), "chat") == 0)
- twitter_groupchat_init(ic);
-
txl = g_new0(struct twitter_xml_list, 1);
txl->list = td->follow_ids;
@@ -662,26 +654,6 @@ static char *twitter_msg_add_id(struct im_connection *ic,
}
}
-static void twitter_groupchat_init(struct im_connection *ic)
-{
- char *name_hint;
- struct groupchat *gc;
- struct twitter_data *td = ic->proto_data;
- GSList *l;
-
- td->timeline_gc = gc = imcb_chat_new(ic, "twitter/timeline");
-
- name_hint = g_strdup_printf("%s_%s", td->prefix, ic->acc->user);
- imcb_chat_name_hint(gc, name_hint);
- g_free(name_hint);
-
- for (l = ic->bee->users; l; l = l->next) {
- bee_user_t *bu = l->data;
- if (bu->ic == ic)
- imcb_chat_add_buddy(td->timeline_gc, bu->handle);
- }
-}
-
/**
* Function that is called to see the statuses in a groupchat window.
*/
@@ -694,12 +666,7 @@ static void twitter_groupchat(struct im_connection *ic, GSList * list)
guint64 last_id = 0;
// Create a new groupchat if it does not exsist.
- if (!td->timeline_gc)
- twitter_groupchat_init(ic);
-
- gc = td->timeline_gc;
- if (!gc->joined)
- imcb_chat_add_buddy(gc, ic->acc->user);
+ gc = twitter_groupchat_init(ic);
for (l = list; l; l = g_slist_next(l)) {
char *msg;
@@ -743,13 +710,10 @@ static void twitter_private_message_chat(struct im_connection *ic, GSList * list
struct twitter_data *td = ic->proto_data;
GSList *l = NULL;
struct twitter_xml_status *status;
- char from[MAX_STRING];
- gboolean mode_one;
+ char from[MAX_STRING] = "";
guint64 last_id = 0;
- mode_one = g_strcasecmp(set_getstr(&ic->acc->set, "mode"), "one") == 0;
-
- if (mode_one) {
+ if (td->flags & TWITTER_MODE_ONE) {
g_snprintf(from, sizeof(from) - 1, "%s_%s", td->prefix, ic->acc->user);
from[MAX_STRING - 1] = '\0';
}
@@ -764,17 +728,17 @@ static void twitter_private_message_chat(struct im_connection *ic, GSList * list
last_id = status->id;
strip_html(status->text);
- if (mode_one)
+ if (td->flags & TWITTER_MODE_ONE)
prefix = g_strdup_printf("\002<\002%s\002>\002 ",
- status->user->screen_name);
+ status->user->screen_name);
else
twitter_add_buddy(ic, status->user->screen_name, status->user->name);
text = twitter_msg_add_id(ic, status, prefix ? prefix : "");
imcb_buddy_msg(ic,
- mode_one ? from : status->user->screen_name,
- text ? text : status->text, 0, status->created_at);
+ *from ? from : status->user->screen_name,
+ text ? text : status->text, 0, status->created_at);
// Update the timeline_id to hold the highest id, so that by the next request
// we won't pick up the updates already in the list.
@@ -1016,7 +980,7 @@ void twitter_flush_timeline(struct im_connection *ic)
imcb_connected(ic);
// See if the user wants to see the messages in a groupchat window or as private messages.
- if (g_strcasecmp(set_getstr(&ic->acc->set, "mode"), "chat") == 0)
+ if (td->flags & TWITTER_MODE_CHAT)
twitter_groupchat(ic, output);
else
twitter_private_message_chat(ic, output);
0 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409