Hello! I ask not that help, but more advice. I do standalone application using vk api. So I want the sound of a new message to be reproduced in my application when the user received it. It was thought to make a timer and request messages.get in it, but if you leave the sound playing in the timer, the sound will be repeated until the user reads all new messages. So how is it better to realize that the sound was once a message arrives?
- and what prevents you from playing the message only once, without repetition? - DreamChild
- So I don’t understand how to do it ... - Adept22
- well, it's pretty simple. Now I will try to describe in more detail - DreamChild
4 answers
I do not know the logic of your code, but I think you can do something like:
// переменная, в которой нужно хранить статусы сообщений (был ли проигран звук или нет) Dictionary<int, bool> messages = new Dictionary<int, bool>(); // этот код нужно вызывать при получении сообщения messages[newMessageId] = false; // этот код нужно вызывать в таймере foreach(var message in messages) { if(!message.value) { // ваша функция, вызывающая звуковой сигнал Ring(); // устанавливаем флаг, означающий, // что звуковой сигнал по сообщению уже был проигран message.Value = true; } } - Make a check for the existence of a key, and if it exists, then you don’t need to change the value - DreamChild
- Can't tell me how to do it? - Adept22
- use the ContainsKey method of a Dictionary - DreamChild
- Well thank you! - Adept22
- There is also an error in this place // set the flag, which means that // the sound signal according to the message has already been lost message. Value = true; Says: "Unable to assign value to property or indexer read-only access" - Adept22
Use push notifications. See account.registerDevice()
Well, I would check if there are any new messages, and if so, I remembered how many of them I had croaked. And when you click to view, I remembered how much I read. Then, when checking by timer, if there are unreads, then we subtract from the last number of unreadings the number of clicks Read. And if more than 0, then we scribble,)) well, somehow. In general, VC did not work, but I think every message has an ID, and, probably, it increases with each message.
Crutch, of course) But can immediately mark a message as read? And in your UI some indicator of the presence of new messages.
How is it not contained? Well, here is a link to the method for mark as read. https://vk.com/dev/messages.markAsRead How I see this for myself. In a loop in a separate thread, you request the presence of new unread messages. If there are any, you take the message id and save it to some sheet. The message is marked as read. Play the signal. On the form you are doing, for example, PicBox with a green circle, which will signal the presence of new messages. The user clicks on picBox and he is issued all unread messages by id from the list. Sheet cleaned and work on.