database design for chat application [closed] - entity-framework

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have a task to do chat application like whats-app, but more simple
requirements:
-Chat between ONLY 2 users
-For every contact to get the last message(same like whatsapp).
-need to refresh each 10 seconds and gets the new messages only that received to he user.
I was thinking of design to make one-to-many between User and Messages
for Each Users there many Messages, and in Messages to save only the messages that related User sent
And one-to-many between User and Contacts(friends)
But the problem is that in loadMessages I will have to check two user tables and get relevant messages.
and also to update lastMessage to contact is problem.
What you think
Thanks

My thoughts are:
1:N means 1-to-many relationship
N:N means many-to-many relationship
User:
ID
Name
1:N Messages Sent (Sender Id on message)
1:N Messages Received (Recipient Id on message)
User Relationships (N:N Linking table)
User1 Id
User2 Id
Relationship Type (i.e. friend)
Message:
Message Id
Sender Id
Recipient Id
Content
Time Stamp
We can only put Receiver ID in here because you said the chat can only be between two people.
If you want multiple recipients you'll want to create a message recipients table with:
Message Id
Recipient Id
Then create as many rows of this as there are recipients for the message.
You could make it even more generic by creating a Message Parties table:
Message Id
Party Id
Party Type (i.e. user)
Party Role (i.e. sender, recipient, etc.)

Related

Force Mailapp to always send from specific email address? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
The community is reviewing whether to reopen this question as of 1 year ago.
Improve this question
I've written a script that reads the date from a column in a spreadsheet in Google Sheets. It's separately attached to a trigger that runs daily. When the trigger runs, the date column is analyzed and compares the date to the current date to detect when it's 2 days out from date listed in the aforementioned column. For any matches, it pulls in other data from the same row(s) and generates an email for each row.
The trigger runs from a paid Google account since this script can send a lot of emails on any given day. The automation works perfectly fine.
However, I also have a use case where this same email needs to be manually triggered by users who work with this spreadsheet.
I have the script written to read the rows selected by the user, followed by allowing them to trigger the function under the macros. However, this causes the email generated by the script to be triggered from the active user, rather than through my paid account/email. Some users are using personal addresses, which causes a spoofing issue preventing email delivery in a series of instances.
How can I force the sender address to be from the paid account that's running the daily trigger, even in these scenarios where a user is manually triggering the macro/function?
MailApp hasn't a parameter to specify the sender, it always will use the email address of the effective user.
The active user is the user that that have opened the web app being used to run the function. The effective user might be different i.e. then a function has being executed by an installable trigger.
GmailApp allows to sent as the sender an email alias of the effective user. Another option is to use domain wide delegation of authority to impersonate a user from your domain.
Related
How to use the Gmail API, OAuth2 for Apps Script, and Domain-Wide Delegation to set email signatures for users in a G Suite domain
Resources
https://developers.google.com/apps-script/reference/gmail/
https://developers.google.com/apps-script/reference/mail/
If by "manual," you mean actually going into the editor and hitting run, there's not much that can be done for security reasons. However, if you deploy the app as a web app, it gives you an option in your deployment settings for users to execute as you (the paid account) or them.
Fig. 1
Fig. 2

How to manage user access level? Determine if he is admin or basic user [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I am new to Firebase, I am using Swift 4, There are lots of examples to do basic user authentication but I would like to know how I can create users as either admin or with basic access level and I would like to be able to determine when the user is logged in if he is admin or just a basic user?
Any concrete example on github based on KSigWyatt's answer below would be really appreciated.
Thank you
I would recommend that you use Firebase Database and save an attribute (something like isAdmin as a bool flag) for the user permissions.
There's no way to save application specific user attributes within Authentication. The only data that Auth stores are things like email address', social accounts, passwords of the user accounts.
First
Try something like this for your database:
Database/
Users/
UID/ -- Each of these are Unique
id: -Lrye7w8qtrewfr
isAdmin: true
...
...
...
Afterward...
Using ref.observeSingleEvent() once the user is logged in will return the snapshot for the child Document/Table "User" and the second child of the user's UID via Auth.auth().currentUser.uid
Capture the return using the same key as the attribute in the database. ["isAdmin"]

Send mail to a particular user from subscriber list in Sendy API

I have multiple users in Subscriber list (suppose 10 users) and I want to send email to only one user from that list. I cannot create one list per user as I will need to generate report also. So how can I achieve this without making any changes in their core code.
Thanks

Friend list through relations

I'm creating a social media app. I'm able to allow the current user to search for a PFUser and add the user to a friendship relation. I'm struggling on accessing the friendship relation and getting all the friends to create a table view right now. Could someone help me with this?
A Relation type in Parse represents just like what it literal meaning is. It's just a relation that contains no data. If you want to access the data inside the relation. You will need to perform query on it like so:
let query = relation.query() // I assume relation is an instance of PFRelation you want
Actually, Parse tutorial provides us a very comprehensive guide and you should check that first: https://parse.com/docs/ios/guide#relations
NOTE: This answer provides alternatives to using Relations to make a Friend System
I have created a friend system in two ways using Parse and both a function of your specific needs.
The first time I implemented a friend system. I had a table of Users and a table of Relationships. The Relationships table stored the usernames (or ObjectIds) of the two users in a relationship and the state of that relationship (friends, request sent, etc). The problem with this is that the queries can be kinda complicated, and if you have a lot of users, this may end up being too slow.
The second option is storing friend information in the User table itself. For each user, you add the columns with they type Array: Friends, RequestSent, and RequestReceived. Anytime a user sends a request they update their own user row and send a message to CloudCode to update the other affected user. Take a look at this example:
User A sends a request to User B:
User A adds user B's name to RequestSent
User A sends a message to cloud code that he/she wants to add user B
CloudCode adds User A's name to User B's RequestReceived
User B wants to accept User A's request
User B adds user A's name to Friends
User B removes user A's name from RequestSent
User B sends a message to CloudCode that he/she wants to accept User A's friend Request
CloudCode adds user A's name to Friends
CloudCode removes user A's name from RequestReceived
With this option, you never perform any server side queries. You only ever perform get operations. The downside to this option is if the logged-in user has thousands of friends/requests, it will take a while to download that information.
Note: The reason you have to use CloudCode is that a User can only change information about him/herself. The other option is to have CloudCode manage all the adding/removing so better checks can be made.
I found with this method that you can sometimes have one user who is listed a a friend in another users row but not their own. Controlling everything from CloudCode could eliminate this kind of error.

Email address as resource identifier in a REST API [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Say my application has users, and each user is uniquely identified by their email address. In that case, it makes sense to use the natural key of email rather than using an auto incrementing ID as the primary key, which is common in most systems.
Then, in my REST API, would it be okay to access a particular user like this?
https://api.whatever.com/v1/users/john#smith.com
Traditionally, you'd use the user ID in place of john#smith.com, but in my application the email address is the unique identifier for user accounts.
What would you pick? Using email as a natural key in REST URLs or create a user ID field to use instead?
I would use a user id. A person and their email address don't have a 1 to 1 relationship and they don't have the same life cycle, so using one as the identifier for the other is a bad idea.
People may have more than one email. Maybe they don't have an email account (it happens). Maybe they change their email. If you use the email address as the key, you might run into problems later on.
Should be url encoded
https://api.whatever.com/v1/users/john%40smith%2Ecom
Else fetching by id could by faster than by mail, and maybe you want to open the API to another application person, that should get the knowledge of the E-Mail address