Skip to content

Commit 8b182b7

Browse files
committed
Added option clearattachments <String> to gam [<UserTypeMessage>] update chatmessage
1 parent e9d911b commit 8b182b7

File tree

3 files changed

+42
-13
lines changed

3 files changed

+42
-13
lines changed

src/GamCommands.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2057,7 +2057,7 @@ gam create chatmessage <ChatSpace>
20572057
[(thread <ChatThread>)|(threadkey <String>) [replyoption fail|fallbacktonew]]
20582058
[returnidonly]
20592059
gam update chatmessage name <ChatMessage>
2060-
<ChatContent>
2060+
[<ChatContent>] [clearattachments <String>]
20612061
gam delete chatmessage name <ChatMessage>
20622062

20632063
<ChatMessageFieldName> ::=
@@ -6586,7 +6586,7 @@ gam <UserTypeEntity> create chatmessage <ChatSpace>
65866586
[replyoption fail|fallback]
65876587
[returnidonly]
65886588
gam <UserTypeEntity> update chatmessage name <ChatMessage>
6589-
<ChatContent>
6589+
[<ChatContent>] [clearattachments <String>]
65906590
gam <UserTypeEntity> delete chatmessage name <ChatMessage>
65916591

65926592
<ChatMessageFieldName> ::=

src/GamUpdate.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
7.27.02
2+
3+
Added option `clearattachments <String>` to `gam [<UserTypeMessage>] update chatmessage`
4+
that clears all attachments from a Chat message. If `<ChatContent>` is not specified,
5+
the current message text is retained and `<String>` is appended; `<String>` must be specified
6+
but can be empty in which case the current message test is preserved as-is.
7+
18
7.27.01
29

310
Fixed bug in `gam <UserTypeEntity> claim ownership <DriveFileEntity> ... onlyUsers|skipusers <UserTypeEntity>`

