aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2021-11-14 00:10:04 +0100
committerTheJackiMonster <thejackimonster@gmail.com>2021-11-14 00:10:04 +0100
commit41b1445ce9191b4f4a3a6355dad24d39945f3b69 (patch)
treebb4ca42dffc1108f8fb52b53e21fe3c833bc6035
parent22d772e80767fb3222c1c7eecf43f77994ef7701 (diff)
downloadlibgnunetchat-41b1445ce9191b4f4a3a6355dad24d39945f3b69.tar.gz
libgnunetchat-41b1445ce9191b4f4a3a6355dad24d39945f3b69.zip
Joining members will automatically be added as contacts
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r--src/gnunet_chat_handle_intern.c84
-rw-r--r--src/gnunet_chat_lib.c4
2 files changed, 50 insertions, 38 deletions
diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c
index 450c8c9..e212699 100644
--- a/src/gnunet_chat_handle_intern.c
+++ b/src/gnunet_chat_handle_intern.c
@@ -185,6 +185,47 @@ notify_handle_fs_progress(void* cls, const struct GNUNET_FS_ProgressInfo* info)
185 return NULL; 185 return NULL;
186} 186}
187 187
188int
189intern_provide_contact_for_member(struct GNUNET_CHAT_Handle *handle,
190 const struct GNUNET_MESSENGER_Contact *member,
191 struct GNUNET_CHAT_Context *context)
192{
193 GNUNET_assert((handle) && (handle->contacts));
194
195 if (!member)
196 return GNUNET_OK;
197
198 struct GNUNET_ShortHashCode shorthash;
199 util_shorthash_from_member(member, &shorthash);
200
201 struct GNUNET_CHAT_Contact *contact = GNUNET_CONTAINER_multishortmap_get(
202 handle->contacts, &shorthash
203 );
204
205 if (contact)
206 {
207 if ((context) && (NULL == contact->context))
208 contact->context = context;
209
210 return GNUNET_OK;
211 }
212
213 contact = contact_create_from_member(
214 handle, member
215 );
216
217 if (context)
218 contact->context = context;
219
220 if (GNUNET_OK == GNUNET_CONTAINER_multishortmap_put(
221 handle->contacts, &shorthash, contact,
222 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
223 return GNUNET_OK;
224
225 contact_destroy(contact);
226 return GNUNET_SYSERR;
227}
228
188struct GNUNET_CHAT_CheckHandleRoomMembers 229struct GNUNET_CHAT_CheckHandleRoomMembers
189{ 230{
190 const struct GNUNET_IDENTITY_PublicKey *ignore_key; 231 const struct GNUNET_IDENTITY_PublicKey *ignore_key;
@@ -257,21 +298,9 @@ request_handle_context_by_room (struct GNUNET_CHAT_Handle *handle,
257 { 298 {
258 context->type = GNUNET_CHAT_CONTEXT_TYPE_CONTACT; 299 context->type = GNUNET_CHAT_CONTEXT_TYPE_CONTACT;
259 300
260 struct GNUNET_CHAT_Contact *contact = contact_create_from_member( 301 if (GNUNET_OK == intern_provide_contact_for_member(
261 handle, check.contact 302 handle, check.contact, context))
262 );
263
264 contact->context = context;
265
266 struct GNUNET_ShortHashCode shorthash;
267 util_shorthash_from_member(check.contact, &shorthash);
268
269 if (GNUNET_OK == GNUNET_CONTAINER_multishortmap_put(
270 handle->contacts, &shorthash, contact,
271 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
272 return GNUNET_OK; 303 return GNUNET_OK;
273
274 contact_destroy(contact);
275 } 304 }
276 else if (checks >= 2) 305 else if (checks >= 2)
277 { 306 {
@@ -327,28 +356,10 @@ scan_handle_room_members (void* cls,
327{ 356{
328 struct GNUNET_CHAT_Handle *handle = cls; 357 struct GNUNET_CHAT_Handle *handle = cls;
329 358
330 GNUNET_assert((handle) && 359 if (GNUNET_OK == intern_provide_contact_for_member(handle, member, NULL))
331 (handle->contacts) &&
332 (member));
333
334 struct GNUNET_ShortHashCode shorthash;
335 util_shorthash_from_member(member, &shorthash);
336
337 if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_contains(
338 handle->contacts, &shorthash))
339 return GNUNET_YES; 360 return GNUNET_YES;
340 361 else
341 struct GNUNET_CHAT_Contact *contact = contact_create_from_member( 362 return GNUNET_NO;
342 handle, member
343 );
344
345 if (GNUNET_OK == GNUNET_CONTAINER_multishortmap_put(
346 handle->contacts, &shorthash, contact,
347 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
348 return GNUNET_YES;
349
350 contact_destroy(contact);
351 return GNUNET_NO;
352} 363}
353 364
354int 365int
@@ -427,7 +438,8 @@ on_handle_message (void *cls,
427 (msg) && 438 (msg) &&
428 (hash)); 439 (hash));
429 440
430 if (GNUNET_OK != request_handle_context_by_room(handle, room)) 441 if ((GNUNET_OK != request_handle_context_by_room(handle, room)) ||
442 (GNUNET_OK != intern_provide_contact_for_member(handle, sender, NULL)))
431 return; 443 return;
432 444
433 struct GNUNET_CHAT_Context *context = GNUNET_CONTAINER_multihashmap_get( 445 struct GNUNET_CHAT_Context *context = GNUNET_CONTAINER_multihashmap_get(
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
index 2e5c583..ffaa6a0 100644
--- a/src/gnunet_chat_lib.c
+++ b/src/gnunet_chat_lib.c
@@ -257,7 +257,7 @@ void
257GNUNET_CHAT_contact_set_name (struct GNUNET_CHAT_Contact *contact, 257GNUNET_CHAT_contact_set_name (struct GNUNET_CHAT_Contact *contact,
258 const char *name) 258 const char *name)
259{ 259{
260 if (!contact) 260 if ((!contact) || (!(contact->context)))
261 return; 261 return;
262 262
263 util_set_name_field(name, &(contact->context->nick)); 263 util_set_name_field(name, &(contact->context->nick));
@@ -270,7 +270,7 @@ GNUNET_CHAT_contact_get_name (const struct GNUNET_CHAT_Contact *contact)
270 if (!contact) 270 if (!contact)
271 return NULL; 271 return NULL;
272 272
273 if (contact->context->nick) 273 if ((contact->context) && (contact->context->nick))
274 return contact->context->nick; 274 return contact->context->nick;
275 275
276 return GNUNET_MESSENGER_contact_get_name(contact->member); 276 return GNUNET_MESSENGER_contact_get_name(contact->member);