Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User tagging in chats #203

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions extension/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,26 @@ def get_friends(request):
'type': 'contact'})
if len(data) > 5:
break

url = request.GET.get('url', '')

messages = ChatMessage.objects.filter(url=url).order_by('-date').select_related()

id_list = []
for suggested_user in data:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just create id_list above and add an append inside the for loop where items get added to data?

id_list.append(suggested_user['id'])

for message in messages:
commenter = message.author
if not query or query in commenter.username.lower():
if commenter.userprofile.id not in id_list:
id_list.append(commenter.userprofile.id)
data.append({'id': commenter.userprofile.id,
'name': '@%s' % (commenter.username),
'avatar': gravatar_for_user(commenter),
'type': 'contact'})
if len(data) > 10:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be >= 10? (if we want a maximum of 10 results).

break

return {'res': data}

Expand Down