I am trying to create a part of my app which allows users to message one another. The messages will only be one-to-one PM. I'm using Parse as the backend. Any suggestions?
You need to have an associative table ( create it from your Parse.com website account ) that should contains the pointer to the sender User, the pointer to the Receiver User and the message to send. So:
let's call the table class you need as "UsersChat"
objectId (string) default parse field
senderUser (Pointer:User) pointer to the user who send the message
receiverUser (Pointer:User) pointer to the user who will receive the message
message (string) concrete message to send
createdAt (Date) default parse field that contains the creation row, so the sent message date/time we can say
updatedAt (Date) default parse field
ACL (ACL) default parse field
Related
The Agora.io doc is specifing for the joinChannel method :
The user ID. A 32-bit unsigned integer with a value ranging from 1 to
(2^32 -1). This parameter must be unique. If uid is not assigned (or set
as 0), the SDK assigns a uid and reports it in the joinChannelSuccess
callback. The app must maintain this user ID.
I have 2 use cases :
For the users registered to my app : i want the app to assign an uid
For the users not registered to my app : I want to let agora.io decide of the uid
The issue is that doing so, I may get into collisions between userIds assigned by the app and usersIds assigned by agora lib.
But if you are assigning uids within a range of values (other than 1 -> 2^32) then i could rely on that.
Is it the case ?
thx.
in this case, i think you can use the string user name to join the channel. You can take a look at this doc: https://docs.agora.io/en/faq/string
Is there a way to pass the data as an entity within another entity? What I'm trying to get to is this: I'm passing customer details to my database, via the webmethod : PostData. What I want is to pass details such as name, surname, etc as string, but I want to group some details, like vehicle details to be passed as : vehicle.Manufacturer vehicle.Model... etc The other data that are not group-able will be passed as an ordinary string. Hope that makes sense. Is there a way to do this?
You can do this either by XML or JSON, so the object that in the part of request will be like in XML :
<VehicleEntity>
<attribute1>value</attribute1>
<attribute2>value</attribute2>
</VehicleEntity>
or Similarly using JSON
VehilceEntity{
attribute1 :value;
attribute2 :value;
}
Basically it is similar to how you are passing parameter, here it is custom parameter VehicleEntity
Suppose I am updating a employee record
url - /api/employees/10
body -
{
id : 10,
name : xyz
}
Should I validate for the employee id in url is same as in response? Because one employee can hit the url himself but update the data of another employee by sending another value in the PUT body.
If you have to validate, it's likely that you want to use POST. A POST is not idempotent and you are supposed to manage the change.
PUT is idempotent, and it just creates a resource. It implies that you don't actually care what id 10 is and whether it is a new id or an existing id. You just replace id 10 with the resource you supply. You only use PUT when you know what the uri should be.
Yes, if the representation of the object in the body contains its own key, you should validate that it matches the key from the URL. It's an error for the client to try to PUT an object at /api/employees/10 that isn't a valid value for employee #10's record, so you should check for that and report it as an error just as you would check that the object has correct syntax.
I believe that the best error code to return in this case is 422 Unprocessable Entity, but I might be wrong about that.
Another thing you can do instead is don't include the key at all in the body. However I find that keeping the key in makes sense for consistency with the way the same type of object is represented in other parts of the API (possibly embedded inside other objects). This is especially true when using XML (although it looks like you are using JSON here).
SCENARIO: After the user has successfully logged in, I want to create an Account object (Account class is a part of my model) and fetch and store the user's information in it. I want this Account object to be accessible to all my controllers (HomeController, AccountController etc) and also, I want the ability to edit its content from inside any controller. (1) How can I achieve this scenario? (2) How can I pass a model object from one controller to another?
I intend to keep it till the user logs out
Then you can use session. But I suggest not saving a lot of information. So for example you have this model or entity:
public class AccountModel {
public int Id {get;set;}
public string Username {get;set;}
// and a whole lot more of properties
}
I suggest you just store an identifier field, either the Id or the Username. Then when another request comes in and you need to either validate the request or update that same model, you can:
Fetch the data again for that user and all relevant information
Update the necessary fields
Save it in your database
So you would do something like:
// to save it in a session after logging in
Session["current_user_id"] = id_variable;
// to retrieve it from session after another request comes in
var id = (int)Session["current_user_id"];
// fetch from your database
// do the necessary update
// persist the changes
(1) How can I achieve this scenario?
You could retrieve the Account model from your datastore when you need to access it.
(2) How can I pass a model object from one controller to another?
See (1). Since you are retrieving it from the data store you don't need to be passing it around.
I need to display a list of friend request that I have sent to. I tried using FQL:
SELECT time, message FROM friend_request WHERE uid_from = me()
However, this alway returns an error message:
The uid_from field is not indexed
Is there any way to achieve this?
This is not possible - the Documentation for the friend_request FQL table clearly shows that the only indexable field in the table is uid_to
You can read a list of friend requests sent to the current user, or check the status of any friend request sent by the current user provided that you know which user it was sent to.
i.e
SELECT time, message FROM friend_request WHERE uid_to = me()
or
SELECT time, message FROM friend_request WHERE uid_from = me() and uid_to = [USER ID HERE]
You cannot retrieve all friend requests sent by the current user.