Trying to get the server timestamp at the CreatedAt document field before the document is added to the cloud. So it could be applied to the Time property and also saved locally, However this is what I get:
My ChatTestMessageGroup Model
public class ChatTestMessageGroup : TimeTest
{
public long MessageId { get; set; }
public string Message { get; set; }
public string Time { get; set; }
}
public class TimeTest
{
[ServerTimestamp]
public Timestamp CreatedAt { get; set; }
public Timestamp StampAt { get; set; }
}
Send Message Execution code
private async Task SendTestMessageAsync()
{
if (string.IsNullOrWhiteSpace(Message)) return;
// under testing.
var test = new ChatTestMessageGroup()
{
MessageId = new Timestamp().ToDateTime().Ticks,
Message = Message.Trim(),
};
test.Time = $"{test.CreatedAt.ToDateTime():HH:mm}";
await CloudService.CS.SendMessageAsync(test);
Message = "";
}
Write To Cloud Code
public async Task SendMessageAsync(ChatTestMessageGroup testMessage)
{
IDocumentReference doc = CrossCloudFirestore.Current.Instance.Collection("Testing").Document(DateTime.Now.Day.ToString());
await doc.Collection("Tester").Document(${testMessage.CreatedAt.Seconds}").SetAsync(testMessage);
}
The plugin I'm using Plugin.CloudFirestore