本文整理汇总了C++中DB::listUnreadMessages方法的典型用法代码示例。如果您正苦于以下问题:C++ DB::listUnreadMessages方法的具体用法?C++ DB::listUnreadMessages怎么用?C++ DB::listUnreadMessages使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DB
的用法示例。
在下文中一共展示了DB::listUnreadMessages方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HandlePacket
bool HandlePacket (Packet& request, Packet& response) {
int uid, mid;
if (request.getType() == PacketType::LOGIN_REQUEST) {
response.setType(PacketType::LOGIN_RESPONSE);
if (request.getData().size() == 2 && (uid = db.logIn(request.getData()[0], request.getData()[1])) != -1) {
__uint64_t sid = ((((__uint64_t) rand () & 0x77777777) << 32) | (rand () & 0x77777777));
sids [sid] = uid;
response.setSID(sid);
response.getData().push_back("1");
} else {
response.getData().push_back("0");
}
return true;
}
auto it = sids.find(request.getSID());
if (it == sids.end ()) {
response.setType(request.getType() + 1);
response.setSID (0);
return true;
}
response.setSID(request.getSID());
uid = it-> second;
switch (request.getType()) {
case PacketType::LOGOUT_REQUEST:
response.setType(PacketType::LOGOUT_RESPONSE);
sids.erase(request.getSID());
response.getData().push_back("1");
return true;
case PacketType::LATEST_REQUEST:
response.setType(PacketType::LATEST_RESPONSE);
response.getData().push_back(db.latestCheck(uid));
return true;
case PacketType::PULL_REQUEST:
response.setType(PacketType::PULL_RESPONSE);
if (request.getData().size() == 1) {
try {
mid = stoi (request.getData()[0]);
string msg = db.readMessage(uid, mid);
response.getData().push_back(msg);
} catch (exception& ex) { printf ("%s\r\n", ex. what ()); }
}
return true;
case PacketType::REMOVE_REQUEST:
response.setType(PacketType::REMOVE_RESPONSE);
if (request.getData().size() == 1) {
try {
mid = stoi (request.getData()[0]);
if (db.removeMessage(uid, mid)) {
response.getData().push_back("1");
return true;
}
} catch (exception& ex) { printf ("%s\r\n", ex. what ()); }
}
response.getData().push_back("0");
return true;
case PacketType::SEND_REQUEST:
response.setType(PacketType::SEND_RESPONSE);
if (request.getData().size() == 2 && db.sendMessage(uid, request.getData()[0], request.getData()[1])) {
response.getData().push_back("1");
return true;
}
response.getData().push_back("0");
return true;
case PacketType::NEWMESSAGES_REQUEST:
response.setType(PacketType::NEWMESSAGES_RESPONSE);
for (string id : db.listUnreadMessages(uid)) {
response.getData().push_back(id);
}
return true;
case PacketType::LISTMESSAGES_REQUEST:
response.setType(PacketType::LISTMESSAGES_RESPONSE);
for (string id : db.listAllMessages(uid)) {
response.getData().push_back(id);
}
return true;
case PacketType::LISTSENTMESSAGES_REQUEST:
response.setType(PacketType::LISTSENTMESSAGES_RESPONSE);
for (string id : db.listSentMessages(uid)) {
response.getData().push_back(id);
}
return true;
default:
return false;
}
}