3
* Copyright 2011, Google Inc.
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions are met:
8
* 1. Redistributions of source code must retain the above copyright notice,
9
* this list of conditions and the following disclaimer.
10
* 2. Redistributions in binary form must reproduce the above copyright notice,
11
* this list of conditions and the following disclaimer in the documentation
12
* and/or other materials provided with the distribution.
13
* 3. The name of the author may not be used to endorse or promote products
14
* derived from this software without specific prior written permission.
16
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
#include "talk/xmpp/mucroomhistorytask.h"
29
#include "talk/xmpp/constants.h"
33
// TODO: Move these to xmpp/constants.cc once it's publicly
35
const char NS_GOOGLE_SETTING[] = "google:setting";
36
const StaticQName QN_MEETING_HISTORY = { NS_GOOGLE_SETTING, "meetinghistory" };
37
const StaticQName QN_MEETING_ITEM = { NS_GOOGLE_SETTING, "item" };
39
MucRoomHistoryGetTask::MucRoomHistoryGetTask(XmppTaskParentInterface* parent,
40
const buzz::Jid& user_jid)
41
: IqTask(parent, STR_GET, user_jid, MakeRequest()) {
44
// <iq type='get' id='user-setting-1'>
45
// <meetinghistory xmlns='google:setting' />
47
XmlElement* MucRoomHistoryGetTask::MakeRequest() {
48
XmlElement* history = new XmlElement(QN_MEETING_HISTORY, true);
53
// to='romeo@gmail.com/orchard'
54
// id='user-setting-1'>
55
// <meetinghistory xmlns='google:setting'>
56
// <item jid=’private-muc-abc-...@groupchat.google.com’ name=’Hangout'
57
// time=’2011-01-31T13:20:00Z’ />
58
// <item jid=’private-muc-abc-...@groupchat.google.com’ name=’Planning’
59
// time=’2011-02-11T 14:20:00Z />
60
// <item jid=’private-muc-abc-...@groupchat.google.com’ name=’TGIF’
61
// time=’2011-03-21T15:20:00Z’ />
64
void MucRoomHistoryGetTask::HandleResult(const XmlElement* stanza) {
65
std::vector<MucRoomHistoryInfo> meeting_rooms;
67
const XmlElement* history = stanza->FirstNamed(QN_MEETING_HISTORY);
68
if (history == NULL) {
69
SignalResult(meeting_rooms);
73
const XmlElement* history_item = history->FirstNamed(QN_MEETING_ITEM);
74
while (history_item != NULL) {
75
MucRoomHistoryInfo room;
76
room.room_name = history_item->Attr(QN_NAME);
77
room.last_enter_time = history_item->Attr(QN_TIME);
78
meeting_rooms.push_back(room);
80
history_item = history_item->NextNamed(QN_MEETING_ITEM);
83
SignalResult(meeting_rooms);
86
MucRoomHistorySetTask::MucRoomHistorySetTask(XmppTaskParentInterface* parent,
87
MucRoomHistoryTaskCommand command,
88
const buzz::Jid& user_jid,
89
const std::string& room_name)
90
: IqTask(parent, STR_SET, user_jid, MakeRequest(command, room_name)) {
95
// to='romeo@gmail.com'
96
// id='user-setting-3'>
97
// <meetinghistory xmlns='google:setting'>
98
// <item jid=’private-muc-abc@groupchat.google.com’
99
// name=’Hangout' action=’add’ />
105
// to='romeo@gmail.com'
106
// id='user-setting-3'>
107
// <meetinghistory xmlns='google:setting'>
108
// <item jid=’private-muc-abc@groupchat.google.com’
109
// name=’Hangout' action=’remove’ />
115
// from='romeo@gmail.com/orchard'
116
// to='romeo@gmail.com'
117
// id='user-setting-3'>
118
// <meetinghistory xmlns='google:setting' />
120
XmlElement* MucRoomHistorySetTask::MakeRequest(
121
MucRoomHistoryTaskCommand command, const std::string& room_name) {
122
XmlElement* history = new XmlElement(QN_MEETING_HISTORY, true);
123
if (command != HT_CLEAR_ALL) {
124
XmlElement* item = new XmlElement(QN_MEETING_ITEM, false);
125
// TODO - remove QN_JID attribute when 21446107 is submitted &
126
// deployed. no harm to leave in after the change is made.
127
item->AddAttr(QN_JID, room_name);
128
item->AddAttr(QN_NAME, room_name);
129
item->AddAttr(QN_ACTION, command == HT_ADD ? "add" : "remove");
131
history->AddElement(item);
139
// to='romeo@gmail.com/orchard'
140
// from='romeo@gmail.com'
141
// id='user-setting-3' />
142
void MucRoomHistorySetTask::HandleResult(const XmlElement* stanza) {