How to create ChatRooms with Flutter/Firestore? - firebase

How do i go about creating chat groups where :
1- users can only join 1 group at a time.
2-that means users will not be able to see anything from that group without joining.
3- and useres have to exit existing group to join another.
4 also that means whatever been shared by users in that group will persist after user existing.
So I'm trying to create a session like functionality, but i have no idea how to implement that, any ideas?

Related

How to manage groups in SignalR core? (joining/leaving from all)

I have some questions about SignalR.
An app scenario: An user can join/leave to many groups (NxN). But
those groups can be changed with a new request. So, how to remove an
user from all joined groups and add him to new list of groups? (Such
as: in first request i join A,B,C groups and with second request i
want to be in only groupS X,Z -i'm not listening a,b,c groups anymore-).
How to check a group name if it's already exists?
How to remove a group if it has no users/members in it? (garbage collector)
Hope someone helps me here!
(Signalr core: 2.2)
SignalR don't provide you the list of users that are in groups, how many groups there are and their names. So the logic that you need to implement is create for example a Dictionary so you can add there the name of your group and the users that are associated to that group. So when a request comes to change user from group A to group B you can do:
Lookup in what groups the user is.
Remove the user from the group.
Create the new group and add it to your Dictionary.
Add the user to the new group.
I believe this is a good aproach if you have one SignalR app/host because if you will have many instances of your signalR app, you can not access to the Dictionary to see if there is a user in some group in some other instance.

NoSQL query of items,lists, Groups and Users using Firebase

Am looking at the data structure in this post and want to know how you would go about getting the emails of users who belong to a certain group when they could belong to several groups and the GroupID stored against that user is the current group they are participating in?
Do you store the email addresses with the userid under the "members" or, instead, for each member of the group, get that user's email address from the "users" document userid (this would mean iterating through the group/members collection and doing a query for each user. Not very efficient).
Am used to SQL so this is all new to me.
You should have a single node for each user
/users/UID/emails/
/users/UID/emailunread/
/users/UID/settings/
/users/UID/details/
/users/UID/payments/
So you can simply do a subscription for a singular node path this.myDatasubscription = this.DB.list('users/' + this.uid).snapshotChanges() ensuring changes like new emails or account settings will detected and rolled out in real time back to the app, so your are using angular/ng or something similar client side then your variables {{this.email_list}} should update real time with no page changes.
Take a look at this one.
error: Property 'getChildren' does not exist on type 'DataSnapshot'

How to obtain list of common users from different groups in firebase DB

Is there any way I can find if users is present in both the groups here: user 1 so that notification/data can be sent to only that set of common users only?
As DB grows I think it will be inefficient to check if every user in one group is present in another or not.
Yes there is. You can create a list of users from GroupA, then create another list of users from GroupsB and then just simply use this line of code using Java8:
!Collections.disjoint(list1, list2);

Drupal 7 OG Group Unsubscribe after given time period

I am new to drupal 7 and was willing to implement something like time based unsubscription from a OG Group.
I have users added in OG Group.
I want to implement time based unsubscription of the users already added in the group say 'Computers'.
User say 'Tony' is added to the group 'Computers' today, now I wish that a user 'Tony' should be unsubscribed from the group 'Computers' after a subscription of 3 months (a specific time period).
A Notification message should be sent to user 'Tony'.
All the process should be based on systems current date and the joining date of user 'Tony' to the group 'Computers'.
Please help me with any solution.
Try using the rules module: http://drupal.org/project/rules
Once you've enabled the module, you can create a rule (Administration » Configuration » Workflow » Rules) that runs each time cron is run on your site. I'm assuming cron runs hourly or daily.
On your new rule that runs with cron, you'll have to add several actions
Get group members from certain group
Loop on those members
Unsubscribe each user
Does that work for you?
Addition:
Another thing that may help you get your list of groups and/or group members for this is installing and using the Views Bulk Operations module: http://drupal.org/project/views_bulk_operations
Rules integrates with that, so maybe you can do the following:
Create a VBO view that lists all your members from a certain group you're interested in keeping clean. Use as a filter on your view the time they've been a member if you'd like...
Go back to your rule that runs on cron and choosing the following under 'Actions': 'Load list of entity ids from a VBO View' (screenshot attached)
Then add a loop on those users (second action)
Then add an action for that loop that unsubscribes the users (third action)

Permission based on one column - secure?

I am developing an early version of my site and before I create the production version, I'd like people's opinions on whether I'm going about things the right way. The main objective is to allow users to share playlists. I have the User table (ASP.NET Membership), Playlist table and a permission table. I'd like a user to create a playlist and grant/deny access to it for a given user. My approach to this is to have the permission table contain a "pStatus" column where 0/null = deny, 1 = read.
When a user requests permission to access a playlist, the creator chooses the pStatus enumeration. The column is then changed accordingly for the recipient. When accessing the recipient's profile page, a scan of the column is done to check all playlists the recipient has access to and the relevant playlists are displayed.
Is this an efficient and secure way of doing things? Or is relying on one column not enough?
(nb - playlists can be considered to be similar to Facebook groups)
Thanks for any advice
I would use some sort of bitmask in the n-m relation table I'm guessing is in between User and PlayList (i.e. a table named UserPlaylist, because 1 user can have access to more than 1 playlist and vice versa 1 playlist can be accessed by more than 1 user).
If you define the needed permission levels up front (i.e. 0 = no access, 1 = read, 2 = write, etc.), you can just add a column to the UserPlayList table, that represents the access level.
So the UserPlaylist table will have 2 foreign key columns of which the combination should be unique (i.e. define the primary key to be the 2 foreign key columns) and a column that holds the level of access in the form of a bit / integer.
So Permission has foreign keys to User and Playlist. Is there any reason for the third column specifying permission level? It sounds like it should be: If a row exists in Permission, the user is allowed to access the playlist.
Otherwise, that sounds good to me.

Resources