Stop Firebase from adding index number of ObservableCollection - firebase-realtime-database

Does anyone know how I can stop Real Time Firebase from adding the index of an observable collection as a title? All code is listed below along with how the data is shown in Firebase.
How data is presented in Firebase:
Index 0 is added to the DB as title '0'
//Await task that post the code to firebase
public static async Task AddExercise(ObservableCollection<Exercise> exercisepassed)
{
await Client.Child("exercises").PostAsync(exercisepassed);
}
Code that get sent to await task :
addexercise1.Add(new Exercise
{
id = uniqeexid,
title = title,
UserId = uid,
DurationMinutes = durationMinutes,
StartDate = startdate,
NotificationIds = notificationIds,
Time = time,
VideoId = videoId,
Often = often,
exerciseid = exid });
await DbFirebase.AddExercise(addexercise1);

If you want to get rid of the -N7... type keys, call PutAsync instead of PostAsync.
If you want to get rid of the 0, then don't post a ObservableCollection<Exercise>, but instead post a single Exercise object.

Related

Updating event via MS Graph API removing Join Button in the event

I have created an event in the outlook calendar. The event contains Teams join link.
While I am updating the event from MS Graph API, the join button is being removed.
Here is the sample code of what I am doing:
void UpdateEventInCalendar(string eventId)
{
var getCalEvent = Task.Run(() =>
{
return service.Me.Events[eventId].Request().GetAsync();
});
Task.WaitAll(getCalEvent);
BodyType bodyType = BodyType.Text;
Event eventToUpdate = getCalEvent.Result;
Event updatedEvent = new Event();
updatedEvent.Id = eventToUpdate.Id;
updatedEvent.Subject = "Updated text";
updatedEvent.ShowAs = eventToUpdate.ShowAs;
updatedEvent.Body = new ItemBody
{
ContentType = bodyType,
Content = "Some new content"
};
graphServiceClient.Me.Events[updatedEvent.Id].Request().UpdateAsync(updatedEvent.Id);
}
Event before update:
Event update content:
Event after update:
How to keep the event while updating the event?
As a workaround you can try this to keep your online meeting appeared:
First: in your addEvent function, your body should be like this
AddedEvent.Body = new ItemBody
{
ContentType = BodyType.Html,
Content = "<p id = 'MsgContent'>Your Body</p>"
};
Second: In the update event, you can change the body content like this
HtmlDocument html = new HtmlDocument();
html.LoadHtml(EventToUpdate.Body.Content);
html.GetElementbyId("Msgcontent").InnerHtml = "Your new body";
updatedEvent.Body = EventToUpdate.Body;
updatedEvent.Body.Content = html.DocumentNode.OuterHtml;
Try not updating the body and you will be able to make it work. See this thread. Yes, if you update the body without isonlinemeeting, the teams meeting blob will be removed and this makes the isonlinemeeting property to false and we are loosing the button.
I faced the same issue and I got out with this solution, hope it helps.
You create an online event through the API with an empty body. The response from the server contains the HTML body with the join link and you store it. Then, if you update the event preserving all the online meeting related content, the event keeps having the join button, so you get the needed result.
If you update the event body deleting the online meeting related content, you loose the join button and, according to the docs, there's not much you can do about it.

Graph Api Delta token is not returning correct data

I am trying to use delta query to get the changes in one of the rooms calendars, when i use the start date and end date to set the initial request, it returns the correct events data and then afterwards when I use the delta token next time to make request, but it returns event data with tag saying this particular event has been deleted and does not return any valuable info apart form ID.
Here is my code
private async Task<IEventDeltaCollectionPage> GetEventData(GraphServiceClient graphClient, object deltaLink)
{
IEventDeltaCollectionPage page;
if (lastPage == null)
{
var queryOptions = new List<QueryOption>();
if (deltaLink == null)
{
queryOptions = new List<QueryOption>()
{
new QueryOption("startdatetime", "2020-01-16T00:00:00Z"),
new QueryOption("enddatetime", "2020-01-24T00:00:00Z")
};
}
else
{
queryOptions = new List<QueryOption>()
{
new QueryOption("$deltatoken", deltaLink.ToString())
};
}
page = await graphClient
.Users["nitroom2#domain.onmicrosoft.com"].CalendarView
.Delta()
.Request(queryOptions)
.GetAsync();
}
else
{
lastPage.InitializeNextPageRequest(graphClient, deltaLink.ToString());
page = await lastPage.NextPageRequest.GetAsync();
}
lastPage = page;
return page;
}
AS you can see this code will either look for dates range or delta token. so what I do is I initially make a call without a delta token, then once I get the final response I get the delta token. I restart the application this time and I provide the hard-coded delta token. Before restarting the application I also make sure that there is either a new event created or updated in the rooms calendar and then I restart the application with the delta token. I get a response back with some event data but that's telling me the event has been deleted, but that's not true.
Not sure what i am misisng here. can any abody suggest?
when using delta query Microsoft Graph returns as deleted new/updated/deleted items that are not in start-end date range of the initial request.
please check if that was your case :)

