diff options
author | Tim Cooper <tim.cooper@layeh.com> | 2015-07-10 15:14:07 +0300 |
---|---|---|
committer | Mikkel Krautz <mikkel@krautz.dk> | 2016-05-08 17:45:52 +0300 |
commit | 7df16ed90aec70ff4008d92499370694c34c514a (patch) | |
tree | c0d5c28c85df5df72329dc63af6f515a069cc7d6 /src/murmur/RPC.cpp | |
parent | cace36d61a78e9e52b6127bc6cf1b7cc1f141e42 (diff) |
grpc: move TextMessageService_Send logic to RPC.cpp
Diffstat (limited to 'src/murmur/RPC.cpp')
-rw-r--r-- | src/murmur/RPC.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/murmur/RPC.cpp b/src/murmur/RPC.cpp index 4b68483c9..bcb7b5191 100644 --- a/src/murmur/RPC.cpp +++ b/src/murmur/RPC.cpp @@ -189,6 +189,67 @@ bool Server::setChannelState(Channel *cChannel, Channel *cParent, const QString return true; } +void Server::sendTextMessage(const ::MumbleProto::TextMessage &tm) { + MumbleProto::TextMessage mptm; + mptm.set_message(tm.message()); + + if (tm.has_actor()) { + mptm.set_actor(tm.actor()); + } + + // Broadcast + if (!tm.session_size() && !tm.channel_id_size() && !tm.tree_id_size()) { + sendAll(mptm); + return; + } + + // Single targets + for (int i = 0; i < tm.session_size(); i++) { + ServerUser *user = qhUsers.value(tm.session(i)); + if (!user) { + continue; + } + mptm.add_session(user->uiSession); + sendMessage(user, mptm); + mptm.clear_session(); + } + + // Channel targets + QSet<Channel *> chans; + + for (int i = 0; i < tm.channel_id_size(); i++) { + Channel *channel = qhChannels.value(tm.channel_id(i)); + if (!channel) { + continue; + } + chans.insert(channel); + mptm.add_channel_id(channel->iId); + } + + QQueue<Channel *> chansQ; + for (int i = 0; i < tm.tree_id_size(); i++) { + Channel *channel = qhChannels.value(tm.tree_id(i)); + if (!channel) { + continue; + } + chansQ.enqueue(channel); + mptm.add_tree_id(channel->iId); + } + while (!chansQ.isEmpty()) { + Channel *c = chansQ.dequeue(); + chans.insert(c); + foreach(c, c->qlChannels) { + chansQ.enqueue(c); + } + } + + foreach(Channel *c, chans) { + foreach(::User *p, c->qlUsers) { + sendMessage(static_cast<::ServerUser *>(p), mptm); + } + } +} + void Server::sendTextMessage(Channel *cChannel, ServerUser *pUser, bool tree, const QString &text) { MumbleProto::TextMessage mptm; mptm.set_message(u8(text)); |