group unread count

This commit is contained in:
2458773093
2019-07-20 02:04:08 +03:00
parent a6f09dc0c7
commit c5c2585239
3 changed files with 24 additions and 8 deletions

View File

@@ -10,14 +10,22 @@ module GroupInteractions
end
def admin_map(target_group_ids, account_id)
follow_mapping(GroupAccount.where(group_id: target_group_ids, account_id: account_id, role: :admin), :group_id)
end
follow_mapping(GroupAccount.where(group_id: target_group_ids, account_id: account_id, role: :admin), :group_id)
end
def unread_count_map(target_group_ids, account_id)
unread_count_mapping(GroupAccount.where(group_id: target_group_ids, account_id: account_id), :unread_count)
end
private
def follow_mapping(query, field)
query.pluck(field).each_with_object({}) { |id, mapping| mapping[id] = true }
end
def unread_count_mapping(query, field)
query.pluck(:group_id, :unread_count).each_with_object({}) { |e, mapping| mapping[e[0]] = e[1] }
end
end
end