Stripe IOS SDK not matching AllResponseFields?

I'm trying to do a simple count check for a customer to see if they need to add a source before moving onto another page. However, my calls to the STPCustomer object's attributes are not matching the information for the full response.
I've tried clearing the customer cache and reloading the customer, but uh... still no match.
Here's a truncated like, essentials code. The class has the STPPaymentContextDelegate attached.
private var customerContext = STPCustomerContext?
private var paymentContext = STPPaymentContext?
func setupStripe() {
self.paymentContext = STPPaymentContext(customerContext: self.customerContext!)
self.paymentContext?.hostViewController = self
self.paymentContext?.delegate = self
self.paymentView = STPPaymentMethodsViewController(configuration: STPPaymentConfiguration.shared(), theme: STPTheme.default(), customerContext: self.customerContext!, delegate: self)
}
func getCustomerSources() {
if let customer = customerContext.retrieveCustomer({ (customer, error) in
if customer != nil {
print(customer.sources.count)
print(customer.sources)
print(customer.allResponseFields)
}
})
}
When I run getCustomerSources() on the test customer, I am expecting:
1
[ba_1Dvf46LrBVaGM6Sq9qIYhOlJ]
AnyHashable("id"): cus_number, AnyHashable("email"): rosa_diaz#gmail.com, AnyHashable("default_source"): ba_1Dvf46LrBVaGM6Sq9qIYhOlJ, AnyHashable("created"): 1548220659, AnyHashable("description"): LiG8WbVhT8SVhta8LdfUuWzOwQn2, AnyHashable("livemode"): 0, AnyHashable("object"): customer, AnyHashable("sources"): {
data = (
{
"bank_name" = "STRIPE TEST BANK";
country = US;
currency = usd;
customer = "cus_EOQzwwGPjzopjS";
fingerprint = 1AQMB9nzeGSGXHst;
id = "ba_1Dvf46LrBVaGM6Sq9qIYhOlJ";
last4 = 6789;
metadata = {
};
object = "bank_account";
"routing_number" = 110000000;
status = verified;
}
);
"has_more" = 0;
object = list;
"total_count" = 1;
url = "/v1/customers/cus_EOQzwwGPjzopjS/sources";
}])
However, instead of my 1 and ba_1Dvf46LrBVaGM6Sq9qIYhOlJ, I am getting 0 and []. But the allResponseFields section is the same.
Any ideas as to why there's a discrepancy between what the STPCustomer object attributes are returning and what the actual response is telling me?
it's hard to say what's going on without knowing more about the error parameter that your callback receives. It sounds like there might be an error parsing the API response, and printing the error passed into your retrieveCustomer block should give you a better idea about what's going on. If the error persists I'd recommend contacting support#stripe.com with details, as they can help directly with iOS app questions!

HTPP POST to Google Forms or Alternative