src/gam/__init__.py

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"""
2626

2727
__author__ = 'GAM Team <[email protected]>'
28-
__version__ = '7.27.01'
28+
__version__ = '7.27.02'
2929
__license__ = 'Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)'
3030

3131
#pylint: disable=wrong-import-position
@@ -9182,7 +9182,7 @@ def _show(objectName, objectValue, subObjectKey, level, subSkipObjects):
91829182
return
91839183
if objectName is not None:
91849184
printJSONKey(objectName)
9185-
subObjectKey = dictObjectsKey.get(objectName)
9185+
subObjectKey = dictObjectsKey.get(objectName)
91869186
if isinstance(objectValue, list):
91879187
if objectName in simpleLists:
91889188
printJSONValue(' '.join(objectValue))
@@ -26506,14 +26506,18 @@ def _cleanChatMessage(message):
2650626506
def _showChatItem(citem, entityType, FJQC, i=0, count=0):
2650726507
if entityType == Ent.CHAT_SPACE:
2650826508
_cleanChatSpace(citem)
26509+
dictObjectsKey = {None: 'displayName'}
2650926510
elif entityType == Ent.CHAT_MESSAGE:
2651026511
_cleanChatMessage(citem)
26512+
dictObjectsKey = {None: 'text'}
26513+
else:
26514+
dictObjectsKey={}
2651126515
if FJQC.formatJSON:
2651226516
printLine(json.dumps(cleanJSON(citem, timeObjects=CHAT_TIME_OBJECTS), ensure_ascii=False, sort_keys=True))
2651326517
return
2651426518
printEntity([entityType, citem['name']], i, count)
2651526519
Ind.Increment()
26516-
showJSON(None, citem, timeObjects=CHAT_TIME_OBJECTS)
26520+
showJSON(None, citem, timeObjects=CHAT_TIME_OBJECTS, dictObjectsKey=dictObjectsKey)
2651726521
Ind.Decrement()
2651826522

2651926523
def _printChatItem(user, citem, parent, entityType, csvPF, FJQC, addCSVData=None):
@@ -27986,10 +27990,11 @@ def _getChatSenderEmail(cd, sender):
2798627990
sender['email'], _ = convertUIDtoEmailAddressWithType(f'uid:{senderUid}', cd, None, emailTypes=['user'])
2798727991

2798827992
def trimChatMessageIfRequired(body):
27989-
msgLen = len(body['text'])
27990-
if msgLen > 4096:
27991-
stderrWarningMsg(Msg.TRIMMED_MESSAGE_FROM_LENGTH_TO_MAXIMUM.format(msgLen, 4096))
27992-
body['text'] = body['text'][:4095]
27993+
if 'text' in body:
27994+
msgLen = len(body['text'])
27995+
if msgLen > 4096:
27996+
stderrWarningMsg(Msg.TRIMMED_MESSAGE_FROM_LENGTH_TO_MAXIMUM.format(msgLen, 4096))
27997+
body['text'] = body['text'][:4095]
2799327998

2799427999
CHAT_MESSAGE_REPLY_OPTION_MAP = {
2799528000
'fail': 'REPLY_MESSAGE_OR_FAIL',
@@ -28066,22 +28071,29 @@ def doCreateChatMessage():
2806628071
createChatMessage([None])
2806728072

2806828073
# gam [<UserTypeMessage>] update chatmessage name <ChatMessage>
28069-
# <ChatContent>
28074+
# [<ChatContent>] [clearattachments <String>]
2807028075
def updateChatMessage(users):
2807128076
name = None
2807228077
body = {}
28078+
updateMask = []
28079+
clearMsg = ''
2807328080
while Cmd.ArgumentsRemaining():
2807428081
myarg = getArgument()
2807528082
if myarg == 'name':
2807628083
name = getString(Cmd.OB_CHAT_MESSAGE)
2807728084
elif myarg in SORF_TEXT_ARGUMENTS:
2807828085
body['text'] = getStringOrFile(myarg, minLen=0, unescapeCRLF=True)[0]
28086+
updateMask.append('text')
28087+
elif myarg == 'clearattachments':
28088+
clearMsg = getString(Cmd.OB_STRING, minLen=0)
28089+
body['attachment'] = []
28090+
updateMask.append('attachment')
2807928091
else:
2808028092
unknownArgumentExit()
2808128093
if not name:
2808228094
missingArgumentExit('name')
28083-
if 'text' not in body:
28084-
missingArgumentExit('text or textfile')
28095+
if not updateMask:
28096+
missingArgumentExit('text|textfile|clearattachments')
2808528097
trimChatMessageIfRequired(body)
2808628098
i, count, users = getEntityArgument(users)
2808728099
for user in users:
@@ -28090,9 +28102,19 @@ def updateChatMessage(users):
2809028102
if not chat:
2809128103
continue
2809228104
try:
28105+
if 'attachment' in updateMask and 'text' not in updateMask:
28106+
resp = callGAPI(chat.spaces().messages(), 'get',
28107+
throwReasons=[GAPI.NOT_FOUND, GAPI.INVALID_ARGUMENT, GAPI.PERMISSION_DENIED, GAPI.FAILED_PRECONDITION],
28108+
name=name, fields='text')
28109+
body['text'] = resp.get('text', '')
28110+
if clearMsg:
28111+
body['text'] += clearMsg
28112+
elif not body['text']:
28113+
body['text'] = 'Attachments cleared'
28114+
updateMask.append('text')
2809328115
resp = callGAPI(chat.spaces().messages(), 'patch',
2809428116
throwReasons=[GAPI.NOT_FOUND, GAPI.INVALID_ARGUMENT, GAPI.PERMISSION_DENIED, GAPI.FAILED_PRECONDITION],
28095-
name=name, updateMask='text', body=body)
28117+
name=name, updateMask=','.join(updateMask), body=body)
2809628118
kvList.extend([Ent.CHAT_THREAD, resp['thread']['name']])
2809728119
entityActionPerformed(kvList, i, count)
2809828120
except (GAPI.notFound, GAPI.invalidArgument, GAPI.permissionDenied) as e:

0 commit comments

Comments
 (0)