I have a google form setup that emails me upon a manual submission when somebody fills it out (new lead) and transfers the information to a Google spreadsheet. Easy enough to figure that out.
However, now I'm trying to figure out how to send the same information information contained within a url string and automatically POST that information to the form. Or find a company who offers that ability, via an api or other means. So far I've tested out jotform and a few others. The information passed along fine, but it doesn't auto populate the fields. I assume it's because it doesn't know that x=y due to the fields being named differently. I've found a ton of documentation about pre-populating the forms, but not much about filling out a form every time a new POST url is generated.
URL looks like the following
VARhttps://script.google.com/macros/s/XXXXXXXXXXXXXXXX/exec?/--A--
first_name--B--/--A--last_name--B--/--A--address1--B--/--A--city--B--/--A--
state--B--/--A--postal_code--B--/--A--phone_number--B--/--A--date_of_birth--
B--/--A--email--B--
Information passed is as follows
https://website
here.com/Pamela/Urne/123+Test+Street/Henderson/TX/75652/281XXXXXX/1974-01-
01/test0101cw#test.com
The script I'm testing out
// original from: http://mashe.hawksey.info/2014/07/google-sheets-as-a-database-insert-with-apps-script-using-postget-methods-with-ajax-example/
// original gist: https://gist.github.com/willpatera/ee41ae374d3c9839c2d6
function doGet(e){
return handleResponse(e);
}
// Enter sheet name where data is to be written below
var SHEET_NAME = "Sheet1";
var SCRIPT_PROP = PropertiesService.getScriptProperties(); // new property service
function handleResponse(e) {
// shortly after my original solution Google announced the LockService[1]
// this prevents concurrent access overwritting data
// [1] http://googleappsdeveloper.blogspot.co.uk/2011/10/concurrency-and-google-apps-script.html
// we want a public lock, one that locks for all invocations
var lock = LockService.getPublicLock();
lock.waitLock(30000); // wait 30 seconds before conceding defeat.
try {
// next set where we write the data - you could write to multiple/alternate destinations
var doc = SpreadsheetApp.openById(SCRIPT_PROP.getProperty("key"));
var sheet = doc.getSheetByName(SHEET_NAME);
// we'll assume header is in row 1 but you can override with header_row in GET/POST data
var headRow = e.parameter.header_row || 1;
var headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues()[0];
var nextRow = sheet.getLastRow()+1; // get next row
var row = [];
// loop through the header columns
for (i in headers){
if (headers[i] == "Timestamp"){ // special case if you include a 'Timestamp' column
row.push(new Date());
} else { // else use header name to get data
row.push(e.parameter[headers[i]]);
}
}
// more efficient to set values as [][] array than individually
sheet.getRange(nextRow, 1, 1, row.length).setValues([row]);
// return json success results
return ContentService
.createTextOutput(JSON.stringify({"result":"success", "row": nextRow}))
.setMimeType(ContentService.MimeType.JSON);
} catch(e){
// if error return this
return ContentService
.createTextOutput(JSON.stringify({"result":"error", "error": e}))
.setMimeType(ContentService.MimeType.JSON);
} finally { //release lock
lock.releaseLock();
}
}
function setup() {
var doc = SpreadsheetApp.getActiveSpreadsheet();
SCRIPT_PROP.setProperty("key", doc.getId());
}
I get a success message after accessing the url, but all information listed in the spreadsheet is "Undefined."
That's as far as I got so far. If somebody knows an easier solution or can point me in the right direction I'd appreciate it.

Let user turn off different notification types using parse.com's cloud code

First time posting on here so bear with me. I am taking a dive into parse.com's cloud code without any knowledge of javascript so I could use a little help.
I got an afterSave push notification working with Cloud Code but I need a way to allow users to subscribe/unsubscribe from different types of notifications. The way I am currently attempting to do this is by storing bool values in the parse user table for the different types of notifications but I'm having trouble getting that value in cloud code. Here is my cloud code:
Parse.Cloud.afterSave("Comment", function(request){
var comment = request.object;
var fromUser = request.user;
var onIdea = comment.get("ideaPointer");
var ideaOwner = onIdea.get("owner");
var getNotification = ideaOwner.get("getCommentNotifications");
var message = fromUser.getUsername() + " commented on your idea.";
if (getNotification){
var pushQuery = new Parse.Query(Parse.Installation);
pushQuery.equalTo("user", ideaOwner);
Parse.Push.send({
where: pushQuery,
data: {
alert: message,
ideaId: onIdea.id
}
});
}
});
Here is the error that gets printed to the logs when a comment is saved:
Result: TypeError: Cannot call method 'get' of undefined at main.js:6:34
Here is the line it is having a problem with because it was working before I added it along with the if statement:
var getNotification = ideaOwner.get("getCommentNotifications");
getCommentNotifications is the bool value in the user table.
I'm also not sure if my if statement is written correctly or not:
if (getNotification){}
I have also verified that getCommentNotifications value for the ideaOwner I'm testing on isn't empty.
Any help with this issue or ideas on a better way to allow users to subscribe/unsubscribe from different notifications types would be much appreciated.
The other ends of the those pointers must be fetched. If they really are pointers, then you can treat them as incompletely initialized objects, so...
Parse.Cloud.afterSave("Comment", function(request){
var comment = request.object;
var fromUser = request.user;
var onIdea = comment.get("ideaPointer");
onIdea.fetch().then(function(onIdeaObject) {
var ideaOwner = onIdea.get("owner");
return ideaOwner.fetch();
}).then(function(ideaOwnerObject) {
var getNotification = ideaOwnerObject.get("getCommentNotifications");
if (getNotification) {
var message = fromUser.getUsername() + " commented on your idea.";
var pushQuery = new Parse.Query(Parse.Installation);
pushQuery.equalTo("user", ideaOwnerObject);
return Parse.Push.send({ where: pushQuery, data: { alert: message, ideaId: onIdea.id } });
}
});
});

Resources